diff --git a/library/NGNPro/Records/EnumRanges.php b/library/NGNPro/Records/EnumRanges.php index 5077304..58061c0 100644 --- a/library/NGNPro/Records/EnumRanges.php +++ b/library/NGNPro/Records/EnumRanges.php @@ -1,815 +1,850 @@ 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']) ); parent::__construct($SoapEngine); $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); if (is_array($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]; } } else { $this->record_generator = $this->login_credentials['reseller_filters'][$this->reseller]['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']) ); // 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); $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 <<< END
$this->rows records found

END; 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->ranges[$i]) break; $range = $result->ranges[$i]; - $index=$this->next+$i+1; + $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) + $delete_url = array( + 'service' => $this->SoapEngine->service, + 'action' => 'Delete', + 'prefix_filter' => $range->id->prefix, + 'tld_filter' => $range->id->tld ); - if ($this->adminonly) $_url.= sprintf ("&reseller_filter=%s",$range->reseller); + if ($this->adminonly) $delete_url['reseller_filter'] = $range->reseller; if ($_REQUEST['action'] == 'Delete' && $_REQUEST['prefix_filter'] == $range->id->prefix && $_REQUEST['tld_filter'] == $range->id->tld) { - $_url .= "&confirm=1"; - $actionText = "Confirm"; + $delete_url['confirm'] = 1; + $actionText = "Confirm"; } else { $actionText = "Delete"; } + $_url = sprintf( + "%s&%s", + $this->url, + http_build_query($delete_url) + ); + + $range_url_data = array( + 'service' => $this->SoapEngine->service, + 'prefix_filter' => $range->id->prefix, + 'tld_filter' => $range->id->tld + ); + 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); + $range_url_data['reseller_filter'] = $range->reseller; } + $range_url = sprintf( + '%s', + $this->url, + http_build_query($range_url_data), + $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); + $generator_url = sprintf( + '+Numbers', + $this->url, + http_build_query( + array( + 'generatorId' => $this->record_generator, + 'range' => sprintf('%s@%s', $range->id->prefix, $range->id->tld), + 'number_length' => $range->maxDigits, + 'reseller_filter' => $range->reseller + ) + ) + ); } else { $generator_url=''; } if ($range->size) { $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) + $_customer_url = sprintf( + 's&%s', + $this->url, + http_build_query( + array( + 'service' => sprintf('customers@%s', $this->SoapEngine->customer_engine), + 'customer_filter' => $range->customer + ) + ) ); $_nameservers=''; foreach ($range->nameservers as $_ns) { $_nameservers.= $_ns.' '; } 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 "
Id Owner Prefix TLD Serial TTL Info Min Max Size Used Change date Actions
%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'], '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'] ) ) ) ); 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']); print "
"; print ""; $this->showCustomerTextBox(); printf( "
Prefix +
", $_REQUEST['prefix'] ); print "
TLD"; if ($_REQUEST['tld']) { printf("
", $_REQUEST['tld']); } elseif ($this->filters['tld']) { printf("", $this->filters['tld']); } elseif ($_tld = $this->getCustomerProperty('enum_ranges_last_tld')) { printf("", $_tld); } else { printf(""); } print <<< END
TTL
Min Digits
Max Digits
END; printf( "
Info
", $_REQUEST['info'] ); $this->printHiddenFormElements(); print "
"; } 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; } 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)) ) ); $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'] ); print "
TLD"; if (count($this->allowedDomains) > 0) { $selected_tld[$this->filters['tld']]='selected'; print <<< END
"); } else { printf("", $this->filters['tld']); } printf( "
Info
", $this->filters['info'] ); } function getAllowedDomains() { // Filter $filter = array( 'prefix' => '' ); // Range $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'] ); // Compose query $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 { 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]++; } if (!$seen[$this->SoapEngine->default_enum_tld]) { $this->allowedDomains[] = $this->SoapEngine->default_enum_tld; } } } function showRecord($range) { print <<< END
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"; } $item_value = $nameservers; } else { $item_value = $range->$item; } if ($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'] ); } else { 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']; } else { $item_name = ucfirst($item); } if ($item == 'nameservers') { $nameservers = ''; foreach ($range->$item as $_item) { $nameservers.=$_item."\n"; } $item_value = $nameservers; } else { $item_value = $range->$item; } if ($this->Fields[$item]['type'] == 'text') { printf( " ", $item_name, $item, $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("", $range->id->tld); printf("", $range->id->prefix); $this->printFiltersToForm(); $this->printHiddenFormElements(); print <<< END
DNS zone%s
%s %s
%s %s
%s %s
%s %s %s
%s %s
END; } function updateRecord() { //print "

Updating range ..."; if (!$_REQUEST['prefix_filter'] || !$_REQUEST['tld_filter']) return; $rangeid = array( 'prefix' => $_REQUEST['prefix_filter'], 'tld' => $_REQUEST['tld_filter'] ); if (!$range = $this->getRecord($rangeid)) { return false; } $range_old = $range; foreach (array_keys($this->Fields) as $item) { $var_name = $item.'_form'; //printf("
%s=%s",$var_name, $_REQUEST[$var_name]); if ($this->Fields[$item]['type'] == 'integer') { $range->$item = intval($_REQUEST[$var_name]); } elseif ($item == 'nameservers') { $_txt = trim($_REQUEST[$var_name]); if (!strlen($_txt)) { unset($range->$item); } else { $_nameservers = array(); $_lines = explode("\n", $_txt); foreach ($_lines as $_line) { $_ns = trim($_line); $_nameservers[] = $_ns; } $range->$item = $_nameservers; } } else { $range->$item = trim($_REQUEST[$var_name]); } } if ($this->adminonly) { foreach (array_keys($this->FieldsAdminOnly) as $item) { $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']))) ); $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'] ); // Range $range = array( 'start' => 0, 'count' => 1 ); // Order $orderBy = array( 'attribute' => 'changeDate', 'direction' => 'DESC' ); // Compose query $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]) { return $result->ranges[0]; } else { return false; } } } }