diff --git a/library/NGNPro/Records/EnumRanges.php b/library/NGNPro/Records/EnumRanges.php index d203a06..5077304 100644 --- a/library/NGNPro/Records/EnumRanges.php +++ b/library/NGNPro/Records/EnumRanges.php @@ -1,713 +1,815 @@ array('type'=>'integer', - 'help' => 'Range owner') - ); - - var $Fields=array( - 'customer' => array('type'=>'integer', - 'help' => 'Range owner' - ), - 'serial' => array('type'=>'integer', - 'help'=>'DNS serial number', - 'readonly' => 1 - ), - 'ttl' => array('type'=>'integer', - 'help'=>'Cache period in DNS clients' - ), - 'info' => array('type'=>'string', - 'help' =>'Range description' - ), - 'size' => array('type'=>'integer', - 'help'=>'Maximum number of telephone numbers' - ), - 'minDigits' => array('type'=>'integer', - 'help'=>'Minimum number of digits for telephone numbers' - ), - 'maxDigits' => array('type'=>'integer', - 'help'=>'Maximum number of digits for telephone numbers' - ) - ); + var $deniedPrefixes = array( + '1','20','210','211','212','213','214','215','216','217','218','219','220','221','222','223','224','225','226', + '227','228','229','230','231','232','233','234','235','236','237','238','239','240','241','242','243','244', + '245','246','247','248','249','250','251','252','253','254','255','256','257','258','259','260','261','262', + '263','264','265','266','267','268','269','27','280','281','282','283','284','285','286','287','288','289', + '290','291','292','293','294','295','296','297','298','299','30','31','32','33','34','350','351','352','353', + '354','355','356','357','358','359','36','370','371','372','373','374','375','376','377','378','379','380', + '381','382','383','384','385','386','387','388','389','39','40','41','420','421','422','423','424','425','426', + '427','428','429','43','44','45','46','47','48','49','500','501','502','503','504','505','506','507','508', + '509','51','52','53','54','55','56','57','58','590','591','592','593','594','595','596','597','598','599','60', + '61','62','63','64','65','66','670','671','672','673','674','675','676','677','678','679','680','681','682', + '683','684','685','686','687','688','689','690','691','692','693','694','695','696','697','698','699','7', + '800','801','802','803','804','805','806','807','808','809','81','82','830','831','832','833','834','835', + '836','837','838','839','84','850','851','852','853','854','855','856','857','858','859','86','870','871', + '872','873','874','875','876','877','878','879','880','881','882','883','884','885','886','887','888','889', + '890','891','892','893','894','895','896','897','898','899','90','91','92','93','94','95','960','961','962', + '963','964','965','966','967','968','969','970','971','972','973','974','975','976','977','978','979','98', + '990','991','992','993','994','995','996','997','998','999' + ); + + var $FieldsAdminOnly = array( + 'reseller' => array( + 'type'=>'integer', + 'help' => 'Range owner' + ) + ); + + var $Fields = array( + 'customer' => array('type'=>'integer', + 'help' => 'Range owner' + ), + 'serial' => array('type'=>'integer', + 'help'=>'DNS serial number', + 'readonly' => 1 + ), + 'ttl' => array('type'=>'integer', + 'help'=>'Cache period in DNS clients' + ), + 'info' => array('type'=>'string', + 'help' =>'Range description' + ), + 'size' => array('type'=>'integer', + 'help'=>'Maximum number of telephone numbers' + ), + 'minDigits' => array('type'=>'integer', + 'help'=>'Minimum number of digits for telephone numbers' + ), + 'maxDigits' => array('type'=>'integer', + 'help'=>'Maximum number of digits for telephone numbers' + ) + ); public function __construct($SoapEngine) { dprint("init EnumRanges"); - $this->filters = array('prefix' => trim(ltrim($_REQUEST['prefix_filter']),'+'), - 'tld' => trim($_REQUEST['tld_filter']), - 'info' => trim($_REQUEST['info_filter']) - ); + $this->filters = array( + 'prefix' => trim(ltrim($_REQUEST['prefix_filter']), '+'), + 'tld' => trim($_REQUEST['tld_filter']), + 'info' => trim($_REQUEST['info_filter']) + ); parent::__construct($SoapEngine); - $this->sortElements=array('changeDate' => 'Change date', - 'prefix' => 'Prefix', - 'tld' => 'TLD' - ); + $this->sortElements = array( + 'changeDate' => 'Change date', + 'prefix' => 'Prefix', + 'tld' => 'TLD' + ); /* $this->Fields['nameservers'] = array('type'=>'text', 'name'=>'Name servers', 'help'=>'Name servers authoritative for this DNS zone' ); */ if ($this->login_credentials['reseller_filters'][$this->reseller]['record_generator']) { - //printf ("Engine: %s",$this->SoapEngine->soapEngine); + //printf("Engine: %s",$this->SoapEngine->soapEngine); if (is_array($this->login_credentials['reseller_filters'][$this->reseller]['record_generator'])) { - $_rg=$this->login_credentials['reseller_filters'][$this->reseller]['record_generator']; + $_rg = $this->login_credentials['reseller_filters'][$this->reseller]['record_generator']; if ($_rg[$this->SoapEngine->soapEngine]) { - $this->record_generator=$_rg[$this->SoapEngine->soapEngine]; + $this->record_generator = $_rg[$this->SoapEngine->soapEngine]; } } else { - $this->record_generator=$this->login_credentials['reseller_filters'][$this->reseller]['record_generator']; + $this->record_generator = $this->login_credentials['reseller_filters'][$this->reseller]['record_generator']; } - } else if (strlen($this->SoapEngine->record_generator)) { - $this->record_generator=$this->SoapEngine->record_generator; + } elseif (strlen($this->SoapEngine->record_generator)) { + $this->record_generator = $this->SoapEngine->record_generator; } } function listRecords() { $this->getAllowedDomains(); $this->showSeachForm(); // Filter - $filter=array('prefix' => $this->filters['prefix'], - 'tld' => $this->filters['tld'], - 'info' => $this->filters['info'], - 'customer' => intval($this->filters['customer']), - 'reseller' => intval($this->filters['reseller']) - ); + $filter = array( + 'prefix' => $this->filters['prefix'], + 'tld' => $this->filters['tld'], + 'info' => $this->filters['info'], + 'customer' => intval($this->filters['customer']), + 'reseller' => intval($this->filters['reseller']) + ); // Range - $range=array('start' => intval($this->next), - 'count' => intval($this->maxrowsperpage) - ); + $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'] - ); + $orderBy = array( + 'attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] + ); // Compose query - $Query=array('filter' => $filter, - 'orderBy' => $orderBy, - 'range' => $range - ); + $Query = array( + 'filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getRanges'); $result = $this->SoapEngine->soapclient->getRanges($Query); if ($this->checkLogSoapError($result, true)) { return false; } else { - $this->rows = $result->total; if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') { $this->showActionsForm(); } - print " -
$this->rows records found
-

- - + print <<< END +
+
$this->rows records found
+
+

+

+ - - - - - - - - - - - - - - - "; + + + + + + + + + + + + + + + +END; if (!$this->next) $this->next=0; - if ($this->rows > $this->maxrowsperpage) { + if ($this->rows > $this->maxrowsperpage) { $maxrows = $this->maxrowsperpage + $this->next; if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage; } else { - $maxrows=$this->rows; + $maxrows = $this->rows; } $i=0; if ($this->rows) { while ($i < $maxrows) { if (!$result->ranges[$i]) break; $range = $result->ranges[$i]; $index=$this->next+$i+1; $_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 ($this->adminonly) $_url.= sprintf ("&reseller_filter=%s",$range->reseller); if ($_REQUEST['action'] == 'Delete' && $_REQUEST['prefix_filter'] == $range->id->prefix && $_REQUEST['tld_filter'] == $range->id->tld) { $_url .= "&confirm=1"; $actionText = "Confirm"; } else { $actionText = "Delete"; } if ($this->adminonly) { $range_url=sprintf('%s',$this->url, $this->SoapEngine->service, $range->reseller, $range->id->prefix, $range->id->tld, $range->id->prefix); } else { $range_url=sprintf('%s',$this->url, $this->SoapEngine->service, $range->id->prefix, $range->id->tld, $range->id->prefix); } if ($this->record_generator) { $generator_url=sprintf('+Numbers',$this->url, $this->record_generator, $range->id->prefix, $range->id->tld, $range->maxDigits, $range->reseller); } else { $generator_url=''; } if ($range->size) { - $usage=intval(100*$range->used/$range->size); - $bar=$this->makebar($usage); + $usage = intval(100 * $range->used / $range->size); + $bar = $this->makebar($usage); } else { $bar=""; } $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", urlencode($this->SoapEngine->customer_engine), urlencode($range->customer) ); $_nameservers=''; foreach ($range->nameservers as $_ns) { $_nameservers.= $_ns.' '; } - printf(" + printf( + " - ", + + ", $index, $_customer_url, $range->customer, $range->reseller, $range_url, $range->id->tld, $range->serial, $range->ttl, $range->info, $range->minDigits, $range->maxDigits, $range->size, $range->used, $bar, $range->changeDate, $_url, $actionText, $generator_url ); $i++; } } print "
IdOwnerPrefix TLDSerialTTLInfoMinMaxSizeUsedChange dateActions
IdOwnerPrefix TLDSerialTTLInfoMinMaxSizeUsedChange dateActions
%s %s.%s +%s %s %s %s %s %s %s %s %s %s %s %s%s
"; if ($this->rows == 1) { $this->showRecord($range); } else { $this->showPagination($maxrows); } return true; } } function deleteRecord($dictionary = array()) { if (!$dictionary['confirm'] && !$_REQUEST['confirm']) { print "

