Issues (108)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

lib/helper.php (6 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * ownCloud - Documents App
5
 *
6
 * @author Victor Dubiniuk
7
 * @copyright 2013 Victor Dubiniuk [email protected]
8
 *
9
 * This file is licensed under the Affero General Public License version 3 or
10
 * later.
11
 */
12
13
namespace OCA\Documents;
14
15
class Helper {
16
17
	const APP_ID = 'documents';
18
19 1
	public static function getNewFileName($view, $path, $prepend = ' '){
20 1
		$fileNum = 1;
21
22 1
		while ($view->file_exists($path)){
23
			$fileNum += 1;
24
			$path = preg_replace('/(\.odt|' . $prepend . '\(\d+\)\.odt)$/', $prepend . '(' . $fileNum . ').odt', $path);
25
		};
26
27 1
		return $path;
28
	}
29
	
30
	public static function getArrayValueByKey($array, $key, $default=''){
31
		if (array_key_exists($key, $array)){
32
			return $array[$key];
33
		}
34
		return $default;
35
	}
36
37
	public static function isVersionsEnabled(){
38
		return \OCP\App::isEnabled('files_versions');
39
	}
40
41
	public static function getRandomColor(){
42
		$str = dechex(floor(rand(0, 16777215)));
43
		return '#' . str_pad($str, 6, "0", STR_PAD_LEFT);
44
	}
45
46
	/**
47
	 * @param string $name
48
	 * @return string
49
	 */
50
	public static function getMemberColor($name){
51
		$hash = md5($name);
52
		$maxRange = hexdec('ffffffffffffffffffffffffffffffff');
53
		$hue = hexdec($hash) / $maxRange * 256;
54
		return '#' . self::convertHSLToRGB($hue, 90, 60);
55
	}
56
57
	/**
58
	 * @param integer $iH
59
	 * @param integer $iS
60
	 * @param integer $iV
61
	 * @return string
62
	 */
63
	protected static function convertHSLToRGB($iH, $iS, $iV){
64
		if ($iH < 0){
65
			$iH = 0;   // Hue:
66
		}
67
		if ($iH > 360){
68
			$iH = 360; //   0-360
69
		}
70
		if ($iS < 0){
71
			$iS = 0;   // Saturation:
72
		}
73
		if ($iS > 100){
74
			$iS = 100; //   0-100
75
		}
76
		if ($iV < 0){
77
			$iV = 0;   // Lightness:
78
		}
79
		if ($iV > 100){
80
			$iV = 100; //   0-100
81
		}
82
83
		$dS = $iS / 100.0; // Saturation: 0.0-1.0
84
		$dV = $iV / 100.0; // Lightness:  0.0-1.0
85
		$dC = $dV * $dS;   // Chroma:     0.0-1.0
86
		$dH = $iH / 60.0;  // H-Prime:    0.0-6.0
87
		$dT = $dH;	   // Temp variable
88
89
		while ($dT >= 2.0)
90
			$dT -= 2.0; // php modulus does not work with float
91
		$dX = $dC * (1 - abs($dT - 1));	 // as used in the Wikipedia link
92
93
		switch ($dH){
94 View Code Duplication
			case($dH >= 0.0 && $dH < 1.0):
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
				$dR = $dC;
96
				$dG = $dX;
97
				$dB = 0.0;
98
				break;
99 View Code Duplication
			case($dH >= 1.0 && $dH < 2.0):
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
				$dR = $dX;
101
				$dG = $dC;
102
				$dB = 0.0;
103
				break;
104 View Code Duplication
			case($dH >= 2.0 && $dH < 3.0):
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105
				$dR = 0.0;
106
				$dG = $dC;
107
				$dB = $dX;
108
				break;
109 View Code Duplication
			case($dH >= 3.0 && $dH < 4.0):
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
				$dR = 0.0;
111
				$dG = $dX;
112
				$dB = $dC;
113
				break;
114 View Code Duplication
			case($dH >= 4.0 && $dH < 5.0):
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
				$dR = $dX;
116
				$dG = 0.0;
117
				$dB = $dC;
118
				break;
119 View Code Duplication
			case($dH >= 5.0 && $dH < 6.0):
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
120
				$dR = $dC;
121
				$dG = 0.0;
122
				$dB = $dX;
123
				break;
124
			default:
125
				$dR = 0.0;
126
				$dG = 0.0;
127
				$dB = 0.0;
128
				break;
129
		}
130
131
		$dM = $dV - $dC;
132
		$dR += $dM;
133
		$dG += $dM;
134
		$dB += $dM;
135
		$dR *= 255;
136
		$dG *= 255;
137
		$dB *= 255;
138
139
		$dR = str_pad(dechex(round($dR)), 2, "0", STR_PAD_LEFT);
140
		$dG = str_pad(dechex(round($dG)), 2, "0", STR_PAD_LEFT);
141
		$dB = str_pad(dechex(round($dB)), 2, "0", STR_PAD_LEFT);
142
		return $dR.$dG.$dB;
143
	}
144
	
145
	public static function findOpenOffice(){
146
		$config = \OC::$server->getConfig();
147
		$cmd = '';
148
		if (is_string($config->getSystemValue('preview_libreoffice_path', null))){
149
			$cmd = $config->getSystemValue('preview_libreoffice_path', null);
150
		}
151
152
		$whichLibreOffice = shell_exec('which libreoffice');
153
		if ($cmd === '' && !empty($whichLibreOffice)){
154
			$cmd = 'libreoffice';
155
		}
156
157
		$whichOpenOffice = shell_exec('which openoffice');
158
		if ($cmd === '' && !empty($whichOpenOffice)){
159
			$cmd = 'openoffice';
160
		}
161
		
162
		if (empty($cmd)){
163
			\OC::$server->getLogger()->warning(
164
				'Pure configuration issue. Missing open office binary that is mandatory for conversion.',
165
				['app' => 'documents']
166
				
167
			);
168
			\OC::$server->getLogger()->debug(
169
				'If openoffice or libreoffice is already installed please specify the path to it using preview_libreoffice_path config. Refer to admin manual for details.',
170
				['app' => 'documents']
171
				
172
			);
173
			throw new \RuntimeException('Missing open office binary that is mandatory for conversion.');
174
		}
175
		
176
		return $cmd;
177
	}
178
179
}
180