author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Filesystem Class for implementing SSH2 |
|
4 |
* |
|
5 |
* To use this class you must follow these steps for PHP 5.2.6+ |
|
6 |
* |
|
7 |
* @contrib http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/ - Installation Notes |
|
8 |
* |
|
16 | 9 |
* Compile libssh2 (Note: Only 0.14 is officaly working with PHP 5.2.6+ right now, But many users have found the latest versions work) |
0 | 10 |
* |
11 |
* cd /usr/src |
|
16 | 12 |
* wget https://www.libssh2.org/download/libssh2-0.14.tar.gz |
0 | 13 |
* tar -zxvf libssh2-0.14.tar.gz |
14 |
* cd libssh2-0.14/ |
|
15 |
* ./configure |
|
16 |
* make all install |
|
17 |
* |
|
18 |
* Note: Do not leave the directory yet! |
|
19 |
* |
|
20 |
* Enter: pecl install -f ssh2 |
|
21 |
* |
|
22 |
* Copy the ssh.so file it creates to your PHP Module Directory. |
|
23 |
* Open up your PHP.INI file and look for where extensions are placed. |
|
24 |
* Add in your PHP.ini file: extension=ssh2.so |
|
25 |
* |
|
26 |
* Restart Apache! |
|
27 |
* Check phpinfo() streams to confirm that: ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp exist. |
|
28 |
* |
|
19 | 29 |
* Note: As of WordPress 2.8, this utilizes the PHP5+ function `stream_get_contents()`. |
0 | 30 |
* |
31 |
* @since 2.7.0 |
|
32 |
* |
|
33 |
* @package WordPress |
|
34 |
* @subpackage Filesystem |
|
35 |
*/ |
|
36 |
class WP_Filesystem_SSH2 extends WP_Filesystem_Base { |
|
37 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
/** |
9 | 39 |
* @since 2.7.0 |
40 |
* @var resource |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
*/ |
5 | 42 |
public $link = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
|
5 | 44 |
/** |
9 | 45 |
* @since 2.7.0 |
5 | 46 |
* @var resource |
47 |
*/ |
|
48 |
public $sftp_link; |
|
9 | 49 |
|
50 |
/** |
|
51 |
* @since 2.7.0 |
|
52 |
* @var bool |
|
53 |
*/ |
|
5 | 54 |
public $keys = false; |
0 | 55 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
/** |
9 | 57 |
* Constructor. |
58 |
* |
|
59 |
* @since 2.7.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
* @param array $opt |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
public function __construct( $opt = '' ) { |
0 | 64 |
$this->method = 'ssh2'; |
65 |
$this->errors = new WP_Error(); |
|
66 |
||
16 | 67 |
// Check if possible to use ssh2 functions. |
9 | 68 |
if ( ! extension_loaded( 'ssh2' ) ) { |
69 |
$this->errors->add( 'no_ssh2_ext', __( 'The ssh2 PHP extension is not available' ) ); |
|
5 | 70 |
return; |
0 | 71 |
} |
72 |
||
73 |
// Set defaults: |
|
9 | 74 |
if ( empty( $opt['port'] ) ) { |
0 | 75 |
$this->options['port'] = 22; |
9 | 76 |
} else { |
0 | 77 |
$this->options['port'] = $opt['port']; |
9 | 78 |
} |
0 | 79 |
|
9 | 80 |
if ( empty( $opt['hostname'] ) ) { |
81 |
$this->errors->add( 'empty_hostname', __( 'SSH2 hostname is required' ) ); |
|
82 |
} else { |
|
0 | 83 |
$this->options['hostname'] = $opt['hostname']; |
9 | 84 |
} |
0 | 85 |
|
86 |
// Check if the options provided are OK. |
|
9 | 87 |
if ( ! empty( $opt['public_key'] ) && ! empty( $opt['private_key'] ) ) { |
88 |
$this->options['public_key'] = $opt['public_key']; |
|
0 | 89 |
$this->options['private_key'] = $opt['private_key']; |
90 |
||
19 | 91 |
$this->options['hostkey'] = array( 'hostkey' => 'ssh-rsa,ssh-ed25519' ); |
0 | 92 |
|
93 |
$this->keys = true; |
|
9 | 94 |
} elseif ( empty( $opt['username'] ) ) { |
95 |
$this->errors->add( 'empty_username', __( 'SSH2 username is required' ) ); |
|
0 | 96 |
} |
97 |
||
9 | 98 |
if ( ! empty( $opt['username'] ) ) { |
0 | 99 |
$this->options['username'] = $opt['username']; |
9 | 100 |
} |
0 | 101 |
|
9 | 102 |
if ( empty( $opt['password'] ) ) { |
5 | 103 |
// Password can be blank if we are using keys. |
9 | 104 |
if ( ! $this->keys ) { |
105 |
$this->errors->add( 'empty_password', __( 'SSH2 password is required' ) ); |
|
106 |
} |
|
0 | 107 |
} else { |
108 |
$this->options['password'] = $opt['password']; |
|
109 |
} |
|
110 |
} |
|
111 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
/** |
9 | 113 |
* Connects filesystem. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
* |
9 | 115 |
* @since 2.7.0 |
116 |
* |
|
117 |
* @return bool True on success, false on failure. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
*/ |
5 | 119 |
public function connect() { |
0 | 120 |
if ( ! $this->keys ) { |
9 | 121 |
$this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'] ); |
0 | 122 |
} else { |
9 | 123 |
$this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'], $this->options['hostkey'] ); |
0 | 124 |
} |
125 |
||
126 |
if ( ! $this->link ) { |
|
9 | 127 |
$this->errors->add( |
128 |
'connect', |
|
129 |
sprintf( |
|
16 | 130 |
/* translators: %s: hostname:port */ |
9 | 131 |
__( 'Failed to connect to SSH2 Server %s' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
$this->options['hostname'] . ':' . $this->options['port'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
); |
16 | 135 |
|
0 | 136 |
return false; |
137 |
} |
|
138 |
||
9 | 139 |
if ( ! $this->keys ) { |
140 |
if ( ! @ssh2_auth_password( $this->link, $this->options['username'], $this->options['password'] ) ) { |
|
141 |
$this->errors->add( |
|
142 |
'auth', |
|
143 |
sprintf( |
|
16 | 144 |
/* translators: %s: Username. */ |
9 | 145 |
__( 'Username/Password incorrect for %s' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
$this->options['username'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
); |
16 | 149 |
|
0 | 150 |
return false; |
151 |
} |
|
152 |
} else { |
|
9 | 153 |
if ( ! @ssh2_auth_pubkey_file( $this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] ) ) { |
154 |
$this->errors->add( |
|
155 |
'auth', |
|
156 |
sprintf( |
|
16 | 157 |
/* translators: %s: Username. */ |
9 | 158 |
__( 'Public and Private keys incorrect for %s' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
$this->options['username'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
); |
16 | 162 |
|
0 | 163 |
return false; |
164 |
} |
|
165 |
} |
|
166 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
$this->sftp_link = ssh2_sftp( $this->link ); |
16 | 168 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
if ( ! $this->sftp_link ) { |
9 | 170 |
$this->errors->add( |
171 |
'connect', |
|
172 |
sprintf( |
|
16 | 173 |
/* translators: %s: hostname:port */ |
9 | 174 |
__( 'Failed to initialize a SFTP subsystem session with the SSH2 Server %s' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
$this->options['hostname'] . ':' . $this->options['port'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
); |
16 | 178 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
} |
0 | 181 |
|
182 |
return true; |
|
183 |
} |
|
184 |
||
5 | 185 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
* Gets the ssh2.sftp PHP stream wrapper path to open for the given file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
* This method also works around a PHP bug where the root directory (/) cannot |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
* be opened by PHP functions, causing a false failure. In order to work around |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
* this, the path is converted to /./ which is semantically the same as / |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
* See https://bugs.php.net/bug.php?id=64169 for more details. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
* @param string $path The File/Directory path on the remote server to return |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
196 |
* @return string The ssh2.sftp:// wrapped path to use. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
public function sftp_path( $path ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
if ( '/' === $path ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
$path = '/./'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
} |
16 | 202 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
/** |
9 | 207 |
* @since 2.7.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
* |
5 | 209 |
* @param string $command |
16 | 210 |
* @param bool $returnbool |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
* @return bool|string True on success, false on failure. String if the command was executed, `$returnbool` |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
* is false (default), and data from the resulting stream was retrieved. |
5 | 213 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
public function run_command( $command, $returnbool = false ) { |
9 | 215 |
if ( ! $this->link ) { |
0 | 216 |
return false; |
9 | 217 |
} |
0 | 218 |
|
16 | 219 |
$stream = ssh2_exec( $this->link, $command ); |
220 |
||
221 |
if ( ! $stream ) { |
|
9 | 222 |
$this->errors->add( |
223 |
'command', |
|
224 |
sprintf( |
|
16 | 225 |
/* translators: %s: Command. */ |
9 | 226 |
__( 'Unable to perform command: %s' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
$command |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
); |
0 | 230 |
} else { |
231 |
stream_set_blocking( $stream, true ); |
|
232 |
stream_set_timeout( $stream, FS_TIMEOUT ); |
|
233 |
$data = stream_get_contents( $stream ); |
|
234 |
fclose( $stream ); |
|
235 |
||
9 | 236 |
if ( $returnbool ) { |
16 | 237 |
return ( false === $data ) ? false : '' !== trim( $data ); |
9 | 238 |
} else { |
0 | 239 |
return $data; |
9 | 240 |
} |
0 | 241 |
} |
16 | 242 |
|
0 | 243 |
return false; |
244 |
} |
|
245 |
||
5 | 246 |
/** |
9 | 247 |
* Reads entire file into a string. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
* |
9 | 249 |
* @since 2.7.0 |
250 |
* |
|
251 |
* @param string $file Name of the file to read. |
|
252 |
* @return string|false Read data on success, false if no temporary file could be opened, |
|
253 |
* or if the file couldn't be retrieved. |
|
5 | 254 |
*/ |
255 |
public function get_contents( $file ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
return file_get_contents( $this->sftp_path( $file ) ); |
0 | 257 |
} |
258 |
||
5 | 259 |
/** |
9 | 260 |
* Reads entire file into an array. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
* |
9 | 262 |
* @since 2.7.0 |
263 |
* |
|
264 |
* @param string $file Path to the file. |
|
265 |
* @return array|false File contents in an array on success, false on failure. |
|
5 | 266 |
*/ |
9 | 267 |
public function get_contents_array( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
return file( $this->sftp_path( $file ) ); |
0 | 269 |
} |
270 |
||
5 | 271 |
/** |
9 | 272 |
* Writes a string to a file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
* |
9 | 274 |
* @since 2.7.0 |
275 |
* |
|
276 |
* @param string $file Remote path to the file where to write the data. |
|
277 |
* @param string $contents The data to write. |
|
278 |
* @param int|false $mode Optional. The file permissions as octal number, usually 0644. |
|
279 |
* Default false. |
|
280 |
* @return bool True on success, false on failure. |
|
5 | 281 |
*/ |
9 | 282 |
public function put_contents( $file, $contents, $mode = false ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
$ret = file_put_contents( $this->sftp_path( $file ), $contents ); |
0 | 284 |
|
16 | 285 |
if ( strlen( $contents ) !== $ret ) { |
0 | 286 |
return false; |
9 | 287 |
} |
0 | 288 |
|
9 | 289 |
$this->chmod( $file, $mode ); |
0 | 290 |
|
291 |
return true; |
|
292 |
} |
|
293 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
/** |
9 | 295 |
* Gets the current working directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
* |
9 | 297 |
* @since 2.7.0 |
298 |
* |
|
299 |
* @return string|false The current working directory on success, false on failure. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
*/ |
5 | 301 |
public function cwd() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
$cwd = ssh2_sftp_realpath( $this->sftp_link, '.' ); |
16 | 303 |
|
5 | 304 |
if ( $cwd ) { |
305 |
$cwd = trailingslashit( trim( $cwd ) ); |
|
306 |
} |
|
16 | 307 |
|
0 | 308 |
return $cwd; |
309 |
} |
|
310 |
||
5 | 311 |
/** |
9 | 312 |
* Changes current directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
* |
9 | 314 |
* @since 2.7.0 |
315 |
* |
|
316 |
* @param string $dir The new current directory. |
|
317 |
* @return bool True on success, false on failure. |
|
5 | 318 |
*/ |
9 | 319 |
public function chdir( $dir ) { |
320 |
return $this->run_command( 'cd ' . $dir, true ); |
|
0 | 321 |
} |
322 |
||
5 | 323 |
/** |
9 | 324 |
* Changes the file group. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
* |
9 | 326 |
* @since 2.7.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
327 |
* |
9 | 328 |
* @param string $file Path to the file. |
329 |
* @param string|int $group A group name or number. |
|
330 |
* @param bool $recursive Optional. If set to true, changes file group recursively. |
|
331 |
* Default false. |
|
332 |
* @return bool True on success, false on failure. |
|
5 | 333 |
*/ |
9 | 334 |
public function chgrp( $file, $group, $recursive = false ) { |
335 |
if ( ! $this->exists( $file ) ) { |
|
0 | 336 |
return false; |
9 | 337 |
} |
16 | 338 |
|
9 | 339 |
if ( ! $recursive || ! $this->is_dir( $file ) ) { |
340 |
return $this->run_command( sprintf( 'chgrp %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true ); |
|
341 |
} |
|
16 | 342 |
|
9 | 343 |
return $this->run_command( sprintf( 'chgrp -R %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true ); |
0 | 344 |
} |
345 |
||
5 | 346 |
/** |
9 | 347 |
* Changes filesystem permissions. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
* |
9 | 349 |
* @since 2.7.0 |
350 |
* |
|
351 |
* @param string $file Path to the file. |
|
352 |
* @param int|false $mode Optional. The permissions as octal number, usually 0644 for files, |
|
353 |
* 0755 for directories. Default false. |
|
16 | 354 |
* @param bool $recursive Optional. If set to true, changes file permissions recursively. |
9 | 355 |
* Default false. |
356 |
* @return bool True on success, false on failure. |
|
5 | 357 |
*/ |
9 | 358 |
public function chmod( $file, $mode = false, $recursive = false ) { |
359 |
if ( ! $this->exists( $file ) ) { |
|
0 | 360 |
return false; |
9 | 361 |
} |
0 | 362 |
|
363 |
if ( ! $mode ) { |
|
9 | 364 |
if ( $this->is_file( $file ) ) { |
0 | 365 |
$mode = FS_CHMOD_FILE; |
9 | 366 |
} elseif ( $this->is_dir( $file ) ) { |
0 | 367 |
$mode = FS_CHMOD_DIR; |
9 | 368 |
} else { |
0 | 369 |
return false; |
9 | 370 |
} |
0 | 371 |
} |
372 |
||
9 | 373 |
if ( ! $recursive || ! $this->is_dir( $file ) ) { |
374 |
return $this->run_command( sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ), true ); |
|
375 |
} |
|
16 | 376 |
|
9 | 377 |
return $this->run_command( sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ), true ); |
0 | 378 |
} |
379 |
||
380 |
/** |
|
9 | 381 |
* Changes the owner of a file or directory. |
0 | 382 |
* |
9 | 383 |
* @since 2.7.0 |
0 | 384 |
* |
9 | 385 |
* @param string $file Path to the file or directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* @param string|int $owner A user name or number. |
9 | 387 |
* @param bool $recursive Optional. If set to true, changes file owner recursively. |
388 |
* Default false. |
|
389 |
* @return bool True on success, false on failure. |
|
0 | 390 |
*/ |
5 | 391 |
public function chown( $file, $owner, $recursive = false ) { |
9 | 392 |
if ( ! $this->exists( $file ) ) { |
0 | 393 |
return false; |
9 | 394 |
} |
16 | 395 |
|
9 | 396 |
if ( ! $recursive || ! $this->is_dir( $file ) ) { |
397 |
return $this->run_command( sprintf( 'chown %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true ); |
|
398 |
} |
|
16 | 399 |
|
9 | 400 |
return $this->run_command( sprintf( 'chown -R %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true ); |
0 | 401 |
} |
402 |
||
5 | 403 |
/** |
9 | 404 |
* Gets the file owner. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
* |
9 | 406 |
* @since 2.7.0 |
407 |
* |
|
408 |
* @param string $file Path to the file. |
|
409 |
* @return string|false Username of the owner on success, false on failure. |
|
5 | 410 |
*/ |
9 | 411 |
public function owner( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
$owneruid = @fileowner( $this->sftp_path( $file ) ); |
16 | 413 |
|
9 | 414 |
if ( ! $owneruid ) { |
0 | 415 |
return false; |
9 | 416 |
} |
16 | 417 |
|
9 | 418 |
if ( ! function_exists( 'posix_getpwuid' ) ) { |
0 | 419 |
return $owneruid; |
9 | 420 |
} |
16 | 421 |
|
9 | 422 |
$ownerarray = posix_getpwuid( $owneruid ); |
16 | 423 |
|
424 |
if ( ! $ownerarray ) { |
|
425 |
return false; |
|
426 |
} |
|
427 |
||
0 | 428 |
return $ownerarray['name']; |
429 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
|
5 | 431 |
/** |
9 | 432 |
* Gets the permissions of the specified file or filepath in their octal format. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
* |
9 | 434 |
* @since 2.7.0 |
435 |
* |
|
436 |
* @param string $file Path to the file. |
|
437 |
* @return string Mode of the file (the last 3 digits). |
|
5 | 438 |
*/ |
9 | 439 |
public function getchmod( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
return substr( decoct( @fileperms( $this->sftp_path( $file ) ) ), -3 ); |
0 | 441 |
} |
442 |
||
5 | 443 |
/** |
9 | 444 |
* Gets the file's group. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
* |
9 | 446 |
* @since 2.7.0 |
447 |
* |
|
448 |
* @param string $file Path to the file. |
|
449 |
* @return string|false The group on success, false on failure. |
|
5 | 450 |
*/ |
9 | 451 |
public function group( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
$gid = @filegroup( $this->sftp_path( $file ) ); |
16 | 453 |
|
9 | 454 |
if ( ! $gid ) { |
0 | 455 |
return false; |
9 | 456 |
} |
16 | 457 |
|
9 | 458 |
if ( ! function_exists( 'posix_getgrgid' ) ) { |
0 | 459 |
return $gid; |
9 | 460 |
} |
16 | 461 |
|
9 | 462 |
$grouparray = posix_getgrgid( $gid ); |
16 | 463 |
|
464 |
if ( ! $grouparray ) { |
|
465 |
return false; |
|
466 |
} |
|
467 |
||
0 | 468 |
return $grouparray['name']; |
469 |
} |
|
470 |
||
5 | 471 |
/** |
9 | 472 |
* Copies a file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
* |
9 | 474 |
* @since 2.7.0 |
475 |
* |
|
476 |
* @param string $source Path to the source file. |
|
477 |
* @param string $destination Path to the destination file. |
|
478 |
* @param bool $overwrite Optional. Whether to overwrite the destination file if it exists. |
|
479 |
* Default false. |
|
480 |
* @param int|false $mode Optional. The permissions as octal number, usually 0644 for files, |
|
481 |
* 0755 for dirs. Default false. |
|
482 |
* @return bool True on success, false on failure. |
|
5 | 483 |
*/ |
9 | 484 |
public function copy( $source, $destination, $overwrite = false, $mode = false ) { |
485 |
if ( ! $overwrite && $this->exists( $destination ) ) { |
|
0 | 486 |
return false; |
9 | 487 |
} |
16 | 488 |
|
9 | 489 |
$content = $this->get_contents( $source ); |
16 | 490 |
|
9 | 491 |
if ( false === $content ) { |
0 | 492 |
return false; |
9 | 493 |
} |
16 | 494 |
|
9 | 495 |
return $this->put_contents( $destination, $content, $mode ); |
0 | 496 |
} |
497 |
||
5 | 498 |
/** |
9 | 499 |
* Moves a file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
* |
9 | 501 |
* @since 2.7.0 |
502 |
* |
|
503 |
* @param string $source Path to the source file. |
|
504 |
* @param string $destination Path to the destination file. |
|
505 |
* @param bool $overwrite Optional. Whether to overwrite the destination file if it exists. |
|
506 |
* Default false. |
|
507 |
* @return bool True on success, false on failure. |
|
5 | 508 |
*/ |
9 | 509 |
public function move( $source, $destination, $overwrite = false ) { |
16 | 510 |
if ( $this->exists( $destination ) ) { |
511 |
if ( $overwrite ) { |
|
512 |
// We need to remove the destination file before we can rename the source. |
|
513 |
$this->delete( $destination, false, 'f' ); |
|
514 |
} else { |
|
515 |
// If we're not overwriting, the rename will fail, so return early. |
|
516 |
return false; |
|
517 |
} |
|
518 |
} |
|
519 |
||
520 |
return ssh2_sftp_rename( $this->sftp_link, $source, $destination ); |
|
0 | 521 |
} |
522 |
||
5 | 523 |
/** |
9 | 524 |
* Deletes a file or directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
* |
9 | 526 |
* @since 2.7.0 |
527 |
* |
|
528 |
* @param string $file Path to the file or directory. |
|
16 | 529 |
* @param bool $recursive Optional. If set to true, deletes files and folders recursively. |
9 | 530 |
* Default false. |
531 |
* @param string|false $type Type of resource. 'f' for file, 'd' for directory. |
|
532 |
* Default false. |
|
533 |
* @return bool True on success, false on failure. |
|
5 | 534 |
*/ |
9 | 535 |
public function delete( $file, $recursive = false, $type = false ) { |
16 | 536 |
if ( 'f' === $type || $this->is_file( $file ) ) { |
9 | 537 |
return ssh2_sftp_unlink( $this->sftp_link, $file ); |
538 |
} |
|
16 | 539 |
|
9 | 540 |
if ( ! $recursive ) { |
541 |
return ssh2_sftp_rmdir( $this->sftp_link, $file ); |
|
542 |
} |
|
16 | 543 |
|
9 | 544 |
$filelist = $this->dirlist( $file ); |
16 | 545 |
|
9 | 546 |
if ( is_array( $filelist ) ) { |
547 |
foreach ( $filelist as $filename => $fileinfo ) { |
|
548 |
$this->delete( $file . '/' . $filename, $recursive, $fileinfo['type'] ); |
|
0 | 549 |
} |
550 |
} |
|
16 | 551 |
|
9 | 552 |
return ssh2_sftp_rmdir( $this->sftp_link, $file ); |
0 | 553 |
} |
554 |
||
5 | 555 |
/** |
9 | 556 |
* Checks if a file or directory exists. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
* |
9 | 558 |
* @since 2.7.0 |
559 |
* |
|
560 |
* @param string $file Path to file or directory. |
|
561 |
* @return bool Whether $file exists or not. |
|
5 | 562 |
*/ |
9 | 563 |
public function exists( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
return file_exists( $this->sftp_path( $file ) ); |
0 | 565 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
|
5 | 567 |
/** |
9 | 568 |
* Checks if resource is a file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
* |
9 | 570 |
* @since 2.7.0 |
571 |
* |
|
572 |
* @param string $file File path. |
|
573 |
* @return bool Whether $file is a file. |
|
5 | 574 |
*/ |
9 | 575 |
public function is_file( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
return is_file( $this->sftp_path( $file ) ); |
0 | 577 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
|
5 | 579 |
/** |
9 | 580 |
* Checks if resource is a directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
* |
9 | 582 |
* @since 2.7.0 |
583 |
* |
|
584 |
* @param string $path Directory path. |
|
585 |
* @return bool Whether $path is a directory. |
|
5 | 586 |
*/ |
9 | 587 |
public function is_dir( $path ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
return is_dir( $this->sftp_path( $path ) ); |
0 | 589 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
|
5 | 591 |
/** |
9 | 592 |
* Checks if a file is readable. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
* |
9 | 594 |
* @since 2.7.0 |
595 |
* |
|
596 |
* @param string $file Path to file. |
|
597 |
* @return bool Whether $file is readable. |
|
5 | 598 |
*/ |
9 | 599 |
public function is_readable( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
return is_readable( $this->sftp_path( $file ) ); |
0 | 601 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
|
5 | 603 |
/** |
9 | 604 |
* Checks if a file or directory is writable. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
* |
9 | 606 |
* @since 2.7.0 |
607 |
* |
|
608 |
* @param string $file Path to file or directory. |
|
609 |
* @return bool Whether $file is writable. |
|
5 | 610 |
*/ |
9 | 611 |
public function is_writable( $file ) { |
16 | 612 |
// PHP will base its writable checks on system_user === file_owner, not ssh_user === file_owner. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
return true; |
0 | 614 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
|
5 | 616 |
/** |
9 | 617 |
* Gets the file's last access time. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
* |
9 | 619 |
* @since 2.7.0 |
620 |
* |
|
621 |
* @param string $file Path to file. |
|
622 |
* @return int|false Unix timestamp representing last access time, false on failure. |
|
5 | 623 |
*/ |
9 | 624 |
public function atime( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
return fileatime( $this->sftp_path( $file ) ); |
0 | 626 |
} |
627 |
||
5 | 628 |
/** |
9 | 629 |
* Gets the file modification time. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
* |
9 | 631 |
* @since 2.7.0 |
632 |
* |
|
633 |
* @param string $file Path to file. |
|
634 |
* @return int|false Unix timestamp representing modification time, false on failure. |
|
5 | 635 |
*/ |
9 | 636 |
public function mtime( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
return filemtime( $this->sftp_path( $file ) ); |
0 | 638 |
} |
639 |
||
5 | 640 |
/** |
9 | 641 |
* Gets the file size (in bytes). |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
* |
9 | 643 |
* @since 2.7.0 |
644 |
* |
|
645 |
* @param string $file Path to file. |
|
646 |
* @return int|false Size of the file in bytes on success, false on failure. |
|
5 | 647 |
*/ |
9 | 648 |
public function size( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
return filesize( $this->sftp_path( $file ) ); |
0 | 650 |
} |
651 |
||
5 | 652 |
/** |
9 | 653 |
* Sets the access and modification times of a file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
654 |
* |
9 | 655 |
* Note: Not implemented. |
656 |
* |
|
657 |
* @since 2.7.0 |
|
658 |
* |
|
659 |
* @param string $file Path to file. |
|
660 |
* @param int $time Optional. Modified time to set for file. |
|
661 |
* Default 0. |
|
662 |
* @param int $atime Optional. Access time to set for file. |
|
663 |
* Default 0. |
|
5 | 664 |
*/ |
9 | 665 |
public function touch( $file, $time = 0, $atime = 0 ) { |
666 |
// Not implemented. |
|
0 | 667 |
} |
668 |
||
5 | 669 |
/** |
9 | 670 |
* Creates a directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
671 |
* |
9 | 672 |
* @since 2.7.0 |
673 |
* |
|
18 | 674 |
* @param string $path Path for new directory. |
675 |
* @param int|false $chmod Optional. The permissions as octal number (or false to skip chmod). |
|
676 |
* Default false. |
|
677 |
* @param string|int|false $chown Optional. A user name or number (or false to skip chown). |
|
678 |
* Default false. |
|
679 |
* @param string|int|false $chgrp Optional. A group name or number (or false to skip chgrp). |
|
680 |
* Default false. |
|
9 | 681 |
* @return bool True on success, false on failure. |
5 | 682 |
*/ |
9 | 683 |
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { |
684 |
$path = untrailingslashit( $path ); |
|
16 | 685 |
|
9 | 686 |
if ( empty( $path ) ) { |
0 | 687 |
return false; |
9 | 688 |
} |
0 | 689 |
|
9 | 690 |
if ( ! $chmod ) { |
0 | 691 |
$chmod = FS_CHMOD_DIR; |
9 | 692 |
} |
16 | 693 |
|
9 | 694 |
if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path, $chmod, true ) ) { |
0 | 695 |
return false; |
9 | 696 |
} |
16 | 697 |
|
698 |
// Set directory permissions. |
|
699 |
ssh2_sftp_chmod( $this->sftp_link, $path, $chmod ); |
|
700 |
||
9 | 701 |
if ( $chown ) { |
702 |
$this->chown( $path, $chown ); |
|
703 |
} |
|
16 | 704 |
|
9 | 705 |
if ( $chgrp ) { |
706 |
$this->chgrp( $path, $chgrp ); |
|
707 |
} |
|
16 | 708 |
|
0 | 709 |
return true; |
710 |
} |
|
711 |
||
5 | 712 |
/** |
9 | 713 |
* Deletes a directory. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
* |
9 | 715 |
* @since 2.7.0 |
716 |
* |
|
717 |
* @param string $path Path to directory. |
|
718 |
* @param bool $recursive Optional. Whether to recursively remove files/directories. |
|
719 |
* Default false. |
|
720 |
* @return bool True on success, false on failure. |
|
5 | 721 |
*/ |
9 | 722 |
public function rmdir( $path, $recursive = false ) { |
723 |
return $this->delete( $path, $recursive ); |
|
0 | 724 |
} |
725 |
||
5 | 726 |
/** |
9 | 727 |
* Gets details for files in a directory or a specific file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
728 |
* |
9 | 729 |
* @since 2.7.0 |
730 |
* |
|
731 |
* @param string $path Path to directory or file. |
|
732 |
* @param bool $include_hidden Optional. Whether to include details of hidden ("." prefixed) files. |
|
733 |
* Default true. |
|
734 |
* @param bool $recursive Optional. Whether to recursively include file details in nested directories. |
|
735 |
* Default false. |
|
736 |
* @return array|false { |
|
737 |
* Array of files. False if unable to list directory contents. |
|
738 |
* |
|
739 |
* @type string $name Name of the file or directory. |
|
740 |
* @type string $perms *nix representation of permissions. |
|
19 | 741 |
* @type string $permsn Octal representation of permissions. |
9 | 742 |
* @type string $owner Owner name or ID. |
743 |
* @type int $size Size of file in bytes. |
|
744 |
* @type int $lastmodunix Last modified unix timestamp. |
|
745 |
* @type mixed $lastmod Last modified month (3 letter) and day (without leading 0). |
|
746 |
* @type int $time Last modified time. |
|
747 |
* @type string $type Type of resource. 'f' for file, 'd' for directory. |
|
19 | 748 |
* @type mixed $files If a directory and `$recursive` is true, contains another array of files. |
9 | 749 |
* } |
5 | 750 |
*/ |
9 | 751 |
public function dirlist( $path, $include_hidden = true, $recursive = false ) { |
752 |
if ( $this->is_file( $path ) ) { |
|
753 |
$limit_file = basename( $path ); |
|
754 |
$path = dirname( $path ); |
|
0 | 755 |
} else { |
756 |
$limit_file = false; |
|
757 |
} |
|
758 |
||
16 | 759 |
if ( ! $this->is_dir( $path ) || ! $this->is_readable( $path ) ) { |
0 | 760 |
return false; |
9 | 761 |
} |
0 | 762 |
|
763 |
$ret = array(); |
|
16 | 764 |
$dir = dir( $this->sftp_path( $path ) ); |
0 | 765 |
|
9 | 766 |
if ( ! $dir ) { |
0 | 767 |
return false; |
9 | 768 |
} |
0 | 769 |
|
9 | 770 |
while ( false !== ( $entry = $dir->read() ) ) { |
771 |
$struc = array(); |
|
0 | 772 |
$struc['name'] = $entry; |
773 |
||
16 | 774 |
if ( '.' === $struc['name'] || '..' === $struc['name'] ) { |
775 |
continue; // Do not care about these folders. |
|
9 | 776 |
} |
0 | 777 |
|
16 | 778 |
if ( ! $include_hidden && '.' === $struc['name'][0] ) { |
0 | 779 |
continue; |
9 | 780 |
} |
0 | 781 |
|
18 | 782 |
if ( $limit_file && $struc['name'] !== $limit_file ) { |
9 | 783 |
continue; |
784 |
} |
|
785 |
||
786 |
$struc['perms'] = $this->gethchmod( $path . '/' . $entry ); |
|
787 |
$struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] ); |
|
788 |
$struc['number'] = false; |
|
789 |
$struc['owner'] = $this->owner( $path . '/' . $entry ); |
|
790 |
$struc['group'] = $this->group( $path . '/' . $entry ); |
|
791 |
$struc['size'] = $this->size( $path . '/' . $entry ); |
|
792 |
$struc['lastmodunix'] = $this->mtime( $path . '/' . $entry ); |
|
16 | 793 |
$struc['lastmod'] = gmdate( 'M j', $struc['lastmodunix'] ); |
794 |
$struc['time'] = gmdate( 'h:i:s', $struc['lastmodunix'] ); |
|
9 | 795 |
$struc['type'] = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f'; |
0 | 796 |
|
16 | 797 |
if ( 'd' === $struc['type'] ) { |
9 | 798 |
if ( $recursive ) { |
799 |
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive ); |
|
800 |
} else { |
|
0 | 801 |
$struc['files'] = array(); |
9 | 802 |
} |
0 | 803 |
} |
804 |
||
805 |
$ret[ $struc['name'] ] = $struc; |
|
806 |
} |
|
16 | 807 |
|
0 | 808 |
$dir->close(); |
9 | 809 |
unset( $dir ); |
16 | 810 |
|
0 | 811 |
return $ret; |
812 |
} |
|
813 |
} |