From: <abe...@us...> - 2014-03-20 19:40:57
|
Revision: 6473 http://sourceforge.net/p/astlinux/code/6473 Author: abelbeck Date: 2014-03-20 19:40:53 +0000 (Thu, 20 Mar 2014) Log Message: ----------- web interface, PhoneProv tab, sanity check MAC address from imported text file and make lower case Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/phoneprov.php Modified: branches/1.0/package/webinterface/altweb/admin/phoneprov.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phoneprov.php 2014-03-19 19:30:30 UTC (rev 6472) +++ branches/1.0/package/webinterface/altweb/admin/phoneprov.php 2014-03-20 19:40:53 UTC (rev 6473) @@ -222,13 +222,15 @@ if ($line = trim(fgets($fp, 1024))) { if ($line[0] !== '#') { if (preg_match('/^([^ \t]+)[ \t]+([^ \t]+)[ \t]+([^ \t]+)[ \t]+([^ \t]+)(.*)$/', $line, $tokens)) { - $enabled = '1'; - $template = $tokens[1]; - $mac = $tokens[2]; - $ext_cid = $tokens[3]; - $password = $tokens[4]; - $account = trim($tokens[5]); - $result = addPHONEPROVmac($family, $mac, $enabled, $template, $ext_cid, $password, $account); + $mac = strtolower($tokens[2]); + if (preg_match('/^([0-9a-f]{2}:){5}([0-9a-f]{2})$/', $mac)) { + $enabled = '1'; + $template = $tokens[1]; + $ext_cid = $tokens[3]; + $password = $tokens[4]; + $account = trim($tokens[5]); + $result = addPHONEPROVmac($family, $mac, $enabled, $template, $ext_cid, $password, $account); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2015-08-03 00:08:00
|
Revision: 7173 http://sourceforge.net/p/astlinux/code/7173 Author: abelbeck Date: 2015-08-03 00:07:58 +0000 (Mon, 03 Aug 2015) Log Message: ----------- web interface, PhoneProv tab, add real-time buttons for 'Status Info', 'Reload Config' and 'Reboot' Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/phoneprov.php Modified: branches/1.0/package/webinterface/altweb/admin/phoneprov.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phoneprov.php 2015-08-02 14:21:20 UTC (rev 7172) +++ branches/1.0/package/webinterface/altweb/admin/phoneprov.php 2015-08-03 00:07:58 UTC (rev 7173) @@ -1,6 +1,6 @@ <?php -// Copyright (C) 2014 Lonnie Abelbeck +// Copyright (C) 2015 Lonnie Abelbeck // This is free software, licensed under the GNU General Public License // version 3 as published by the Free Software Foundation; you can // redistribute it and/or modify it under the terms of the GNU @@ -8,15 +8,20 @@ // phoneprov.php for AstLinux // 03-14-2014 +// 08-02-2015, Add Status Info, Reload Config and Reboot buttons // // System location of /mnt/kd/rc.conf.d directory $PHONEPROVCONFDIR = '/mnt/kd/rc.conf.d'; // System location of gui.phoneprov.conf file $PHONEPROVCONFFILE = '/mnt/kd/rc.conf.d/gui.phoneprov.conf'; +// Asterisk sip_notify config file +$ASTERISK_SIP_NOTIFY_CONF = '/etc/asterisk/sip_notify.conf'; $family = "phoneprov"; $myself = $_SERVER['PHP_SELF']; +$info_data_mac = ''; + require_once '../common/functions.php'; $MAXNUM = (int)getPREFdef($global_prefs, 'phoneprov_extensions_displayed'); @@ -33,6 +38,159 @@ 'EXTIF' => 'External Interface' ); +$sip_notify_reload = array ( + 'aastra' => 'aastra-check-cfg', + 'cisco' => 'cisco-check-cfg', + 'linksys' => 'linksys-warm-restart', + 'polycom' => 'polycom-check-cfg', + 'sipura' => 'sipura-check-cfg', + 'snom' => 'snom-check-cfg', + 'yealink' => 'snom-check-cfg' +); + +$sip_notify_reboot = array ( + 'linksys' => 'linksys-cold-restart', + 'snom' => 'snom-reboot', + 'yealink' => 'snom-reboot' +); + +// Function: isMACinSQL +// +function isMACinSQL($mac) { + + if (! class_exists('PDO')) { + return(FALSE); + } + + $db_file = '/mnt/kd/asterisk-odbc.sqlite3'; + if (! is_file("$db_file")) { + return(FALSE); + } + + $sql = array(); + try { + $pdo_db = new PDO("sqlite:$db_file"); + $pdo_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $sql_str = "SELECT account,model,vendor FROM phoneprov WHERE mac_addr='$mac'"; + foreach ($pdo_db->query($sql_str) as $row) { + if ($row['account'] !== '') { + $sql['account'] = $row['account']; + $sql['model'] = ($row['model'] !== '') ? $row['model'] : 'unknown'; + $sql['vendor'] = ($row['vendor'] !== '') ? $row['vendor'] : 'unknown'; + break; + } + } + $pdo_db = NULL; + } catch (PDOException $e) { + return(FALSE); + } + + if (! isset($sql['account'])) { + return(FALSE); + } + return($sql); +} + +// Function: isMACinfo +// +function isMACinfo($mac, $sql) { + + if (($text = asteriskCMDtext('sip show peer '.$sql['account'])) === FALSE) { + return(FALSE); + } + + $match = array ( + 'useragent', + 'addr->ip', + 'status' + ); + + $info = array(); + foreach ($match as $value) { + foreach ($text as $line) { + $strtokens = explode(':', $line, 2); + $label = trim($strtokens[0]); + if ($value === strtolower($label)) { + if (($field = trim($strtokens[1])) !== '') { + $info[$label] = $field; + } + break; + } + } + } + if (count($info) < 1) { + return(FALSE); + } + return($info); +} + +// Function: isMACreload +// +function isMACreload($mac, $sql, $map) { + global $ASTERISK_SIP_NOTIFY_CONF; + + $model = $sql['model'].'-reload'; + $vendor = $sql['vendor'].'-reload'; + $name = $ASTERISK_SIP_NOTIFY_CONF; + if (is_file($name)) { + $cmd = 'grep -q "^\['.$model.'\]" '.$name; + shell($cmd.' >/dev/null 2>/dev/null', $status); + if ($status == 0) { + return($model); + } + $cmd = 'grep -q "^\['.$vendor.'\]" '.$name; + shell($cmd.' >/dev/null 2>/dev/null', $status); + if ($status == 0) { + return($vendor); + } + if (isset($map[$sql['vendor']])) { + return($map[$sql['vendor']]); + } + } + return(FALSE); +} + +// Function: isMACreboot +// +function isMACreboot($mac, $sql, $map) { + global $ASTERISK_SIP_NOTIFY_CONF; + + $model = $sql['model'].'-reboot'; + $vendor = $sql['vendor'].'-reboot'; + $name = $ASTERISK_SIP_NOTIFY_CONF; + if (is_file($name)) { + $cmd = 'grep -q "^\['.$model.'\]" '.$name; + shell($cmd.' >/dev/null 2>/dev/null', $status); + if ($status == 0) { + return($model); + } + $cmd = 'grep -q "^\['.$vendor.'\]" '.$name; + shell($cmd.' >/dev/null 2>/dev/null', $status); + if ($status == 0) { + return($vendor); + } + if (isset($map[$sql['vendor']])) { + return($map[$sql['vendor']]); + } + } + return(FALSE); +} + +// Function: asteriskCMDtext +// +function asteriskCMDtext($cmd) { + + $tmpfile = tempnam("/tmp", "PHP_"); + if (asteriskCMD($cmd, $tmpfile) == 0) { + $text = @file($tmpfile, FILE_IGNORE_NEW_LINES); + } else { + $text = FALSE; + } + @unlink($tmpfile); + return($text); +} + // Function: putACTIONresult // function putACTIONresult($result_str, $status) { @@ -451,6 +609,48 @@ } else { putHtml('<p> </p>'); } + } elseif (isset($_GET['info'])) { + $mac = rawurldecode($_GET['info']); + if (($sql = isMACinSQL($mac)) !== FALSE) { + if (($info_data = isMACinfo($mac, $sql)) !== FALSE) { + $info_data_mac = $mac; + putHtml('<p> </p>'); + } else { + putHtml('<p style="color: red;">Status Info Failed.</p>'); + } + } else { + putHtml('<p style="color: red;">SQL Action Failed.</p>'); + } + } elseif (isset($_GET['reload'])) { + $mac = rawurldecode($_GET['reload']); + if (($sql = isMACinSQL($mac)) !== FALSE) { + if (($sip_notify = isMACreload($mac, $sql, $sip_notify_reload)) !== FALSE) { + if (($sip_notify_text = asteriskCMDtext('sip notify '.$sip_notify.' '.$sql['account'])) !== FALSE) { + putHtml('<p>'.$sip_notify_text[0].'</p>'); + } else { + putHtml('<p style="color: red;">Reload Config Failed.</p>'); + } + } else { + putHtml('<p style="color: red;">Reload Config Failed.</p>'); + } + } else { + putHtml('<p style="color: red;">SQL Action Failed.</p>'); + } + } elseif (isset($_GET['reboot'])) { + $mac = rawurldecode($_GET['reboot']); + if (($sql = isMACinSQL($mac)) !== FALSE) { + if (($sip_notify = isMACreboot($mac, $sql, $sip_notify_reboot)) !== FALSE) { + if (($sip_notify_text = asteriskCMDtext('sip notify '.$sip_notify.' '.$sql['account'])) !== FALSE) { + putHtml('<p>'.$sip_notify_text[0].'</p>'); + } else { + putHtml('<p style="color: red;">Reboot Failed.</p>'); + } + } else { + putHtml('<p style="color: red;">Reboot Failed.</p>'); + } + } else { + putHtml('<p style="color: red;">SQL Action Failed.</p>'); + } } else { putHtml('<p> </p>'); } @@ -591,6 +791,26 @@ $sel = ($data[$i]['enabled'] === '0') ? ' checked="checked"' : ''; echo '<td style="text-align: center;">', '<input type="checkbox" name="disabled[]" value="', $mac, '"'.$sel.' />', '</td>'; echo '<td style="text-align: center;">', '<input type="checkbox" name="delete[]" value="', $mac, '" />', '</td>'; + if (($sql = isMACinSQL($mac)) !== FALSE) { + putHtml("</tr>"); + echo '<tr ', ($i % 2 == 0) ? 'class="dtrow0"' : 'class="dtrow1"', '>'; + echo '<td> </td>'; + echo '<td colspan="6">'; + echo ' <a href="'.$myself.'?info='.rawurlencode($mac).'" class="actionText">Status Info</a>'; + echo ' <a href="'.$myself.'?reload='.rawurlencode($mac).'" class="actionText">Reload Config</a>'; + echo ' <a href="'.$myself.'?reboot='.rawurlencode($mac).'" class="actionText">Reboot</a>'; + echo '</td>'; + if ($info_data_mac === $mac) { + foreach ($info_data as $info_label => $info_field) { + putHtml("</tr>"); + echo '<tr ', ($i % 2 == 0) ? 'class="dtrow0"' : 'class="dtrow1"', '>'; + echo '<td style="text-align: right;">'.htmlspecialchars($info_label).':</td>'; + echo '<td colspan="6">'; + echo htmlspecialchars($info_field); + echo '</td>'; + } + } + } } } else { if ($db['status'] == 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2015-08-04 21:43:54
|
Revision: 7178 http://sourceforge.net/p/astlinux/code/7178 Author: abelbeck Date: 2015-08-04 21:43:52 +0000 (Tue, 04 Aug 2015) Log Message: ----------- web interface, PhoneProv tab, add support for pjsip if 'sip_driver=pjsip' is defined in the template Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/phoneprov.php Modified: branches/1.0/package/webinterface/altweb/admin/phoneprov.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phoneprov.php 2015-08-04 21:37:45 UTC (rev 7177) +++ branches/1.0/package/webinterface/altweb/admin/phoneprov.php 2015-08-04 21:43:52 UTC (rev 7178) @@ -9,6 +9,7 @@ // phoneprov.php for AstLinux // 03-14-2014 // 08-02-2015, Add Status, Reload and Reboot links +// 08-04-2015, Add pjsip support // // System location of /mnt/kd/rc.conf.d directory $PHONEPROVCONFDIR = '/mnt/kd/rc.conf.d'; @@ -16,6 +17,8 @@ $PHONEPROVCONFFILE = '/mnt/kd/rc.conf.d/gui.phoneprov.conf'; // Asterisk sip_notify config file $ASTERISK_SIP_NOTIFY_CONF = '/etc/asterisk/sip_notify.conf'; +// Asterisk pjsip_notify config file +$ASTERISK_PJSIP_NOTIFY_CONF = '/etc/asterisk/pjsip_notify.conf'; $family = "phoneprov"; $myself = $_SERVER['PHP_SELF']; @@ -49,6 +52,7 @@ ); $sip_notify_reboot = array ( + 'cisco' => 'linksys-cold-restart', 'linksys' => 'linksys-cold-restart', 'snom' => 'snom-reboot', 'yealink' => 'snom-reboot' @@ -72,12 +76,13 @@ $pdo_db = new PDO("sqlite:$db_file"); $pdo_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $sql_str = "SELECT account,model,vendor FROM phoneprov WHERE mac_addr='$mac'"; + $sql_str = "SELECT * FROM phoneprov WHERE mac_addr='$mac'"; foreach ($pdo_db->query($sql_str) as $row) { - if ($row['account'] !== '') { + if ($row['account'] != '') { $sql['account'] = $row['account']; - $sql['model'] = ($row['model'] !== '') ? $row['model'] : 'unknown'; - $sql['vendor'] = ($row['vendor'] !== '') ? $row['vendor'] : 'unknown'; + $sql['model'] = ($row['model'] != '') ? $row['model'] : 'unknown'; + $sql['vendor'] = ($row['vendor'] != '') ? $row['vendor'] : 'unknown'; + $sql['sip_driver'] = ($row['sip_driver'] != '') ? $row['sip_driver'] : 'sip'; break; } } @@ -96,6 +101,9 @@ // function isMACinfo($mac, $sql) { + if ($sql['sip_driver'] === 'pjsip') { + return(FALSE); + } if (($text = asteriskCMDtext('sip show peer '.$sql['account'])) === FALSE) { return(FALSE); } @@ -129,10 +137,11 @@ // function isMACreload($mac, $sql, $map) { global $ASTERISK_SIP_NOTIFY_CONF; + global $ASTERISK_PJSIP_NOTIFY_CONF; $model = $sql['model'].'-reload'; $vendor = $sql['vendor'].'-reload'; - $name = $ASTERISK_SIP_NOTIFY_CONF; + $name = ($sql['sip_driver'] === 'pjsip') ? $ASTERISK_PJSIP_NOTIFY_CONF : $ASTERISK_SIP_NOTIFY_CONF; if (is_file($name)) { $cmd = 'grep -q "^\['.$model.'\]" '.$name; shell($cmd.' >/dev/null 2>/dev/null', $status); @@ -155,10 +164,11 @@ // function isMACreboot($mac, $sql, $map) { global $ASTERISK_SIP_NOTIFY_CONF; + global $ASTERISK_PJSIP_NOTIFY_CONF; $model = $sql['model'].'-reboot'; $vendor = $sql['vendor'].'-reboot'; - $name = $ASTERISK_SIP_NOTIFY_CONF; + $name = ($sql['sip_driver'] === 'pjsip') ? $ASTERISK_PJSIP_NOTIFY_CONF : $ASTERISK_SIP_NOTIFY_CONF; if (is_file($name)) { $cmd = 'grep -q "^\['.$model.'\]" '.$name; shell($cmd.' >/dev/null 2>/dev/null', $status); @@ -625,7 +635,10 @@ $mac = rawurldecode($_GET['reload']); if (($sql = isMACinSQL($mac)) !== FALSE) { if (($sip_notify = isMACreload($mac, $sql, $sip_notify_reload)) !== FALSE) { - if (($sip_notify_text = asteriskCMDtext('sip notify '.$sip_notify.' '.$sql['account'])) !== FALSE) { + $notify_cmd = ($sql['sip_driver'] === 'pjsip') ? 'pjsip send notify '.$sip_notify.' endpoint ' + : 'sip notify '.$sip_notify.' '; + $notify_cmd .= $sql['account']; + if (($sip_notify_text = asteriskCMDtext($notify_cmd)) !== FALSE) { putHtml('<p>'.$sip_notify_text[0].'</p>'); } else { putHtml('<p style="color: red;">Reload Action Failed.</p>'); @@ -640,7 +653,10 @@ $mac = rawurldecode($_GET['reboot']); if (($sql = isMACinSQL($mac)) !== FALSE) { if (($sip_notify = isMACreboot($mac, $sql, $sip_notify_reboot)) !== FALSE) { - if (($sip_notify_text = asteriskCMDtext('sip notify '.$sip_notify.' '.$sql['account'])) !== FALSE) { + $notify_cmd = ($sql['sip_driver'] === 'pjsip') ? 'pjsip send notify '.$sip_notify.' endpoint ' + : 'sip notify '.$sip_notify.' '; + $notify_cmd .= $sql['account']; + if (($sip_notify_text = asteriskCMDtext($notify_cmd)) !== FALSE) { putHtml('<p>'.$sip_notify_text[0].'</p>'); } else { putHtml('<p style="color: red;">Reboot Action Failed.</p>'); @@ -795,7 +811,9 @@ putHtml("</tr>"); echo '<tr ', ($i % 2 == 0) ? 'class="dtrow0"' : 'class="dtrow1"', '>'; echo '<td style="text-align: right;" colspan="7">'; - echo ' <a href="'.$myself.'?info='.rawurlencode($mac).'" class="headerText" title="Show SIP Peer Info">Status</a>'; + if ($sql['sip_driver'] !== 'pjsip') { + echo ' <a href="'.$myself.'?info='.rawurlencode($mac).'" class="headerText" title="Show SIP Peer Info">Status</a>'; + } echo ' <a href="'.$myself.'?reload='.rawurlencode($mac).'" class="headerText" title="Send SIP Notify to Reload Config">Reload</a>'; echo ' <a href="'.$myself.'?reboot='.rawurlencode($mac).'" class="headerText" title="Send SIP Notify to Reboot Phone">Reboot</a>'; echo '</td>'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2015-08-06 04:05:43
|
Revision: 7182 http://sourceforge.net/p/astlinux/code/7182 Author: abelbeck Date: 2015-08-06 04:05:40 +0000 (Thu, 06 Aug 2015) Log Message: ----------- web interface, jump to the displayed Status link data Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/phoneprov.php Modified: branches/1.0/package/webinterface/altweb/admin/phoneprov.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phoneprov.php 2015-08-05 22:44:59 UTC (rev 7181) +++ branches/1.0/package/webinterface/altweb/admin/phoneprov.php 2015-08-06 04:05:40 UTC (rev 7182) @@ -799,7 +799,7 @@ putHtml("</tr>"); $mac = $data[$i]['mac']; echo '<tr ', ($i % 2 == 0) ? 'class="dtrow0"' : 'class="dtrow1"', '>'; - echo '<td><a href="'.$myself.'?key='.rawurlencode($mac).'" class="actionText">'.$mac.'</a>', '</td>'; + echo '<td'.($info_data_mac === $mac ? ' id="to_status"' : '').'><a href="'.$myself.'?key='.rawurlencode($mac).'" class="actionText">'.$mac.'</a>', '</td>'; echo '<td>', htmlspecialchars($data[$i]['template']), '</td>'; echo '<td>', wordwrap(htmlspecialchars(expandPHONEPROVexttext($data[$i])), 10, '<br />', FALSE), '</td>'; echo '<td>', htmlspecialchars(substr($data[$i]['password'], 0, 6)), '…', '</td>'; @@ -812,7 +812,7 @@ echo '<tr ', ($i % 2 == 0) ? 'class="dtrow0"' : 'class="dtrow1"', '>'; echo '<td style="text-align: right;" colspan="7">'; if ($sql['sip_driver'] !== 'pjsip') { - echo ' <a href="'.$myself.'?info='.rawurlencode($mac).'" class="headerText" title="Show SIP Peer Info">Status</a>'; + echo ' <a href="'.$myself.'?info='.rawurlencode($mac).'&#to_status" class="headerText" title="Show SIP Peer Info">Status</a>'; } echo ' <a href="'.$myself.'?reload='.rawurlencode($mac).'" class="headerText" title="Send SIP Notify to Reload Config">Reload</a>'; echo ' <a href="'.$myself.'?reboot='.rawurlencode($mac).'" class="headerText" title="Send SIP Notify to Reboot Phone">Reboot</a>'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2015-08-06 15:39:32
|
Revision: 7183 http://sourceforge.net/p/astlinux/code/7183 Author: abelbeck Date: 2015-08-06 15:39:29 +0000 (Thu, 06 Aug 2015) Log Message: ----------- web interface, PhoneProv tab, add an HTTP external link for the Phone Web Admin using the status info data Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/phoneprov.php Modified: branches/1.0/package/webinterface/altweb/admin/phoneprov.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phoneprov.php 2015-08-06 04:05:40 UTC (rev 7182) +++ branches/1.0/package/webinterface/altweb/admin/phoneprov.php 2015-08-06 15:39:29 UTC (rev 7183) @@ -133,6 +133,19 @@ return($info); } +// Function: addSpecialInfo +// +function addSpecialInfo($label, $field) { + $str = ''; + + if (strtolower($label) === 'addr->ip') { + if (preg_match('/^([0-9]+[.][0-9]+[.][0-9]+[.][0-9]+).*$/', $field, $ips)) { + $str = ' <a href="http://'.$ips[1].'/" class="headerText" title="Phone Web Admin" target="_blank">Admin</a>'; + } + } + return($str); +} + // Function: isMACreload // function isMACreload($mac, $sql, $map) { @@ -823,7 +836,7 @@ echo '<tr ', ($i % 2 == 0) ? 'class="dtrow0"' : 'class="dtrow1"', '>'; echo '<td style="text-align: right;">'.htmlspecialchars($info_label).':</td>'; echo '<td colspan="6">'; - echo htmlspecialchars($info_field); + echo htmlspecialchars($info_field).addSpecialInfo($info_label, $info_field); echo '</td>'; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |