7 |
global $privkey_file; |
global $privkey_file; |
8 |
global $pubkey_file; |
global $pubkey_file; |
9 |
|
|
10 |
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist. You must install the ssh2 module from pecl library!"); |
if (!function_exists("ssh2_connect")) die("sshdo(): function ssh2_connect doesn't exist. You must install the ssh2 module from pecl library!"); |
11 |
|
|
12 |
if(!($con = ssh2_connect($ip, "22"))) |
if(!($con = ssh2_connect($ip, "22"))) |
13 |
{ |
{ |
14 |
echo "failure, could not connect\n"; |
echo "sshdo(): failure, could not connect\n"; |
15 |
} |
} |
16 |
else |
else |
17 |
{ |
{ |
18 |
if(!ssh2_auth_pubkey_file($con, $user, $pubkey_file, $privkey_file)) |
if(!ssh2_auth_pubkey_file($con, $user, $pubkey_file, $privkey_file)) |
19 |
{ |
{ |
20 |
echo "failure, could not login\n"; |
echo "sshdo(): failure, could not login\n"; |
21 |
} |
} |
22 |
else |
else |
23 |
{ |
{ |
24 |
echo "logged in\n"; |
//echo "logged in\n"; |
25 |
|
|
26 |
if(!($stream = ssh2_exec($con, "source /etc/profile; ".$cmd."; echo '__RETVAL__:'$?"))) |
if(!($stream = ssh2_exec($con, "source /etc/profile; ".$cmd."; echo '__RETVAL__:'$?"))) |
27 |
{ |
{ |
28 |
echo "failure, could not execute command '".$cmd."'\n"; |
echo "sshdo(): failure, could not execute command '".$cmd."'\n"; |
29 |
} |
} |
30 |
else |
else |
31 |
{ |
{ |
53 |
global $ip; |
global $ip; |
54 |
|
|
55 |
// sed cmd: ssh -l root 10.11.12.13 'sed -i -e "s|^\(VAR=\).*|\1\"VALUE\"| FILE' |
// sed cmd: ssh -l root 10.11.12.13 'sed -i -e "s|^\(VAR=\).*|\1\"VALUE\"| FILE' |
56 |
sshdo('if [[ ! -z $(grep "^'.$var.'=" '.file.') ]]; then sed -i -e "s|^\('.$var.'=\).*|\1\"'.$value.'\"|" '.$file. 'else echo "'.$var.'=\"'.$value.'\"" >> '.file, $ip); |
sshdo('if [[ ! -z $(grep "^'.$var.'=" '.$file.') ]]; then sed -i -e "s|^\('.$var.'=\).*|\1\"'.$value.'\"|" '.$file. 'else echo "'.$var.'=\"'.$value.'\"" >> '.file, $ip); |
57 |
} |
} |
58 |
|
|
59 |
function online($ip) |
function online($ip) |