diff --git a/library/NGNPro/Records/DnsRecords.php b/library/NGNPro/Records/DnsRecords.php new file mode 100644 index 0000000..1f45da3 --- /dev/null +++ b/library/NGNPro/Records/DnsRecords.php @@ -0,0 +1,1549 @@ + 'Change date', + 'type' => 'Type', + 'name' => 'Name' + ); + + var $FieldsReadOnly = array( + 'customer', + 'reseller' + ); + + var $Fields = array( + 'type' => array('type'=>'string'), + 'priority' => array('type'=>'integer'), + 'value' => array('type'=>'string'), + 'ttl' => array('type'=>'integer') + ); + + var $recordTypes = array( + 'A' => 'IP address', + 'AAAA' => 'IP v6 address', + 'CNAME' => 'Hostname alias', + 'MX' => 'Mail server address', + 'SRV' => 'Server resource', + 'NS' => 'Name server address', + 'NAPTR' => 'Name authority', + 'PTR' => 'Reverse IP address', + 'TXT' => 'Text', + 'LOC' => 'Geo location' + ); + + var $havePriority = array('MX','SRV','NAPTR'); + + var $addRecordFunction = 'addRecord'; + var $deleteRecordFunction = 'deleteRecord'; + var $updateRecordFunction = 'updateRecord'; + var $getRecordsFunction = 'getRecords'; + var $getRecordFunction = 'getRecord'; + + var $recordTypesTemplate = array( + 'sip2sip' => array( + 'name' => 'SIP2SIP infrastructure', + 'records' => array( + 'naptr1' => array( + 'name' => '', + 'type' => 'NAPTR', + 'priority' => '100', + 'ttl' => '600', + 'value' => '20 100 "s" "SIP+D2T" "" _sip._tcp' + ), + 'naptr2' => array( + 'name' => '', + 'type' => 'NAPTR', + 'priority' => '100', + 'ttl' => '600', + 'value' => '30 100 "s" "SIP+D2U" "" _sip._udp' + ), + 'naptr3' => array( + 'name' => '', + 'type' => 'NAPTR', + 'priority' => '100', + 'ttl' => '600', + 'value' => '10 100 "s" "SIPS+D2T" "" _sips._tcp' + ), + 'srv1' => array( + 'name' => '_sip._tcp', + 'type' => 'SRV', + 'priority' => '100', + 'ttl' => '600', + 'value' => '100 5060 proxy.sipthor.net' + ), + 'srv2' => array( + 'name' => '_sip._udp', + 'type' => 'SRV', + 'priority' => '100', + 'ttl' => '600', + 'value' => '100 5060 proxy.sipthor.net' + ), + 'srv3' => array( + 'name' => '_sips._tcp', + 'type' => 'SRV', + 'priority' => '100', + 'ttl' => '600', + 'value' => '100 5061 proxy.sipthor.net' + ), + 'srv4' => array( + 'name' => '_stun._udp', + 'type' => 'SRV', + 'priority' => '0', + 'value' => '10 3478 stun1.sipthor.net' + ), + 'srv5' => array( + 'name' => '_stun._udp', + 'type' => 'SRV', + 'priority' => '0', + 'value' => '10 3478 stun2.sipthor.net' + ), + 'srv6' => array( + 'name' => '_msrps._tcp', + 'type' => 'SRV', + 'priority' => '10', + 'value' => '0 2855 msrprelay.sipthor.net' + ), + 'txt1' => array( + 'name' => 'xcap', + 'type' => 'TXT', + 'priority' => '10', + 'value' => 'https://xcap.sipthor.net/xcap-root' + ) + ), + ), + 'siptcp' => array( + 'name' => 'SIP - TCP transport', + 'records' => array( + 'naptr' => array( + 'name' => '', + 'type' => 'NAPTR', + 'priority' => '100', + 'ttl' => '3600', + 'value' => '10 100 "s" "SIP+D2T" "" _sip._tcp' + ), + 'srv' => array( + 'name' => '_sip._tcp', + 'type' => 'SRV', + 'priority' => '100', + 'ttl' => '3600', + 'value' => '100 5060 #VALUE#|10 5060 sip' + ) + ), + ), + 'siptls' => array( + 'name' => 'SIP - TLS transport', + 'records' => array( + 'naptr' => array( + 'name' => '', + 'type' => 'NAPTR', + 'priority' => '100', + 'ttl' => '3600', + 'value' => '20 100 "s" "SIPS+D2T" "" _sips._tcp' + ), + 'srv' => array( + 'name' => '_sips._tcp', + 'type' => 'SRV', + 'priority' => '100', + 'ttl' => '3600', + 'value' => '100 5061 #VALUE#|10 5061 sip' + ) + ) + ), + 'sipudp' => array( + 'name' => 'SIP - UDP transport', + 'records' => array( + 'naptr' => array( + 'name' => '', + 'type' => 'NAPTR', + 'priority' => '100', + 'ttl' => '3600', + 'value' => '30 100 "s" "SIP+D2U" "" _sip._udp' + ), + 'srv' => array( + 'name' => '_sip._udp', + 'type' => 'SRV', + 'priority' => '100', + 'ttl' => '3600', + 'value' => '100 5060 #VALUE#|10 5060 sip' + ) + ), + ), + 'stun' => array( + 'name' => 'STUN - NAT mirror', + 'records' => array( + 'srv' => array( + 'name' => '_stun._udp', + 'type' => 'SRV', + 'priority' => '0', + 'value' => '10 3478 #VALUE#|10 3478 stun' + ) + ), + ), + 'xmpp-server' => array( + 'name' => 'XMPP server-to-server over TCP', + 'records' => array( + 'srv' => array( + 'name' => '_xmpp-server._tcp', + 'type' => 'SRV', + 'priority' => '0', + 'value' => '10 5269 #VALUE#|10 5269 xmpp' + ), + 'srv1' => array( + 'name' => '_jabber._tcp', + 'type' => 'SRV', + 'priority' => '0', + 'value' => '10 5269 #VALUE#|10 5269 xmpp' + ) + ), + ), + 'xmpp-client' => array( + 'name' => 'XMPP client-to-server over TCP', + 'records' => array( + 'srv' => array( + 'name' => '_xmpp-client._tcp', + 'type' => 'SRV', + 'priority' => '0', + 'value' => '10 5222 #VALUE#|10 5222 xmpp' + ) + ), + ), + 'xmpps-server' => array( + 'name' => 'XMPP server-to-server over TLS', + 'records' => array( + 'srv' => array( + 'name' => '_xmpps-server._tcp', + 'type' => 'SRV', + 'priority' => '0', + 'value' => '10 5269 #VALUE#|10 5269 xmpp' + ), + 'srv1' => array( + 'name' => '_jabbers._tcp', + 'type' => 'SRV', + 'priority' => '0', + 'value' => '10 5269 #VALUE#|10 5269 xmpp' + ) + ), + ), + 'xmpps-client' => array( + 'name' => 'XMPP client-to-server over TLS', + 'records' => array( + 'srv' => array( + 'name' => '_xmpps-client._tcp', + 'type' => 'SRV', + 'priority' => '0', + 'value' => '10 5222 #VALUE#|10 5222 xmpp' + ) + ), + ), + 'msrp' => array( + 'name' => 'MSRP - IM relay', + 'records' => array( + 'srv' => array( + 'name' => '_msrps._tcp', + 'type' => 'SRV', + 'priority' => '10', + 'value' => '0 2855 msrprelay' + ) + ) + ), + 'sipthor' => array( + 'name' => 'SIP - Thor network', + 'records' => array( + 'eventserver' => array( + 'name' => '_eventserver._tcp', + 'type' => 'SRV', + 'priority' => '10', + 'value' => '0 8000 eventserver' + ), + 'sipserver' => array( + 'name' => '_sip._udp', + 'type' => 'SRV', + 'priority' => '10', + 'value' => '30 5060 proxy' + ), + 'sipns1' => array( + 'name' => 'proxy', + 'type' => 'NS', + 'value' => 'ns1' + ), + 'sipns2' => array( + 'name' => 'proxy', + 'type' => 'NS', + 'value' => 'ns2' + ), + 'sipns3' => array( + 'name' => 'proxy', + 'type' => 'NS', + 'value' => 'ns3' + ), + 'ngnproserver' => array( + 'name' => '_ngnpro._tcp', + 'type' => 'SRV', + 'priority' => '10', + 'value' => '0 9200 ngnpro' + ), + 'ngnns1' => array( + 'name' => 'ngnpro', + 'type' => 'NS', + 'value' => 'ns1' + ), + 'ngnns2' => array( + 'name' => 'ngnpro', + 'type' => 'NS', + 'value' => 'ns2' + ), + 'ngnns3' => array( + 'name' => 'ngnpro', + 'type' => 'NS', + 'value' => 'ns3' + ), + 'xcapserver' => array( + 'name' => '_xcap._tcp', + 'type' => 'SRV', + 'priority' => '10', + 'value' => '0 443 xcap' + ), + 'xcapns1' => array( + 'name' => 'xcap', + 'type' => 'NS', + 'value' => 'ns1' + ), + 'xcapns2' => array( + 'name' => 'xcap', + 'type' => 'NS', + 'value' => 'ns2' + ), + 'xcapns3' => array( + 'name' => 'xcap', + 'type' => 'NS', + 'value' => 'ns3' + ), + 'msrpserver' => array( + 'name' => '_msrps._tcp', + 'type' => 'SRV', + 'priority' => '10', + 'value' => '0 2855 msrprelay' + ), + 'msrpns1' => array( + 'name' => 'msrprelay', + 'type' => 'NS', + 'value' => 'ns1' + ), + 'msrpns2' => array( + 'name' => 'msrprelay', + 'type' => 'NS', + 'value' => 'ns2' + ), + 'msrpns3' => array( + 'name' => 'msrprelay', + 'type' => 'NS', + 'value' => 'ns3' + ), + 'voicemail' => array( + 'name' => '_voicemail._tcp', + 'type' => 'SRV', + 'priority' => '10', + 'value' => '0 9200 voicemail' + ), + 'vmns1' => array( + 'name' => 'voicemail', + 'type' => 'NS', + 'value' => 'ns1' + ), + 'vmns2' => array( + 'name' => 'voicemail', + 'type' => 'NS', + 'value' => 'ns2' + ), + 'vmns3' => array( + 'name' => 'voicemail', + 'type' => 'NS', + 'value' => 'ns3' + ) + ) + ) + ); + + + public function __construct($SoapEngine) + { + dprint("init DnsRecords"); + + $_name = trim($_REQUEST['name_filter']); + + if (strlen($_name) && !strstr($_name,'.') && !strstr($_name,'%')) { + $_name .= '%'; + } + + if ($this->typeFilter) { + $this->filters = array( + 'id' => trim($_REQUEST['id_filter']), + 'zone' => trim($_REQUEST['zone_filter']), + 'name' => $_name, + 'type' => $this->typeFilter, + 'value' => trim($_REQUEST['value_filter']), + 'owner' => trim($_REQUEST['owner_filter']) + ); + } else { + $this->filters = array( + 'id' => trim($_REQUEST['id_filter']), + 'zone' => trim($_REQUEST['zone_filter']), + 'name' => $_name, + 'type' => trim($_REQUEST['type_filter']), + 'value' => trim($_REQUEST['value_filter']), + 'owner' => trim($_REQUEST['owner_filter']) + ); + } + + parent::__construct($SoapEngine); + $this->getAllowedDomains(); + } + + function listRecords() { + $this->showSeachForm(); + + if ($this->typeFilter) { + $filter = array( + 'id' => intval($this->filters['id']), + 'zone' => $this->filters['zone'], + 'name' => $this->filters['name'], + 'type' => $this->typeFilter, + 'value' => $this->filters['value'], + 'owner' => intval($this->filters['owner']), + 'customer' => intval($this->filters['customer']), + 'reseller' => intval($this->filters['reseller']) + ); + } else { + $filter = array( + 'id' => intval($this->filters['id']), + '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); + $this->log_action($this->getRecordsFunction); + + // Call function + $result = call_user_func_array(array($this->SoapEngine->soapclient,$this->getRecordsFunction),array($Query)); + + if ((new PEAR)->isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + $log = sprintf( + "SOAP request error from %s: %s (%s): %s", + $this->SoapEngine->SOAPurl, + $error_msg, + $error_fault->detail->exception->errorcode, + $error_fault->detail->exception->errorstring + ); + syslog(LOG_NOTICE, $log); + return false; + } else { + $this->rows = $result->total; + + if ($this->rows > 1 && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') { + $this->showActionsForm(); + } + + print " +
+
+ | Zone owner | +Zone | +Id | +Name | +Type | +Value | +Owner | +Change date | +Actions | +|
---|---|---|---|---|---|---|---|---|---|---|
+ | Zone owner | +Zone | +Id | +Name | +Type | +Priority | +Value | +TTL | +Change date | +Actions | +
%s | +%s.%s | +%s | +%s | +%s | +%s | +%s | +%s | +%s | +%s | +|
%s | +%s.%s | +%s | +%s | +%s | +%s | +%s | +%s | +%s | +%s | +%s | +
Please press on Confirm to confirm the delete. "; + return true; + } + + if ($dictionary['id']) { + $id=$dictionary['id']; + } else { + $id=$this->filters['id']; + } + + if (!$id) { + print "
Missing record id. "; + return false; + } + + $function = array( + 'commit' => array( + 'name' => $this->deleteRecordFunction, + 'parameters' => array($id), + 'logs' => array('success' => sprintf('DNS record %s has been deleted',$id)) + ) + ); + + $zone=$this->filters['zone']; + unset($this->filters); + $this->filters['zone']=$zone; + + $result = $this->SoapEngine->execute($function,$this->html); + + if ((new PEAR)->isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + $log = sprintf( + "SOAP request error from %s: %s (%s): %s", + $this->SoapEngine->SOAPurl, + $error_msg, + $error_fault->detail->exception->errorcode, + $error_fault->detail->exception->errorstring + ); + syslog(LOG_NOTICE, $log); + return false; + } else { + return true; + } + + } + + function showAddForm() { + /* + if ($this->adminonly) { + if (!$this->filters['reseller']) { + print "
To add a new record you must search first for a customer"; + return; + } + } + */ + + printf("
+ "; + } + + function getAllowedDomains() { + // Filter + $filter = array( + 'customer' => intval($this->filters['customer']), + 'reseller' => intval($this->filters['reseller']) + ); + // Range + $range = array( + 'start' => 0, + 'count' => $this->max_zones_selection + ); + + // Order + $orderBy = array( + 'attribute' => 'name', + 'direction' => 'ASC' + ); + + // Compose query + $Query = array( + 'filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); + + $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); + $this->log_action('getZones'); + $result = $this->SoapEngine->soapclient->getZones($Query); + + if ((new PEAR)->isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + $log = sprintf( + "SOAP request error from %s: %s (%s): %s", + $this->SoapEngine->SOAPurl, + $error_msg, + $error_fault->detail->exception->errorcode, + $error_fault->detail->exception->errorstring + ); + syslog(LOG_NOTICE, $log); + return false; + } else { + if ($result->total > $this->max_zones_selection) return false; + 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 ($this->typeFilter) { + $type = $this->typeFilter; + } else if ($dictionary['type']) { + $type = $dictionary['type']; + } else { + $type = trim($_REQUEST['type']); + } + + if ($dictionary['name']) { + $name = $dictionary['name']; + } else { + $name = trim($_REQUEST['name']); + } + + $name = rtrim($name,"."); + + if (preg_match("/^(.+)@(.*)$/", $name, $m)) { + $zone = $m[2]; + } else { + if ($dictionary['zone']) { + $zone=$dictionary['zone']; + $this->skipSaveProperties=true; + } else if ($_REQUEST['zone']) { + $zone=$_REQUEST['zone']; + } + + if ($type == 'MBOXFW') { + $name .= '@'.$zone; + } + } + + if (!strlen($zone)) { + if ($this->html) { + echo "Updating record ...";
+
+ if (!$_REQUEST['id_filter']) return;
+
+ if (!$record = $this->getRecord(intval($_REQUEST['id_filter']))) {
+ 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]);
+ }
+ }
+
+ $function=array('commit' => array('name' => $this->updateRecordFunction,
+ 'parameters' => array($record),
+ 'logs' => array('success' => sprintf('Record %s has been updated',$_REQUEST['id_filter'])))
+ );
+
+ $result = $this->SoapEngine->execute($function,$this->html);
+ dprint_r($result);
+
+ if ((new PEAR)->isError($result)) {
+ $error_msg = $result->getMessage();
+ $error_fault= $result->getFault();
+ $error_code = $result->getCode();
+ $log = sprintf(
+ "SOAP request error from %s: %s (%s): %s",
+ $this->SoapEngine->SOAPurl,
+ $error_msg,
+ $error_fault->detail->exception->errorcode,
+ $error_fault->detail->exception->errorstring
+ );
+ syslog(LOG_NOTICE, $log);
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ function showTextBeforeCustomerSelection() {
+ print _("Zone owner");
+ }
+
+}
+
diff --git a/library/NGNPro/Records/DnsZones.php b/library/NGNPro/Records/DnsZones.php
index c372e53..408007d 100644
--- a/library/NGNPro/Records/DnsZones.php
+++ b/library/NGNPro/Records/DnsZones.php
@@ -1,903 +1,904 @@
array(
'type'=>'integer',
'help' => 'Zone owner'
)
);
var $Fields = array(
'customer' => array(
'type' => 'integer',
'help' => 'Zone owner'
),
'serial' => array(
'type' => 'integer',
'help' => 'Serial number',
'readonly' => 1
),
'email' => array(
'type' => 'string',
'help' => 'Administrator address'
),
'ttl' => array(
'type' => 'integer',
'help' => 'Time to live of SOA record'
),
'minimum' => array(
'type' => 'integer',
'help' => 'Default time to live period'
),
'retry' => array(
'type' => 'integer',
'help' => 'Retry transfer period'
),
'expire' => array(
'type' => 'integer',
'help' => 'Expire period'
),
'info' => array(
'type' => 'string',
'help' => 'Zone description'
)
);
public function __construct($SoapEngine)
{
dprint("init DnsZones");
$this->filters = array(
'name' => trim($_REQUEST['name_filter']),
'info' => trim($_REQUEST['info_filter'])
);
parent::__construct($SoapEngine);
$this->sortElements = array(
'changeDate' => 'Change date',
'name' => 'Name'
);
$this->Fields['nameservers'] = array(
'type'=>'text',
'name'=>'Name servers',
'help'=>'Authoritative name servers'
);
}
function showAfterEngineSelection()
{
if ($this->SoapEngine->name_servers) {
//printf(" Available name servers: %s", $this->SoapEngine->name_servers);
}
}
function listRecords()
{
$this->showSeachForm();
// Filter
$filter = array(
'name' => $this->filters['name'],
'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('getZones');
$result = $this->SoapEngine->soapclient->getZones($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
Id | Owner | Zone | Administrator | Info | Serial | Default TTL | Change date | Actions | |
---|---|---|---|---|---|---|---|---|---|
%s | %s.%s | %s | %s | %s | Records | %s | %s | %s | %s |
Please press on Confirm to confirm the delete. "; return true; } if (!strlen($this->filters['name'])) { print "
Error: missing Dns zone name "; return false; } $name = $this->filters['name']; $function = array( 'commit' => array( 'name' => 'deleteZone', 'parameters' => array($name), 'logs' => array( 'success' => sprintf('Dns zone %s has been deleted', $this->filters['name']) ) ) ); 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( "
"; } function addRecord($dictionary = array()) { $name = trim($_REQUEST['name']); $info = trim($_REQUEST['info']); $name_servers = trim($_REQUEST['name_servers']); if ($_FILES['import_file']['tmp_name']) { $content = fread(fopen($_FILES['import_file']['tmp_name'], "r"), $_FILES['import_file']['size']); //print_r($content); if (!$imported_data = json_decode($content, true)) { printf("Error: reading imported data. "); return false; } //print_r($imported_data); if (!in_array('dns_zones', array_keys($imported_data))) { printf("
Error: Missing zones in imported data. "); return false; } if (!in_array('dns_records', array_keys($imported_data))) { return false; printf("
Error: Missing records in imported data. "); } foreach ($imported_data['customers'] as $customer) { // Insert credetials $this->SoapEngine->soapclientCustomers->addHeader($this->SoapEngine->SoapAuth); $customer['credit'] = floatval($customer['credit']); $customer['balance'] = floatval($customer['balance']); // Call function $this->log_action('addAccount'); $result = $this->SoapEngine->soapclientCustomers->addAccount($customer); if ((new PEAR)->isError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); if ($error_fault->detail->exception->errorcode == 5001) { $result = $this->SoapEngine->soapclientCustomers->updateCustomer($customer); if (!$this->checkLogSoapError($result, true, true)) { printf('
Customer %s has been updated', $customer['id']); } } else { $log = sprintf( "SOAP request error from %s: %s (%s): %s", $this->SoapEngine->SOAPurl, $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring ); syslog(LOG_NOTICE, $log); printf("
Error: $log"); } } else { printf('
Customer %s has been added', $customer['id']); } } $name_servers = array(); foreach ($imported_data['dns_zones'] as $zone) { flush(); $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('addZone'); $result = $this->SoapEngine->soapclient->addZone($zone); $name_servers[$zone['name']] = $zone['nameservers']; if ((new PEAR)->isError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); if ($error_fault->detail->exception->errorcode == 7001) { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('updateZone'); $result = $this->SoapEngine->soapclient->updateZone($zone); if (!$this->checkLogSoapError($result, true, true)) { printf('
Zone %s has been updated', $zone['name']); } } else { $log = sprintf( "SOAP request error from %s: %s (%s): %s", $this->SoapEngine->SOAPurl, $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring ); syslog(LOG_NOTICE, $log); printf("
Error: $log"); } } else { printf('
Zone %s has been added', $zone['name']); } } $added = 0; $updated = 0; foreach ($imported_data['dns_records'] as $record) { flush(); if (in_array($record['name'], $name_servers[$record['zone']]) && $record['type'] == "A") { continue; } $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('addRecord'); $result = $this->SoapEngine->soapclient->addRecord($record); if ((new PEAR)->isError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); if ($error_fault->detail->exception->errorcode == 7003) { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('updateRecord'); $result = $this->SoapEngine->soapclient->updateRecord($record); if (!$this->checkLogSoapError($result, true, true)) { $added += 1; } } else { $log = sprintf( "SOAP request error from %s: %s (%s): %s", $this->SoapEngine->SOAPurl, $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring ); syslog(LOG_NOTICE, $log); printf("
Error: $log"); } } else { $added += 1; } } printf('
%d DNS records added and %d updated', $added, $updated); return true; } else { if (isset($this->SoapEngine->allow_none_local_dns_zones)) { $allow_none_local_dns_zones = $this->SoapEngine->allow_none_local_dns_zones; } else { $allow_none_local_dns_zones = false; } if (!strlen($name)) { printf("
Error: Missing zone name.
"); return false; } $lookup1 = dns_get_record($name); //dprint_r($lookup1); $ns_array1=explode(" ", trim($this->SoapEngine->name_servers)); if (empty($lookup1) || $allow_none_local_dns_zones) { $valid = 1; } else { $valid = 0; foreach ($lookup1 as $lrecord) { if ($lrecord['type'] == 'NS') { if (in_array($lrecord['target'], $ns_array1)) { $valid = 1 ; } } } } if ($valid==0) { printf("Error: DNS zone already exists on other server. Please contact our support if you plan to transfer this DNS zone to this system.
"); return false; } if (is_numeric($prefix)) { printf("Error: Numeric zone names are not allowed. Use ENUM port instead. "); return false; } list($customer, $reseller)=$this->customerFromLogin($dictionary); if (!trim($_REQUEST['ttl'])) { $ttl=3600; } else { $ttl = intval(trim($_REQUEST['ttl'])); } if ($name_servers) { $ns_array = explode(" ", trim($name_servers)); } elseif ($this->login_credentials['login_type'] != 'admin' && $this->SoapEngine->name_servers) { $ns_array = explode(" ", trim($this->SoapEngine->name_servers)); } else { $ns_array = array(); } $zone = array( 'name' => $name, 'ttl' => $ttl, 'info' => $info, 'customer' => intval($customer), 'reseller' => intval($reseller), 'nameservers' => $ns_array ); $function = array('commit' => array('name' => 'addZone', 'parameters' => array($zone), 'logs' => array('success' => sprintf('DNS zone %s has been added', $name))) ); $result = $this->SoapEngine->execute($function, $this->html); dprint_r($result); if ($this->checkLogSoapError($result, true)) { return false; } else { return true; } } } function showSeachFormCustom() { printf( "
Updating zone %s...", $_REQUEST['name_filter']);
$filter = array('name' => $_REQUEST['name_filter']);
if (!$zone = $this->getRecord($filter)) {
return false;
}
$zone_old = $zone;
foreach (array_keys($this->Fields) as $item) {
$var_name = $item.'_form';
//printf(" %s at %s as %s ", $this->soap_class, $this->SOAPurl, $this->SOAPurl, $this->soapUsername ); dprint($log); $this->SoapAuth = array('auth', $this->SOAPlogin , 'urn:AGProjects:NGNPro', 0, ''); $this->SoapAuthAdmin = array('auth', $this->SOAPloginAdmin , 'urn:AGProjects:NGNPro', 0, ''); // Instantiate the SOAP client if (!class_exists($this->soap_class)) return ; $this->soapclient = new $this->soap_class($this->SOAPurl); $this->soapclient->setOpt('curl', 'CURLOPT_SSL_VERIFYPEER', 0); $this->soapclient->setOpt('curl', 'CURLOPT_SSL_VERIFYHOST', 0); // set the timeout $this->soapclient->_options['timeout'] = $this->timeout; if ($this->customer_engine) { $this->SOAPloginCustomers = array( "username" => $this->soapEngines[$this->customer_engine]['username'], "password" => $this->soapEngines[$this->customer_engine]['password'], "admin" => true, "impersonate" => intval($this->reseller) ); $this->SoapAuthCustomers = array('auth', $this->SOAPloginCustomers , 'urn:AGProjects:NGNPro', 0, ''); $this->SOAPurlCustomers = $this->soapEngines[$this->customer_engine]['url']; $this->soapclientCustomers = new WebService_NGNPro_CustomerPort($this->SOAPurlCustomers); $this->soapclientCustomers->setOpt('curl', 'CURLOPT_SSL_VERIFYPEER', 0); $this->soapclientCustomers->setOpt('curl', 'CURLOPT_SSL_VERIFYHOST', 0); if (strlen($this->soapEngines[$this->customer_engine]['timeout'])) { $this->soapclientCustomers->_options['timeout'] = intval($this->soapEngines[$this->customer_engine]['timeout']); } else { $this->soapclientCustomers->_options['timeout'] = $this->timeout; } } if ($this->voicemail_engine) { $this->SOAPloginVoicemail = array( "username" => $this->soapEngines[$this->voicemail_engine]['username'], "password" => $this->soapEngines[$this->voicemail_engine]['password'], "admin" => true, "impersonate" => intval($this->reseller) ); $this->SoapAuthVoicemail = array('auth', $this->SOAPloginVoicemail , 'urn:AGProjects:NGNPro', 0, ''); $this->SOAPurlVoicemail = $this->soapEngines[$this->voicemail_engine]['url']; $this->soapclientVoicemail = new WebService_NGNPro_VoicemailPort($this->SOAPurlVoicemail); $this->soapclientVoicemail->setOpt('curl', 'CURLOPT_SSL_VERIFYPEER', 0); $this->soapclientVoicemail->setOpt('curl', 'CURLOPT_SSL_VERIFYHOST', 0); if (strlen($this->soapEngines[$this->voicemail_engine]['timeout'])) { $this->soapclientVoicemail->_options['timeout'] = intval($this->soapEngines[$this->voicemail_engine]['timeout']); } else { $this->soapclientVoicemail->_options['timeout'] = $this->timeout; } } } else { print "Error: No SOAP credentials defined."; } $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]) ); } $this->support_email = $this->soapEngines[$this->soapEngine]['support_email']; $this->support_web = $this->soapEngines[$this->soapEngine]['support_web']; $this->welcome_message = $this->soapEngines[$this->soapEngine]['welcome_message']; } /** * returns a list of allowed engines based on a filter * the filter format is: * engine1:port1,port2 engine2 engine3:port1 */ public function getSoapEngineAllowed($soapEngines, $filter) { if (!$filter) { $soapEngines_checked = $soapEngines; } else { $_filter_els = explode(" ", $filter); foreach (array_keys($soapEngines) as $_engine) { foreach ($_filter_els as $_filter) { unset($_allowed_engine); $_allowed_ports = array(); list($_allowed_engine, $_allowed_ports_els) = explode(":", $_filter); if ($_allowed_ports_els) { $_allowed_ports = explode(",", $_allowed_ports_els); } if (count($_allowed_ports) == 0) { $_allowed_ports = array_keys($this->ports); } if ($_engine == $_allowed_engine) { $soapEngines_checked[$_engine] = $soapEngines[$_engine]; $this->allowedPorts[$_engine] = $_allowed_ports; continue; } } } } return $soapEngines_checked; } /** * $function = array( * 'commit' => array( * 'name' => 'addAccount', * 'parameters' => array( * $param1, * $param2 * ), * 'logs' => array( * 'success' => 'The function was a success', * 'failure' => 'The function has failed' * ) * ) * ); */ public function execute($function, $html = true, $adminonly = false) { if (!$function['commit']['name']) { if ($html) { print "Error: no function name supplied"; } else { print "Error: no function name supplied\n"; } return false; } if ($adminonly) { $this->soapclient->addHeader($this->SoapAuthAdmin); } else { $this->soapclient->addHeader($this->SoapAuth); } $result = call_user_func_array( array( $this->soapclient, $function['commit']['name'] ), $function['commit']['parameters'] ); if ((new PEAR)->isError($result)) { $this->error_msg = $result->getMessage(); $this->error_fault = $result->getFault(); $this->error_code = $result->getCode(); $this->exception = $this->error_fault->detail->exception; $log = sprintf( "SOAP request error from %s: %s (%s): %s", $this->SOAPurl, $this->error_msg, $this->error_fault->detail->exception->errorcode, $this->error_fault->detail->exception->errorstring ); syslog(LOG_NOTICE, $log); if ($html) { $log = sprintf( "SOAP query failed: %s (%s): %s", $this->error_msg, $this->error_fault->detail->exception->errorcode, $this->error_fault->detail->exception->errorstring ); print "$log"; } return false; } else { $this->result = $result; if ($function['commit']['logs']['success']) { if ($html) { printf( " %s \n", htmlentities($function['commit']['logs']['success']) ); } } if (is_object($result) || strlen($result)) { return $result; } else { return true; } } } } class Records { public $maxrowsperpage = '20'; public $sip_settings_page = 'sip_settings.phtml'; public $allowedDomains = array(); public $selectionActive = false; public $selectionKeys = array(); public $resellers = array(); public $customers = array(); public $record_generator = false; public $customer_properties = array(); public $loginProperties = array(); public $errorMessage = ''; public $html = true; public $filters = array(); public $selectionActiveExceptions = array(); public function log_action($action = 'Unknown') { global $CDRTool; $location = "Unknown"; $_loc = geoip_record_by_name($_SERVER['REMOTE_ADDR']); if ($_loc['country_name']) { $location = $_loc['country_name']; } $log = sprintf( "CDRTool login username=%s, type=%s, impersonate=%s, IP=%s, location=%s, action=%s:%s, script=%s", $this->login_credentials['username'], $this->login_credentials['login_type'], $CDRTool['impersonate'], $_SERVER['REMOTE_ADDR'], $location, $this->SoapEngine->port, $action, $_SERVER['PHP_SELF'] ); syslog(LOG_NOTICE, $log); } public function checkLogSoapError($result, $syslog = false, $print = false) { if (!(new PEAR)->isError($result)) { return false; } $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); if ($syslog) { $log = sprintf( "SOAP request error from %s: %s (%s): %s", $this->SoapEngine->SOAPurl, $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring ); syslog(LOG_NOTICE, $log); if ($print) { printf(" Error: $log"); } } else { printf( "Error: %s (%s): %s", $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring ); } return true; } public function __construct($SoapEngine) { $this->SoapEngine = $SoapEngine; $this->version = $this->SoapEngine->version; $this->login_credentials = $this->SoapEngine->login_credentials; $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->customer = $this->SoapEngine->customer; $this->impersonate = $this->SoapEngine->impersonate; $this->url = $this->SoapEngine->url; foreach (array_keys($this->filters) as $_filter) { if (strlen($this->filters[$_filter]) && !in_array($_filter, $this->selectionActiveExceptions)) { $this->selectionActive = true; break; } } if ($this->adminonly) { $this->url .= sprintf('&adminonly=%s', $this->adminonly); if ($this->login_credentials['reseller']) { $this->filters['reseller'] = $this->login_credentials['reseller']; } else { $this->filters['reseller'] = trim($_REQUEST['reseller_filter']); } } $this->filters['customer'] = trim($_REQUEST['customer_filter']); //$this->getResellers(); $this->getCustomers(); $this->getLoginAccount(); if (strlen($this->SoapEngine->sip_settings_page)) { $this->sip_settings_page = $this->SoapEngine->sip_settings_page; } if (strlen($this->SoapEngine->digest_settings_page)) { $this->digest_settings_page = $this->SoapEngine->digest_settings_page; } $this->support_email = $this->SoapEngine->support_email; $this->support_web = $this->SoapEngine->support_web; } function showEngineSelection() { $selected_soapEngine[$this->SoapEngine->service] =' selected'; $pstn_access = $this->getCustomerProperty('pstn_access'); printf(""); printf( "", $this->url ); } function showAfterEngineSelection() { } function showCustomerSelection() { $this->showCustomerForm(); } function showResellerSelection() { if ($this->adminonly) { $this->showResellerForm(); } else { printf("%s", $this->reseller); } } 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 "
%s", $this->SoapEngine->ports[$this->SoapEngine->port]['description'] ); printf( " |