Issues (3)

Security Analysis    no request data  

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.

src/FileService.php (1 issue)

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
 * Created by PhpStorm.
4
 * User: onysko
5
 * Date: 19.11.2014
6
 * Time: 19:04
7
 */
8
namespace samsonphp\fs;
9
10
use samson\core\CompressableService;
11
use samsonframework\core\ConfigurableInterface;
12
use samsonphp\event\Event;
13
14
/**
15
 * File system module controller
16
 * @package samsonphp\fs
17
 */
18
class FileService extends CompressableService implements IFileSystem, ConfigurableInterface
19
{
20
    /** @var string Module identifier */
21
    protected $id = 'fs';
22
23
    /** @var string Configurable file service class name */
24
    public $fileServiceClassName = 'samsonphp\fs\LocalFileService';
25
26
    /** @var array Collection of configuration parameters */
27
    public $configuration = array();
28
29
    /** @var \samsonphp\fs\AbstractFileService Pointer to file system adapter */
30
    protected $fileService;
31
32
    /**
33
     * Initialize module
34
     * @param array $params Collection of module parameters
35
     * @return bool True if module successfully initialized
36
     */
37
    public function init(array $params = array())
38
    {
39
        if (!$this->loadExternalService($this->fileServiceClassName)) {
0 ignored issues
show
Blank line found at start of control structure
Loading history...
40
41
            // Signal error
42
            Event::fire(
43
                'error',
44
                array(
45
                    $this,
46
                    'Cannot initialize file system adapter[' . $this->fileServiceClassName . ']'
47
                )
48
            );
49
        }
50
51
        // Call parent initialization
52
        return parent::init($params);
53
    }
54
55
    /**
56
     * Load external file service instance
57
     * @param string $serviceClassName File service class name for loading
58
     * @return bool True if external service instance has been created
59
     */
60
    public function loadExternalService($serviceClassName)
61
    {
62
        // If defined file service is supported
63
        if (class_exists($serviceClassName)) {
64
            /** @var \samsonphp\fs\AbstractFileService Create file service instance */
65
            $this->fileService = new $serviceClassName();
66
67
            // Set nested file service instance parameters
68
            foreach ($this->configuration as $key => $value) {
69
                $this->fileService->$key = $value;
70
            }
71
72
            // Initialize file service
73
            $this->fileService->initialize();
74
75
            return true;
76
        }
77
78
        return false;
79
    }
80
81
    /**
82
     * @param mixed $entityConfiguration current instance for configuration
83
     * @return boolean False if something went wrong otherwise true
84
     */
85
    public function configure($entityConfiguration)
86
    {
87
        // Convert object to array
88
        $this->configuration = (array)$entityConfiguration;
89
        // Set fileServiceClassName parameter from config
90
        if (!empty($this->configuration['fileServiceClassName']{0})) {
91
	        $this->fileServiceClassName = $this->configuration['fileServiceClassName'];
92
        }
93
    }
94
95
    /**
96
     * Write data to a specific relative location
97
     *
98
     * @param mixed $data Data to be written
99
     * @param string $filename File name
100
     * @param string $uploadDir Relative file path
101
     * @return string|boolean Relative path to created file, false if there were errors
102
     */
103
    public function write($data, $filename = '', $uploadDir = '')
104
    {
105
        return $this->fileService->write($data, $filename, $uploadDir);
106
    }
107
108
    /**
109
     * Check existing current file in current file system
110
     * @param $filename string Filename
111
     * @return boolean File exists or not
112
     */
113
    public function exists($filename)
114
    {
115
        return $this->fileService->exists($filename);
116
    }
117
118
    /**
119
     * Read the file from current file system
120
     * @param $filePath string Full path to file
121
     * @param $filename string File name
122
     * @return string File data
123
     */
124
    public function read($filePath, $filename = null)
125
    {
126
        return $this->fileService->read($filePath, $filename);
127
    }
128
129
    /**
130
     * Delete file from current file system
131
     * @param $filename string File for deleting
132
     * @return mixed
133
     */
134
    public function delete($filename)
135
    {
136
        return $this->fileService->delete($filename);
137
    }
138
139
    /**
140
     * Get file extension in current file system
141
     * @param $filePath string Path
142
     * @return string|bool false if extension not found, otherwise file extension
143
     */
144
    public function extension($filePath)
145
    {
146
        return $this->fileService->extension($filePath);
147
    }
148
149
    /**
150
     * Define if $filePath is directory
151
     * @param string $filePath Path
152
     * @return boolean Is $path a directory or not
153
     */
154
    public function isDir($filePath)
155
    {
156
        return $this->fileService->isDir($filePath);
157
    }
158
159
    /**
160
     * Get recursive $path listing collection
161
     * @param string $path Path for listing contents
162
     * @param array $restrict Collection of restricted paths
163
     * @param array $result   Collection of restricted paths
164
     * @return array $path recursive directory listing
165
     */
166
    public function dir($path, $restrict = array(), & $result = array())
167
    {
168
        return $this->fileService->dir($path, $restrict, $result);
169
    }
170
171
    /**
172
     * Get file mime type in current file system
173
     * @param $filePath string Path to file
174
     * @return false|integer|string false if mime not found, otherwise file mime type
175
     */
176
    public function mime($filePath)
177
    {
178
        return $this->fileService->mime($filePath);
179
    }
180
181
    /**
182
     * Get relative path from $path
183
     * @param string $fullPath Full file path
184
     * @param string $fileName File name
185
     * @param string $basePath Base path, must end WITHOUT '/', if not passed
186
     *                          $fullPath one level top directory is used.
187
     * @return string Relative path to file
188
     */
189
    public function relativePath($fullPath, $fileName, $basePath = null)
190
    {
191
        return $this->fileService->relativePath($fullPath, $fileName, $basePath);
192
    }
193
194
    /**
195
     * Copy file/folder to selected location.
196
     * Copy can be performed from file($filePath) to file($newPath),
197
     * also copy can be performed from folder($filePath) to folder($newPath),
198
     * currently copying from file($filePath) to folder($newPath) is not supported.
199
     *
200
     * @param string $filePath      Source path or file path
201
     * @param string $newPath       New path or file path
202
     * @return boolean False if failed otherwise true if file/folder has been copied
203
     */
204
    public function copyPath($filePath, $newPath)
205
    {
206
        return $this->fileService->copyPath($filePath, $newPath);
207
    }
208
209
    /**
210
     * Create catalog in selected location
211
     * @param string    $path   Path for new catalog
212
     * @return boolean  Result of catalog creating
213
     */
214
    public function mkDir($path)
215
    {
216
        return $this->fileService->mkDir($path);
217
    }
218
219
    /** Обработчик сериализации объекта */
220
    public function __sleep()
221
    {
222
        // Remove all unnecessary fields from serialization
223
        return array_diff(array_keys(get_object_vars($this)), array('fileService'));
224
    }
225
}
226