Please press on Confirm to confirm the delete. "; return true; } if (!strlen($this->filters['prefix']) || !strlen($this->filters['tld'])) { print "

Error: missing ENUM range id "; return false; } - $rangeId=array('prefix'=>$this->filters['prefix'], + $rangeId = array('prefix'=>$this->filters['prefix'], 'tld'=>$this->filters['tld']); - $function=array('commit' => array('name' => 'deleteRange', - 'parameters' => array($rangeId), - 'logs' => array('success' => sprintf('ENUM range +%s under %s has been deleted',$this->filters['prefix'], $this->filters['tld']) - ) - ) - ); + $function = array( + 'commit' => array( + 'name' => 'deleteRange', + 'parameters' => array($rangeId), + 'logs' => array( + 'success' => sprintf( + 'ENUM range +%s under %s has been deleted', + $this->filters['prefix'], + $this->filters['tld'] + ) + ) + ) + ); - unset($this->filters); + unset($this->filters); $result = $this->SoapEngine->execute($function, $this->html); if ($this->checkLogSoapError($result, true)) { return false; } else { return true; } } function showAddForm() { if ($this->selectionActive) return; - printf ("

",$_SERVER['PHP_SELF']); + printf("",$_SERVER['PHP_SELF']); - print " -
- "; + print "
"; + + print ""; - print " - - "; $this->showCustomerTextBox(); - printf ("
Prefix +
",$_REQUEST['prefix']); - printf ("
TLD"); + printf( + " +
+
+ Prefix + +
+ ", + $_REQUEST['prefix'] + ); + print "
TLD"; if ($_REQUEST['tld']) { - printf ("
",$_REQUEST['tld']); - } else if ($this->filters['tld']) { - printf ("
",$this->filters['tld']); - } else if ($_tld=$this->getCustomerProperty('enum_ranges_last_tld')) { - printf ("",$_tld); + printf("", $_REQUEST['tld']); + } elseif ($this->filters['tld']) { + printf("", $this->filters['tld']); + } elseif ($_tld = $this->getCustomerProperty('enum_ranges_last_tld')) { + printf("", $_tld); } else { - printf (""); + printf(""); } - printf ("
TTL
"); - printf ("
Min Digits
"); - printf ("
Max Digits
"); - printf ("
Info
",$_REQUEST['info']); + print <<< END +
TTL
+
+ Min Digits +
+
+ Max Digits +
+END; + printf( + "
Info
", + $_REQUEST['info'] + ); $this->printHiddenFormElements(); print "
"; } - function addRecord($dictionary=array()) + function addRecord($dictionary = array()) { $tld = trim($_REQUEST['tld']); $prefix = trim($_REQUEST['prefix']); $size = trim($_REQUEST['size']); $info = trim($_REQUEST['info']); if (!strlen($tld)) { - $tld=$this->SoapEngine->default_enum_tld; + $tld = $this->SoapEngine->default_enum_tld; } if (!strlen($tld) || !strlen($prefix) || !is_numeric($prefix)) { printf("

Error: Missing TLD or prefix. "); return false; } if (!$this->adminonly) { if (in_array($prefix, $this->deniedPrefixes)) { print "

Error: Only an administrator account can create the prefix coresponding to a country code."; return false; } } list($customer, $reseller)=$this->customerFromLogin($dictionary); if (!trim($_REQUEST['ttl'])) { $ttl = 3600; } else { $ttl = intval(trim($_REQUEST['ttl'])); } $range = array( 'id' => array( 'prefix' => $prefix, 'tld' => $tld ), 'ttl' => $ttl, 'info' => $info, 'minDigits' => intval(trim($_REQUEST['minDigits'])), 'maxDigits' => intval(trim($_REQUEST['maxDigits'])), 'size' => intval($size), 'customer' => intval($customer), 'reseller' => intval($reseller) ); $deleteRange = array( 'prefix'=>$prefix, 'tld'=>$tld ); $_p = array( array( 'name' => 'enum_ranges_last_tld', 'category' => 'web', 'value' => "$tld", 'permission' => 'customer' ) ); $this->setCustomerProperties($_p); $function = array( 'commit' => array( 'name' => 'addRange', 'parameters' => array($range), - 'logs' => array('success' => sprintf('ENUM range +%s under %s has been added',$prefix, $tld)) + 'logs' => array('success' => sprintf('ENUM range +%s under %s has been added', $prefix, $tld)) ) ); $result = $this->SoapEngine->execute($function, $this->html); dprint_r($result); if ($this->checkLogSoapError($result, true)) { return false; } else { return true; } } function showSeachFormCustom() { - printf ("

Prefix
",$this->filters['prefix']); - printf ("
TLD"); + printf( + " +
+ Prefix + +
+ ", + $this->filters['prefix'] + ); + print "
TLD"; if (count($this->allowedDomains) > 0) { $selected_tld[$this->filters['tld']]='selected'; - printf (" +
"); + printf("
"); } else { - printf ("",$this->filters['tld']); + printf("", $this->filters['tld']); } - printf ("
Info
",$this->filters['info']); + printf( + " +
+ Info + +
+ ", + $this->filters['info'] + ); } function getAllowedDomains() { // Filter - $filter=array('prefix' => ''); + $filter = array( + 'prefix' => '' + ); // Range - $range=array('start' => 0, - 'count' => 500 - ); + $range = array( + 'start' => 0, + 'count' => 500 + ); // 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'] - ); + $orderBy = array( + 'attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] + ); // Compose query - $Query=array('filter' => $filter, - 'orderBy' => $orderBy, - 'range' => $range - ); + $Query = array( + 'filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getRanges'); - $result = $this->SoapEngine->soapclient->getRanges($Query); + $result = $this->SoapEngine->soapclient->getRanges($Query); if ($this->checkLogSoapError($result, true)) { return false; } else { - foreach($result->ranges as $range) { - $this->ranges[]=array('prefix' => $range->id->prefix, - 'tld' => $range->id->tld, - 'minDigits' => $range->minDigits, - 'maxDigits' => $range->maxDigits - ); + 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; + $this->allowedDomains[] = $range->id->tld; $seen[$range->id->tld]++; } if (!$seen[$this->SoapEngine->default_enum_tld]) { - $this->allowedDomains[]=$this->SoapEngine->default_enum_tld; + $this->allowedDomains[] = $this->SoapEngine->default_enum_tld; } } } function showRecord($range) { - print ""; - print " - + print <<< END +
+
- "; - printf ("",$_SERVER['PHP_SELF']); - print ""; - - print " - "; - - printf ("", - $this->tel2enum($range->id->prefix, $range->id->tld)); +
-
DNS zone%s
+END; + printf("", $_SERVER['PHP_SELF']); + print <<< END + + + + +END; + + printf( + "", + $this->tel2enum($range->id->prefix, $range->id->tld) + ); if ($this->adminonly) { - foreach (array_keys($this->FieldsAdminOnly) as $item) { if ($item == 'nameservers') { + $nameservers = ''; foreach ($range->$item as $_item) { - $nameservers.=$_item."\n"; + $nameservers .= $_item."\n"; } - $item_value=$nameservers; + $item_value = $nameservers; } else { - $item_value=$range->$item; + $item_value = $range->$item; } if ($this->FieldsAdminOnly[$item]['name']) { - $item_name=$this->FieldsAdminOnly[$item]['name']; + $item_name = $this->FieldsAdminOnly[$item]['name']; } else { $item_name=ucfirst($item); } if ($this->FieldsAdminOnly[$item]['type'] == 'text') { - printf (" - - - - ", - $item_name, - $item, - $item_value, - $this->FieldsAdminOnly[$item]['help'] + printf( + " + + + + + + ", + $item_name, + $item, + $item_value, + $this->FieldsAdminOnly[$item]['help'] ); } else { - printf (" - - - - ", - $item_name, - $item, - $item_value, - $this->FieldsAdminOnly[$item]['help'] + printf( + " + + + + + + ", + $item_name, + $item, + $item_value, + $this->FieldsAdminOnly[$item]['help'] ); } } } foreach (array_keys($this->Fields) as $item) { if ($this->Fields[$item]['name']) { - $item_name=$this->Fields[$item]['name']; + $item_name = $this->Fields[$item]['name']; } else { - $item_name=ucfirst($item); + $item_name = ucfirst($item); } if ($item == 'nameservers') { + $nameservers = ''; foreach ($range->$item as $_item) { $nameservers.=$_item."\n"; } - $item_value=$nameservers; + $item_value = $nameservers; } else { - $item_value=$range->$item; + $item_value = $range->$item; } if ($this->Fields[$item]['type'] == 'text') { - printf (" - - - - ", - $item_name, - $item, - $item_value, - $this->Fields[$item]['help'] + printf( + " + + + + + + ", + $item_name, + $item, + $item_value, + $this->Fields[$item]['help'] ); - }else if ($this->Fields[$item]['readonly']) { - printf (" - - - - ", - $item_name, - $item_value, - $this->Fields[$item]['help'] + } elseif ($this->Fields[$item]['readonly']) { + printf( + " + + + + + + ", + $item_name, + $item_value, + $this->Fields[$item]['help'] ); } else { - printf (" - - - - ", - $item_name, - $item, - $item_value, - $this->Fields[$item]['help'] + printf( + " + + + + + + ", + $item_name, + $item, + $item_value, + $this->Fields[$item]['help'] ); } } - printf ("",$range->id->tld); - printf ("",$range->id->prefix); + printf("", $range->id->tld); + printf("", $range->id->prefix); $this->printFiltersToForm(); $this->printHiddenFormElements(); - print ""; - print " -
DNS zone%s
%s%s
%s%s
%s%s
%s%s
%s%s
%s%s
%s%s%s
%s%s%s
%s%s
%s%s
- "; + print <<< END + +
+END; } function updateRecord() { //print "

Updating range ..."; if (!$_REQUEST['prefix_filter'] || !$_REQUEST['tld_filter']) return; - $rangeid=array('prefix' => $_REQUEST['prefix_filter'], - 'tld' => $_REQUEST['tld_filter'] - ); + $rangeid = array( + 'prefix' => $_REQUEST['prefix_filter'], + 'tld' => $_REQUEST['tld_filter'] + ); if (!$range = $this->getRecord($rangeid)) { return false; } - $range_old=$range; + $range_old = $range; foreach (array_keys($this->Fields) as $item) { - $var_name=$item.'_form'; - //printf ("
%s=%s",$var_name, $_REQUEST[$var_name]); + $var_name = $item.'_form'; + //printf("
%s=%s",$var_name, $_REQUEST[$var_name]); if ($this->Fields[$item]['type'] == 'integer') { $range->$item = intval($_REQUEST[$var_name]); - } else if ($item == 'nameservers') { - $_txt=trim($_REQUEST[$var_name]); + } elseif ($item == 'nameservers') { + $_txt = trim($_REQUEST[$var_name]); if (!strlen($_txt)) { unset($range->$item); } else { - $_nameservers=array(); - $_lines=explode("\n",$_txt); + $_nameservers = array(); + $_lines = explode("\n", $_txt); foreach ($_lines as $_line) { - $_ns=trim($_line); - $_nameservers[]=$_ns; + $_ns = trim($_line); + $_nameservers[] = $_ns; } - $range->$item=$_nameservers; + $range->$item = $_nameservers; } } else { $range->$item = trim($_REQUEST[$var_name]); } } if ($this->adminonly) { foreach (array_keys($this->FieldsAdminOnly) as $item) { - $var_name=$item.'_form'; + $var_name = $item.'_form'; if ($this->FieldsAdminOnly[$item]['type'] == 'integer') { $range->$item = intval($_REQUEST[$var_name]); } else { $range->$item = trim($_REQUEST[$var_name]); } } } - $function=array('commit' => array('name' => 'updateRange', - 'parameters' => array($range), - 'logs' => array('success' => sprintf('ENUM range +%s under %s has been updated',$rangeid['prefix'], $rangeid['tld']))) - ); + $function = array('commit' => array( + 'name' => 'updateRange', + 'parameters' => array($range), + 'logs' => array( + 'success' => sprintf('ENUM range +%s under %s has been updated', $rangeid['prefix'], $rangeid['tld']))) + ); $result = $this->SoapEngine->execute($function, $this->html); dprint_r($result); if ($this->checkLogSoapError($result, true)) { return false; } else { return true; } } function getRecord($rangeid) { // Filter if (!$rangeid['prefix'] || !$rangeid['tld']) { print "Error in getRecord(): Missing prefix or tld"; return false; } - $filter=array('prefix' => $rangeid['prefix'], - 'tld' => $rangeid['tld'] - ); + $filter = array( + 'prefix' => $rangeid['prefix'], + 'tld' => $rangeid['tld'] + ); // Range - $range=array('start' => 0, - 'count' => 1 - ); + $range = array( + 'start' => 0, + 'count' => 1 + ); // Order - $orderBy = array('attribute' => 'changeDate', - 'direction' => 'DESC' - ); + $orderBy = array( + 'attribute' => 'changeDate', + 'direction' => 'DESC' + ); // Compose query - $Query=array('filter' => $filter, - 'orderBy' => $orderBy, - 'range' => $range - ); + $Query = array( + 'filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getRanges'); $result = $this->SoapEngine->soapclient->getRanges($Query); if ($this->checkLogSoapError($result, true)) { return false; } else { - if ($result->ranges[0]){ + if ($result->ranges[0]) { return $result->ranges[0]; } else { return false; } } } } diff --git a/library/NGNPro/Records/SipAliases.php b/library/NGNPro/Records/SipAliases.php index 42003d0..6114b30 100644 --- a/library/NGNPro/Records/SipAliases.php +++ b/library/NGNPro/Records/SipAliases.php @@ -1,576 +1,582 @@ 1) { $target_domain = $target_filters_els[1]; } $this->filters = array( 'alias_username' => strtolower(trim($_REQUEST['alias_username_filter'])), 'alias_domain' => strtolower(trim($_REQUEST['alias_domain_filter'])), 'target_username' => strtolower($target_username), 'target_domain' => strtolower($target_domain) ); parent::__construct($SoapEngine); $this->sortElements = array( 'changeDate' => 'Change date', 'aliasUsername' => 'Alias user', 'aliasDomain' => 'Alias domain', 'targetUsername' => 'Target user', 'targetDomain' => 'Target domain', ); } function getRecordKeys() { // Filter $filter = array( 'aliasUsername' => $this->filters['alias_username'], 'aliasDomain' => $this->filters['alias_domain'], 'targetUsername' => $this->filters['target_username'], 'targetDomain' => $this->filters['target_domain'], 'owner' => intval($this->filters['owner']), 'customer' => intval($this->filters['customer']), 'reseller' => intval($this->filters['reseller']) ); // Range $range = array( 'start' => 0, 'count' => 500 ); // 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 ); //dprint_r($Query); // Insert credetials $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAliases'); // Call function $result = $this->SoapEngine->soapclient->getAliases($Query); if ($this->checkLogSoapError($result, true)) { 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 $this->showSeachForm(); // Filter $filter = array('aliasUsername' => $this->filters['alias_username'], 'aliasDomain' => $this->filters['alias_domain'], 'targetUsername' => $this->filters['target_username'], 'targetDomain' => $this->filters['target_domain'], 'owner' => intval($this->filters['owner']), '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); $this->log_action('getAliases'); // Call function $result = $this->SoapEngine->soapclient->getAliases($Query); if ($this->checkLogSoapError($result, true)) { return false; } else { $this->rows = $result->total; if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') { $this->showActionsForm(); } print "

$this->rows records found

"; 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; $deleteUrl = array( 'service' => $this->SoapEngine->service, 'action' => 'Delete', 'alias_username_filter' => $alias->id->username, 'alias_domain_filter' => $alias->id->domain ); if ($_REQUEST['action'] == 'Delete' && $_REQUEST['alias_username_filter'] == $alias->id->username && $_REQUEST['alias_domain_filter'] == $alias->id->domain) { $deleteUrl['confirm'] = 1; $actionText = "Confirm"; } else { $actionText = "Delete"; } $_url = sprintf( "%s&%s", $this->url, http_build_query($deleteUrl) ); /* $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", urlencode($this->SoapEngine->customer_engine), urlencode($alias->customer) ); */ $_sip_accounts_url = sprintf( '%s&%s', $this->url, http_build_query( array( 'service' => sprintf('sip_accounts@%s', $this->SoapEngine->soapEngine), 'username_filter' => $alias->target->username, 'domain_filter' => $alias->target->domain ) ) ); if ($alias->owner) { $_owner_url = sprintf( '%s', $this->url, http_build_query( array( 'service' => sprintf('customers@%s', $this->SoapEngine->soapEngine), 'customer_filter' => $alias->owner ) ), $alias->owner ); } else { $_owner_url=''; } printf( " ", $index, $alias->id->username, $alias->id->domain, $_sip_accounts_url, $alias->target->username, $alias->target->domain, $_owner_url, $alias->changeDate, $_url, $actionText ); $i++; } } print "
Id SIP alias Redirect target Owner Change date Actions
%s %s@%s %s@%s %s %s %s
"; $this->showPagination($maxrows); /* $_properties=array( array('name' => $this->SoapEngine->port.'_sortBy', 'value' => $this->sorting['sortBy'], 'permission' => 'customer', 'category' => 'web' ), array('name' => $this->SoapEngine->port.'_sortOrder', 'value' => $this->sorting['sortOrder'], 'permission' => 'customer', 'category' => 'web' ) ); print_r($_properties); $this->setCustomerProperties($_properties); */ return true; } } function deleteRecord($dictionary = array()) { if (!$dictionary['confirm'] && !$_REQUEST['confirm']) { print "

Please press on Confirm to confirm the delete. "; return true; } if ($dictionary['alias_username']) { $alias_username = $dictionary['alias_username']; } else { $alias_username = $this->filters['alias_username']; } if ($dictionary['alias_domain']) { $alias_domain = $dictionary['alias_domain']; } else { $alias_domain = $this->filters['alias_domain']; } if (!strlen($alias_username) || !strlen($alias_domain)) { print "

Error: missing SIP alias username or domain. "; return false; } $alias = array('username' => $alias_username, 'domain' => $alias_domain ); - $function = array('commit' => array('name' => 'deleteAlias', - 'parameters' => array($alias), - 'logs' => array('success' => sprintf('SIP alias %s@%s has been deleted',$this->filters['alias_username'], $this->filters['alias_domain']) - ) - ) - - ); + $function = array( + 'commit' => array( + 'name' => 'deleteAlias', + 'parameters' => array($alias), + 'logs' => array( + 'success' => sprintf( + 'SIP alias %s@%s has been deleted', + $this->filters['alias_username'], + $this->filters['alias_domain'] + ) + ) + ) + ); unset($this->filters); return $this->SoapEngine->execute($function, $this->html); } function showSeachFormCustom() { printf( "

SIP alias
", $this->filters['alias_username'] ); print "@"; if (count($this->allowedDomains) > 0) { if ($this->filters['alias_domain'] && !in_array($this->filters['alias_domain'], $this->allowedDomains)) { printf("", $this->filters['alias_domain']); } else { $selected_domain[$this->filters['alias_domain']]='selected'; printf(""); } } else { printf("", $this->filters['alias_domain']); } printf( "
Redirect target
", trim($_REQUEST['target_username_filter']) ); printf( "
Owner
", $this->filters['owner'] ); } function showAddForm() { if ($this->selectionActive) return; if (!count($this->allowedDomains)) { print "

You must create at least one SIP domain before adding SIP aliases"; return false; } printf("

", $_SERVER['PHP_SELF']); print <<< END
END; print <<< END
SIP alias
END; if ($_REQUEST['domain']) { $_domain = $_REQUEST['domain']; $selected_domain[$_REQUEST['domain']]='selected'; } elseif ($_domain = $this->getCustomerProperty('sip_aliases_last_domain')) { $selected_domain[$_domain]='selected'; } if (count($this->allowedDomains) > 0) { print "@"; } else { printf("", $_domain); } print <<< END
Redirect target
END; print <<< END
Owner
END; $this->printHiddenFormElements(); print <<< END
END; } function addRecord($dictionary = array()) { if ($dictionary['alias']) { $alias_els = explode("@", $dictionary['alias']); $this->skipSaveProperties = true; } else { $alias_els = explode("@", trim($_REQUEST['alias'])); } if ($dictionary['target']) { $target_els = explode("@", $dictionary['target']); } else { $target_els = explode("@", trim($_REQUEST['target'])); } if ($dictionary['owner']) { $owner = $dictionary['owner']; } else { $owner = $_REQUEST['owner']; } if (preg_match("/:(.*)$/", $target_els[0], $m)) { $target_username = $m[1]; } else { $target_username = $target_els[0]; } if (preg_match("/:(.*)$/", $alias_els[0], $m)) { $username = $m[1]; } else { $username = $alias_els[0]; } if (strlen($alias_els[1])) { $domain = $alias_els[1]; } elseif (trim($_REQUEST['domain'])) { $domain = trim($_REQUEST['domain']); } else { if ($this->html) { printf("

Error: Missing SIP domain"); } return false; } if (!$this->validDomain($domain)) { if ($this->html) { print "Error: invalid domain name"; } return false; } list($customer, $reseller)=$this->customerFromLogin($dictionary); if (!$this->skipSaveProperties = true) { $_p = array( array('name' => 'sip_aliases_last_domain', 'category' => 'web', 'value' => strtolower($domain), 'permission' => 'customer' ) ); $this->setCustomerProperties($_p); } $alias = array( 'id' => array('username' => strtolower($username), 'domain' => strtolower($domain) ), 'target' => array('username' => strtolower($target_username), 'domain' => strtolower($target_els[1]) ), 'owner' => intval($owner) ); $deleteAlias = array('username' => strtolower($username), 'domain' => strtolower($domain) ); $function = array( 'commit' => array( 'name' => 'addAlias', 'parameters' => array($alias), 'logs' => array( 'success' => sprintf('SIP alias %s@%s has been added', $username, $domain))) ); return $this->SoapEngine->execute($function, $this->html); } function getAllowedDomains() { // Filter $filter = array( 'domain' => '' ); // Range $range = array( 'start' => 0, 'count' => 500 ); $orderBy = array( 'attribute' => 'domain', 'direction' => 'ASC' ); // Compose query $Query = array( 'filter' => $filter, 'orderBy' => $orderBy, 'range' => $range ); $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getDomains'); $result = $this->SoapEngine->soapclient->getDomains($Query); if ($this->checkLogSoapError($result, true)) { return false; } else { foreach ($result->domains as $_domain) { if ($this->validDomain($_domain->domain)) { $this->allowedDomains[] = $_domain->domain; } } } } function showTextBeforeCustomerSelection() { print _("Domain owner"); } }