Created
July 12, 2018 08:25
-
-
Save inabhi9/31a93b570691774ef625251e44274f14 to your computer and use it in GitHub Desktop.
PHP script to switch Huawei Airtel dongle to NDIS mode in pfsense
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/php-cgi -f | |
<?php | |
sleep(5); | |
$cnt = 0; | |
$hw_addr = "$MAC_ADDRESS"; | |
$found_hw = false; | |
// call usb mode switch | |
$cmd = 'timeout 7 /usr/local/sbin/usb_modeswitch -c /usr/local/share/usb_modeswitch/12d1:1f01 -v 12d1 -p 1f01 > /var/log/usb_modeswitch.log'; | |
system($cmd); | |
while ($cnt < 10) { | |
$out = shell_exec("ifconfig"); | |
if (strpos($out, $hw_addr) !== false) { | |
$found_hw = true; | |
break; | |
} | |
$cnt++; | |
sleep(1); | |
} | |
if ($found_hw === false) { | |
echo 'Cannot found hw'; | |
die(); | |
} | |
// Starting interface as pfsense doesn't automatically do it when interface become available | |
shell_exec('/etc/rc.linkup interface=opt5 action=start'); | |
die('Done\n'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment