From: <abe...@us...> - 2013-11-01 03:05:57
|
Revision: 6254 http://sourceforge.net/p/astlinux/code/6254 Author: abelbeck Date: 2013-11-01 03:05:53 +0000 (Fri, 01 Nov 2013) Log Message: ----------- dialproxy.php, add support for POST method with number filtering Modified Paths: -------------- branches/1.0/package/webinterface/altweb/dialproxy.php Modified: branches/1.0/package/webinterface/altweb/dialproxy.php =================================================================== --- branches/1.0/package/webinterface/altweb/dialproxy.php 2013-10-31 00:18:21 UTC (rev 6253) +++ branches/1.0/package/webinterface/altweb/dialproxy.php 2013-11-01 03:05:53 UTC (rev 6254) @@ -1,6 +1,6 @@ <?php -// Copyright (C) 2008-2009 Lonnie Abelbeck +// Copyright (C) 2008-2013 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,13 +8,16 @@ // dialproxy.php for AstLinux // 09-03-2009 +// 10-31-2013, Add POST method // -// With permissions 'nobody' (by default) +// GET Method: // Usage: http://pbx/dialproxy.php?num=2223334444&ext=default -// -// With permissions 'root' // Usage: https://pbx/dialproxy.php?num=2223334444&ext=default // +// POST Method: +// Usage: curl --data-urlencode 'num=2223334444' --data-urlencode 'ext=default' http://pbx/dialproxy.php +// Usage: curl --data-urlencode 'num=2223334444' --data-urlencode 'ext=default' --insecure https://pbx/dialproxy.php +// // [webinterface] manager.conf context must contain // read = command,call,originate // write = command,call,originate @@ -171,9 +174,48 @@ return($info['timed_out'] ? 3 : 0); } -$num = isset($_GET['num']) ? $_GET['num'] : ''; -$ext = isset($_GET['ext']) ? $_GET['ext'] : ''; +// Function: normalize_phone_number +// +function normalize_phone_number($num) { + if ($num !== '') { + if (($df = trim(shell_exec('. /etc/rc.conf; echo "$DIALING_PREFIX_NUMBERS"'))) !== '') { + $df_opts = explode('~', $df); + $internationalprefix = isset($df_opts[0]) ? $df_opts[0] : ''; + $nationalprefix = isset($df_opts[1]) ? $df_opts[1] : ''; + $countryprefix = isset($df_opts[2]) ? $df_opts[2] : ''; + + if ($nationalprefix !== '') { + $num = preg_replace('/\('.$nationalprefix.'\)/', '', $num); + } + $num = preg_replace('/[^0-9+]/', '', $num); + if ($countryprefix !== '') { + $match = '+'.$countryprefix; + if (strncmp($num, $match, strlen($match)) == 0) { + $num = $nationalprefix.substr($num, strlen($match)); + } + } + if (strncmp($num, '+', 1) == 0) { + $num = $internationalprefix.substr($num, 1); + } + } else { + $num = preg_replace('/[^0-9]/', '', $num); + } + } + return($num); +} + +if (isset($_POST['num'], $_POST['ext'])) { + $num = normalize_phone_number($_POST['num']); + $ext = $_POST['ext']; +} elseif (isset($_GET['num'], $_GET['ext'])) { + $num = $_GET['num']; + $ext = $_GET['ext']; +} else { + $num = ''; + $ext = ''; +} + if ($num === '' || $ext === '') { myexit(1, 'Error'); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |