Page MenuHomePhabricator

No OneTemporary

diff --git a/provisioning/provisioning_logic.phtml b/provisioning/provisioning_logic.phtml
index cf404a3..b4ea101 100644
--- a/provisioning/provisioning_logic.phtml
+++ b/provisioning/provisioning_logic.phtml
@@ -1,6065 +1,6091 @@
<?
class recordGenerator extends SOAPEngine {
var $template=array();
function recordGenerator($generatorId,$recordGenerators,$soapEngines,$extraFormElements,$loginCredentials) {
$this->recordGenerators = $recordGenerators;
$this->generatorId=$generatorId;
$keys = array_keys($this->recordGenerators);
if (!$generatorId) $generatorId=$keys[0];
if (!in_array($generatorId,array_keys($this->recordGenerators))) {
return false;
}
// sip zones
$sipEngine = $this->recordGenerators[$generatorId]['sipEngineId'].'@'.'SIP accounts';
$this->SipSOAPEngine = new SOAPEngine($sipEngine,$soapEngines,$extraFormElements,$loginCredentials);
$_sip_class = $this->SipSOAPEngine->recordsClass;
$this->sipRecords = new $_sip_class(&$this->SipSOAPEngine);
$this->sipRecords->getAllowedDomains();
// enum mappings
$enumEngine = $this->recordGenerators[$generatorId]['enumEngineId'].'@'.'ENUM Numbers';
$this->EnumSOAPEngine = new SOAPEngine($enumEngine,$soapEngines,$extraFormElements,$loginCredentials);
$_enum_class = $this->EnumSOAPEngine->recordsClass;
$this->enumRecords = new $_enum_class(&$this->EnumSOAPEngine);
$this->enumRecords->getAllowedDomains();
}
function generateRecords() {
print "<p>Generating records
<ol>";
if (!$this->checkGenerateRequest()) return false;
$i=0;
while ($i < $this->template['nr_records']) {
$number = sprintf("%.0f", $this->start_padded + $i);
$username = substr($number,$this->template['strip_digits']);
$mapto = 'sip:'.$username.'@'.$this->template['domain'];
print "<li>";
printf ('Generating number +%s with mapping %s ',$number,$mapto);
flush();
$enumMapping = array('tld' => $this->template['tld'],
'number' => $number,
'type' => 'sip',
'mapto' => $mapto,
'owner' => $this->template['owner']
);
if ($this->template['create_sip']) {
$groups=array();
if ($this->template['pstn']) $groups[]='free-pstn';
printf ('and sip account %s@%s ',$username,$this->template['domain']);
$sipAccount = array('account' => $username.'@'.$this->template['domain'],
'owner' => $this->template['owner'],
'quota' => $this->template['quota'],
'prepaid' => $this->template['prepaid'],
'password' => $this->template['password'],
'groups' => $groups
);
} else {
unset($sipAccount);
}
if (is_array($enumMapping)) $this->enumRecords->addRecord($enumMapping);
if (is_array($sipAccount)) $this->sipRecords->addRecord($sipAccount);
$i++;
}
print "</ol>";
return true;
}
function checkGenerateRequest() {
// check number of records
$this->template['create_sip']=trim($_REQUEST['create_sip']);
$nr_records=trim($_REQUEST['nr_records']);
if (!is_numeric($nr_records) || $nr_records < 1 || $nr_records > 200) {
print "Error: number of records must be a number between 1 and 200.";
return false;
}
$this->template['nr_records'] = $nr_records;
// length of generated record
$len=trim($_REQUEST['len']);
if (!is_numeric($len) || $len < 4 || $len > 15) {
print "Error: number length must be a number between 4 and 15.";
return false;
}
$this->template['len'] = $len;
// sip domain
$domain=trim($_REQUEST['domain']);
if (!strlen($domain)) {
print "Error: SIP domain missing";
return false;
}
$this->template['domain'] = $domain;
$nr_start=trim($_REQUEST['nr_start']);
if (strlen($nr_start) && !is_numeric($nr_start)) {
print "Error: Use prefix must be numeric";
return false;
}
$this->template['nr_start'] = $nr_start;
// check ENUM TLD
list($prefix,$tld)=explode('@',trim($_REQUEST['range']));
$this->template['prefix'] = intval($prefix);
$this->template['tld'] = $tld;
$this->template['quota'] = intval($_REQUEST['quota']);
$this->template['owner'] = intval($_REQUEST['owner']);
$this->template['pstn'] = intval($_REQUEST['pstn']);
$this->template['prepaid'] = intval($_REQUEST['prepaid']);
$this->template['password'] = trim($_REQUEST['password']);
///////////////////////////////////////
// logical checks
if (strlen($this->template['nr_start'])) {
$start = $this->template['nr_start'];
} else {
$start = 0;
}
$digits = $this->template['len']-strlen($this->template['prefix']);
$this->start_padded = $this->template['prefix'].str_pad($start,$digits,'0');
$this->top = sprintf("%.0f", $this->start_padded + pow(10,$digits-strlen($this->template['nr_start'])));
$maxNumbers = pow(10,$digits-strlen($this->template['nr_start']));
if ($maxNumbers < $this->template['nr_records']) {
printf ("Error: Insufficient numbers in range, requested = %d, available = %d",$this->template['nr_records'],$maxNumbers);
return false;
}
return true;
}
function showGeneratorForm() {
if (!count($this->enumRecords->ranges)) return false;
print "
<form method=post target=_new>
<table cellspacing=1 cellpadding=1 bgcolor=black>
<tr>
<td>
<table cellspacing=3 cellpadding=4 width=100% bgcolor=#444444>
<tr>
<td>
<font color=white>
<b>";
print _("Record generator");
print "</b>
</font>
</td>
</tr>
</table>
</tr>
<tr>
<td colspan=100%>
<table cellpadding=2 bgcolor=white width=100%>
<tr>
<td colspan=3>
</td>
</tr>
";
print "
<tr>
<td>";
print _("Range");
print "
<td align=right>";
if (is_array($this->enumRecords->ranges)) {
print "<select name=range>";
$selected_range[$_REQUEST['range']]='selected';
foreach ($this->enumRecords->ranges as $_range) {
$rangeId=$_range['prefix'].'@'.$_range['tld'];
printf ("<option value=%s %s>+%s under %s",$rangeId,$selected_range[$rangeId],$_range['prefix'],$_range['tld']);
}
print "</select>";
}
print "<td>
</tr>
";
print "
<tr>
<td colspan=2>
";
print "<b>";
print _("ENUM mapping template");
print "</b>";
print "</td>
</tr>
";
print "
<tr>
<td>";
print _("Use prefix:");
printf ("
<td align=right>
<input type=text name=nr_start size=10 maxsize=15 value='%s'>
</td>
</tr>
",$_REQUEST['nr_start']);
print "
<tr>
<td>";
print _("Number length:");
printf ("
<td align=right>
<input type=text name=len size=10 maxsize=15 value='%s'>
<tr>
<td>
",$_REQUEST['len']);
print _("SIP domain");
print "
<td align=right>
";
if (count($this->sipRecords->allowedDomains)) {
print "
<select name=domain>
";
$selected_range[$_REQUEST['domain']]='selected';
foreach ($this->sipRecords->allowedDomains as $domain) {
printf ("<option value='%s' %s>%s",$domain,$selected_range[$domain],$domain);
}
print "</select> ";
} else {
print "<input type=text size=15 name=domain>";
}
print "
</td>
<td>";
print "
</td>
</tr>
";
print "
<tr>
<td>";
print _("Strip from username");
printf ("
<td align=right>first
<input type=text size=5 name=strip_digits value='%s'>digits
</td>
</tr>
",$_REQUEST['strip_digits']);
print "
<tr>
<td>";
print _("Owner");
printf ("
<td align=right><input type=text size=6 maxsize=6 name=owner value='%s'>
<td>",$_REQUEST['owner']);
print "
</td>
</tr>";
if (count($this->sipRecords->allowedDomains)) {
print "
<tr>
<td colspan=3><hr noshade size=1>
</td>
</tr>
";
print "
<tr>
<td colspan=2>
";
print "<b>";
print _("SIP account template");
print "</b>";
print "</td>
</tr>
";
print "
<tr>
<td>";
print _("Create SIP records");
if ($_REQUEST['create_sip']) {
$checked_create_sip='checked';
} else {
$checked_create_sip='';
}
printf ("
<td align=right><input type=checkbox name=create_sip value=1 %s>
</td>
</tr>
",$checked_create_sip);
if ($_REQUEST['pstn']) {
$checked_pstn='checked';
} else {
$checked_pstn='';
}
print "
<tr>
<td>";
print _("PSTN");
printf ("
<td align=right><input type=checkbox name=pstn value=1 %s>
</td>
</tr>
",$checked_pstn);
if ($_REQUEST['prepaid']) {
$checked_prepaid='checked';
} else {
$checked_prepaid='';
}
print "
<tr>
<td>";
print _("Prepaid");
printf ("
<td align=right><input type=checkbox name=prepaid value=1 %s>
</td>
</tr>
",$checked_prepaid);
print "
<tr>
<td>";
print _("Prefix Caller-ID");
printf ("
<td align=right><input type=text size=5 name=rpid_prefix value='%s'>
</td>
</tr>
",$_REQUEST['rpid_prefix']);
print "
<tr>
<td>";
print _("Quota");
printf ("
<td align=right><input type=text size=5 name=quota value='%s'>
</td>
</tr>
",$_REQUEST['quota']);
print "
<tr>
<td>";
print _("Password");
printf ("
<td align=right><input type=text size=15 name=password value='%s'>
</td>
</tr>
",$_REQUEST['password']);
print "
<tr>
<td colspan=3>
<hr noshade size=1 with=100%>
</td>
</tr>
";
print "
<tr>
<td>
";
if ($_REQUEST['nr_records']) {
$nr_records=$_REQUEST['nr_records'];
} else {
$nr_records=1;
}
print "<input type=hidden value=Generate>";
print "<input type=submit value=";
print _("Generate");
print ">";
printf ("<td align=right>
<input type=text size=4 name=nr_records value='%s'>
",$nr_records);
print _("records");
print "<td>";
print "
</tr>
";
print "
<tr>
<td colspan=2>
<br>
<input type=hidden name=action value=Generate>
<p>";
print _("Existing records will not be overwritten. ");
print "</td>
</tr>
";
}
$this->printHiddenFormElements();
print "
</table>
</form>
</td>
</tr>
</table>
";
}
function printHiddenFormElements () {
printf("<input type=hidden name=generatorId value='%s'>",$this->generatorId);
if ($this->adminonly) {
printf("<input type=hidden name=adminonly value='%s'>",$this->adminonly);
}
foreach (array_keys($this->extraFormElements) as $element) {
if (!strlen($this->extraFormElements[$element])) continue;
printf ("<input type=hidden name=%s value='%s'>\n",$element,$this->extraFormElements[$element]);
}
}
}
class SOAPEngine {
var $version = 1;
var $adminonly = 0;
var $reseller = 0;
var $loginType = 'reseller';
var $services=array(
'SIP accounts' => array('recordsClass' => 'SipAccounts',
'soapClass' => 'WebService_NGNPro_SipPort'
),
'SIP Aliases' => array('recordsClass' => 'SipAliases',
'soapClass' => 'WebService_NGNPro_SipPort'
),
'SIP Domains' => array('recordsClass' => 'Domains',
'soapClass' => 'WebService_NGNPro_SipPort'
),
'SIP Usage' => array('recordsClass' => 'DomainStatistics',
'soapClass' => 'WebService_NGNPro_SipPort'
),
'ENUM Numbers' => array('recordsClass' => 'EnumMappings',
'soapClass' => 'WebService_NGNPro_EnumPort'
),
'ENUM Ranges' => array('recordsClass' => 'EnumRanges',
'soapClass' => 'WebService_NGNPro_EnumPort'
),
'Trusted Peers' => array('recordsClass' => 'TrustedPeers',
'soapClass' => 'WebService_NGNPro_SipPort'
),
'PSTN Gateways' => array('recordsClass' => 'Gateways',
'soapClass' => 'WebService_NGNPro_NetworkPort'
),
'Gateway groups' => array('recordsClass' => 'GatewayGroups',
'soapClass' => 'WebService_NGNPro_NetworkPort'
),
'PSTN Routes' => array('recordsClass' => 'Routes',
'soapClass' => 'WebService_NGNPro_NetworkPort'
),
'Operators' => array('recordsClass' => 'Customers',
'soapClass' => 'WebService_NGNPro_CustomerPort'
)
);
function SOAPEngine($service,$soapEngines,$extraFormElements,$loginCredentials) {
/*
$soapEngines=array(
'mdns' => array('name'=> 'Managed DNS',
'username'=> 'soapadmin',
'password'=> 'passwd',
'url' => 'http://example.com:9200/',
'impersonate' => 1745
),
*/
if ($loginCredentials['loginType'] == 'admin') $this->adminonly = 1;
$this->loginType = $loginCredentials['loginType'];
$this->soapEngines = $soapEngines;
if (is_array($this->soapEngines)) {
if (!$service) {
$_services = array_keys($this->services);
$_soapids = array_keys($this->soapEngines);
$service = $_soapids[0].'@'.$_services[0];
}
if (is_array($extraFormElements)) {
$this->extraFormElements = $extraFormElements;
}
$this->service = $service;
$_els=explode('@',$this->service);
$this->soapEngineId = $_els[0];
$this->soapEngineIdSettingsPage=$this->soapEngineId;
$this->soapEnginePort = $_els[1];
$this->recordsClass = $this->services[$this->soapEnginePort]['recordsClass'];
$this->soapClass = $this->services[$this->soapEnginePort]['soapClass'];
foreach(array_keys($this->soapEngines) as $_key ) {
$this->skipServices[$_key]=$this->soapEngines[$_key]['skipServices'];
$this->skip[$_key]=$this->soapEngines[$_key]['skip'];
}
if (strlen($this->soapEngines[$this->soapEngineId]['version'])) {
$this->version = $this->soapEngines[$this->soapEngineId]['version'];
}
$this->defaultEnumTLD = $this->soapEngines[$this->soapEngineId]['defaultEnumTLD'];
if (!$loginCredentials['reseller'] && $this->soapEngines[$this->soapEngineId]['impersonate']) {
$this->reseller = $this->soapEngines[$this->soapEngineId]['impersonate'];
} else if (strlen($loginCredentials['reseller'])) {
$this->reseller = $loginCredentials['reseller'];
}
if (strlen($loginCredentials['customer'])) {
$this->reseller = $loginCredentials['customer'];
}
if (strlen($this->soapEngines[$this->soapEngineId]['soapEngineIdSettingsPage'])) {
$this->soapEngineIdSettingsPage=$this->soapEngines[$this->soapEngineId]['soapEngineIdSettingsPage'];
}
if (strlen($this->soapEngines[$this->soapEngineId]['recordGenerator'])) {
$this->recordGenerator=$this->soapEngines[$this->soapEngineId]['recordGenerator'];
}
$this->SOAPlogin = array(
"username" => $this->soapEngines[$this->soapEngineId]['username'],
"password" => $this->soapEngines[$this->soapEngineId]['password'],
"admin" => true,
"impersonate" => intval($this->reseller)
);
$this->SOAPurl=$this->soapEngines[$this->soapEngineId]['url'];
printf ("Connection to %s at <a href=%swsdl target=wsdl>%s</a> as %s/%s ",$this->soapClass,$this->SOAPurl,$this->SOAPurl,$this->soapEngines[$this->soapEngineId]['username'],$this->reseller);
$this->SoapAuth = array('auth', $this->SOAPlogin , 'urn:AGProjects:NGNPro', 0, '');
// Instantiate the SOAP client
if (!class_exists($this->soapClass)) return ;
$this->soapclient = new $this->soapClass($this->SOAPurl);
$this->soapclient->setOpt('curl', CURLOPT_TIMEOUT, 5);
$this->soapclient->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0);
$this->soapclient->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0);
$this->soapRemoteId=$this->soapEngines[$this->soapEngineId]['depends'];
if (strlen($this->soapRemoteId) && in_array($this->soapRemoteId,array_keys($this->soapEngines))) {
$this->soapEngineIdRemote = $this->soapEngines[$this->soapRemoteId];
$impersonateRemote=intval($this->soapEngines[$this->soapRemoteId]['impersonate']);
$this->SOAPloginRemote = array(
"username" => $this->soapEngines[$this->soapRemoteId]['username'],
"password" => $this->soapEngines[$this->soapRemoteId]['password'],
"admin" => true,
"impersonate" => $impersonateRemote
);
//print_r($this->SOAPloginRemote);
$this->SOAPurlRemote=$this->soapEngines[$this->soapRemoteId]['url'];
printf ("and syncronize writes at <a href=%swsdl target=wsdl>%s</a>",$this->SOAPurlRemote,$this->SOAPurlRemote);
$this->SoapAuthRemote = array('auth', $this->SOAPloginRemote , 'urn:AGProjects:NGNPro', 0, '');
// Instantiate the SOAP client depends
$this->soapclientRemote = new $this->soapClass($this->SOAPurlRemote);
$this->soapclientRemote->setOpt('curl', CURLOPT_TIMEOUT, 5);
$this->soapclientRemote->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0);
$this->soapclientRemote->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0);
}
if ($this->version > 1) {
$this->soapclientCustomers = new WebService_NGNPro_CustomerPort($this->SOAPurl);
$this->soapclientCustomers->setOpt('curl', CURLOPT_TIMEOUT, 5);
$this->soapclientCustomers->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0);
$this->soapclientCustomers->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0);
}
} else {
print "<font color=red>Error: No SOAP credentials defined.</font>";
}
$this->url = $_SERVER['PHP_SELF']."?1=1";
foreach (array_keys($this->extraFormElements) as $element) {
if (!strlen($this->extraFormElements[$element])) continue;
$this->url .= sprintf('&%s=%s',$element,urlencode($this->extraFormElements[$element]));
}
}
function execute($function) {
/*
$function=array('commit' => array('name' => 'addAccount',
'parameters' => array($param1,$param2),
'logs' => array('success' => 'The function was a success',
'failure' => 'The function has failed'
)
),
'rollback' => array('name' => 'addAccount',
'parameters' => array($param1,$param2),
'logs' => array('success' => 'The function was a success',
'failure' => 'The function has failed'
)
)
);
*/
if (!$function['commit']['name']) {
print "<font color=red>Error: no function name supplied</font>";
return false;
}
if (is_object($this->soapclientRemote)) {
$this->soapclientRemote->addHeader($this->SoapAuthRemote);
$resultRemote = call_user_func_array(array($this->soapclientRemote,$function['commit']['name']),$function['commit']['parameters']);
if (PEAR::isError($resultRemote)) {
$error_msg=$resultRemote->getMessage();
$error_fault=$resultRemote->getFault();
$error_code=$resultRemote->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPurlRemote,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>%s %s </font>",$function['commit']['logs']['success'],$this->SOAPurlRemote);
$this->soapclient->addHeader($this->SoapAuth);
$result = call_user_func_array(array($this->soapclient,$function['commit']['name']),$function['commit']['parameters']);
if (PEAR::isError($result)) {
$error_msg=$result->getMessage();
$error_fault=$result->getFault();
$error_code=$result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
if ($function['rollback']['name']) {
$this->soapclientRemote->addHeader($this->SoapAuthRemote);
$this->counterRemote++;
$resultRemote = call_user_func_array(array($this->soapclientRemote,$function['rollback']['name']),$function['rollback']['parameters']);
if (PEAR::isError($result)) {
$error_msg=$result->getMessage();
$error_fault=$result->getFault();
$error_code=$result->getCode();
printf ("<p><font color=red>Error roll back at %s: %s (%s): %s</font>",$this->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
} else {
printf ("<p><font color=green>Rolled back action at %s </font>",$this->SOAPurlRemote);
}
}
return false;
} else {
if ($function['commit']['logs']['success']) {
printf ("<p><font color=green>%s %s </font>",$function['commit']['logs']['success'],$this->SOAPurl);
}
}
}
} else {
$this->soapclient->addHeader($this->SoapAuth);
$result = call_user_func_array(array($this->soapclient,$function['commit']['name']),$function['commit']['parameters']);
if (PEAR::isError($result)) {
$error_msg=$result->getMessage();
$error_fault=$result->getFault();
$error_code=$result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
if ($function['commit']['logs']['success']) {
printf ("<p><font color=green>%s </font>",$function['commit']['logs']['success']);
}
}
}
return true;
}
}
class Records {
var $maxrowsperpage = '15';
var $SipSettingsPage = 'sip_settings.phtml';
var $allowedDomains = false;
var $selectionActive = false;
var $selectionKeys = array();
var $resellers = array();
var $customers = array();
var $recordGenerator = false;
function Records(&$SOAPEngine) {
$this->SOAPEngine = &$SOAPEngine;
$this->version = $this->SOAPEngine->version;
$this->sorting['sortBy'] = trim($_REQUEST['sortBy']);
$this->sorting['sortOrder'] = trim($_REQUEST['sortOrder']);
$this->next = $_REQUEST['next'];
$this->adminonly = $this->SOAPEngine->adminonly;
$this->reseller = $this->SOAPEngine->reseller;
$this->url = $this->SOAPEngine->url;
$this->loginType = $this->SOAPEngine->loginType;
foreach(array_keys($this->filters) as $_filter) {
if (strlen($this->filters[$_filter])) {
$this->selectionActive=true;
break;
}
}
if ($this->adminonly) {
$this->url .= sprintf('&adminonly=%s',$this->adminonly);
}
$this->filters['customer']=trim($_REQUEST['customer_filter']);
if (!$this->adminonly && $this->reseller) {
// Force filter if reseller
$this->filters['reseller']=$this->reseller;
} else {
$this->filters['reseller']=trim($_REQUEST['reseller_filter']);
}
$this->getResellers();
$this->getCustomers();
//printf ('<p>%s',$this->url);
}
function showEngineSelection() {
$selected_soapEngine[$this->SOAPEngine->service]='selected';
printf ("<select name=service onChange=\"document.soapengine.submit.disabled = true; location.href = '%s&service=' + this.options[this.selectedIndex].value\">",$this->url);
$j=1;
foreach (array_keys($this->SOAPEngine->soapEngines) as $_engine) {
if ($this->SOAPEngine->skip[$_engine]) continue;
if ($j>1) printf ("<option value=''>--------");
$k=1;
foreach (array_keys($this->SOAPEngine->services) as $_service) {
$idx=$_engine.'@'.$_service;
if (in_array($_service,$this->SOAPEngine->skipServices[$_engine])) continue;
if ($_engine == 'Operators' && $this->version <= 1) continue;
printf ("<option value='%s@%s' %s>%d.%d %s@%s",$_engine,$_service,$selected_soapEngine[$idx],$j,$k,ucfirst($_service),$this->SOAPEngine->soapEngines[$_engine]['name']);
$k++;
}
$j++;
}
printf ("</select>");
print "OP";
if ($this->adminonly) {
$this->showResellerForm();
if ($this->filters['reseller']) {
print ".";
$this->showCustomerForm();
}
} else {
printf ("%s",$this->reseller);
print ".";
$this->showCustomerForm();
}
}
function showPagination($maxrows) {
$url .= $this->url.'&'.$this->addFiltersToURL().
sprintf("&service=%s&sortBy=%s&sortOrder=%s",
urlencode($this->SOAPEngine->service),
urlencode($this->sorting['sortBy']),
urlencode($this->sorting['sortOrder'])
);
print "
<p>
<table border=0 align=center>
<tr>
<td>
";
if ($this->next != 0 ) {
$show_next=$this->maxrowsperpage-$this->next;
if ($show_next < 0) {
$mod_show_next = $show_next-2*$show_next;
}
if (!$mod_show_next) $mod_show_next=0;
if ($mod_show_next/$this->maxrowsperpage >= 1) {
printf ("<a href='%s&next=0'>Begin</a> ",$url);
}
printf ("<a href='%s&next=%s'>Previous</a> ",$url,$mod_show_next);
}
print "
</td>
<td>
";
if ($this->next + $this->maxrowsperpage < $this->rows) {
$show_next = $this->maxrowsperpage + $this->next;
printf ("<a href='%s&next=%s'>Next</a> ",$url,$show_next);
}
print "
</td>
</tr>
</table>
";
}
function showSeachFormCustom() {
}
function showSeachForm() {
print "
<p>
<table border=0 class=border width=100%>
<tr>
";
printf ("<form method=post name=soapengine action=%s>",$_SERVER['PHP_SELF']);
print "
<td align=left>
";
$this->showEngineSelection();
$this->showSeachFormCustom();
print "
</td>
<td align=right>
";
$this->showSortForm();
print "
<input type=submit name=action value=Search>
";
$this->printHiddenFormElements();
print "
</td>
</form>
</tr>
</table>
";
if ($_REQUEST['action'] != 'Delete') $this->showAddForm();
}
function listRecords() {
}
function getRecordKeys() {
}
function addRecord() {
}
function deleteRecord() {
}
function tel2enum($tel,$tld) {
if (strlen($tld) == 0) $tld="e164.arpa";
// transform telephone number in FQDN Enum style domain name
if (preg_match("/^[+]?(\d+)$/",$tel,$m)) {
$l=strlen($m[1]);
$rev_num="";
$z=0;
while ($z < $l) {
$ss=substr($m[1],$z,1);
$enum=$ss.".".$enum;
$z++;
}
preg_match("/^(.*)\.$/",$enum,$m);
$enum=$m[1];
$enum=$enum.".$tld.";
return($enum);
} else {
return($tel);
}
}
function showAddForm() {
if ($this->selectionActive) return;
}
function showSortForm() {
if (!count($this->sortElements)) {
return;
}
$selected_sortBy[$this->sorting['sortBy']]='selected';
//print " Sort ";
print "<select name=sortBy>";
foreach (array_keys($this->sortElements) as $key) {
printf ("<option value='%s' %s>%s",$key,$selected_sortBy[$key],$this->sortElements[$key]);
}
print "</select>";
$selected_sortOrder[$this->sorting['sortOrder']]='selected';
print "<select name=sortOrder>";
printf ("<option value='DESC' %s>DESC",$selected_sortOrder['DESC']);
printf ("<option value='ASC' %s>ASC",$selected_sortOrder['ASC']);
print "</select>";
}
function showTimezones() {
if (!$fp = fopen("timezones", "r")) {
print _("Failed to open timezone file.");
return false;
}
print "<select name=timezone>";
print "<option>";
while ($buffer = fgets($fp,1024)) {
$buffer=trim($buffer);
if ($this->timezone==$buffer) {
$selected="selected";
} else {
$selected="";
}
printf ("<option %s>%s>",$selected,$buffer);
}
print "</select>";
fclose($fp);
}
function printHiddenFormElements () {
printf("<input type=hidden name=service value='%s'>",$this->SOAPEngine->service);
if ($this->adminonly) {
printf("<input type=hidden name=adminonly value='%s'>",$this->adminonly);
}
foreach (array_keys($this->SOAPEngine->extraFormElements) as $element) {
if (!strlen($this->SOAPEngine->extraFormElements[$element])) continue;
printf ("<input type=hidden name=%s value='%s'>\n",$element,$this->SOAPEngine->extraFormElements[$element]);
}
}
function getAllowedDomains() {
}
function showActionsForm() {
if (!$this->selectionActive) {
return;
}
$class_name=get_class($this).'Actions';
if (class_exists($class_name)) {
$actions=new $class_name(&$this->SOAPEngine);
$actions->showActionsForm($this->filters,$this->sorting);
}
}
function performActions() {
$this->showSeachForm();
$this->getRecordKeys();
//print_r($this->selectionKeys);
$class_name=get_class($this).'Actions';
if (class_exists($class_name)) {
$actions=new $class_name(&$this->SOAPEngine);
$actions->performActions(&$this->selectionKeys,$_REQUEST['sub_action'],trim($_REQUEST['sub_action_parameter']));
}
}
function getCustomers() {
if (!$this->version <= 1 ) return;
if (!$this->filters['reseller']) {
return;
}
// Filter
$filter=array('reseller'=>intval($this->filters['reseller']));
$range=array('start' => 0,
'count' => 100
);
// Order
$orderBy = array('attribute' => 'customer',
'direction' => 'ASC'
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Insert credetials
$this->SOAPEngine->soapclientCustomers->addHeader($this->SOAPEngine->SoapAuth);
// Call function
$result = $this->SOAPEngine->soapclientCustomers->getCustomers($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
if ($result->total > $range['count']) return;
if ($range['count'] <= $result->total) {
$max=$range['count'];
} else {
$max=$result->total;
}
$i=0;
while ($i < $max) {
$customer=$result->accounts[$i];
$this->customers[$customer->id] = $customer->firstName.' '.$customer->lastName;
$i++;
}
return true;
}
}
function getResellers() {
if (!$this->version <= 1 ) return;
if (!$this->adminonly) {
return;
}
// Filter
$filter=array('reseller'=>intval($this->filters['reseller']));
$range=array('start' => 0,
'count' => 200
);
// Order
$orderBy = array('attribute' => 'customer',
'direction' => 'ASC'
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Insert credetials
$this->SOAPEngine->soapclientCustomers->addHeader($this->SOAPEngine->SoapAuth);
// Call function
$result = $this->SOAPEngine->soapclientCustomers->getResellers($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
//if ($result->total > $range['count']) return;
if ($range['count'] <= $result->total) {
$max=$range['count'];
} else {
$max=$result->total;
}
$i=0;
while ($i < $max) {
$reseller = $result->accounts[$i];
if (strlen($reseller->organization) && $reseller->organization!= 'N/A') {
$this->resellers[$reseller->id] = $reseller->organization;
} else {
$this->resellers[$reseller->id] = $reseller->firstName.' '.$reseller->lastName;
}
$i++;
}
//print_r($this->resellers);
return true;
}
}
function showCustomerForm($name='customer_filter') {
if (count($this->customers) && count($this->customers) < 200) {
$select_customer[$this->filters['customer']]='selected';
printf ("<select name=%s>",$name);
print "<option>";
foreach (array_keys($this->customers) as $_res) {
printf ("<option value='%s' %s>%s (%s)\n",$_res,$select_customer[$_res],$_res,$this->customers[$_res]);
}
print "</select>";
} else {
printf ("<input type=text size=5 name=%s value='%s'>",$name,$this->filters['customer']);
}
}
function showResellerForm($name='reseller_filter') {
if (count($this->resellers) && count($this->resellers) < 200) {
$select_reseller[$this->filters['reseller']]='selected';
printf ("<select name=%s>",$name);
print "<option>";
foreach (array_keys($this->resellers) as $_res) {
printf ("<option value='%s' %s>%s (%s)\n",$_res,$select_reseller[$_res],$_res,$this->resellers[$_res]);
}
print "</select>";
} else {
printf ("<input type=text size=5 name=%s value='%s'>",$name,$this->filters['reseller']);
}
}
function addFiltersToURL() {
$j=0;
foreach(array_keys($this->filters) as $filter) {
if (strlen(trim($this->filters[$filter]))) {
if ($j) $url .='&';
$url .= sprintf('%s_filter=%s',$filter,urlencode(trim($this->filters[$filter])));
}
$j++;
}
return $url;
}
}
class Domains extends Records {
var $maxrowsperpage= 200;
function Domains(&$SOAPEngine) {
$this->filters = array(
'domain' => trim($_REQUEST['domain_filter'])
);
$this->Records(&$SOAPEngine);
}
function listRecords() {
$this->showSeachForm();
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$filter=$this->filters['domain'];
// Call function
$result = $this->SOAPEngine->soapclient->getDomains($filter);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
$this->rows = count($result);
if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') {
$this->showActionsForm();
}
print "
<table border=0 align=center>
<tr><td>$this->rows records found</td></tr>
</table>
<p>
<table border=0 cellpadding=2 width=100%>
<tr bgcolor=lightgrey>
<td><b>Id</b></th>
";
if ($this->version > 1) print "<td><b>Operator</b></td>";
print"
<td><b>Domain</b></td>
<td><b>Last change</b></td>
<td><b>Action</b></td>
</tr>
";
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows=$this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
$domain = $result[$i];
$index = $this->next+$i+1;
$rr=floor($index/2);
$mod=$index-$rr*2;
if ($mod ==0) {
$bgcolor="lightgrey";
} else {
$bgcolor="white";
}
$_url = $this->url.sprintf("&service=%s&action=Delete&domain_filter=%s",
urlencode($this->SOAPEngine->service),
urlencode($domain)
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['domain_filter'] == $domain) {
$_url .= "&confirm=1";
$actionText = "<font color=red>Confirm</font>";
} else {
$actionText = "Delete";
}
if ($this->version > 1) {
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s.%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
$index,
$domain->customer,
$domain->reseller,
$domain,
$domain->changeDate,
$_url,
$actionText
);
} else {
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
$index,
$domain,
$domain->changeDate,
$_url,
$actionText
);
}
$i++;
}
}
print "</table>";
$this->showPagination($maxrows);
return true;
}
}
function showSeachFormCustom() {
printf (" Domain<input type=text size=15 name=domain_filter value='%s'>",$this->filters['domain']);
}
function deleteRecord() {
if (!$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return 1;
}
if (!strlen($this->filters['domain']) || !strlen($this->filters['domain'])) {
print "<p><font color=red>Error: missing SIP domain. </font>";
return 0;
}
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->deleteDomain($this->filters['domain']);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>SIP domain %s has been deleted. </font> ",$this->filters['domain']);
unset($this->filters);
return 1;
}
}
function showAddForm() {
if ($this->selectionActive) return;
print "
<p>
<table border=0 class=border width=100%>
<tr>
";
printf ("<form method=post name=addform action=%s>",$_SERVER['PHP_SELF']);
print "
<td align=left>
";
print "
<input type=submit name=action value=Add>
";
printf (" Domain<input type=text size=20 name=domain>");
print "OP";
if ($this->adminonly) {
$this->showResellerForm('reseller');
print ".";
$this->showCustomerForm('customer');
} else {
$this->showCustomerForm('customer');
}
print "
</td>
<td align=right>
";
print "
</td>
";
$this->printHiddenFormElements();
print "
</form>
</tr>
</table>
";
}
function addRecord() {
$domain = trim($_REQUEST['domain']);
if ($this->adminonly) {
$reseller = trim($_REQUEST['reseller']);
$customer = trim($_REQUEST['customer']);
} else {
$reseller = $this->reseller;
$customer = trim($_REQUEST['customer']);
if (!$customer || !in_array($customer,array_keys($this->customers))) {
$customer=$reseller;
}
}
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->addDomain($domain);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>SIP domain %s has been added. </font>",$domain);
return true;
}
}
}
class SIPAccounts extends Records {
var $sortElements=array('changeDate' => 'Change date',
'username' => 'Username',
'domain' => 'Domain'
);
function SIPAccounts(&$SOAPEngine) {
$this->filters = array('username' => trim($_REQUEST['username_filter']),
'domain' => trim($_REQUEST['domain_filter']),
'fullname' => trim($_REQUEST['fullname_filter'])
);
$this->Records(&$SOAPEngine);
}
function getRecordKeys() {
if (preg_match("/^(.*)@(.*)$/",$this->filters['username'],$m)) {
$this->filters['username'] = $m[1];
$this->filters['domain'] = $m[2];
}
if ($this->filters['domain'] && $this->allowedDomains && !in_array($this->filters['domain'],$this->allowedDomains)) {
$this->filters['domain'] = $this->allowedDomains[0];
}
// Filter
$filter=array('username' => $this->filters['username'],
'domain' => $this->filters['domain'],
'name' => $this->filters['fullname']
);
// Range
$range=array('start' => 0,
'count' => 1000
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
// Call function
$result = $this->SOAPEngine->soapclient->getAccounts($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
foreach ($result->accounts as $account) {
$this->selectionKeys[]=array('username' => $account->id->username,
'domain' => $account->id->domain
);
}
return true;
}
return false;
}
function listRecords() {
$this->getAllowedDomains();
if (preg_match("/^(.*)@(.*)$/",$this->filters['username'],$m)) {
$this->filters['username'] = $m[1];
$this->filters['domain'] = $m[2];
}
// Make sure we apply the domain filter from the login credetials
if ($this->allowedDomains && !$this->filters['domain']) {
//$this->filters['domain'] = $this->allowedDomains[0];
}
if ($this->filters['domain'] && $this->allowedDomains && !in_array($this->filters['domain'],$this->allowedDomains)) {
$this->filters['domain'] = $this->allowedDomains[0];
}
$this->showSeachForm();
// Filter
$filter=array('username' => $this->filters['username'],
'domain' => $this->filters['domain'],
'name' => $this->filters['fullname'],
'customer' => intval($this->filters['customer']),
'reseller' => intval($this->filters['reseller'])
);
// Range
$range=array('start' => intval($this->next),
'count' => intval($this->maxrowsperpage)
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
// Call function
$result = $this->SOAPEngine->soapclient->getAccounts($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
$this->rows = $result->total;
if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') {
$this->showActionsForm();
}
print "
<p>
<table border=0 align=center>
<tr><td>$this->rows records found</td></tr>
</table>
<p>
<table border=0 cellpadding=2 width=100%>
<tr bgcolor=lightgrey>
<td><b>Id</b></th>
";
if ($this->version > 1) print "<td><b>Operator</b></td>";
print"
<td><b>SIP account</b></td>
<td><b>Name</b></td>
<td><b>Email</b></td>
<td><b>Caller Id</b></td>
<td><b>Quota</b></td>
<td><b>Groups</b></td>
<td><b>Last change</b></td>
<td><b>Owner</b></td>
<td><b>Action</b></td>
</tr>
";
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows=$this->rows;
}
$i=0;
//print "<pre>";
//print_r($result->accounts);
if ($this->rows) {
while ($i < $maxrows) {
if (!$result->accounts[$i]) break;
$account = $result->accounts[$i];
$index=$this->next+$i+1;
$rr=floor($index/2);
$mod=$index-$rr*2;
if ($mod ==0) {
$bgcolor="lightgrey";
} else {
$bgcolor="white";
}
$_url = $this->url.sprintf("&service=%s&action=Delete&username_filter=%s&domain_filter=%s",
urlencode($this->SOAPEngine->service),
urlencode($account->id->username),
urlencode($account->id->domain)
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['username_filter'] == $account->id->username &&
$_REQUEST['domain_filter'] == $account->id->domain) {
$_url .= "&confirm=1";
$actionText = "<font color=red>Confirm</font>";
} else {
$actionText = "Delete";
}
if ($account->reseller) {
$resellerSipSettingsPage=$account->reseller;
} else {
$resellerSipSettingsPage=$this->reseller;
}
if ($this->SipSettingsPage) {
$url=sprintf('%s?account=%s@%s&reseller=%s&soapEngineIdSipPort=%s',$this->SipSettingsPage,$account->id->username,$account->id->domain,
$resellerSipSettingsPage,$this->SOAPEngine->soapEngineIdSettingsPage);
if ($this->adminonly) $url .= sprintf('&adminonly=%s',$this->adminonly);
foreach (array_keys($this->SOAPEngine->extraFormElements) as $element) {
if (!strlen($this->SOAPEngine->extraFormElements[$element])) continue;
$url .= sprintf('&%s=%s',$element,urlencode($this->SOAPEngine->extraFormElements[$element]));
}
$sip_account=sprintf("
<a href=\"javascript:void(null);\" onClick=\"return window.open('%s', 'SIP_Settings',
'toolbar=1,status=1,menubar=1,scrollbars=1,resizable=1,width=800,height=720')\">
%s@%s</a>",$url,$account->id->username,$account->id->domain);
} else {
$sip_account=sprintf("%s@%s",$account->id->username,$account->id->domain);
}
unset($groups);
foreach ($account->groups as $_grp) $groups.=$_grp.' ';
if ($this->version > 1) {
printf("
<tr bgcolor=%s>
<td>%s </td>
<td>%s.%s</td>
<td>%s</td>
<td>%s %s</td>
<td><a href=mailto:%s>%s</a></td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>
",
$bgcolor,
$index,
$account->reseller,
$account->customer,
$sip_account,
$account->firstName,
$account->lastName,
$account->email,
$account->email,
$account->rpid,
$account->quota,
$groups,
$account->changeDate,
$account->owner,
$_url,
$actionText
);
} else {
printf("
<tr bgcolor=%s>
<td>%s </td>
<td>%s</td>
<td>%s %s</td>
<td><a href=mailto:%s>%s</a></td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>
",
$bgcolor,
$index,
$sip_account,
$account->firstName,
$account->lastName,
$account->email,
$account->email,
$account->rpid,
$account->quota,
$groups,
$account->changeDate,
$account->owner,
$_url,
$actionText
);
}
$i++;
}
}
print "</table>";
$this->showPagination($maxrows);
return true;
}
}
function showSeachFormCustom() {
printf ("User<input type=text size=15 name=username_filter value='%s'>",$this->filters['username']);
printf ("@");
if ($this->allowedDomains) {
$selected_domain[$this->filters['domain']]='selected';
printf ("<select name=domain_filter>
<option>");
foreach ($this->allowedDomains as $_domain) {
printf ("<option value='$_domain' %s>$_domain",$selected_domain[$_domain]);
}
printf ("</select>");
} else {
printf ("<input type=text size=15 name=domain_filter value='%s'>",$this->filters['domain']);
}
printf (" Name<input type=text size=15 name=fullname_filter value='%s'>",$this->filters['fullname']);
}
function deleteRecord() {
if (!$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return 1;
}
if (!strlen($this->filters['username']) || !strlen($this->filters['domain'])) {
print "<p><font color=red>Error: missing SIP account username or domain. </font>";
return 0;
}
$account=array('username' => $this->filters['username'],
'domain' => $this->filters['domain']
);
$function=array('commit' => array('name' => 'deleteAccount',
'parameters' => array($account),
'logs' => array('success' => sprintf('<p>SIP account %s@%s has been deleted',$this->filters['username'],$this->filters['domain'])
)
)
);
if ($this->SOAPEngine->execute($function)) {
unset($this->filters);
}
return true;
}
function showAddForm() {
if ($this->selectionActive) return;
print "
<p>
<table border=0 class=border width=100%>
<tr>
";
printf ("<form method=post name=addform action=%s>",$_SERVER['PHP_SELF']);
print "
<td align=left>
";
print "
<input type=submit name=action value=Add>
";
printf (" User<input type=text size=15 name=account value='%s'>",$_REQUEST['account']);
if (is_array($this->allowedDomains)) {
print "@<select name=domain>";
foreach ($this->allowedDomains as $_domain) {
print "<option value=$_domain>$_domain\n";
}
print "</select>";
}
printf (" Pass<input type=password size=10 name=password value='%s'>",$_REQUEST['password']);
printf (" Name<input type=text size=15 name=fullname value='%s'>",$_REQUEST['fullname']);
printf (" Email<input type=text size=15 name=email value='%s'>",$_REQUEST['email']);
//printf (" CallerId<input type=text size=11 name=rpid value='%s'>",$_REQUEST['rpid']);
printf ("<nobr>Owner<input type=text size=5 name=owner value='%s'></nobr> ",$_REQUEST['owner']);
printf ("<nobr>PSTN<input type=checkbox name=pstn value=1></nobr> ");
printf ("<nobr>Quota<input type=text size=5 name=quota value='%s'></nobr> ",$_REQUEST['quota']);
printf ("<nobr>Prepaid<input type=checkbox name=prepaid value=1></nobr> ");
print "<nobr>OP";
if ($this->adminonly) {
$this->showResellerForm('reseller');
print ".";
$this->showCustomerForm('customer');
} else {
$this->showCustomerForm('customer');
}
print "</nobr>";
print "
</td>
<td align=right>
";
print "
</td>
";
$this->printHiddenFormElements();
print "
</form>
</tr>
</table>
";
}
function addRecord($dictionary=array()) {
if ($dictionary['account']) {
$account_els = explode("@", $dictionary['account']);
} else {
$account_els = explode("@", trim($_REQUEST['account']));
}
if ($this->adminonly) {
if ($dictionary['reseller']) {
$reseller = $dictionary['reseller'];
} else {
$reseller = trim($_REQUEST['reseller']);
}
if ($dictionary['customer']) {
$customer = $dictionary['customer'];
} else {
$customer = trim($_REQUEST['customer']);
}
if (!$customer) $customer=$reseller;
} else {
$reseller = $this->reseller;
if ($dictionary['customer']) {
$customer = $dictionary['customer'];
} else {
$customer = trim($_REQUEST['customer']);
}
if (!$customer || !in_array($customer,array_keys($this->customers))) {
$customer=$reseller;
}
}
$username=$account_els[0];
if (strlen($account_els[1])) {
$domain=$account_els[1];
} else if ($dictionary['domain']) {
$domain=$dictionary['domain'];
} else if ($_REQUEST['domain']) {
$domain=trim($_REQUEST['domain']);
} else {
printf ("<p><font color=red>Error: Missing SIP domain</font>");
return false;
}
if (is_array($this->allowedDomains) && !in_array($domain,$this->allowedDomains)) {
printf ("<p><font color=red>Error: SIP domain %s is not allowed</font>",$domain);
return false;
}
if ($dictionary['fullname']) {
$name_els = explode(" ", $dictionary['fullname']);
} else {
$name_els = explode(" ", trim($_REQUEST['fullname']));
}
if (strlen($name_els[0])) {
$firstName=$name_els[0];
} else {
$firstName='Account';
}
if (strlen($name_els[1])) {
$lastName=$name_els[1];
} else {
$lastName=$username;
}
if (strlen($dictionary['timezone'])) {
$timezone=$dictionary['timezone'];
} else if (strlen(trim($_REQUEST['timezone']))) {
$timezone=trim($_REQUEST['timezone']);
} else {
$timezone='Europe/Amsterdam';
}
if (strlen($dictionary['password'])) {
$password=$dictionary['password'];
} else if (strlen(trim($_REQUEST['password']))) {
$password=trim($_REQUEST['password']);
} else {
$password=$this->RandomPassword(6);
}
$groups=array();
if($dictionary['pstn'] || $_REQUEST['pstn']) $groups[]='free-pstn';
if (strlen($dictionary['email'])) {
$email=$dictionary['email'];
} else {
$email=trim($_REQUEST['email']);
}
if (strlen($dictionary['owner'])) {
$owner=intval($dictionary['owner']);
} else {
$owner=intval($_REQUEST['owner']);
}
if (strlen($dictionary['quota'])) {
$quota=intval($dictionary['quota']);
} else {
$quota=intval($_REQUEST['quota']);
}
if (strlen($dictionary['prepaid'])) {
$prepaid=intval($dictionary['prepaid']);
} else {
$prepaid=intval($_REQUEST['prepaid']);
}
$regexp = "/^([a-z0-9][a-z0-9_.-]*)@([a-z0-9][a-z0-9-]*\.)+([a-z0-9]{2,})$/i";
if (!preg_match($regexp, $uri)) $email=$username.'@'.$domain;
$account=array(
'id' => array('username' => $username,
'domain' => $domain),
'firstName' => $firstName,
'lastName' => $lastName,
'password' => $password,
'timezone' => $timezone,
'email' => $email,
'owner' => $owner,
'customer' => intval($customer),
'reseller' => intval($reseller),
'groups' => $groups,
'prepaid' => $prepaid,
'quota' => $quota,
'region' => ''
);
//print_r($account);
$deleteAccount=array('username' => $username,
'domain' => $domain);
$function=array('commit' => array('name' => 'addAccount',
'parameters' => array($account),
'logs' => array('success' => sprintf('<p>SIP account %s@%s has been added',$username,$domain))),
'rollback' => array('name' => 'deleteAlias',
'parameters' => array($deleteAccount))
);
return $this->SOAPEngine->execute($function);
}
function RandomPassword($len=11) {
$alf=array("a","b","c","d","e","f",
"h","i","j","k","l","m",
"n","p","r","s","t","w",
"x","y","1","2","3","4",
"5","6","7","8","9");
$i=0;
while($i < $len) {
srand((double)microtime()*1000000);
$randval = rand(0,28);
$string="$string"."$alf[$randval]";
$i++;
}
return $string;
}
function getAllowedDomains() {
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
//print_r($this->SOAPEngine->soapclient->headersOut);
$result = $this->SOAPEngine->soapclient->getDomains();
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error in getAllowedDomains from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
//return false;
} else {
$this->allowedDomains=$result;
}
}
}
class SIPAliases extends Records {
var $sortElements=array(
'aliasUsername' => 'Alias user',
'aliasDomain' => 'Alias domain',
'targetUsername' => 'Target user',
'targetDomain' => 'Target domain'
);
function SIPAliases(&$SOAPEngine) {
$this->filters = array('aliasUsername' => trim($_REQUEST['alias_username_filter']),
'aliasDomain' => trim($_REQUEST['alias_domain_filter']),
'targetUsername' => trim($_REQUEST['target_username_filter']),
'targetDomain' => trim($_REQUEST['target_domain_filter'])
);
$this->Records(&$SOAPEngine);
}
function getRecordKeys() {
// Make sure we apply the domain filter from the login credetials
if ($this->allowedDomains && !$this->filters['aliasDomain']) {
//$this->filters['aliasDomain'] = $this->allowedDomains[0];
}
if ($this->filters['aliasDomain'] && $this->allowedDomains && !in_array($this->filters['aliasDomain'],$this->allowedDomains)) {
$this->filters['aliasDomain'] = $this->allowedDomains[0];
}
// Filter
$filter=array('aliasUsername' => $this->filters['aliasUsername'],
'aliasDomain' => $this->filters['aliasDomain'],
'targetUsername' => $this->filters['targetUsername'],
'targetDomain' => $this->filters['targetDomain']
);
// Range
$range=array('start' => 0,
'count' => 1000
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'aliasUsername';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
//print_r($Query);
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
// Call function
$result = $this->SOAPEngine->soapclient->getAliases($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
foreach ($result->aliases as $alias) {
$this->selectionKeys[]=array('username' => $alias->id->username,
'domain' => $alias->id->domain);
}
return true;
}
}
function listRecords() {
$this->getAllowedDomains();
// Make sure we apply the domain filter from the login credetials
if ($this->allowedDomains && !$this->filters['aliasDomain']) {
//$this->filters['aliasDomain'] = $this->allowedDomains[0];
}
if ($this->filters['aliasDomain'] && $this->allowedDomains && !in_array($this->filters['aliasDomain'],$this->allowedDomains)) {
$this->filters['aliasDomain'] = $this->allowedDomains[0];
}
$this->showSeachForm();
// Filter
$filter=array('aliasUsername' => $this->filters['aliasUsername'],
'aliasDomain' => $this->filters['aliasDomain'],
'targetUsername' => $this->filters['targetUsername'],
'targetDomain' => $this->filters['targetDomain'],
'customer' => intval($this->filters['customer']),
'reseller' => intval($this->filters['reseller'])
);
// Range
$range=array('start' => intval($this->next),
'count' => intval($this->maxrowsperpage)
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'aliasUsername';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
// Call function
$result = $this->SOAPEngine->soapclient->getAliases($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
$this->rows = $result->total;
if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') {
$this->showActionsForm();
}
print "
<p>
<table border=0 align=center>
<tr><td>$this->rows records found</td></tr>
</table>
<p>
<table border=0 cellpadding=2 width=100%>
<tr bgcolor=lightgrey>
<td><b>Id</b></th>
";
if ($this->version > 1) print "<td><b>Operator</b></td>";
print"
<td><b>Alias</b></td>
<td><b>Target</b></td>
<td><b>Owner</b></td>
<td><b>Last change</b></td>
<td><b>Action</b></td>
</tr>
";
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows=$this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
if (!$result->aliases[$i]) break;
$alias = $result->aliases[$i];
$index=$this->next+$i+1;
$rr=floor($index/2);
$mod=$index-$rr*2;
if ($mod ==0) {
$bgcolor="lightgrey";
} else {
$bgcolor="white";
}
$_url = $this->url.sprintf("&service=%s&action=Delete&alias_username_filter=%s&alias_domain_filter=%s",
urlencode($this->SOAPEngine->service),
urlencode($alias->id->username),
urlencode($alias->id->domain)
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['alias_username_filter'] == $alias->id->username &&
$_REQUEST['alias_domain_filter'] == $alias->id->domain) {
$_url .= "&confirm=1";
$actionText = "<font color=red>Confirm</font>";
} else {
$actionText = "Delete";
}
if ($this->version > 1) {
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s.%s</td>
<td>%s@%s</td>
<td>%s@%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>
",
$bgcolor,
$index,
$alias->reseller,
$alias->customer,
$alias->id->username,
$alias->id->domain,
$alias->target->username,
$alias->target->domain,
$alias->owner,
$alias->changeDate,
$_url,
$actionText
);
} else {
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s@%s</td>
<td>%s@%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>
",
$bgcolor,
$index,
$alias->id->username,
$alias->id->domain,
$alias->target->username,
$alias->target->domain,
$alias->owner,
$alias->changeDate,
$_url,
$actionText
);
}
$i++;
}
}
print "</table>";
$this->showPagination($maxrows);
return true;
}
}
function deleteRecord() {
if (!$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return 1;
}
if (!strlen($this->filters['aliasUsername']) || !strlen($this->filters['aliasDomain'])) {
print "<p><font color=red>Error: missing SIP alias username or domain. </font>";
return 0;
}
$alias=array('username' => $this->filters['aliasUsername'],
'domain' => $this->filters['aliasDomain']
);
$function=array('commit' => array('name' => 'deleteAlias',
'parameters' => array($alias),
'logs' => array('success' => sprintf('<p>SIP alias %s@%s has been deleted',$this->filters['aliasUsername'],$this->filters['aliasDomain'])
)
)
);
if ($this->SOAPEngine->execute($function)) {
unset($this->filters);
return true;
} else {
return flase;
}
}
function showSeachFormCustom() {
printf (" Alias<input type=text size=10 name=alias_username_filter value='%s'>",$this->filters['aliasUsername']);
printf ("@");
if ($this->allowedDomains) {
$selected_domain[$this->filters['aliasDomain']]='selected';
printf ("<select name=alias_domain_filter>
<option>");
foreach ($this->allowedDomains as $_domain) {
printf ("<option value='$_domain' %s>$_domain",$selected_domain[$_domain]);
}
printf ("</select>");
} else {
printf ("<input type=text size=10 name=alias_domain_filter value='%s'>",$this->filters['aliasDomain']);
}
printf (" Target<input type=text size=10 name=target_username_filter value='%s'>",$this->filters['targetUsername']);
printf (" @<input type=text size=10 name=target_domain_filter value='%s'>",$this->filters['targetDomain']);
}
function showAddForm() {
if ($this->selectionActive) return;
print "
<p>
<table border=0 class=border width=100%>
<tr>
";
printf ("<form method=post name=addform action=%s>",$_SERVER['PHP_SELF']);
print "
<td align=left>
";
print "
<input type=submit name=action value=Add>
";
printf (" Alias<input type=text size=15 name=alias>");
if (is_array($this->allowedDomains)) {
print "@<select name=domain>";
foreach ($this->allowedDomains as $_domain) {
print "<option value=$_domain>$_domain\n";
}
print "</select>";
}
printf (" Target<input type=text size=35 name=target>");
print "OP";
if ($this->adminonly) {
$this->showResellerForm('reseller');
print ".";
$this->showCustomerForm('customer');
} else {
$this->showCustomerForm('customer');
}
printf (" Owner<input type=text size=5 name=owner>");
print "
</td>
<td align=right>
";
print "
</td>
";
$this->printHiddenFormElements();
print "
</form>
</tr>
</table>
";
}
function addRecord() {
$alias_els = explode("@", trim($_REQUEST['alias']));
$target_els = explode("@", trim($_REQUEST['target']));
$username=$alias_els[0];
if (strlen($alias_els[1])) {
$domain=$alias_els[1];
} else if (trim($_REQUEST['domain'])) {
$domain=trim($_REQUEST['domain']);
} else {
printf ("<p><font color=red>Error: Missing SIP domain</font>");
return false;
}
if (is_array($this->allowedDomains) && !in_array($domain,$this->allowedDomains)) {
printf ("<p><font color=red>Error: SIP domain %s is not allowed</font>",$domain);
return false;
}
if ($this->adminonly) {
$reseller = trim($_REQUEST['reseller']);
$customer = trim($_REQUEST['customer']);
if (!$customer) $customer=$reseller;
} else {
$reseller = $this->reseller;
$customer = trim($_REQUEST['customer']);
if (!$customer || !in_array($customer,array_keys($this->customers))) {
$customer=$reseller;
}
}
$alias=array(
'id' => array('username' => $username,
'domain' => $domain
),
'target' => array('username' => $target_els[0],
'domain' => $target_els[1]
),
'owner' => intval($_REQUEST['owner']),
'customer' => intval($customer),
'reseller' => intval($reseller)
);
//print_r($alias);
$deleteAlias=array('username' => $username,
'domain' => $domain);
$function=array('commit' => array('name' => 'addAlias',
'parameters' => array($alias),
'logs' => array('success' => sprintf('<p>SIP alias %s@%s has been added',$username,$domain))),
'rollback' => array('name' => 'deleteAlias',
'parameters' => array($deleteAlias))
);
return $this->SOAPEngine->execute($function);
}
function getAllowedDomains() {
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getDomains();
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
$this->allowedDomains=$result;
}
}
}
class ENUMranges extends Records {
function ENUMranges(&$SOAPEngine) {
$this->filters = array('prefix' => trim($_REQUEST['prefix_filter']),
'tld' => trim($_REQUEST['tld_filter'])
);
$this->Records(&$SOAPEngine);
if ($this->version > 1) {
$this->sortElements=array('changeDate' => 'Change date',
'prefix' => 'Prefix',
'tld' => 'TLD'
);
}
}
function listRecords() {
$this->getAllowedDomains();
$this->showSeachForm();
if ($this->version > 1) {
// Filter
$filter=array('prefix' => $this->filters['prefix'],
'tld' => $this->filters['tld'],
'customer' => intval($this->filters['customer']),
'reseller' => intval($this->filters['reseller'])
);
// Range
$range=array('start' => intval($this->next),
'count' => intval($this->maxrowsperpage)
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getRanges($Query);
} else {
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getRanges();
}
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
if ($this->version > 1) {
$this->rows = $result->total;
} else {
$this->rows = count($result);
}
if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') {
$this->showActionsForm();
}
print "
<p>
<table border=0 align=center>
<tr><td>$this->rows records found</td></tr>
</table>
<p>
<table border=0 cellpadding=2 width=100%>
<tr bgcolor=lightgrey>
<td><b>Id</b></th>
";
if ($this->version > 1) print "<td><b>Operator</b></td>";
print"
<td><b>Prefix </b></td>
<td><b>TLD</b></td>
<td><b>TTL</b></td>
<td><b>Min digits</b></td>
<td><b>Max digits</b></td>
<td><b>Used</b></td>
<td><b>Last change</b></td>
<td><b>Action</b></td>
</tr>
";
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows=$this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
if ($this->version > 1) {
if (!$result->ranges[$i]) break;
$range = $result->ranges[$i];
} else {
$range = $result[$i];
}
$index=$this->next+$i+1;
$rr=floor($index/2);
$mod=$index-$rr*2;
if ($mod ==0) {
$bgcolor="lightgrey";
} else {
$bgcolor="white";
}
$_url = $this->url.sprintf("&service=%s&action=Delete&prefix_filter=%s&tld_filter=%s",
urlencode($this->SOAPEngine->service),
urlencode($range->id->prefix),
urlencode($range->id->tld)
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['prefix_filter'] == $range->id->prefix &&
$_REQUEST['tld_filter'] == $range->id->tld) {
$_url .= "&confirm=1";
$actionText = "<font color=red>Confirm</font>";
} else {
$actionText = "Delete";
}
if (strlen($this->SOAPEngine->recordGenerator)) {
$range_link=sprintf('<a href=%s&generatorId=%s&range=%s@%s&len=%s target=generator>%s</a>',$this->url,$this->SOAPEngine->recordGenerator,$range->id->prefix,$range->id->tld,$range->maxDigits,$range->id->prefix);
} else {
$range_link=$range->id->prefix;
}
if ($this->version > 1) {
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s.%s</td>
<td>+%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
$index,
$range->reseller,
$range->customer,
$range_link,
$range->id->tld,
$range->ttl,
$range->minDigits,
$range->maxDigits,
$range->used,
$range->changeDate,
$_url,
$actionText
);
} else {
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>+%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
$index,
$range_link,
$range->id->tld,
$range->ttl,
$range->minDigits,
$range->maxDigits,
$range->used,
$range->changeDate,
$_url,
$actionText
);
}
printf("
</tr>
");
$i++;
}
}
print "</table>";
$this->showPagination($maxrows);
return true;
}
}
function deleteRecord() {
if (!$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return 1;
}
if (!strlen($this->filters['prefix']) || !strlen($this->filters['tld'])) {
print "<p><font color=red>Error: missing ENUM range id </font>";
return 0;
}
$rangeId=array('prefix'=>$this->filters['prefix'],
'tld'=>$this->filters['tld']);
$function=array('commit' => array('name' => 'deleteRange',
'parameters' => array($rangeId),
'logs' => array('success' => sprintf('<p>ENUM range +%s under %s has been deleted',$this->filters['prefix'],$this->filters['tld'])
)
)
);
unset($this->filters);
return $this->SOAPEngine->execute($function);
}
function showAddForm() {
if ($this->selectionActive) return;
print "
<p>
<table border=0 class=border width=100%>
<tr>
";
printf ("<form method=post name=addform action=%s>",$_SERVER['PHP_SELF']);
print "
<td align=left>
";
print "
<input type=submit name=action value=Add>
";
printf ("Prefix +<input type=text size=5 name=prefix> ");
printf (" TLD");
/*
if (is_array($this->allowedDomains)) {
print "<select name=tld>";
foreach ($this->allowedDomains as $_tld) {
print "<option value=$_tld>$_tld\n";
}
print "</select>";
} else {
print "<input type=text size=15 name=tld>";
}
*/
print "<input type=text size=15 name=tld>";
printf ("TTL<input type=text size=5 name=ttl value=3600> ");
printf ("Min Digits<input type=text size=3 name=minDigits value=11> ");
printf ("Max Digits<input type=text size=3 name=maxDigits value=11> ");
print "OP";
if ($this->adminonly) {
$this->showResellerForm('reseller');
print ".";
$this->showCustomerForm('customer');
} else {
$this->showCustomerForm('customer');
}
//printf ("Info<input type=text size=15 name=info> ");
print "
</td>
<td align=right>
";
print "
</td>
";
$this->printHiddenFormElements();
print "
</form>
</tr>
</table>
";
}
function addRecord() {
$tld = trim($_REQUEST['tld']);
$prefix = trim($_REQUEST['prefix']);
$info = trim($_REQUEST['info']);
if (!strlen($tld)) {
if (strlen($this->SOAPEngine->defaultEnumTLD)) {
$tld=$this->SOAPEngine->defaultEnumTLD;
} else {
$tld='e164.arpa';
}
}
if (!strlen($tld) || !strlen($prefix) || !is_numeric($prefix)) {
printf ("<p><font color=red>Error: Missing TLD or prefix. </font>");
return false;
}
if ($this->adminonly) {
$reseller = trim($_REQUEST['reseller']);
$customer = trim($_REQUEST['customer']);
if (!$customer) $customer=$reseller;
} else {
$reseller = $this->reseller;
$customer = trim($_REQUEST['customer']);
if (!$customer || !in_array($customer,array_keys($this->customers))) {
$customer=$reseller;
}
}
if (!trim($_REQUEST['ttl'])) {
$ttl=3600;
} else {
$ttl=intval(trim($_REQUEST['ttl']));
}
$range=array(
'id' => array('prefix' => $prefix,
'tld' => $tld),
'ttl' => $ttl,
'minDigits' => intval(trim($_REQUEST['minDigits'])),
'maxDigits' => intval(trim($_REQUEST['maxDigits'])),
'customer' => intval($customer),
'reseller' => intval($reseller)
);
$deleteRange=array('prefix'=>$prefix,
'tld'=>$tld);
$function=array('commit' => array('name' => 'addRange',
'parameters' => array($range),
'logs' => array('success' => sprintf('<p>ENUM range +%s under %s has been added',$prefix,$tld))),
'rollback' => array('name' => 'deleteRange',
'parameters' => array($deleteRange))
);
return $this->SOAPEngine->execute($function);
}
function showSeachFormCustom() {
if ($this->version > 1) {
printf (" Prefix<input type=text size=10 name=prefix_filter value='%s'>",$this->filters['prefix']);
printf (" TLD");
if ($this->allowedDomains) {
$selected_tld[$this->filters['tld_filter']]='selected';
printf ("<select name=tld_filter>
<option>");
foreach ($this->allowedDomains as $_tld) {
printf ("<option value='$_tld' %s>$_tld",$selected_tld[$_tld]);
}
printf ("</select>");
} else {
printf ("<input type=text size=10 name=tld_filter value='%s'>",$this->filters['tld']);
}
}
}
function getAllowedDomains() {
// Insert credetials
if ($this->version > 1) {
// Filter
$filter=array('prefix' => '');
// Range
$range=array('start' => 0,
'count' => 200
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getRanges($Query);
} else {
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getRanges();
}
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
if ($this->version > 1) {
foreach($result->ranges as $range) {
$this->ranges[]=array('prefix' => $range->id->prefix,
'tld' => $range->id->tld,
'minDigits' => $range->minDigits,
'maxDigits' => $range->maxDigits
);
if (in_array($range->id->tld,$this->allowedDomains)) continue;
$this->allowedDomains[]=$range->id->tld;
$seen[$range->id->tld]++;
}
} else {
foreach($result as $range) {
$this->ranges[]=array('prefix' => $range->id->prefix,
'tld' => $range->id->tld,
'minDigits' => $range->minDigits,
'maxDigits' => $range->maxDigits
);
if (in_array($range->id->tld,$this->allowedDomains)) continue;
$this->allowedDomains[]=$range->id->tld;
$seen[$range->id->tld]++;
}
}
if (strlen($this->SOAPEngine->defaultEnumTLD) && !$seen[$this->SOAPEngine->defaultEnumTLD]) {
$this->allowedDomains[]=$this->SOAPEngine->defaultEnumTLD;
}
}
}
}
class ENUMmappings extends Records {
var $sortElements=array('changeDate' => 'Change date',
'number' => 'Number',
'tld' => 'TLD',
'owner' => 'Owner'
);
var $ranges=array();
var $NAPTR_services=array(
"sip" => array("service"=>"sip",
"webname"=>"SIP",
"schemas"=>array("sip:","sips:")),
"mailto" => array("service"=>"mailto",
"webname"=>"Email",
"schemas"=>array("mailto:")),
"web:http" => array("service"=>"web:http",
"webname"=>"WEB (http)",
"schemas"=>array("http://")),
"web:https" => array("service"=>"web:https",
"webname"=>"WEB (https)",
"schemas"=>array("https://")),
"x-skype:callto" => array("service"=>"x-skype:callto",
"webname"=>"Skype",
"schemas"=>array("callto:")),
"h323" => array("service"=>"h323",
"webname"=>"H323",
"schemas"=>array("h323:")),
"iax" => array("service"=>"iax",
"webname"=>"IAX",
"schemas"=>array("iax:")),
"iax2" => array("service"=>"iax2",
"webname"=>"IAX2",
"schemas"=>array("iax2:")),
"mms" => array("service"=>"mms",
"webname"=>"MMS",
"schemas"=>array("tel:","mailto:")),
"sms" => array("service"=>"sms",
"webname"=>"SMS",
"schemas"=>array("tel:","mailto:")),
"ems" => array("service"=>"ems",
"webname"=>"EMS",
"schemas"=>array("tel:","mailto:")),
"im" => array("service"=>"im",
"webname"=>"IM",
"schemas"=>array("im:")),
"npd:tel" => array("service"=>"npd+tel",
"webname"=>"Portability",
"schemas"=>array("tel:")),
"void:mailto" => array("service"=>"void:mailto",
"webname"=>"VOID(mail)",
"schemas"=>array("mailto:")),
"void:http" => array("service"=>"void:http",
"webname"=>"VOID(http)",
"schemas"=>array("http://")),
"void:https" => array("service"=>"void:https",
"webname"=>"VOID(https)",
"schemas"=>array("https://")),
"voice" => array("service"=>"voice",
"webname"=>"Voice",
"schemas"=>array("voice:","tel:")),
"tel" => array("service"=>"tel",
"webname"=>"Tel",
"schemas"=>array("tel:")),
"fax:tel" => array("service"=>"fax:tel",
"webname"=>"Fax",
"schemas"=>array("tel:")),
"ifax:mailto" => array("service"=>"ifax:mailto",
"webname"=>"iFax",
"schemas"=>array("mailto:")),
"pres" => array("service"=>"pres",
"webname"=>"Presence",
"schemas"=>array("pres:")),
"ft:ftp" => array("service"=>"ft:ftp",
"webname"=>"FTP",
"schemas"=>array("ftp://")),
"loc:http" => array("service"=>"loc:http",
"webname"=>"GeoLocation",
"schemas"=>array("http://")),
"key:http" => array("service"=>"key:http",
"webname"=>"Public key",
"schemas"=>array("http://"))
);
function ENUMmappings(&$SOAPEngine) {
$this->filters = array('number' => trim($_REQUEST['number_filter']),
'tld' => trim($_REQUEST['tld_filter']),
'type' => trim($_REQUEST['type_filter']),
'mapto' => trim($_REQUEST['mapto_filter']),
'owner' => trim($_REQUEST['owner_filter'])
);
$this->Records(&$SOAPEngine);
}
function listRecords() {
$this->getAllowedDomains();
$this->showSeachForm();
// Filter
$filter=array('number' => $this->filters['number'],
'type' => $this->filters['type'],
'mapto' => $this->filters['mapto'],
'customer' => intval($this->filters['customer']),
'reseller' => intval($this->filters['reseller'])
);
// Range
$range=array('start' => intval($this->next),
'count' => intval($this->maxrowsperpage)
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
// Call function
$result = $this->SOAPEngine->soapclient->getNumbers($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
$this->rows = $result->total;
if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') {
$this->showActionsForm();
}
print "
<p>
<table border=0 align=center>
<tr><td>$this->rows records found</td></tr>
</table>
<p>
<table border=0 cellpadding=2 width=100%>
<tr bgcolor=lightgrey>
<td><b>Id</b></th>
";
if ($this->version > 1) print "<td><b>Operator</b></td>";
print"
<td><b>Number</b></td>
<td><b>TLD</b></td>
<td><b>DNS name</b></td>
<td><b>Srv</b></td>
<td><b>Map to</b></td>
<td><b>TTL</b></td>
<td><b>Prio</b></td>
<td><b>Owner</b></td>
<td><b>Last change</b></td>
<td><b>Action</b></td>
</tr>
";
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows=$this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
if (!$result->numbers[$i]) break;
$number = $result->numbers[$i];
$index=$this->next+$i+1;
$rr=floor($index/2);
$mod=$index-$rr*2;
if ($mod ==0) {
$bgcolor="lightgrey";
} else {
$bgcolor="white";
}
$j=1;
foreach ($number->mappings as $_mapping) {
$_url = $this->url.sprintf("&service=%s&action=Delete&number_filter=%s&tld_filter=%s&mapto_filter=%s",
urlencode($this->SOAPEngine->service),
urlencode($number->id->number),
urlencode($number->id->tld),
urlencode($_mapping->mapto)
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['number_filter'] == $number->id->number &&
$_REQUEST['tld_filter'] == $number->id->tld &&
$_REQUEST['mapto_filter'] == $_mapping->mapto) {
$_url .= "&confirm=1";
$actionText = "<font color=red>Confirm</font>";
} else {
$actionText = "Delete";
}
if ($j==1) {
if ($this->version > 1) {
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s.%s</td>
<td>+%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
$index,
$number->reseller,
$number->customer,
$number->id->number,
$number->id->tld,
$this->tel2enum($number->id->number,$number->id->tld),
ucfirst($_mapping->type),
$_mapping->mapto,
$_mapping->ttl,
$_mapping->priority,
$number->owner,
$_mapping->lastChange,
$_url,
$actionText
);
} else {
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>+%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
$index,
$number->id->number,
$number->id->tld,
$this->tel2enum($number->id->number,$number->id->tld),
ucfirst($_mapping->type),
$_mapping->mapto,
$_mapping->ttl,
$_mapping->priority,
$number->owner,
$_mapping->lastChange,
$_url,
$actionText
);
}
} else {
if ($this->version > 1) {
printf("
<tr bgcolor=%s>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td></td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
ucfirst($_mapping->type),
$_mapping->mapto,
$_mapping->ttl,
$_mapping->priority,
$_mapping->lastChange,
$_url,
$actionText
);
} else {
printf("
<tr bgcolor=%s>
<td></td>
<td></td>
<td></td>
<td></td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td></td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
ucfirst($_mapping->type),
$_mapping->mapto,
$_mapping->ttl,
$_mapping->priority,
$_mapping->lastChange,
$_url,
$actionText
);
}
}
$j++;
}
printf("
</tr>
");
$i++;
}
}
print "</table>";
$this->showPagination($maxrows);
return true;
}
}
function getLastNumber() {
// Filter
$filter=array('number' => ''
);
// Range
$range=array('start' => 0,
'count' => 1
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
// Call function
$result = $this->SOAPEngine->soapclient->getNumbers($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
if ($result->total) {
$number = array('number' => $result->numbers[0]->id->number,
'tld' => $result->numbers[0]->id->tld,
'mappings' => $result->numbers[0]->mappings
);
return $number;
}
}
return false;
}
function showSeachFormCustom() {
printf (" Number<input type=text size=15 name=number_filter value='%s'>",$this->filters['number']);
printf (" TLD");
if ($this->allowedDomains) {
$selected_tld[$this->filters['tld_filter']]='selected';
printf ("<select name=tld_filter>
<option>");
foreach ($this->allowedDomains as $_tld) {
printf ("<option value='$_tld' %s>$_tld",$selected_tld[$_tld]);
}
printf ("</select>");
} else {
printf ("<input type=text size=10 name=tld_filter value='%s'>",$this->filters['tld']);
}
printf (" Srv");
print "<select name=type_filter>
<option>
";
reset($this->NAPTR_services);
$selected_naptr_service[$this->filters['mapto']];
while (list($k,$v) = each($this->NAPTR_services)) {
printf ("<option value='%s' %s>%s",$k,$selected_naptr_service[$k],$this->NAPTR_services[$k]['webname']);
}
print "
</select>
";
printf (" <nobr>Map to<input type=text size=20 name=mapto_filter value='%s'></nobr>",$this->filters['mapto']);
}
function deleteRecord($dictionary=array()) {
if (!$dictionary['confirm'] && !$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return 1;
}
if ($dictionary['number']) {
$number=$dictionary['number'];
} else {
$number=$this->filters['number'];
}
if ($dictionary['tld']) {
$tld=$dictionary['tld'];
} else {
$tld=$this->filters['tld'];
}
if ($dictionary['mapto']) {
$mapto=$dictionary['mapto'];
} else {
$mapto=$this->filters['mapto'];
}
if (!strlen($number) || !strlen($tld)) {
print "<p><font color=red>Error: missing ENUM number or TLD </font>";
return 0;
}
$enum_id=array('number'=>$number,
'tld'=>$tld);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getNumber($enum_id);
if (!PEAR::isError($result)) {
// the number exists and we make an update
$result_new=$result;
if (count($result->mappings) > 1) {
foreach ($result->mappings as $_mapping) {
if ($_mapping->mapto != $mapto) {
$mappings_new[]=array('type' => $_mapping->type,
'mapto' => $_mapping->mapto,
'ttl' => $_mapping->ttl,
'priority' => $_mapping->priority
);
}
}
$result_new->mappings=$mappings_new;
$function=array('commit' => array('name' => 'updateNumber',
'parameters' => array($result_new),
'logs' => array('success' => sprintf('<p>ENUM mapping %s has been deleted',$mapto))),
'rollback' => array('name' => 'updateNumber',
'parameters' => array($result))
);
} else {
$function=array('commit' => array('name' => 'deleteNumber',
'parameters' => array($enum_id),
'logs' => array('success' => sprintf('<p>ENUM number +%s under %s has been deleted',$number,$tld))),
'rollback' => array('name' => 'addNumber',
'parameters' => array($result))
);
}
unset($this->filters);
return $this->SOAPEngine->execute($function);
} else {
return false;
}
}
function showAddForm() {
if ($this->selectionActive) return;
print "
<p>
<table border=0 class=border width=100%>
<tr>
";
printf ("<form method=post name=addform action=%s>",$_SERVER['PHP_SELF']);
print "
<td align=left>
";
print "
<input type=submit name=action value=Add>
";
printf (" Number +<input type=text size=15 name=number>");
printf (" TLD");
if (is_array($this->allowedDomains)) {
print "<select name=tld>";
foreach ($this->allowedDomains as $_tld) {
print "<option value=$_tld>$_tld\n";
}
print "</select>";
} else {
print "<input type=text size=15 name=tld>";
}
printf (" Map to");
print "<select name=type>
";
reset($this->NAPTR_services);
while (list($k,$v) = each($this->NAPTR_services)) {
printf ("<option value='%s' %s>%s",$k,$selected_naptr_service[$k],$this->NAPTR_services[$k]['webname']);
}
print "
</select>
";
printf (" <input type=text size=25 name=mapto>");
printf (" TTL<input type=text size=5 name=ttl value=3600>");
print "OP";
if ($this->adminonly) {
$this->showResellerForm('reseller');
print ".";
$this->showCustomerForm('customer');
} else {
$this->showCustomerForm('customer');
}
printf (" Owner<input type=text size=5 name=owner>");
printf (" Prio<input type=text size=3 name=priority>");
print "
</td>
<td align=right>
";
print "
</td>
";
$this->printHiddenFormElements();
print "
</form>
</tr>
</table>
";
}
function getAllowedDomains() {
if ($this->version > 1) {
// Filter
$filter=array('prefix' => $this->filters['prefix'],
'tld' => $this->filters['tld'],
'customer' => intval($this->filters['customer']),
'reseller' => intval($this->filters['reseller'])
);
// Range
$range=array('start' => 0,
'count' => 200
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getRanges($Query);
} else {
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getRanges();
}
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
if ($this->version > 1) {
foreach($result->ranges as $range) {
$this->ranges[]=array('prefix' => $range->id->prefix,
'tld' => $range->id->tld,
'minDigits' => $range->minDigits,
'maxDigits' => $range->maxDigits
);
if (in_array($range->id->tld,$this->allowedDomains)) continue;
$this->allowedDomains[]=$range->id->tld;
$seen[$range->id->tld]++;
}
} else {
foreach($result as $range) {
$this->ranges[]=array('prefix' => $range->id->prefix,
'tld' => $range->id->tld,
'minDigits' => $range->minDigits,
'maxDigits' => $range->maxDigits
);
if (in_array($range->id->tld,$this->allowedDomains)) continue;
$this->allowedDomains[]=$range->id->tld;
$seen[$range->id->tld]++;
}
}
if (strlen($this->SOAPEngine->defaultEnumTLD) && !$seen[$this->SOAPEngine->defaultEnumTLD]) {
$this->allowedDomains[]=$this->SOAPEngine->defaultEnumTLD;
}
}
}
function addRecord($dictionary=array()) {
if ($dictionary['tld']) {
$tld=$dictionary['tld'];
} else {
$tld = trim($_REQUEST['tld']);
}
if ($dictionary['number']) {
$number=$dictionary['number'];
} else {
$number = trim($_REQUEST['number']);
}
if (!strlen($tld)) {
if (strlen($this->SOAPEngine->defaultEnumTLD)) {
$tld=$this->SOAPEngine->defaultEnumTLD;
} else {
$tld='e164.arpa';
}
}
if (!strlen($tld) || !strlen($number) || !is_numeric($number)) {
printf ("<p><font color=red>Error: Missing TLD or number. </font>");
return false;
}
if ($this->adminonly) {
if ($dictionary['reseller']) {
$reseller=$dictionary['reseller'];
} else {
$reseller = trim($_REQUEST['reseller']);
}
if ($dictionary['customer']) {
$customer=$dictionary['customer'];
} else {
$customer = trim($_REQUEST['customer']);
}
if (!$customer) $customer=$reseller;
} else {
$reseller = $this->reseller;
if ($dictionary['customer']) {
$customer=$dictionary['customer'];
} else {
$customer = trim($_REQUEST['customer']);
}
if (!$customer || !in_array($customer,array_keys($this->customers))) {
$customer=$reseller;
}
}
if ($dictionary['ttl']) {
$ttl = intval($dictionary['ttl']);
} else {
$ttl = intval(trim($_REQUEST['ttl']));
}
if (!$ttl) $ttl=3600;
if ($dictionary['priority']) {
$priority = intval($dictionary['priority']);
} else {
$priority = intval(trim($_REQUEST['priority']));
}
if ($dictionary['owner']) {
$owner = intval($dictionary['owner']);
} else {
$owner = intval(trim($_REQUEST['owner']));
}
if (!$priority) $priority=5;
$enum_id=array('number' => $number,
'tld' => $tld);
if ($dictionary['mapto']) {
$mapto = $dictionary['mapto'];
} else {
$mapto = trim($_REQUEST['mapto']);
}
if ($dictionary['type']) {
$type = $dictionary['type'];
} else {
$type = trim($_REQUEST['type']);
}
if (preg_match("/^([a-z0-9]+:\/\/)(.*)$/i",$mapto,$m)) {
$_scheme = $m[1];
$_value = $m[2];
} else if (preg_match("/^([a-z0-9]+:)(.*)$/i",$mapto,$m)) {
$_scheme = $m[1];
$_value = $m[2];
} else {
$_scheme = '';
$_value = $mapto;
}
if (!$_value) {
$lastNumber=$this->getLastNumber();
foreach($lastNumber['mappings'] as $_mapping) {
if ($_mapping->type == trim($type)) {
if (preg_match("/^(.*)@(.*)$/",$_mapping->mapto,$m)) {
$_value = $number.'@'.$m[2];
break;
}
}
}
}
if (!$_scheme || !in_array($_scheme,$this->NAPTR_services[trim($type)]['schemas'])) {
$_scheme=$this->NAPTR_services[trim($type)]['schemas'][0];
}
$mapto=$_scheme.$_value;
$enum_number=array('id' => $enum_id,
'owner' => $owner,
'customer' => intval($customer),
'reseller' => intval($reseller),
'mappings' => array(array('type' => $type,
'mapto' => $mapto,
'ttl' => $ttl,
'priority' => $priority
)
)
);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getNumber($enum_id);
if (PEAR::isError($result)) {
$error_msg=$result->getMessage();
$error_fault=$result->getFault();
$error_code=$result->getCode();
if ($error_fault->detail->exception->errorcode == "3002") {
$function=array('commit' => array('name' => 'addNumber',
'parameters' => array($enum_number),
'logs' => array('success' => sprintf('<p>ENUM number +%s under %s has been added',$number,$tld))),
'rollback' => array('name' => 'deleteNumber',
'parameters' => array($enumId))
);
return $this->SOAPEngine->execute($function);
} else {
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
}
} else {
// the number exists and we make an update
$result_new=$result;
foreach ($result->mappings as $_mapping) {
$mappings_new[]=array('type' => $_mapping->type,
'mapto' => $_mapping->mapto,
'ttl' => $_mapping->ttl,
'priority' => $_mapping->priority
);
if ($_mapping->mapto == $mapto) {
printf ("<p><font color=blue>Info: ENUM mapping %s for number %s already exists</font>",$mapto,$number);
return true;
break;
}
}
$mappings_new[]=array('type' => trim($type),
'mapto' => $mapto,
'ttl' => intval(trim($_REQUEST['ttl'])),
'priority'=> intval(trim($_REQUEST['priority'])),
);
// add mapping
$result_new->mappings=$mappings_new;
$function=array('commit' => array('name' => 'updateNumber',
'parameters' => array($result_new),
'logs' => array('success' => sprintf('<p>ENUM number +%s under %s has been updated',$number,$tld))),
'rollback' => array('name' => 'updateNumber',
'parameters' => array($result))
);
return $this->SOAPEngine->execute($function);
}
return true;
}
function getRecordKeys() {
// Filter
$filter=array('number' => $this->filters['number'],
'type' => $this->filters['type'],
'mapto' => $this->filters['mapto']
);
// Range
$range=array('start' => 0,
'count' => 1000
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
// Call function
$result = $this->SOAPEngine->soapclient->getNumbers($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
foreach ($result->numbers as $number) {
$this->selectionKeys[]=array('number' => $number->id->number,
'tld' => $number->id->tld);
}
return true;
}
}
}
class TrustedPeers extends Records {
var $sortElements=array(
'description' => 'Description',
'ip' =>'IP address'
);
function TrustedPeers(&$SOAPEngine) {
$this->filters = array('ip' => trim($_REQUEST['ip_filter']),
'description' => trim($_REQUEST['description_filter'])
);
$this->Records(&$SOAPEngine);
}
function listRecords() {
$this->showSeachForm();
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
// Filter
$filter=array('ip' => $this->filters['ip'],
'description' => $this->filters['description']
);
// Range
$range=array('start' => intval($this->next),
'count' => intval($this->maxrowsperpage)
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'description';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Call function
$result = $this->SOAPEngine->soapclient->getTrustedPeers($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
$this->rows = $result->total;
if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') {
$this->showActionsForm();
}
print "
<table border=0 align=center>
<tr><td>$this->rows records found</td></tr>
</table>
<p>
<table border=0 cellpadding=2 width=100%>
<tr bgcolor=lightgrey>
<td><b>Id</b></th>
";
if ($this->version > 1) print "<td><b>Operator</b></td>";
print"
<td><b>IP address</b></td>
<td><b>Protocol</b></td>
<td><b>From pattern</b></td>
<td><b>Description</b></td>
<td><b>Owner</b></td>
<td><b>Action</b></td>
</tr>
";
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows=$this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
if (!$result->peers[$i]) break;
$peer = $result->peers[$i];
$index=$this->next+$i+1;
$rr=floor($index/2);
$mod=$index-$rr*2;
if ($mod ==0) {
$bgcolor="lightgrey";
} else {
$bgcolor="white";
}
$_url = $this->url.sprintf("&service=%s&action=Delete&ip_filter=%s",
urlencode($this->SOAPEngine->service),
urlencode($peer->ip)
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['ip_filter'] == $peer->ip) {
$_url .= "&confirm=1";
$actionText = "<font color=red>Confirm</font>";
} else {
$actionText = "Delete";
}
if ($this->version > 1) {
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s.%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
$index,
$peer->reseller,
$peer->customer,
$peer->ip,
$peer->protocol,
$peer->fromPattern,
$peer->description,
$peer->owner,
$_url,
$actionText
);
} else {
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
$index,
$peer->ip,
$peer->protocol,
$peer->fromPattern,
$peer->description,
$peer->owner,
$_url,
$actionText
);
}
printf("
</tr>
");
$i++;
}
}
print "</table>";
$this->showPagination($maxrows);
return true;
}
}
function showAddForm() {
if ($this->selectionActive) return;
print "
<p>
<table border=0 class=border width=100%>
<tr>
";
printf ("<form method=post name=addform action=%s>",$_SERVER['PHP_SELF']);
print "
<td align=left>
";
print "
<input type=submit name=action value=Add>
";
printf (" IP address<input type=text size=20 name=ipaddress>");
printf (" Description<input type=text size=30 name=description>");
print "OP";
if ($this->adminonly) {
$this->showResellerForm('reseller');
print ".";
$this->showCustomerForm('customer');
} else {
$this->showCustomerForm('customer');
}
printf (" Owner<input type=text size=5 name=owner>");
print "
</td>
<td align=right>
";
print "
</td>
";
$this->printHiddenFormElements();
print "
</form>
</tr>
</table>
";
}
function addRecord() {
$ipaddress = trim($_REQUEST['ipaddress']);
$description = trim($_REQUEST['description']);
$owner = trim($_REQUEST['owner']);
if ($this->adminonly) {
$reseller = trim($_REQUEST['reseller']);
$customer = trim($_REQUEST['customer']);
if (!$customer) $customer=$reseller;
} else {
$reseller = $this->reseller;
$customer = trim($_REQUEST['customer']);
if (!$customer || !in_array($customer,array_keys($this->customers))) {
$customer=$reseller;
}
}
if (!strlen($ipaddress) || !strlen($description)) {
printf ("<p><font color=red>Error: Missing IP or description. </font>");
return false;
}
$peer=array(
'ip' => $ipaddress,
'description' => $description,
'owner' => intval($_REQUEST['owner']),
'customer' => intval($customer),
'reseller' => intval($reseller)
);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->addTrustedPeer($peer);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>Trusted peers %s has been added. </font>",$ipaddress);
return 1;
}
}
function deleteRecord() {
if (!$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return 1;
}
if (!strlen($this->filters['ip']) || !strlen($this->filters['ip'])) {
print "<p><font color=red>Error: missing IP address. </font>";
return 0;
}
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->deleteTrustedPeer($this->filters['ip']);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>Trusted peer %s has been deleted. </font> ",$this->filters['ip']);
unset($this->filters);
return 1;
}
}
}
class GatewayGroups extends Records {
var $sortElements=array(
'name' => 'Name'
);
function GatewayGroups(&$SOAPEngine) {
$this->filters = array('group' => trim($_REQUEST['group_filter'])
);
$this->Records(&$SOAPEngine);
}
function listRecords() {
$this->showSeachForm();
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
// Filter
$filter=array('name' => $this->filters['group']
);
// Range
$range=array('start' => intval($this->next),
'count' => intval($this->maxrowsperpage)
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'name';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Call function
$result = $this->SOAPEngine->soapclient->getGatewayGroups($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
$this->rows = $result->total;
print "
<table border=0 align=center>
<tr><td>$this->rows records found</td></tr>
</table>
<p>
<table border=0 cellpadding=2 width=100%>
<tr bgcolor=lightgrey>
<td><b>Id</b></th>
<td><b>Name</b></th>
<td><b>Action</b></td>
</tr>
";
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows=$this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
if (!$result->groups[$i]) break;
$group = $result->groups[$i];
$index=$this->next+$i+1;
$rr=floor($index/2);
$mod=$index-$rr*2;
if ($mod ==0) {
$bgcolor="lightgrey";
} else {
$bgcolor="white";
}
$_url = $this->url.sprintf("&service=%s&action=Delete&group_filter=%s",
urlencode($this->SOAPEngine->service),
urlencode($group)
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['group_filter'] == $group) {
$_url .= "&confirm=1";
$actionText = "<font color=red>Confirm</font>";
} else {
$actionText = "Delete";
}
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
$index,
$group,
$_url,
$actionText
);
printf("
</tr>
");
$i++;
}
}
print "</table>";
$this->showPagination($maxrows);
return true;
}
}
function showAddForm() {
if ($this->selectionActive) return;
print "
<p>
<table border=0 class=border width=100%>
<tr>
";
printf ("<form method=post name=addform action=%s>",$_SERVER['PHP_SELF']);
print "
<td align=left>
";
print "
<input type=submit name=action value=Add>
";
printf (" Name<input type=text size=20 name=name>");
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getGatewayGroups();
print "
</td>
<td align=right>
";
print "
</td>
";
$this->printHiddenFormElements();
print "
</form>
</tr>
</table>
";
}
function addRecord() {
$name = trim($_REQUEST['name']);
if (!strlen($name)) {
printf ("<p><font color=red>Error: Missing name. </font>");
return false;
}
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->addGatewayGroup($name);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>Gateway group %s has been added. </font>",$name);
return 1;
}
}
function deleteRecord() {
if (!$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return 1;
}
if (!strlen($this->filters['group'])) {
print "<p><font color=red>Error: missing gateway group. </font>";
return 0;
}
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->deleteGatewayGroup($this->filters['group']);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>Gateway %s has been deleted. </font> ",$this->filters['group']);
unset($this->filters);
return 1;
}
}
function showSeachFormCustom() {
printf (" Group<input type=text size=15 name=group_filter value='%s'>",$this->filters['group']);
}
}
class Gateways extends Records {
var $sortElements=array(
'name' => 'Name',
'group' => 'Group',
'ip' => 'IP address',
'prefix' => 'Prefix'
);
function Gateways(&$SOAPEngine) {
$this->filters = array('name' => trim($_REQUEST['name_filter']),
'group' => trim($_REQUEST['group_filter'])
);
$this->Records(&$SOAPEngine);
}
function listRecords() {
$this->showSeachForm();
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
// Filter
$filter=array('name' => $this->filters['name'],
'group' => $this->filters['group']
);
// Range
$range=array('start' => intval($this->next),
'count' => intval($this->maxrowsperpage)
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'name';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Call function
$result = $this->SOAPEngine->soapclient->getGateways($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
$this->rows = $result->total;
print "
<table border=0 align=center>
<tr><td>$this->rows records found</td></tr>
</table>
<p>
<table border=0 cellpadding=2 width=100%>
<tr bgcolor=lightgrey>
<td><b>Id</b></th>
<td><b>Name</b></th>
<td><b>Group</b></td>
<td><b>Address</b></td>
<td><b>Strip</b></td>
<td><b>Prefix</b></td>
<td><b>Action</b></td>
</tr>
";
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows=$this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
if (!$result->gateways[$i]) break;
$gateway = $result->gateways[$i];
$index=$this->next+$i+1;
$rr=floor($index/2);
$mod=$index-$rr*2;
if ($mod ==0) {
$bgcolor="lightgrey";
} else {
$bgcolor="white";
}
$_url = $this->url.sprintf("&service=%s&action=Delete&name_filter=%s",
urlencode($this->SOAPEngine->service),
urlencode($gateway->name)
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['name_filter'] == $gateway->name) {
$_url .= "&confirm=1";
$actionText = "<font color=red>Confirm</font>";
} else {
$actionText = "Delete";
}
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s:%s:%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
$index,
$gateway->name,
$gateway->group,
$gateway->transport,
$gateway->ip,
$gateway->port,
$gateway->strip,
$gateway->prefix,
$_url,
$actionText
);
printf("
</tr>
");
$i++;
}
}
print "</table>";
$this->showPagination($maxrows);
return true;
}
}
function showAddForm() {
if ($this->selectionActive) return;
print "
<p>
<table border=0 class=border width=100%>
<tr>
";
printf ("<form method=post name=addform action=%s>",$_SERVER['PHP_SELF']);
print "
<td align=left>
";
print "
<input type=submit name=action value=Add>
";
printf (" Name<input type=text size=20 name=name>");
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getGatewayGroups();
printf (" Group: ");
// Compose query
$Query=array('filter' => array('name'=>''),
'orderBy' => array('attribute' => 'name',
'direction' => 'ASC'
),
'range' => array('start' => 0,
'count' => 1000)
);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getGatewayGroups($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
print "<select name=group> ";
foreach ($result->groups as $_grp) {
printf ("<option value='%s'>%s",$_grp,$_grp);
}
printf (" </select>");
}
printf (" Address<input type=text size=25 name=address>");
printf (" Strip: <select name=strip>");
$t=0;
while ($t<10) {
print "<option value=$t>$t";
$t++;
}
print "</select>";
printf (" Prefix<input type=text size=5 name=prefix>");
print "
</td>
<td align=right>
";
print "
</td>
";
$this->printHiddenFormElements();
print "
</form>
</tr>
</table>
";
}
function addRecord() {
$name = trim($_REQUEST['name']);
$group = trim($_REQUEST['group']);
$address = trim($_REQUEST['address']);
$strip = trim($_REQUEST['strip']);
$prefix = trim($_REQUEST['prefix']);
if (!strlen($name) || !strlen($group) || !strlen($address)) {
printf ("<p><font color=red>Error: Missing name, group or address. </font>");
return false;
}
$address_els=explode(':',$address);
if (count($address_els) == 1) {
$ip=$address_els[0];
$transport='udp';
$port='5060';
} else if (count($address_els) == 2) {
$ip=$address_els[0];
$port=$address_els[1];
$transport='udp';
} else if (count($address_els) == 3) {
$ip=$address_els[1];
$port=intval($address_els[2]);
if ($address_els[0] == 'tcp' || $address_els[0] == 'tls' || $address_els[0] == 'udp') {
$transport=$address_els[0];
} else {
$transport='udp';
}
}
$gateway=array(
'name' => $name,
'group' => $group,
'ip' => $ip,
'port' => intval($port),
'uriScheme' => 'sip',
'transport' => $transport,
'strip' => intval($_REQUEST['strip']),
'prefix' => $_REQUEST['prefix']
);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->addGateway($gateway);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>Gateway %s has been added. </font>",$address);
return 1;
}
}
function deleteRecord() {
if (!$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return 1;
}
if (!strlen($this->filters['name'])) {
print "<p><font color=red>Error: missing gateway name. </font>";
return 0;
}
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->deleteGateway($this->filters['name']);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>Gateway %s has been deleted. </font> ",$this->filters['address']);
unset($this->filters);
return 1;
}
}
function showSeachFormCustom() {
printf (" Name<input type=text size=15 name=name_filter value='%s'>",$this->filters['name']);
printf (" Group<input type=text size=15 name=group_filter value='%s'>",$this->filters['group']);
}
}
class Routes extends Records {
var $gatewayGroups=array();
var $sortElements=array(
'prefix' => 'Prefix',
'fromURI' => 'From URI',
'priority' => 'Priority'
);
function Routes(&$SOAPEngine) {
$this->filters = array('prefix' => trim($_REQUEST['prefix_filter']),
'gatewayGroup' => trim($_REQUEST['gatewayGroup_filter']),
'fromURI' => trim($_REQUEST['fromURI_filter'])
);
$this->Records(&$SOAPEngine);
}
function listRecords() {
// Get gateway groups
$Query=array('filter' => array('name'=>''),
'orderBy' => array('attribute' => 'name',
'direction' => 'ASC'
),
'range' => array('start' => 0,
'count' => 1000)
);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getGatewayGroups($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
$this->gatewayGroups=$result->groups;
}
$this->showSeachForm();
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
// Filter
$filter=array('prefix' => $this->filters['prefix'],
'gatewayGroup' => $this->filters['gatewayGroup'],
'fromURI' => $this->filters['fromURI']
);
// Range
$range=array('start' => intval($this->next),
'count' => intval($this->maxrowsperpage)
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'prefix';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Call function
$result = $this->SOAPEngine->soapclient->getRoutes($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
$this->rows = $result->total;
print "
<table border=0 align=center>
<tr><td>$this->rows records found</td></tr>
</table>
<p>
<table border=0 cellpadding=2 width=100%>
<tr bgcolor=lightgrey>
<td><b>Id</b></th>
<td><b>Prefix</b></th>
<td><b>Gateway Group</b></td>
<td><b>From URI</b></td>
<td><b>Priority</b></td>
<td><b>Action</b></td>
</tr>
";
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows=$this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
if (!$result->routes[$i]) break;
$route = $result->routes[$i];
$index=$this->next+$i+1;
$rr=floor($index/2);
$mod=$index-$rr*2;
if ($mod ==0) {
$bgcolor="lightgrey";
} else {
$bgcolor="white";
}
$_url = $this->url.sprintf("&service=%s&action=Delete&prefix_filter=%s&gatewayGroup_filter=%s&fromURI_filter=%s&priority_filter=%s",
urlencode($this->SOAPEngine->service),
urlencode($route->prefix),
urlencode($route->gatewayGroup),
urlencode($route->fromURI),
urlencode($route->priority)
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['prefix_filter'] == $route->prefix &&
$_REQUEST['gatewayGroup_filter'] == $route->gatewayGroup &&
$_REQUEST['fromURI_filter'] == $route->fromURI &&
$_REQUEST['priority_filter'] == $route->priority) {
$_url .= "&confirm=1";
$actionText = "<font color=red>Confirm</font>";
} else {
$actionText = "Delete";
}
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
$index,
$route->prefix,
$route->gatewayGroup,
$route->fromURI,
$route->priority,
$_url,
$actionText
);
printf("
</tr>
");
$i++;
}
}
print "</table>";
$this->showPagination($maxrows);
return true;
}
}
function showAddForm() {
if ($this->selectionActive) return;
print "
<p>
<table border=0 class=border width=100%>
<tr>
";
printf ("<form method=post name=addform action=%s>",$_SERVER['PHP_SELF']);
print "
<td align=left>
";
print "
<input type=submit name=action value=Add>
";
printf (" Prefix<input type=text size=20 name=prefix>");
printf (" Group: ");
print "<select name=gatewayGroup> ";
foreach ($this->gatewayGroups as $_grp) {
printf ("<option value='%s'>%s",$_grp,$_grp);
}
printf (" </select>");
printf (" From<input type=text size=25 name=fromURI>");
printf (" Priority<input type=text size=5 name=priority>");
print "
</td>
<td align=right>
";
print "
</td>
";
$this->printHiddenFormElements();
print "
</form>
</tr>
</table>
";
}
function addRecord() {
$prefix = trim($_REQUEST['prefix']);
$gatewayGroup = trim($_REQUEST['gatewayGroup']);
$fromURI = trim($_REQUEST['fromURI']);
$priority = trim($_REQUEST['priority']);
if (!strlen($prefix) || !strlen($gatewayGroup)) {
printf ("<p><font color=red>Error: Missing prefix or gatewayGroup. </font>");
return false;
}
$route=array(
'prefix' => $prefix,
'gatewayGroup' => $gatewayGroup,
'fromURI' => $fromURI,
'priority' => intval($priority)
);
$routes=array($route);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->addRoutes($routes);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>Route %s has been added. </font>",$prefix);
return 1;
}
}
function deleteRecord() {
if (!$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return 1;
}
if (!strlen($this->filters['prefix']) || !strlen($this->filters['gatewayGroup'])) {
print "<p><font color=red>Error: missing route prefix or gatewayGroup. </font>";
return 0;
}
$route=array(
'prefix' => $this->filters['prefix'],
'gatewayGroup' => $this->filters['gatewayGroup'],
'fromURI' => $this->filters['fromURI'],
'priority' => intval($this->filters['priority'])
);
$routes=array($route);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->deleteRoutes($routes);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>Route %s has been deleted. </font> ",$this->filters['prefix']);
unset($this->filters);
return 1;
}
}
function showSeachFormCustom() {
printf (" Prefix<input type=text size=15 name=prefix_filter value='%s'>",$this->filters['prefix']);
print "<select name=gatewayGroup_filter>
<option>";
$selected_gatewayGroups[$this->filters['gatewayGroup']]='selected';
foreach ($this->gatewayGroups as $_grp) {
printf ("<option value='%s' %s>%s",$_grp,$selected_gatewayGroups[$_grp],$_grp);
}
printf (" </select>");
printf (" From URI<input type=text size=15 name=fromURI_filter value='%s'>",$this->filters['fromURI']);
}
}
class DomainStatistics extends Records {
var $maxrowsperpage= 200;
function DomainStatistics(&$SOAPEngine) {
$this->filters = array(
'domain' => trim($_REQUEST['domain_filter'])
);
$this->Records(&$SOAPEngine);
}
function listRecords() {
$this->showSeachForm();
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$filter=$this->filters['domain'];
// Call function
$result = $this->SOAPEngine->soapclient->getDomainStatistics($filter);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
$this->rows = count($result);
//print_r($result);
print "
<table border=0 align=center>
<tr><td>$this->rows records found</td></tr>
</table>
<p>
<table border=0 cellpadding=2 width=100%>
<tr bgcolor=lightgrey>
<td><b>Id</b></th>
<td><b>SIP domain</b></td>
<td><b>SIP subscribers</b></td>
<td><b>Online subscribers</b></td>
<td><b>Online SIP devices</b></td>
</tr>
";
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows=$this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
$domain = $result[$i];
if (!strlen($domain->users)) break;
$index = $this->next+$i+1;
$rr=floor($index/2);
$mod=$index-$rr*2;
if ($mod ==0) {
$bgcolor="lightgrey";
} else {
$bgcolor="white";
}
$_url = $this->url.sprintf("&service=%s&action=Delete&domain_filter=%s",
urlencode($this->SOAPEngine->service),
urlencode($domain->domain)
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['domain_filter'] == $domain->domain) {
$_url .= "&confirm=1";
$actionText = "<font color=red>Confirm</font>";
} else {
$actionText = "Delete";
}
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>",
$bgcolor,
$index,
$domain->domain,
$domain->users,
$domain->onlineUsers,
$domain->onlineDevices
);
$i++;
}
}
print "</table>";
$this->showPagination($maxrows);
return true;
}
}
function showSeachFormCustom() {
printf (" Domain<input type=text size=15 name=domain_filter value='%s'>",$this->filters['domain']);
}
function deleteRecord() {
if (!$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return 1;
}
if (!strlen($this->filters['domain']) || !strlen($this->filters['domain'])) {
print "<p><font color=red>Error: missing SIP domain. </font>";
return 0;
}
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->deleteDomain($this->filters['domain']);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>SIP domain %s has been deleted. </font> ",$this->filters['domain']);
unset($this->filters);
return 1;
}
}
function addRecord() {
$domain=trim($_REQUEST['domain']);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->addDomain($domain);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>SIP domain %s has been added. </font>",$domain);
return 1;
}
}
}
class Customers extends Records {
var $maxrowsperpage= 20;
var $sortElements=array(
'customer' => 'Customer',
'reseller' => 'Reseller',
'username' => 'Username',
'changeDate' => 'Change date'
);
+ var $preferenceItems = array('sip_credit' => array('name' => 'Credit for SIP account creation',
+ 'category' => 'admin'),
+ 'enum_credit' => array('name' => 'Credit for ENUM numbers creation',
+ 'category' => 'admin'),
+ 'sipa_credit' => array('name' => 'Credit for SIP alias creation',
+ 'category' => 'admin'),
+ 'pstn_access' => array('name' => 'Access to PSTN',
+ 'category' => 'admin'),
+ 'language' => array('name' => 'Language',
+ 'category' => 'general'),
+ 'timezone' => array('name' => 'Timezone',
+ 'category' => 'general'),
+ 'voicemail_server' => array('name' => 'Voicemail server address',
+ 'category' => 'sip'),
+ 'sip_proxy_server' => array('name' => 'SIP Proxy server address',
+ 'category' => 'sip'),
+ 'support_web_site' => array('name' => 'Support web site',
+ 'category' => 'sip'),
+ 'default_sip_domain' => array('name' => 'Default SIP domain',
+ 'category' => 'sip'),
+ 'default_enum_range' => array('name' => 'Default ENUM range',
+ 'category' => 'sip'),
+ 'default_enum_tld' => array('name' => 'Default ENUM Top Level Domain',
+ 'category' => 'sip')
+ );
+
function Customers(&$SOAPEngine) {
$this->filters = array(
'username' => trim($_REQUEST['username_filter'])
);
$this->Records(&$SOAPEngine);
}
function listRecords() {
// Filter
$filter=array('username' => $this->filters['username'],
'customer' => intval($this->filters['customer']),
'reseller' => intval($this->filters['reseller'])
);
// Range
$range=array('start' => intval($this->next),
'count' => intval($this->maxrowsperpage)
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'customer';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC';
$orderBy = array('attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query=array('filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
$this->showSeachForm();
// Insert credetials
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
// Call function
$result = $this->SOAPEngine->soapclient->getCustomers($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
$this->rows = $result->total;
if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') {
$this->showActionsForm();
}
print "
<table border=0 align=center>
<tr><td>$this->rows records found</td></tr>
</table>
<p>
<table border=0 cellpadding=2 width=100%>
<tr bgcolor=lightgrey>
<td><b>Id</b></th>
";
if ($this->version > 1) print "<td><b>Operator</b></td>";
print"
<td><b>Name</b></td>
<td><b>Organization</b></td>
<td><b>E-mail</b></td>
<td><b>Telephone</b></td>
<td><b>Web</b></td>
<td><b>Action</b></td>
</tr>
";
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows=$this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
if (!$result->accounts[$i]) break;
$customer = $result->accounts[$i];
$index = $this->next+$i+1;
$rr=floor($index/2);
$mod=$index-$rr*2;
if ($mod ==0) {
$bgcolor="lightgrey";
} else {
$bgcolor="white";
}
$_url = $this->url.sprintf("&service=%s&action=Delete&customer_filter=%s",
urlencode($this->SOAPEngine->service),
urlencode($customer->id)
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['customer_filter'] == $customer->id) {
$_url .= "&confirm=1";
$actionText = "<font color=red>Confirm</font>";
} else {
$actionText = "Delete";
}
printf("
<tr bgcolor=%s>
<td>%s</td>
<td>%s.%s</td>
<td>%s %s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href=%s>%s</a></td>
</tr>",
$bgcolor,
$index,
$customer->reseller,
$customer->id,
$customer->firstName,
$customer->lastName,
$customer->organization,
$customer->email,
$customer->tel,
$customer->web,
$_url,
$actionText
);
$i++;
}
}
print "</table>";
$this->showPagination($maxrows);
return true;
}
}
function showSeachFormCustom() {
if (!$this->filters['reseller']) {
printf (" Customer<input type=text size=6 name=customer_filter value='%s'>",$this->filters['customer']);
}
printf (" Username<input type=text size=10 name=username_filter value='%s'>",$this->filters['username']);
}
function deleteRecord() {
if (!$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return 1;
}
if (!strlen($this->filters['customer']) || !strlen($this->filters['customer'])) {
print "<p><font color=red>Error: missing customer id. </font>";
return 0;
}
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->deleteAccount(intval($this->filters['customer']));
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
printf ("<p><font color=green>Customer id %s has been deleted. </font> ",$this->filters['customer']);
unset($this->filters);
return 1;
}
}
}
class recordsGenerator {
function recordsGenerator() {
}
function showAddForm() {
print "
<p>
<table border=0 class=border width=100%>
<tr>
";
printf ("<form method=post name=addform action=%s>",$_SERVER['PHP_SELF']);
print "
<td align=left>
";
print "
<input type=submit name=action value=Generate>
";
printf (" Name<input type=text size=20 name=name>");
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getGatewayGroups();
printf (" Group: ");
// Compose query
$Query=array('filter' => array('name'=>''),
'orderBy' => array('attribute' => 'name',
'direction' => 'ASC'
),
'range' => array('start' => 0,
'count' => 1000)
);
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getGatewayGroups($Query);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<p><font color=red>Error from %s: %s (%s): %s</font>",$this->SOAPEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
return false;
} else {
print "<select name=group> ";
foreach ($result->groups as $_grp) {
printf ("<option value='%s'>%s",$_grp,$_grp);
}
printf (" </select>");
}
printf (" Address<input type=text size=25 name=address>");
printf (" Strip: <select name=strip>");
$t=0;
while ($t<10) {
print "<option value=$t>$t";
$t++;
}
print "</select>";
printf (" Prefix<input type=text size=5 name=prefix>");
print "
</td>
<td align=right>
";
print "
</td>
";
$this->printHiddenFormElements();
print "
</form>
</tr>
</table>
";
}
}
class Actions {
var $actions=array();
function Actions(&$SOAPEngine) {
$this->SOAPEngine = $SOAPEngine;
$this->adminonly = $this->SOAPEngine->adminonly;
}
function performActions($selectionKeys,$action,$sub_action_parameter) {
}
function showActionsForm($filters,$sorting,$hideParameter=false) {
if (!count($this->actions)) return;
print "
<p>
<table border=0 class=border width=100%>
<tr>
";
printf ("<form method=post name=actionform action=%s>",$_SERVER['PHP_SELF']);
print "
<td align=left>
";
print "
<input type=submit value='Perform this action on the selection:'>
<input type=hidden name=action value=PerformActions>
";
if ($this->adminonly) {
print "
<input type=hidden name=adminonly value=$this->adminonly>
";
}
print "<select name=sub_action>";
$j=0;
foreach (array_keys($this->actions) as $_action) {
$j++;
printf ("<option value='%s'>%d. %s",$_action,$j,$this->actions[$_action]);
}
print "</select>";
if (!$hideParameter) {
print "
<input type=text size=15 name=sub_action_parameter>
";
}
print "
</td>
<td align=right>
";
print "
</td>
";
foreach (array_keys($filters) as $_filter) {
printf ("<input type=hidden name='%s_filter' value='%s'>\n", $_filter,$filters[$_filter]);
}
foreach (array_keys($sorting) as $_sorting) {
printf ("<input type=hidden name='%s' value='%s'>\n", $_sorting,$sorting[$_sorting]);
}
printf("<input type=hidden name=service value='%s'>",$this->SOAPEngine->service);
foreach (array_keys($this->SOAPEngine->extraFormElements) as $element) {
if (!strlen($this->SOAPEngine->extraFormElements[$element])) continue;
printf ("<input type=hidden name=%s value='%s'>\n",$element,$this->SOAPEngine->extraFormElements[$element]);
}
print "
</form>
</tr>
</table>
";
}
}
class SIPAccountsActions extends Actions {
var $actions=array('block' => 'Block SIP accounts',
'deblock' => 'Deblock SIP accounts',
'enable_pstn' => 'Enable access to PSTN for the SIP accounts',
'disable_pstn' => 'Disable access to PSTN for the SIP accounts',
'deblock_quota' => 'Deblock SIP accounts blocked by quota',
'prepaid' => 'Make SIP accounts prepaid',
'postpaid' => 'Make SIP accounts postpaid',
'delete' => 'Delete SIP accounts',
'setquota' => 'Set quota of SIP account to:',
'rpidasusername' => 'Set PSTN caller ID as the username',
'prefixtorpid' => 'Add to PSTN caller ID this prefix:',
'rmdsfromrpid' => 'Remove from PSTN caller ID digits:',
'addtogroup' => 'Add SIP accounts to group:',
'removefromgroup'=> 'Remove SIP accounts from group:',
'addbalance' => 'Add to prepaid balance value:'
);
function SIPAccountsActions(&$SOAPEngine) {
$this->Actions(&$SOAPEngine);
}
function performActions($selectionKeys,$action,$sub_action_parameter) {
if (!in_array($action,array_keys($this->actions))) {
print "<font color=red>Error: Invalid action $action</font>";
return false;
}
print "<ol>";
foreach($selectionKeys as $key) {
print "<li>";
flush();
//printf ("Performing action=%s on key=%s",$action,$key);
$account=array('username' => $key['username'],
'domain' => $key['domain']
);
if ($action=='block') {
$function=array('commit' => array('name' => 'addToGroup',
'parameters' => array($account,'block'),
'logs' => array('success' => sprintf('SIP account %s@%s has been blocked',$key['username'],$key['domain'])
)
)
);
$this->SOAPEngine->execute($function);
} else if ($action=='deblock') {
$function=array('commit' => array('name' => 'removeFromGroup',
'parameters' => array($account,'block'),
'logs' => array('success' => sprintf('SIP account %s@%s has been de-blocked',$key['username'],$key['domain'])
)
)
);
$this->SOAPEngine->execute($function);
} else if ($action=='removefromgroup') {
if (!strlen($sub_action_parameter)) {
printf ("<font color=red>Error: you must enter a group name</font>");
break;
}
$function=array('commit' => array('name' => 'removeFromGroup',
'parameters' => array($account,$sub_action_parameter),
'logs' => array('success' => sprintf('SIP account %s@%s has been removed from group',$key['username'],$key['domain'],$sub_action_parameter)
)
)
);
$this->SOAPEngine->execute($function);
} else if ($action=='addtogroup') {
if (!strlen($sub_action_parameter)) {
printf ("<font color=red>Error: you must enter a group name</font>");
break;
}
$function=array('commit' => array('name' => 'addToGroup',
'parameters' => array($account,$sub_action_parameter),
'logs' => array('success' => sprintf('SIP account %s@%s is now in group %s',$key['username'],$key['domain'],$sub_action_parameter)
)
)
);
$this->SOAPEngine->execute($function);
} else if ($action=='deblock_quota') {
$function=array('commit' => array('name' => 'removeFromGroup',
'parameters' => array($account,'quota'),
'logs' => array('success' => sprintf('SIP account %s@%s has been deblocked from quota',$key['username'],$key['domain'])
)
)
);
$this->SOAPEngine->execute($function);
} else if ($action=='disable_pstn') {
$function=array('commit' => array('name' => 'removeFromGroup',
'parameters' => array($account,'free-pstn'),
'logs' => array('success' => sprintf('SIP account %s@%s has no access to the PSTN',$key['username'],$key['domain'])
)
)
);
$this->SOAPEngine->execute($function);
} else if ($action=='enable_pstn') {
$function=array('commit' => array('name' => 'addToGroup',
'parameters' => array($account,'free-pstn'),
'logs' => array('success' => sprintf('SIP account %s@%s has access to the PSTN',$key['username'],$key['domain'])
)
)
);
$this->SOAPEngine->execute($function);
} else if ($action=='delete') {
$function=array('commit' => array('name' => 'deleteAccount',
'parameters' => array($account),
'logs' => array('success' => sprintf('SIP account %s@%s has been deleted',$key['username'],$key['domain'])
)
)
);
$this->SOAPEngine->execute($function);
} else if ($action=='prepaid') {
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getAccount($account);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<font color=red>Error: %s (%s): %s</font>",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
break;
} else {
//print_r($result);
// Sanitize data types due to PHP bugs
if (!is_array($result->properties)) $result->properties=array();
if (!is_array($result->groups)) $result->groups=array();
$result->quota = intval($result->quota);
$result->answerTimeout = intval($result->answerTimeout);
$result->prepaid=1;
$function=array('commit' => array('name' => 'updateAccount',
'parameters' => array($result),
'logs' => array('success' => sprintf('SIP account %s@%s is now prepaid',$key['username'],$key['domain'])
)
)
);
$this->SOAPEngine->execute($function);
}
} else if ($action=='postpaid') {
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getAccount($account);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<font color=red>Error: %s (%s): %s</font>",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
break;
} else {
//print_r($result);
// Sanitize data types due to PHP bugs
if (!is_array($result->properties)) $result->properties=array();
if (!is_array($result->groups)) $result->groups=array();
$result->quota = intval($result->quota);
$result->answerTimeout = intval($result->answerTimeout);
$result->prepaid=0;
$function=array('commit' => array('name' => 'updateAccount',
'parameters' => array($result),
'logs' => array('success' => sprintf('SIP account %s@%s is now postpaid',$key['username'],$key['domain'])
)
)
);
$this->SOAPEngine->execute($function);
}
} else if ($action=='setquota') {
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getAccount($account);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<font color=red>Error: %s (%s): %s</font>",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
break;
} else {
//print_r($result);
// Sanitize data types due to PHP bugs
if (!is_array($result->properties)) $result->properties=array();
if (!is_array($result->groups)) $result->groups=array();
$result->quota = intval($sub_action_parameter);
$result->answerTimeout = intval($result->answerTimeout);
$function=array('commit' => array('name' => 'updateAccount',
'parameters' => array($result),
'logs' => array('success' => sprintf('SIP account %s@%s has quota set to %s',$key['username'],$key['domain'],$sub_action_parameter)
)
)
);
$this->SOAPEngine->execute($function);
}
} else if ($action=='rmdsfromrpid') {
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getAccount($account);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<font color=red>Error: %s (%s): %s</font>",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
break;
} else {
//print_r($result);
// Sanitize data types due to PHP bugs
if (!is_array($result->properties)) $result->properties=array();
if (!is_array($result->groups)) $result->groups=array();
if (is_numeric($sub_action_parameter) && strlen($result->rpid) > $sub_action_parameter) {
printf("%s %s",$result->rpid,$sub_action_parameter);
$result->rpid=substr($result->rpid,$sub_action_parameter);
printf("%s %s",$result->rpid,$sub_action_parameter);
} else {
printf ("<font color=red>Error: '%s' must be numeric and less than caller if length</font>",$sub_action_parameter);
continue;
}
$result->quota = intval($result->quota);
$result->answerTimeout = intval($result->answerTimeout);
$function=array('commit' => array('name' => 'updateAccount',
'parameters' => array($result),
'logs' => array('success' => sprintf('SIP account %s@%s has PSTN caller ID set to %s',$key['username'],$key['domain'],$result->rpid)
)
)
);
$this->SOAPEngine->execute($function);
}
} else if ($action=='rpidasusername') {
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getAccount($account);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<font color=red>Error: %s (%s): %s</font>",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
break;
} else {
//print_r($result);
// Sanitize data types due to PHP bugs
if (!is_array($result->properties)) $result->properties=array();
if (!is_array($result->groups)) $result->groups=array();
if (is_numeric($key['username'])) $result->rpid=$key['username'];
$result->quota = intval($result->quota);
$result->answerTimeout = intval($result->answerTimeout);
$function=array('commit' => array('name' => 'updateAccount',
'parameters' => array($result),
'logs' => array('success' => sprintf('SIP account %s@%s has PSTN caller ID set to %s',$key['username'],$key['domain'],$key['username'])
)
)
);
$this->SOAPEngine->execute($function);
}
} else if ($action=='prefixtorpid') {
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getAccount($account);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<font color=red>Error: %s (%s): %s</font>",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
break;
} else {
//print_r($result);
// Sanitize data types due to PHP bugs
if (!is_array($result->properties)) $result->properties=array();
if (!is_array($result->groups)) $result->groups=array();
if (is_numeric($sub_action_parameter)) {
$result->rpid=$sub_action_parameter.$result->rpid;
} else {
printf ("<font color=red>Error: '%s' must be numeric</font>",$sub_action_parameter);
continue;
}
$result->quota = intval($result->quota);
$result->answerTimeout = intval($result->answerTimeout);
$function=array('commit' => array('name' => 'updateAccount',
'parameters' => array($result),
'logs' => array('success' => sprintf('SIP account %s@%s has PSTN caller ID set to %s ',$key['username'],$key['domain'],$result->rpid)
)
)
);
$this->SOAPEngine->execute($function);
}
} else if ($action=='addbalance') {
if (!is_numeric($sub_action_parameter)) {
printf ("<font color=red>Error: you must enter a positive balance</font>");
break;
}
$this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth);
$result = $this->SOAPEngine->soapclient->getAccount($account);
if (PEAR::isError($result)) {
$error_msg = $result->getMessage();
$error_fault= $result->getFault();
$error_code = $result->getCode();
printf ("<font color=red>Error: %s (%s): %s</font>",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
break;
}
if (!$result->prepaid) {
printf ("<font color=red>Info: SIP account %s@%s is not prepaid, no action performed</font>",$key['username'],$key['domain']);
continue;
}
$function=array('commit' => array('name' => 'addBalance',
'parameters' => array($account,$sub_action_parameter),
'logs' => array('success' => sprintf('SIP account %s@%s balance has been increased with %s',$key['username'],$key['domain'],$sub_action_parameter)
)
)
);
$this->SOAPEngine->execute($function);
}
}
print "</ol>";
}
}
class SIPAliasesActions extends Actions {
var $actions=array(
'delete' => 'Delete SIP aliases'
);
function SIPAliases(&$SOAPEngine) {
$this->Actions(&$SOAPEngine);
}
function performActions($selectionKeys,$action,$sub_action_parameter) {
if (!in_array($action,array_keys($this->actions))) {
print "<font color=red>Error: Invalid action $action</font>";
return false;
}
print "<ol>";
foreach($selectionKeys as $key) {
print "<li>";
flush();
//printf ("Performing action=%s on key=%s",$action,$key);
$alias=array('username' => $key['username'],
'domain' => $key['domain']
);
if ($action=='delete') {
$function=array('commit' => array('name' => 'deleteAlias',
'parameters' => array($alias),
'logs' => array('success' => sprintf('SIP alias %s@%s has been deleted',$key['username'],$key['domain'])
)
)
);
//$this->SOAPEngine->execute($function);
}
}
print "</ol>";
}
}
class ENUMMappingsActions extends Actions {
var $actions=array(
'delete' => 'Delete ENUM mappings'
);
function ENUMMappingsActions(&$SOAPEngine) {
$this->Actions(&$SOAPEngine);
}
function performActions($selectionKeys,$action,$sub_action_parameter) {
if (!in_array($action,array_keys($this->actions))) {
print "<font color=red>Error: Invalid action $action</font>";
return false;
}
print "<ol>";
foreach($selectionKeys as $key) {
flush();
print "<li>";
if ($action=='delete') {
//printf ("Performing action=%s on key=%s",$action,$key);
$enum_id=array('number' => $key['number'],
'tld' => $key['tld']
);
$function=array('commit' => array('name' => 'deleteNumber',
'parameters' => array($enum_id),
'logs' => array('success' => sprintf('ENUM number +%s under %s has been deleted',$key['number'],$key['tld'])
)
)
);
$this->SOAPEngine->execute($function);
}
}
print "</ol>";
}
}
?>

File Metadata

Mime Type
text/x-diff
Expires
Sat, Feb 1, 12:42 PM (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3489342
Default Alt Text
(222 KB)

Event Timeline