yf_test_ssh user module

Test sub-class.

Fileplugins/test/modules/test/yf_test_ssh.class.php
Usemodule('test_ssh'), URL ?object=test_ssh

Public properties

PropertyDefaultDescription
None declared in this class.

Public methods 1

test

public function test()

Testing SSH wrapper.

    public function test()
    {
        $body = null;
        $_GET['id'] = preg_replace('/[^0-9\.]/i', '', substr(($_GET['id'] ?? ''), 0, 15));
        $server_info = [
            'ssh_host' => ($_GET['id'] ?? null) ? ($_GET['id'] ?? null) : '192.168.1.2',
            'ssh_user' => 'root',
            'ssh_pswd' => '123456',
        ];
        $ssh = _class('ssh');

        $body = '<br /><b>Test exec "ifconfig"</b><br /><br />';
        $body .= _ssh_exec($server_info, 'ifconfig');
        $body .= '<br />';

        $body .= '<br /><b>File info: "/etc/fstab"</b><br /><br />';
        $body .= print_r($ssh->file_info($server_info, '/etc/fstab'), 1);
        $body .= '<br />';

        $body .= '<br /><b>Read "/etc/fstab"</b><br /><br />';
        $body .= $ssh->read_file($server_info, '/etc/fstab');
        $body .= '<br />';

        $body .= '<br /><b>Test remote "file_exists"</b><br /><br />';
        $_is_file_exists = $ssh->file_exists($server_info, '/etc/fstab');
        $body .= '<br /><br />File must exist: ' . ($_is_file_exists ? 'EXIST' : 'NOT EXIST') . '<br /><br />';
        $_is_file_exists2 = $ssh->file_exists($server_info, '/var/www/UPANEL/db_setup132.php');
        $body .= '<br /><br />File must NOT exist: ' . ($_is_file_exists2 ? 'EXIST' : 'NOT EXIST') . '<br /><br />';


        return '<pre>\n' . $body . '\n</pre>';
    }