PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.0.1
Defender Security – Malware Scanner, Login Security & Firewall v6.0.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / thecodingmachine / safe / generated / ssh2.php

ssh2.php in Defender Security – Malware Scanner, Login Security & Firewall 6.0.1, at vendor/thecodingmachine/safe/generated/ssh2.php

646 lines 17.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Safe;
4
5 use Safe\Exceptions\Ssh2Exception;
6
7 /**
8 * Authenticate over SSH using the ssh agent
9 *
10 * @param resource $session An SSH connection link identifier, obtained from a call to
11 * ssh2_connect.
12 * @param string $username Remote user name.
13 * @throws Ssh2Exception
14 *
15 */
16 function ssh2_auth_agent($session, string $username): void
17 {
18 error_clear_last();
19 $result = \ssh2_auth_agent($session, $username);
20 if ($result === false) {
21 throw Ssh2Exception::createFromPhpError();
22 }
23 }
24
25
26 /**
27 * Authenticate using a public hostkey read from a file.
28 *
29 * @param resource $session An SSH connection link identifier, obtained from a call to
30 * ssh2_connect.
31 * @param string $username
32 * @param string $hostname
33 * @param string $pubkeyfile
34 * @param string $privkeyfile
35 * @param string|null $passphrase If privkeyfile is encrypted (which it should
36 * be), the passphrase must be provided.
37 * @param string|null $local_username If local_username is omitted, then the value
38 * for username will be used for it.
39 *
40 * @throws Ssh2Exception
41 *
42 */
43 function ssh2_auth_hostbased_file($session, string $username, string $hostname, string $pubkeyfile, string $privkeyfile, ?string $passphrase = null, ?string $local_username = null): void
44 {
45 error_clear_last();
46 if ($local_username !== null) {
47 $result = \ssh2_auth_hostbased_file($session, $username, $hostname, $pubkeyfile, $privkeyfile, $passphrase, $local_username);
48 } elseif ($passphrase !== null) {
49 $result = \ssh2_auth_hostbased_file($session, $username, $hostname, $pubkeyfile, $privkeyfile, $passphrase);
50 } else {
51 $result = \ssh2_auth_hostbased_file($session, $username, $hostname, $pubkeyfile, $privkeyfile);
52 }
53 if ($result === false) {
54 throw Ssh2Exception::createFromPhpError();
55 }
56 }
57
58
59 /**
60 * Authenticate over SSH using a plain password. Since version 0.12 this function
61 * also supports keyboard_interactive method.
62 *
63 * @param resource $session An SSH connection link identifier, obtained from a call to
64 * ssh2_connect.
65 * @param string $username Remote user name.
66 * @param string $password Password for username
67 * @throws Ssh2Exception
68 *
69 */
70 function ssh2_auth_password($session, string $username, string $password): void
71 {
72 error_clear_last();
73 $result = \ssh2_auth_password($session, $username, $password);
74 if ($result === false) {
75 throw Ssh2Exception::createFromPhpError();
76 }
77 }
78
79
80 /**
81 * Authenticate using a public key read from a file.
82 *
83 * @param resource $session An SSH connection link identifier, obtained from a call to
84 * ssh2_connect.
85 * @param string $username
86 * @param string $pubkeyfile The public key file needs to be in OpenSSH's format. It should look something like:
87 *
88 * ssh-rsa AAAAB3NzaC1yc2EAAA....NX6sqSnHA8= rsa-key-20121110
89 * @param string $privkeyfile
90 * @param string|null $passphrase If privkeyfile is encrypted (which it should
91 * be), the passphrase must be provided.
92 *
93 * @throws Ssh2Exception
94 *
95 */
96 function ssh2_auth_pubkey_file($session, string $username, string $pubkeyfile, string $privkeyfile, ?string $passphrase = null): void
97 {
98 error_clear_last();
99 if ($passphrase !== null) {
100 $result = \ssh2_auth_pubkey_file($session, $username, $pubkeyfile, $privkeyfile, $passphrase);
101 } else {
102 $result = \ssh2_auth_pubkey_file($session, $username, $pubkeyfile, $privkeyfile);
103 }
104 if ($result === false) {
105 throw Ssh2Exception::createFromPhpError();
106 }
107 }
108
109
110 /**
111 * Establish a connection to a remote SSH server.
112 *
113 * Once connected, the client should verify the server's hostkey using
114 * ssh2_fingerprint, then authenticate using either
115 * password or public key.
116 *
117 * @param string $host
118 * @param int $port
119 * @param array|null $methods methods may be an associative array with up to four parameters
120 * as described below.
121 *
122 *
123 * methods may be an associative array
124 * with any or all of the following parameters.
125 *
126 *
127 *
128 * Index
129 * Meaning
130 * Supported Values*
131 *
132 *
133 *
134 *
135 * kex
136 *
137 * List of key exchange methods to advertise, comma separated
138 * in order of preference.
139 *
140 *
141 * diffie-hellman-group1-sha1,
142 * diffie-hellman-group14-sha1, and
143 * diffie-hellman-group-exchange-sha1
144 *
145 *
146 *
147 * hostkey
148 *
149 * List of hostkey methods to advertise, comma separated
150 * in order of preference.
151 *
152 *
153 * ssh-rsa and
154 * ssh-dss
155 *
156 *
157 *
158 * client_to_server
159 *
160 * Associative array containing crypt, compression, and
161 * message authentication code (MAC) method preferences
162 * for messages sent from client to server.
163 *
164 *
165 *
166 *
167 * server_to_client
168 *
169 * Associative array containing crypt, compression, and
170 * message authentication code (MAC) method preferences
171 * for messages sent from server to client.
172 *
173 *
174 *
175 *
176 *
177 *
178 *
179 * * - Supported Values are dependent on methods supported by underlying library.
180 * See libssh2 documentation for additional
181 * information.
182 *
183 *
184 *
185 * client_to_server and
186 * server_to_client may be an associative array
187 * with any or all of the following parameters.
188 *
189 *
190 *
191 *
192 * Index
193 * Meaning
194 * Supported Values*
195 *
196 *
197 *
198 *
199 * crypt
200 * List of crypto methods to advertise, comma separated
201 * in order of preference.
202 *
203 * [email protected],
204 * aes256-cbc,
205 * aes192-cbc,
206 * aes128-cbc,
207 * 3des-cbc,
208 * blowfish-cbc,
209 * cast128-cbc,
210 * arcfour, and
211 * none**
212 *
213 *
214 *
215 * comp
216 * List of compression methods to advertise, comma separated
217 * in order of preference.
218 *
219 * zlib and
220 * none
221 *
222 *
223 *
224 * mac
225 * List of MAC methods to advertise, comma separated
226 * in order of preference.
227 *
228 * hmac-sha1,
229 * hmac-sha1-96,
230 * hmac-ripemd160,
231 * [email protected], and
232 * none**
233 *
234 *
235 *
236 *
237 *
238 *
239 *
240 * Crypt and MAC method "none"
241 *
242 * For security reasons, none is disabled by the underlying
243 * libssh2 library unless explicitly enabled
244 * during build time by using the appropriate ./configure options. See documentation
245 * for the underlying library for more information.
246 *
247 *
248 *
249 * For security reasons, none is disabled by the underlying
250 * libssh2 library unless explicitly enabled
251 * during build time by using the appropriate ./configure options. See documentation
252 * for the underlying library for more information.
253 * @param array|null $callbacks callbacks may be an associative array with any
254 * or all of the following parameters.
255 *
256 *
257 * Callbacks parameters
258 *
259 *
260 *
261 *
262 * Index
263 * Meaning
264 * Prototype
265 *
266 *
267 *
268 *
269 * ignore
270 *
271 * Name of function to call when an
272 * SSH2_MSG_IGNORE packet is received
273 *
274 * void ignore_cb($message)
275 *
276 *
277 * debug
278 *
279 * Name of function to call when an
280 * SSH2_MSG_DEBUG packet is received
281 *
282 * void debug_cb($message, $language, $always_display)
283 *
284 *
285 * macerror
286 *
287 * Name of function to call when a packet is received but the
288 * message authentication code failed. If the callback returns
289 * TRUE, the mismatch will be ignored, otherwise the connection
290 * will be terminated.
291 *
292 * bool macerror_cb($packet)
293 *
294 *
295 * disconnect
296 *
297 * Name of function to call when an
298 * SSH2_MSG_DISCONNECT packet is received
299 *
300 * void disconnect_cb($reason, $message, $language)
301 *
302 *
303 *
304 *
305 * @return resource Returns a resource on success.
306 * @throws Ssh2Exception
307 *
308 */
309 function ssh2_connect(string $host, int $port = 22, ?array $methods = null, ?array $callbacks = null)
310 {
311 error_clear_last();
312 if ($callbacks !== null) {
313 $result = \ssh2_connect($host, $port, $methods, $callbacks);
314 } elseif ($methods !== null) {
315 $result = \ssh2_connect($host, $port, $methods);
316 } else {
317 $result = \ssh2_connect($host, $port);
318 }
319 if ($result === false) {
320 throw Ssh2Exception::createFromPhpError();
321 }
322 return $result;
323 }
324
325
326 /**
327 * Close a connection to a remote SSH server.
328 *
329 * @param resource $session An SSH connection link identifier, obtained from a call to
330 * ssh2_connect.
331 * @throws Ssh2Exception
332 *
333 */
334 function ssh2_disconnect($session): void
335 {
336 error_clear_last();
337 $result = \ssh2_disconnect($session);
338 if ($result === false) {
339 throw Ssh2Exception::createFromPhpError();
340 }
341 }
342
343
344 /**
345 * Execute a command at the remote end and allocate a channel for it.
346 *
347 * @param resource $session An SSH connection link identifier, obtained from a call to
348 * ssh2_connect.
349 * @param string $command
350 * @param string|null $pty
351 * @param array|null $env env may be passed as an associative array of
352 * name/value pairs to set in the target environment.
353 * @param int $width Width of the virtual terminal.
354 * @param int $height Height of the virtual terminal.
355 * @param int $width_height_type width_height_type should be one of
356 * SSH2_TERM_UNIT_CHARS or
357 * SSH2_TERM_UNIT_PIXELS.
358 *
359 * @return resource Returns a stream on success.
360 * @throws Ssh2Exception
361 *
362 */
363 function ssh2_exec($session, string $command, ?string $pty = null, ?array $env = null, int $width = 80, int $height = 25, int $width_height_type = SSH2_TERM_UNIT_CHARS)
364 {
365 error_clear_last();
366 if ($width_height_type !== SSH2_TERM_UNIT_CHARS) {
367 $result = \ssh2_exec($session, $command, $pty, $env, $width, $height, $width_height_type);
368 } elseif ($height !== 25) {
369 $result = \ssh2_exec($session, $command, $pty, $env, $width, $height);
370 } elseif ($width !== 80) {
371 $result = \ssh2_exec($session, $command, $pty, $env, $width);
372 } elseif ($env !== null) {
373 $result = \ssh2_exec($session, $command, $pty, $env);
374 } elseif ($pty !== null) {
375 $result = \ssh2_exec($session, $command, $pty);
376 } else {
377 $result = \ssh2_exec($session, $command);
378 }
379 if ($result === false) {
380 throw Ssh2Exception::createFromPhpError();
381 }
382 return $result;
383 }
384
385
386 /**
387 *
388 *
389 * @param resource $pkey Publickey Subsystem resource created by ssh2_publickey_init.
390 * @param string $algoname Publickey algorithm (e.g.): ssh-dss, ssh-rsa
391 * @param string $blob Publickey blob as raw binary data
392 * @param bool $overwrite If the specified key already exists, should it be overwritten?
393 * @param array|null $attributes Associative array of attributes to assign to this public key.
394 * Refer to ietf-secsh-publickey-subsystem for a list of supported attributes.
395 * To mark an attribute as mandatory, precede its name with an asterisk.
396 * If the server is unable to support an attribute marked mandatory,
397 * it will abort the add process.
398 *
399 * @throws Ssh2Exception
400 *
401 */
402 function ssh2_publickey_add($pkey, string $algoname, string $blob, bool $overwrite = false, ?array $attributes = null): void
403 {
404 error_clear_last();
405 if ($attributes !== null) {
406 $result = \ssh2_publickey_add($pkey, $algoname, $blob, $overwrite, $attributes);
407 } else {
408 $result = \ssh2_publickey_add($pkey, $algoname, $blob, $overwrite);
409 }
410 if ($result === false) {
411 throw Ssh2Exception::createFromPhpError();
412 }
413 }
414
415
416 /**
417 * Request the Publickey subsystem from an already connected SSH2 server.
418 *
419 * The publickey subsystem allows an already connected and authenticated
420 * client to manage the list of authorized public keys stored on the
421 * target server in an implementation agnostic manner.
422 * If the remote server does not support the publickey subsystem,
423 * the ssh2_publickey_init function will return FALSE.
424 *
425 * @param resource $session
426 * @return resource Returns an SSH2 Publickey Subsystem resource for use
427 * with all other ssh2_publickey_*() methods.
428 * @throws Ssh2Exception
429 *
430 */
431 function ssh2_publickey_init($session)
432 {
433 error_clear_last();
434 $result = \ssh2_publickey_init($session);
435 if ($result === false) {
436 throw Ssh2Exception::createFromPhpError();
437 }
438 return $result;
439 }
440
441
442 /**
443 * Removes an authorized publickey.
444 *
445 * @param resource $pkey Publickey Subsystem Resource
446 * @param string $algoname Publickey algorithm (e.g.): ssh-dss, ssh-rsa
447 * @param string $blob Publickey blob as raw binary data
448 * @throws Ssh2Exception
449 *
450 */
451 function ssh2_publickey_remove($pkey, string $algoname, string $blob): void
452 {
453 error_clear_last();
454 $result = \ssh2_publickey_remove($pkey, $algoname, $blob);
455 if ($result === false) {
456 throw Ssh2Exception::createFromPhpError();
457 }
458 }
459
460
461 /**
462 * Copy a file from the remote server to the local filesystem using the SCP protocol.
463 *
464 * @param resource $session An SSH connection link identifier, obtained from a call to
465 * ssh2_connect.
466 * @param string $remote_file Path to the remote file.
467 * @param string $local_file Path to the local file.
468 * @throws Ssh2Exception
469 *
470 */
471 function ssh2_scp_recv($session, string $remote_file, string $local_file): void
472 {
473 error_clear_last();
474 $result = \ssh2_scp_recv($session, $remote_file, $local_file);
475 if ($result === false) {
476 throw Ssh2Exception::createFromPhpError();
477 }
478 }
479
480
481 /**
482 * Copy a file from the local filesystem to the remote server using the SCP protocol.
483 *
484 * @param resource $session An SSH connection link identifier, obtained from a call to
485 * ssh2_connect.
486 * @param string $local_file Path to the local file.
487 * @param string $remote_file Path to the remote file.
488 * @param int $create_mode The file will be created with the mode specified by
489 * create_mode.
490 * @throws Ssh2Exception
491 *
492 */
493 function ssh2_scp_send($session, string $local_file, string $remote_file, int $create_mode = 0644): void
494 {
495 error_clear_last();
496 $result = \ssh2_scp_send($session, $local_file, $remote_file, $create_mode);
497 if ($result === false) {
498 throw Ssh2Exception::createFromPhpError();
499 }
500 }
501
502
503 /**
504 * Attempts to change the mode of the specified file to that given in
505 * mode.
506 *
507 * @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp.
508 * @param string $filename Path to the file.
509 * @param int $mode Permissions on the file. See the chmod for more details on this parameter.
510 * @throws Ssh2Exception
511 *
512 */
513 function ssh2_sftp_chmod($sftp, string $filename, int $mode): void
514 {
515 error_clear_last();
516 $result = \ssh2_sftp_chmod($sftp, $filename, $mode);
517 if ($result === false) {
518 throw Ssh2Exception::createFromPhpError();
519 }
520 }
521
522
523 /**
524 * Creates a directory on the remote file server with permissions set to
525 * mode.
526 *
527 * This function is similar to using mkdir with the
528 * ssh2.sftp:// wrapper.
529 *
530 * @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp.
531 * @param string $dirname Path of the new directory.
532 * @param int $mode Permissions on the new directory.
533 * @param bool $recursive If recursive is TRUE any parent directories
534 * required for dirname will be automatically created as well.
535 * @throws Ssh2Exception
536 *
537 */
538 function ssh2_sftp_mkdir($sftp, string $dirname, int $mode = 0777, bool $recursive = false): void
539 {
540 error_clear_last();
541 $result = \ssh2_sftp_mkdir($sftp, $dirname, $mode, $recursive);
542 if ($result === false) {
543 throw Ssh2Exception::createFromPhpError();
544 }
545 }
546
547
548 /**
549 * Renames a file on the remote filesystem.
550 *
551 * @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp.
552 * @param string $from The current file that is being renamed.
553 * @param string $to The new file name that replaces from.
554 * @throws Ssh2Exception
555 *
556 */
557 function ssh2_sftp_rename($sftp, string $from, string $to): void
558 {
559 error_clear_last();
560 $result = \ssh2_sftp_rename($sftp, $from, $to);
561 if ($result === false) {
562 throw Ssh2Exception::createFromPhpError();
563 }
564 }
565
566
567 /**
568 * Removes a directory from the remote file server.
569 *
570 * This function is similar to using rmdir with the
571 * ssh2.sftp:// wrapper.
572 *
573 * @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp.
574 * @param string $dirname
575 * @throws Ssh2Exception
576 *
577 */
578 function ssh2_sftp_rmdir($sftp, string $dirname): void
579 {
580 error_clear_last();
581 $result = \ssh2_sftp_rmdir($sftp, $dirname);
582 if ($result === false) {
583 throw Ssh2Exception::createFromPhpError();
584 }
585 }
586
587
588 /**
589 * Creates a symbolic link named link on the remote
590 * filesystem pointing to target.
591 *
592 * @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp.
593 * @param string $target Target of the symbolic link.
594 * @param string $link
595 * @throws Ssh2Exception
596 *
597 */
598 function ssh2_sftp_symlink($sftp, string $target, string $link): void
599 {
600 error_clear_last();
601 $result = \ssh2_sftp_symlink($sftp, $target, $link);
602 if ($result === false) {
603 throw Ssh2Exception::createFromPhpError();
604 }
605 }
606
607
608 /**
609 * Deletes a file on the remote filesystem.
610 *
611 * @param resource $sftp An SSH2 SFTP resource opened by ssh2_sftp.
612 * @param string $filename
613 * @throws Ssh2Exception
614 *
615 */
616 function ssh2_sftp_unlink($sftp, string $filename): void
617 {
618 error_clear_last();
619 $result = \ssh2_sftp_unlink($sftp, $filename);
620 if ($result === false) {
621 throw Ssh2Exception::createFromPhpError();
622 }
623 }
624
625
626 /**
627 * Request the SFTP subsystem from an already connected SSH2 server.
628 *
629 * @param resource $session An SSH connection link identifier, obtained from a call to
630 * ssh2_connect.
631 * @return resource This method returns an SSH2 SFTP resource for use with
632 * all other ssh2_sftp_*() methods and the
633 * ssh2.sftp:// fopen wrapper.
634 * @throws Ssh2Exception
635 *
636 */
637 function ssh2_sftp($session)
638 {
639 error_clear_last();
640 $result = \ssh2_sftp($session);
641 if ($result === false) {
642 throw Ssh2Exception::createFromPhpError();
643 }
644 return $result;
645 }
646