[Added DNS management functions (incomplete yet) Adrian Georgescu **20080629122104] hunk ./library/ngnpro_client.php 164 - 'records_class' => 'Domains', + 'records_class' => 'SipDomains', hunk ./library/ngnpro_client.php 192 + /* hunk ./library/ngnpro_client.php 200 + 'dns_records' => array( + 'records_class' => 'DnsRecords', + 'name' => 'Dns records', + 'soap_class' => 'WebService_NGNPro_DnsPort', + 'category' => 'dns', + 'description' => 'Manage DNS records. Use % to match a pattern. ' + ), + */ + hunk ./library/ngnpro_client.php 1400 -class Domains extends Records { +class SipDomains extends Records { hunk ./library/ngnpro_client.php 1409 - function Domains(&$SoapEngine) { + function SipDomains(&$SoapEngine) { hunk ./library/ngnpro_client.php 5528 - 'reseller' => array('type'=>'integer', + 'reseller' => array('type'=>'integer', hunk ./library/ngnpro_client.php 5533 - 'customer' => array('type'=>'integer', + 'customer' => array('type'=>'integer', hunk ./library/ngnpro_client.php 5537 - 'help'=>'DNS serial number', + 'help'=>'Serial number', hunk ./library/ngnpro_client.php 5540 - 'ttl' => array('type'=>'integer', + 'email' => array('type'=>'string', + 'help'=>'Administrator address' + ), + 'ttl' => array('type'=>'integer', hunk ./library/ngnpro_client.php 5549 - 'expire' => array('type'=>'integer', + 'expire' => array('type'=>'integer', hunk ./library/ngnpro_client.php 5552 - 'info' => array('type'=>'string', + 'info' => array('type'=>'string', hunk ./library/ngnpro_client.php 5636 + hunk ./library/ngnpro_client.php 5688 - $zone_link=sprintf('%s',$this->url,$this->SoapEngine->service,$zone->reseller,$zone->name,$zone->name); + $zone_url=sprintf('%s',$this->url,$this->SoapEngine->service,$zone->reseller,$zone->name,$zone->name); hunk ./library/ngnpro_client.php 5690 - $zone_link=sprintf('%s',$this->url,$this->SoapEngine->service,$zone->name,$zone->name); + $zone_url=sprintf('%s',$this->url,$this->SoapEngine->service,$zone->name,$zone->name); hunk ./library/ngnpro_client.php 5693 - $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", + $customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", hunk ./library/ngnpro_client.php 5698 + $records_url = $this->url.sprintf("&service=dns_records@%s&zone_filter=%s", + urlencode($this->SoapEngine->soapEngine), + urlencode($zone->name) + ); + hunk ./library/ngnpro_client.php 5715 + Records hunk ./library/ngnpro_client.php 5725 - $_customer_url, + $customer_url, hunk ./library/ngnpro_client.php 5728 - $zone_link, + $zone_url, + $records_url, hunk ./library/ngnpro_client.php 5866 - printf (" Name",$this->filters['name']); - printf (" Info",$this->filters['info']); + printf (" Name",$this->filters['name']); + printf (" Info",$this->filters['info']); hunk ./library/ngnpro_client.php 6093 +class DnsRecords extends Records { + + var $default_ttl = 3600; + var $default_priority = 5; + + var $sortElements=array('changeDate' => 'Change date', + 'name' => 'Name' + ); + + var $FieldsReadOnly=array( + 'customer', + 'reseller' + ); + var $Fields=array( + 'owner' => array('type'=>'integer'), + 'value' => array('type'=>'string'), + 'info' => array('type'=>'string') + ); + var $recordTypes=array('A','AAAA','CNAME','MX','SRV','NS','NAPTR','MBOX','URL'); + + function DnsRecords(&$SoapEngine) { + + dprint("init DnsRecords"); + + $this->filters = array( + 'zone' => trim($_REQUEST['zone_filter']), + 'name' => trim($_REQUEST['name_filter']), + 'type' => trim($_REQUEST['type_filter']), + 'value' => trim($_REQUEST['value_filter']), + 'owner' => trim($_REQUEST['owner_filter']) + ); + $this->Records(&$SoapEngine); + $this->getAllowedDomains(); + } + + function listRecords() { + $this->showSeachForm(); + + $filter=array( + 'zone' => $this->filters['zone'], + 'name' => $this->filters['name'], + 'type' => $this->filters['type'], + 'value' => $this->filters['value'], + '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); + + // Call function + $result = $this->SoapEngine->soapclient->getRecords($Query); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("

Error from %s: %s (%s): %s",$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 " +

+ + +
$this->rows records found
+

+ + + + + + + + + + + + + "; + print " + + "; + + 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->records[$i]) break; + + $record = $result->records[$i]; + $index=$this->next+$i+1; + + //print"
";
+                    //print_r($record);
+                    $rr=floor($index/2);
+                    $mod=$index-$rr*2;
+            
+                    if ($mod ==0) {
+                        $bgcolor="lightgrey";
+                    } else {
+                        $bgcolor="white";
+                    }
+
+                    $j=1;
+
+                    $_url = $this->url.sprintf("&service=%s&action=Delete&name_filter=%s&zone_filter=%s",
+                    urlencode($this->SoapEngine->service),
+                    urlencode($record->id->name),
+                    urlencode($record->id->zone)
+                    );
+
+                    if ($_REQUEST['action'] == 'Delete' &&
+                        $_REQUEST['name_filter'] == $record->id->name &&
+                        $_REQUEST['zone_filter'] == $record->id->zone) {
+                        $_url .= "&confirm=1";
+                        $actionText = "Confirm";
+                    } else {
+                        $actionText = "Delete";
+                    }
+
+                    $_number_url = $this->url.sprintf("&service=%s&id_filter=%s",
+                    urlencode($this->SoapEngine->service),
+                    urlencode($record->id)
+                    );
+
+                    $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s",
+                    urlencode($this->SoapEngine->customer_engine),
+                    urlencode($record->customer)
+                    );
+
+                    $_zone_url = $this->url.sprintf("&service=dns_zones@%s&name_filter=%s",
+                    urlencode($this->SoapEngine->soapEngine),
+                    urlencode($record->id->zone)
+                    );
+
+                    if ($record->owner) {
+                        $_owner_url = sprintf
+                        ("%s",
+                        $this->url,
+                        urlencode($this->SoapEngine->soapEngine),
+                        urlencode($record->owner),
+                        $record->owner
+                        );
+                    } else {
+                        $_owner_url='';
+                    }          
+
+                    if (strlen($record->id->name)) {
+                        $name=$record->id->name.'.'.$record->id->zone;
+                    } else {
+                        $name=$record->id->zone;
+                    }
+                    printf("
+                    
+ + + + + + + + + + + + ", + + $bgcolor, + $index, + $_customer_url, + $record->customer, + $record->reseller, + $_zone_url, + $name, + $record->type, + $record->value, + + $record->ttl, + $record->info, + $_owner_url, + $record->changeDate, + $_url, + $actionText + ); + $i++; + + + } + } + + + print "
Id + "; + print " + CustomerZoneNameTypeValueTTLInfoOwnerChange dateActions
%s%s.%sZone%s%s%s%s%s%s%s%s
"; + + if ($this->rows == 1 ) { + } else { + $this->showPagination($maxrows); + } + + return true; + } + } + + function showSeachFormCustom() { + + printf (" Name ",$_REQUEST['name_filter']); + printf (" Type "; + printf (" Value ",$_REQUEST['value_filter']); + + } + + function deleteRecord($dictionary=array()) { + if (!$dictionary['confirm'] && !$_REQUEST['confirm']) { + print "

Please press on Confirm to confirm the delete. "; + return true; + } + + if ($dictionary['name']) { + $name=$dictionary['name']; + } else { + $name=$this->filters['name']; + } + + if ($dictionary['zone']) { + $zone=$dictionary['zone']; + } else { + $zone=$this->filters['zone']; + } + + $record_id=array('name' => $name, + 'zone' => $zone + ); + + $function=array('commit' => array('name' => 'deleteRecord', + 'parameters' => array($record_id), + 'logs' => array('success' => sprintf('Dns record %s under %s has been deleted',$name,$zone))) + ); + unset($this->filters); + return $this->SoapEngine->execute($function,$this->html); + + } + + function showAddForm() { + + print " +

+ + + "; + + printf ("",$_SERVER['PHP_SELF']); + print " + + + "; + + $this->printHiddenFormElements(); + + print " + + +
+ "; + + print " + + "; + printf (" Name"); + + printf (" ",$_REQUEST['name']); + print ""; + + print " + "; + + printf (" ",$_REQUEST['value']); + printf (" Owner",$_REQUEST['owner']); + + print " + + "; + print " +
+ "; + } + + function getAllowedDomains() { + // Filter + $filter=array( + 'customer' => intval($this->filters['customer']), + 'reseller' => intval($this->filters['reseller']) + ); + // Range + $range=array('start' => 0, + 'count' => 200 + ); + + // Order + $orderBy = array('attribute' => 'name', + 'direction' => 'ASC' + ); + + // Compose query + $Query=array('filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); + + $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); + $result = $this->SoapEngine->soapclient->getZones($Query); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("

Error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + return false; + } else { + foreach($result->zones as $zone) { + if (in_array($zone->name,$this->allowedDomains)) continue; + $this->allowedDomains[]=$zone->name; + $seen[$zone->name]++; + } + } + } + + function addRecord($dictionary=array()) { + if ($dictionary['zone']) { + $zone=$dictionary['zone']; + $this->skipSaveProperties=true; + } else if ($_REQUEST['zone']) { + $zone=$_REQUEST['zone']; + } + + if ($dictionary['name']) { + $name = $dictionary['name']; + } else { + $name = trim($_REQUEST['name']); + } + + if (!strlen($zone)) { + printf ("

Error: Missing zone name. "); + return false; + } + + list($customer,$reseller)=$this->customerFromLogin($dictionary); + + 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 ($dictionary['info']) { + $info = $dictionary['info']; + } else { + $info = trim($_REQUEST['info']); + } + + if ($dictionary['value']) { + $value = $dictionary['value']; + } else { + $value = trim($_REQUEST['value']); + } + + if (!strlen($value)) { + printf ("

Error: Missing record value. "); + return false; + } + + if ($dictionary['type']) { + $type = $dictionary['type']; + } else { + $type = trim($_REQUEST['type']); + } + + if (!strlen($type) || !in_array($type,$this->recordTypes)) { + printf ("

Error: Invalid or missing record type. "); + return false; + } + + $record=array('id' => array('name'=>$name, + 'zone'=>$zone), + 'value' => $value, + 'ttl' => $ttl, + 'type' => $type, + 'owner' => $owner, + 'info' => $info + ); + + if (!$this->skipSaveProperties=true) { + + $_p=array( + array('name' => 'dns_records_last_zone', + 'category' => 'web', + 'value' => $_REQUEST['zone'], + 'permission' => 'customer' + ), + array('name' => 'dns_records_last_type', + 'category' => 'web', + 'value' => "$type", + 'permission' => 'customer' + ) + ); + + $this->setLoginProperties($_p); + } + + $function=array('commit' => array('name' => 'addRecord', + 'parameters' => array($record), + 'logs' => array('success' => sprintf('Dns record %s under %s has been added',$name,$zone))), + 'rollback' => array('name' => 'deleteNumber', + 'parameters' => array($record) + ) + ); + + return $this->SoapEngine->execute($function,$this->html); + } + + function getRecordKeys() { + + // Filter + $filter=array('number' => $this->filters['number'], + 'tld' => $this->filters['tld'], + 'type' => $this->filters['type'], + 'mapto' => $this->filters['mapto'], + 'owner' => intval($this->filters['owner']), + 'customer' => intval($this->filters['customer']), + 'reseller' => intval($this->filters['reseller']) + ); + // 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 ("

Error from %s: %s (%s): %s",$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; + } + } + + function showRecord($number) { + + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + + print " + + + + "; + print ""; + print "
"; + print "

Number

"; + print "
"; + print "

Mappings

"; + print "
"; + + print ""; + + printf ("",$_SERVER['PHP_SELF']); + print ""; + + printf ("", + $this->tel2enum($number->id->number,$number->id->tld)); + + foreach (array_keys($this->Fields) as $item) { + if ($this->Fields[$item]['name']) { + $item_name=$this->Fields[$item]['name']; + } else { + $item_name=ucfirst($item); + } + + if ($this->Fields[$item]['type'] == 'text') { + printf (" + + + ", + $item_name, + $item, + $number->$item + ); + } else { + printf (" + + + ", + $item_name, + $item, + $number->$item + ); + } + } + + printf ("id->tld); + printf ("id->number); + + $this->printFiltersToForm(); + $this->printHiddenFormElements(); + + print " +
DNS name%s
%s
%s
+ "; + + print "
"; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + foreach ($number->mappings as $_mapping) { + $j++; + unset($selected_type); + print ""; + print ""; + $selected_type[$_mapping->type]='selected'; + + printf (" + "; + + printf (" + + + ", + $_mapping->mapto, + $_mapping->ttl + ); + print ""; + } + + $j++; + print ""; + print ""; + + printf (" + "; + + printf (" + + + " + ); + + print ""; + + print "
TypeMap toTTL
$j +
+
"; + + print "
+ +
"; + + } + + function getRecord($record) { + + $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); + $result = $this->SoapEngine->soapclient->getRecords($filter); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("

Error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + return false; + } else { + return $result; + } + } + + function updateRecord () { + //print "

Updating record ..."; + + if (!$_REQUEST['id_filter']) return; + + $record=array('number' => $_REQUEST['number_filter'], + 'tld' => $_REQUEST['tld_filter'] + ); + + if (!$number = $this->getRecord($record)) { + return false; + } + + $record_old=$record; + + 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') { + $record->$item = intval($_REQUEST[$var_name]); + } else { + $record->$item = trim($_REQUEST[$var_name]); + } + } + + //print_r($number); + $function=array('commit' => array('name' => 'updateRecord', + 'parameters' => array($record), + 'logs' => array('success' => sprintf('ENUM number +%s under %s has been updated',$enumid['number'],$enumid['tld']))), + 'rollback' => array('name' => 'updateRecord', + 'parameters' => array($record_old)) + ); + + return $this->SoapEngine->execute($function,$this->html); + + } +}