Advertisement
Guest User

Untitled

a guest
Sep 7th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. <?PHP
  2.  
  3. include('../header.php');
  4.  
  5. //Make sure to use this script only on clients already in Routed Mode and with a static IP.
  6.  
  7. //Variables
  8. $username = 'admin';
  9. $password = '2658K';
  10.  
  11.  
  12. // Need to figure this out, seems to work but gives errors...why?
  13. $ipsraw =
  14. '172.16.8.21';
  15.  
  16. //Turns the raw IPs in an array
  17. $iparray = explode(PHP_EOL,$ipsraw);
  18.  
  19. //Loop through each IP in the iparray and change to DHCP Mode
  20. foreach ($iparray as $ip) {
  21.     echo "$ip      ";
  22.    
  23. //Login to Device
  24. $sshObj = new LeadISP\SshCmd($username,$password,$ip);
  25.  
  26. //Set the location for remote file and local file
  27. $remoteFile = '/tmp/system.cfg';
  28. $localFile = "/tmp/$ip.cfg";
  29.  
  30. //Download Config File and Parse it
  31. echo $sshObj->download($remoteFile,$localFile)['text'];
  32. $configLines = parse_ini_file($localFile);
  33.  
  34. //Alter Config Here
  35. $configLines['dhcpc.1.status'] = 'enabled';
  36. $configLines['dhcpc.1.devname'] = 'ath0';
  37. $configLines['dhcpc.1.fallback'] = '192.168.10.1';
  38. $configLines['dhcpc.1.fallback_netmask'] = '255.255.255.0';
  39. $configLines['route.1.status'] = 'disabled';
  40. $configLines['netconf.1.ip'] = '0.0.0.0';
  41.  
  42. //Re-build the config file with new changes
  43. $configOut = '';
  44. foreach($configLines as $key => $config){ //loop through each config in the array and turn it back into a text cfg
  45.     $configOut .= $key .'='.$config .PHP_EOL;
  46. }
  47.  
  48. //save modified config locally
  49. file_put_contents($localFile, $configOut);
  50.  
  51.  
  52. //Upload the config to the device
  53. echo $sshObj->upload($remoteFile, $localFile)['text'];
  54.  
  55.  
  56. //Save the config changes to the device and Reboot
  57. echo $sshObj->cmd('cfgmtd -f /tmp/system.cfg -w;touch /etc/persistent/ct;cfgmtd -wp /etc;reboot')['text'];
  58. echo "<br>";
  59.    
  60. //End Looping through IP's
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement