maymann Posted December 2, 2011 Share Posted December 2, 2011 Hi forum, I would like to create a webpage (no DB) where I internally can reboot my phones (with https+login ofcause...). This is my reboot.php from http://code.google.com/p/php-sip/: --- <?php require_once('PhpSIP.class.php'); try { $api = new PhpSIP('172.30.30.1'); // IP we will bind to $api->setUsername('10000'); // authentication username $api->setPassword('secret'); // authentication password // $api->setProxy('some_ip_here'); $api->addHeader('Event: resync'); $api->setMethod('NOTIFY'); $api->setFrom('sip:10000@sip.domain.com'); $api->setUri('sip:10000@sip.domain.com'); $res = $api->send(); echo "res1: $res\n"; } catch (Exception $e) { echo $e->getMessage()."\n"; } ?> --- What I would like to achieve is to have a index.php with a "SITE" dropdown and a multiselect "PHONE" dropdown - where only marked phone(s) for a selected site can be chosen (most likely some java stuff...?): I need to be able to run this (reboot.php) from linux shell (like: php reboot.php <IP>) so I can schedule remote phonereboots when software has been updated on my provisioning server. It would be awesome if I was also able to choose "SITE"+"ALL" and reboot all phones in a site from both webpage and shell... Thanks in advance :-) ! ~Maymann Quote Link to comment Share on other sites More sharing options...
maymann Posted December 5, 2011 Author Share Posted December 5, 2011 BUMP Quote Link to comment Share on other sites More sharing options...
maymann Posted December 8, 2011 Author Share Posted December 8, 2011 I have a working single-site-phone-reboot script here: --- <html> <body> <form action="polycom-reboot.php" method="post"> PolyCom Phone IP: <select name="ip"> <option value="IP1">IP1</option> <option value="IP2">IP2</option> </select><input type="submit" value="Reboot..."/> </form> </body> </html> --- I am trying to figure out how i can make a multi-site-phone-reboot script - here is what i got so far...: --- <html> <body> <script type="text/javascript"> function setOptions(chosen){ var selbox = document.formName.ip; selbox.options.length = 0; if (chosen == " ") { selbox.options[selbox.options.length] = new Option('No site selected',' '); } if (chosen == "1") { selbox.options[selbox.options.length] = new Option('IP1','IP1'); selbox.options[selbox.options.length] = new Option('IP2','IP2'); } if (chosen == "2") { selbox.options[selbox.options.length] = new Option('IP3','IP3'); selbox.options[selbox.options.length] = new Option('IP4','IP4'); } } </script> <form name="formName" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <select name="site" size="1" onchange="setOptions(document.formName.site.options[document.formName.site.selectedIndex].value);"> <option value=" " selected="selected"></option> <option value="1">SITE1</option> <option value="2">SITE2</option> </select> <select name="ip" size="1" method="post" action="polycom-reboot.php"> <option value=" " selected="selected">No phone selected</option> </select> <input type="submit" value="Reboot..."/> </form> </body> </html> --- Polycom-reboot.php script... --- <html> <body> <form method="POST" action="index.php"> <input type="submit" value="Return" /> </form> <?php require_once('php-sip/PhpSIP.class.php'); /* Check if we are running from commandline or not */ if (isset($_SERVER['argc'])) { $postip = $argv[1]; } else { $postip = $_POST["ip"]; } echo "$postip: "; /* Sends check-sync to Polycom phone */ try { $api = new PhpSIP(); $api->setUsername('USR'); // authentication username $api->setPassword('PWD'); // authentication password // $api->setProxy('PROXY'); $api->addHeader('Event: check-sync'); $api->setMethod('NOTIFY'); $api->setFrom('sip:6000@DEST'); $api->setUri("sip:4000@$postip"); $res = $api->send(); echo "response: $res\n"; } catch (Exception $e) { echo $e; } ?> </body> </html> --- I think my problem is parsing the [ip] from index.php->polycom-reboot.php...? Br. Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 8, 2011 Share Posted December 8, 2011 I don't see a question anywhere. What is this doing or not doing that isn't right? Quote Link to comment Share on other sites More sharing options...
maymann Posted December 9, 2011 Author Share Posted December 9, 2011 Hi sorry for this..., I am trying to figure out how i can make a multi-site-phone-reboot script - here is what i got so far... I have a single-site-phone-reboot script and am trying to get the multi-site-phone-reboot script working, but i don't seem to be able to parse the [ip] variable to polycom-reboot.php script like i do in my single-site-phone-reboot script. Thanks in advance :-) ! Quote Link to comment Share on other sites More sharing options...
haku Posted December 10, 2011 Share Posted December 10, 2011 java != javascript Quote Link to comment Share on other sites More sharing options...
maymann Posted December 10, 2011 Author Share Posted December 10, 2011 Sorry for my miss-spelling - it is of-cause javascript... Quote Link to comment Share on other sites More sharing options...
maymann Posted December 10, 2011 Author Share Posted December 10, 2011 BUMP Quote Link to comment Share on other sites More sharing options...
Drongo_III Posted December 10, 2011 Share Posted December 10, 2011 This might get you on the right track... http://php.net/manual/en/function.shell-exec.php BUMP Quote Link to comment Share on other sites More sharing options...
maymann Posted December 10, 2011 Author Share Posted December 10, 2011 Thanks for that, already fixed this part though... (see polycom-reboot.php script below) now only parsing from java-script multiselect-menu in new index.php to polycom-reboot.php is my problem... Here are my scripts... I have a "old" working index.php script here - I would like to move away from this and replace it with the multiselect one below, that needs some editing somewhere... :-): --- <html> <body> <form action="polycom-reboot.php" method="post"> PolyCom Phone IP: <select name="ip"> <option value="IP1">IP1</option> <option value="IP2">IP2</option> </select><input type="submit" value="Reboot..."/> </form> </body> </html> --- I am trying to figure out how i can make a multi-dropdown index.php - here is what i got so far...: --- <html> <body> <script type="text/javascript"> function setOptions(chosen){ var selbox = document.formName.ip; selbox.options.length = 0; if (chosen == " ") { selbox.options[selbox.options.length] = new Option('No site selected',' '); } if (chosen == "1") { selbox.options[selbox.options.length] = new Option('IP1','IP1'); selbox.options[selbox.options.length] = new Option('IP2','IP2'); } if (chosen == "2") { selbox.options[selbox.options.length] = new Option('IP3','IP3'); selbox.options[selbox.options.length] = new Option('IP4','IP4'); } } </script> <form name="formName" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <select name="site" size="1" onchange="setOptions(document.formName.site.options[document.formName.site.selectedIndex].value);"> <option value=" " selected="selected"></option> <option value="1">SITE1</option> <option value="2">SITE2</option> </select> <select name="ip" size="1" method="post" action="polycom-reboot.php"> <option value=" " selected="selected">No phone selected</option> </select> <input type="submit" value="Reboot..."/> </form> </body> </html> --- Polycom-reboot.php script that is now working from both shell and web... :-): --- <html> <body> <form method="POST" action="index.php"> <input type="submit" value="Return" /> </form> <?php require_once('php-sip/PhpSIP.class.php'); /* Check if we are running from commandline or not */ if (isset($_SERVER['argc'])) { $postip = $argv[1]; } else { $postip = $_POST["ip"]; } echo "$postip: "; /* Sends check-sync to Polycom phone */ try { $api = new PhpSIP(); $api->setUsername('USR'); // authentication username $api->setPassword('PWD'); // authentication password // $api->setProxy('PROXY'); $api->addHeader('Event: check-sync'); $api->setMethod('NOTIFY'); $api->setFrom('sip:6000@DEST'); $api->setUri("sip:4000@$postip"); $res = $api->send(); echo "response: $res\n"; } catch (Exception $e) { echo $e; } ?> </body> </html> --- I don't know how to change my new multi-select dropdown index.php, so it parses the [ip] to polycom-reboot.php in the right way... and then making it multiselect... Thanks in advance :-) ! Quote Link to comment Share on other sites More sharing options...
maymann Posted December 13, 2011 Author Share Posted December 13, 2011 BUMP Quote Link to comment Share on other sites More sharing options...
maymann Posted December 14, 2011 Author Share Posted December 14, 2011 BUMP Quote Link to comment Share on other sites More sharing options...
maymann Posted December 16, 2011 Author Share Posted December 16, 2011 BUMP Quote Link to comment Share on other sites More sharing options...
maymann Posted December 16, 2011 Author Share Posted December 16, 2011 BUMP Quote Link to comment Share on other sites More sharing options...
haku Posted December 19, 2011 Share Posted December 19, 2011 You may want to start by explaining what the problem is and actually asking a question. Quote Link to comment Share on other sites More sharing options...
maymann Posted December 19, 2011 Author Share Posted December 19, 2011 Hi Haku, I have a working single-site-phone-reboot script, and would like to move to a multi-site-phone-reboot script (both listed above [old and new index.php] and using polycom-reboot.php script). My multi-site-phone-reboot script doesn't work, and I'm trying to figure out what is causing this (my guess is: parsing the [ip] from index.php->polycom-reboot.php ?). So input to what could be wrong with my multi-site-phone-reboot script (index.php) are much welcome... and my question could then be "what is wrong with my multi-site-reboot script/how do i make it work like my single-site-reboot script" ? Thanks in advance :-) ! ~maymann Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 You still haven't asked a question. We can't tell you what is wrong with a script when you aren't telling us the symptoms. Plus, you haven't posted relevant code...we don't know what a "multi-site-phone-reboot script" is. So... What is the script doing or not doing that is undesired? Quote Link to comment Share on other sites More sharing options...
maymann Posted December 19, 2011 Author Share Posted December 19, 2011 Hi Scootstah, Thanks for your reply. I have already put all my scripts and briefly described what they do in my initial post...: 1. old index.php = working = single-site-phone-reboot script 2. new index.php = not working = multi-site-phone-reboot script 3. polycom-reboot.php = the script used by index.php taken from http://code.google.com/p/php-sip/ I need to switch old->new index.php for testing as this is running in production and the polycom-reboot.php script has references to index.php... My guess is that I'm parsing the [iP] wrong in the multi-site script (which should be called in the javascript part i guess), which is in php in my single-site script... I can't remember the exact error message (posting from home), will post this tomorrow... or maybe you are able to catch my error even before that...:-) Thanks in advance :-) ! ~maymann Quote Link to comment Share on other sites More sharing options...
haku Posted December 19, 2011 Share Posted December 19, 2011 You still didn't answer the question. Quote Link to comment Share on other sites More sharing options...
maymann Posted December 19, 2011 Author Share Posted December 19, 2011 I would like the same functionality as in my old index.php in my new index.php but with site+phone dropdowns (phones available should be dependent on what site you choose in the first dropdown) which is why i though of making it in javascript. My new index.php is failing, and therefore not doing its purpose, which is to reboot a VoIP phone... so what the script is doing wrong is actually kind of my question I guess... but my best guess is I'm not parsing [iP] the right way... Hope this sums it up. br. ~maymann Quote Link to comment Share on other sites More sharing options...
maymann Posted December 20, 2011 Author Share Posted December 20, 2011 My new index.php actually doesn't give me an error..., but just "refreshes" and doesn't take me to polycom-reboot.php script as my old index.php does (showing the ip of the booting phone and a return button to take me back to index.php) Quote Link to comment Share on other sites More sharing options...
maymann Posted December 27, 2011 Author Share Posted December 27, 2011 Can anyone help with parsing this java-script variable->PHP. Thanks in advance :-) ! ~maymann Quote Link to comment Share on other sites More sharing options...
maymann Posted December 27, 2011 Author Share Posted December 27, 2011 Can anyone help with this, please... Thanks in advance :-) ! ~maymann Quote Link to comment Share on other sites More sharing options...
maymann Posted January 2, 2012 Author Share Posted January 2, 2012 Please... can anyone help with this...? Quote Link to comment Share on other sites More sharing options...
kicken Posted January 2, 2012 Share Posted January 2, 2012 My guess is that I'm parsing the [iP] wrong in the multi-site script Given your past posts, I think the word you want is passing, not parsing. Basically, here's the rundown of what you want to do near as i can tell: 1) Have your index.php print a form with a site select and a phone select. Name the phone select as an array, eg name="phones[]". When you change the site, use javascript to update the options in the phone select. 2) When you submit the page, check for the phones array and then run the command with the proper arguments. I'll assume the value of each of the phone options will be that phone's IP. If not you'll have to look it up. <?php if (isset($_POST['phones']) && is_array($_POST['phones'])){ //escape the arguments $ips = array_map('escapeshellarg', $_POST['phones']); //Run the command with the ip's as arguments exec('/usr/bin/php reboot.php '.implode(' ', $ips), $ret, $output); } 3) Update your reboot script to be able to reboot multiple phones by reading each ip from the command line. They are all available in $_SERVER['argv'][1] ... $_SERVER['argv'][n] $ips=array_slice($_SERVER['argv'], 1); foreach ($ips as $ip){ //reboot $ip; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.