Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- include('../header.php');
- //Make sure to use this script only on clients already in Routed Mode and with a static IP.
- //Variables
- $username = 'admin';
- $password = '2658K';
- // Need to figure this out, seems to work but gives errors...why?
- $ipsraw =
- '172.16.8.21';
- //Turns the raw IPs in an array
- $iparray = explode(PHP_EOL,$ipsraw);
- //Loop through each IP in the iparray and change to DHCP Mode
- foreach ($iparray as $ip) {
- echo "$ip ";
- //Login to Device
- $sshObj = new LeadISP\SshCmd($username,$password,$ip);
- //Set the location for remote file and local file
- $remoteFile = '/tmp/system.cfg';
- $localFile = "/tmp/$ip.cfg";
- //Download Config File and Parse it
- echo $sshObj->download($remoteFile,$localFile)['text'];
- $configLines = parse_ini_file($localFile);
- //Alter Config Here
- $configLines['dhcpc.1.status'] = 'enabled';
- $configLines['dhcpc.1.devname'] = 'ath0';
- $configLines['dhcpc.1.fallback'] = '192.168.10.1';
- $configLines['dhcpc.1.fallback_netmask'] = '255.255.255.0';
- $configLines['route.1.status'] = 'disabled';
- $configLines['netconf.1.ip'] = '0.0.0.0';
- //Re-build the config file with new changes
- $configOut = '';
- foreach($configLines as $key => $config){ //loop through each config in the array and turn it back into a text cfg
- $configOut .= $key .'='.$config .PHP_EOL;
- }
- //save modified config locally
- file_put_contents($localFile, $configOut);
- //Upload the config to the device
- echo $sshObj->upload($remoteFile, $localFile)['text'];
- //Save the config changes to the device and Reboot
- echo $sshObj->cmd('cfgmtd -f /tmp/system.cfg -w;touch /etc/persistent/ct;cfgmtd -wp /etc;reboot')['text'];
- echo "<br>";
- //End Looping through IP's
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement