diff --git a/library/NGNPro/Records/DnsRecords.php b/library/NGNPro/Records/DnsRecords.php index d24cd42..63a61f0 100644 --- a/library/NGNPro/Records/DnsRecords.php +++ b/library/NGNPro/Records/DnsRecords.php @@ -1,1477 +1,1478 @@ '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 ($this->checkLogSoapError($result, true)) { return false; } else { $this->rows = $result->total; if ($this->rows > 1 && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') { $this->showActionsForm(); } print <<< END
$this->rows records found. Click on record id to edit the values.

END; if ($this->fancy) { print <<< END END; } else { print <<< END 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->records[$i]) { break; } $record = $result->records[$i]; $index = $this->next+$i+1; $base_url_data = array( 'service' => $this->SoapEngine->service, 'zone_filter' => $record->zone, 'id_filter' => $record->id ); $delete_url_data = array_merge( $base_url_data, array( 'action' => 'Delete', 'name_filter' => $record->name ) ); $record_url_data = array_merge( $base_url_data, array( 'service' => sprintf( '%s@%s', $this->SoapEngine->service, $this->SoapEngine->soapEngine, ) ) ); + $zone_url_data = array( 'service' => sprintf('dns_zones@%s', $this->SoapEngine->soapEngine), 'zone_filter' => $record->zone ); $customer_url_data = array( 'service' => sprintf('customers@%s', $this->SoapEngine->customer_engine), 'customer_filter' => $record->customer ); if ($this->adminonly) { $delete_url_data['reseller_filter'] = $record->reseller; $zone_url_data['reseller_filter'] = $record->reseller; $record_url_data['reseller_filter'] = $record->reseller; } if ($_REQUEST['action'] == 'Delete' && $_REQUEST['id_filter'] == $record->id) { $delete_url_data['confirm'] = 1; $actionText = "Confirm"; } else { $actionText = "Delete"; } $_url = $this->buildUrl($delete_url_data); $_zone_url = $this->buildUrl($zone_url_data); $_record_url = $this->buildUrl($record_url_data); $_customer_url = $this->buildUrl($customer_url_data); if ($this->fancy) { printf( " ", $index, $_customer_url, $record->customer, $record->reseller, $_zone_url, $record->zone, $_record_url, $record->id, $record->name, $record->type, $record->value, $record->owner, $record->changeDate, $_url, $actionText ); } else { printf( " ", $index, $_customer_url, $record->customer, $record->reseller, $_zone_url, $record->zone, $_record_url, $record->id, $record->name, $record->type, $record->priority, $record->value, $record->ttl, $record->changeDate, $_url, $actionText ); } $i++; } } 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
"; if ($this->rows == 1) { $this->showRecord($record); } else { $this->showPagination($maxrows); } return true; } } function showSeachFormCustom() { printf( "

Record Id
", $this->filters['id'] ); printf( "
Name
", $this->filters['name'] ); if (count($this->allowedDomains) > 0) { $selected_zone[$this->filters['zone']]='selected'; print ""; } else { printf( "
DNS zone
", $this->filters['zone'] ); } if ($this->typeFilter) { printf( " Type %s", $this->typeFilter, $this->typeFilter ); } else { $selected_type[$this->filters['type']]='selected'; echo " "; } printf( "
Value
", $this->filters['value'] ); } function deleteRecord($dictionary = array()) { if (!$dictionary['confirm'] && !$_REQUEST['confirm']) { print "

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); return (bool)$result; } function showAddForm() { /* if ($this->adminonly) { if (!$this->filters['reseller']) { print "

To add a new record you must search first for a customer"; return; } } */ printf("

", $_SERVER['PHP_SELF']); print "
"; if ($this->adminonly) { printf( "", $this->filters['reseller'] ); } print "
Name "; printf( "
", trim($_REQUEST['name']) ); if (count($this->allowedDomains) > 0) { if ($_REQUEST['zone']) { $selected_zone[$_REQUEST['zone']]='selected'; } elseif ($this->filters['zone']) { $selected_zone[$this->filters['zone']]='selected'; } elseif ($_zone = $this->getCustomerProperty('dns_records_last_zone')) { $selected_zone[$_zone]='selected'; } print "."; } else { if ($_REQUEST['zone']) { $_zone_selected = $_REQUEST['zone']; } elseif ($this->filters['zone']) { $_zone_selected = $this->filters['zone']; } elseif ($_zone = $this->getCustomerProperty('dns_records_last_zone')) { $_zone_selected = $_zone; } printf( "
DNS zone
", $_zone_selected ); } if ($this->typeFilter) { printf("Type %s ", $this->typeFilter, $this->typeFilter); } else { print "
Type
"; } printf( "
Value
", trim($_REQUEST['value']) ); if (!$this->fancy) { printf( "
Priority
", trim($_REQUEST['priority']) ); } $this->printHiddenFormElements(); print "
"; } 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 ($this->checkLogSoapError($result, true)) { 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; } elseif ($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; } elseif ($_REQUEST['zone']) { $zone = $_REQUEST['zone']; } if ($type == 'MBOXFW') { $name .= '@'.$zone; } } if (!strlen($zone)) { if ($this->html) { echo "
Error: Missing zone name.
"; } return false; } $this->filters['zone'] = $zone; if (!strlen($type)) { if ($this->html) { echo "
Error: Missing record type.
"; } return false; } if ($dictionary['value']) { $value = $dictionary['value']; } else { $value = trim($_REQUEST['value']); } $value = rtrim($value, "."); if ($this->adminonly) { if ($dictionary['reseller']) { } elseif ($this->filters['reseller']) { } else { if ($this->html) { print <<< END
Error: Missing reseller, please first search zones for a given reseller
END; } return false; } } if ($dictionary['ttl']) { $ttl = intval($dictionary['ttl']); } else { $ttl = intval(trim($_REQUEST['ttl'])); } if (!$ttl) $ttl=3600; if ($dictionary['owner']) { $owner = intval($dictionary['owner']); } else { $owner = intval(trim($_REQUEST['owner'])); } if ($dictionary['priority']) { $priority = $dictionary['priority']; } else { $priority = trim($_REQUEST['priority']); } if (in_array($type, array_keys($this->recordTypes))) { // See RFC 1912 - Section 2.4 if (trim($name).trim($zone) == trim($zone) && $type == 'CNAME') { printf( "
Error: CNAME (%s) equal to zone name (%s) is not allowed
", trim($name).trim($zone), trim($zone) ); return false; } if (!strlen($value)) { if ($this->html) { echo "
Error: Missing record value.
"; } return false; } $record = array( 'name' => trim($name), 'zone' => trim($zone), 'type' => $type, 'value' => trim($value), 'owner' => intval($owner), 'ttl' => intval($ttl), 'priority' => intval($priority) ); 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->setCustomerProperties($_p); } $function = array( 'commit' => array( 'name' => $this->addRecordFunction, 'parameters' => array($record), 'logs' => array('success' => sprintf('DNS record %s under %s has been added', $name, $zone)) ) ); $result = $this->SoapEngine->execute($function, $this->html); dprint_r($result); return (bool)$result; } elseif (in_array($type, array_keys($this->recordTypesTemplate))) { $push_notifications_server = $this->getResellerProperty('push_notifications_server_private') or $this->getResellerProperty('push_notifications_server'); if ($type == "sip2sip" && $push_notifications_server) { if (preg_match("/^(.*):(\d+);transport=(.*)$/", $push_notifications_server, $m)) { $push_hostname = $m[1]; $push_port = $m[2]; $push_transport = $m[3]; if ($push_transport == "tls") { $naptr_type = "_sips._tcp"; $naptr_s = "SIPS+D2T"; } elseif ($push_transport == "tcp") { $naptr_type = "_sip._tcp"; $naptr_s = "SIP+D2T"; } else { $naptr_type = "_sip._udp"; $naptr_s = "SIP+D2U"; } $this->recordTypesTemplate[$type]['records']['push_naptr'] = array( 'name' => 'push', 'type' => 'NAPTR', 'priority' => '100', 'ttl' => '600', 'value' => sprintf('10 100 "s" "%s" "" %s.push', $naptr_s, $naptr_type) ); $this->recordTypesTemplate[$type]['records']['push_srv'] = array( 'name' => sprintf('%s.push', $naptr_type), 'type' => 'SRV', 'priority' => '100', 'ttl' => '600', 'value' => sprintf('100 %d %s', $push_port, $push_hostname) ); } } foreach (array_values($this->recordTypesTemplate[$type]['records']) as $_records) { $value_new=''; if (strlen($_records['value'])) { if (preg_match("/^_sip/", $_records['name'])) { if (!$value) { $value = $this->getCustomerProperty('dns_records_last_sip_server'); if (!$value) { $value = $this->getCustomerProperty('sip_proxy'); } if (!value) { $value = $this->SoapEngine->default_sip_proxy; } $save_new_value = false; } else { $save_new_value = true; } } $els = explode("|", $_records['value']); foreach ($els as $el) { if (preg_match("/#VALUE#/", $el)) { if ($value) { $value_new = preg_replace("/#VALUE#/", $value, $el); } else { continue; } } else { $value_new = $el; } break; } // save value if type sip server if ($save_new_value && $_records['name'] && preg_match("/^_sip/", $_records['name'])) { $_p = array( array( 'name' => 'dns_records_last_sip_server', 'category' => 'web', 'value' => $value, 'permission' => 'customer' ) ); $this->setCustomerProperties($_p); } } if (!in_array($_records['type'], array_keys($this->recordTypes))) { continue; } $record = array( 'name' => $_records['name'], 'zone' => trim($zone), 'type' => $_records['type'], 'value' => $value_new, 'owner' => intval($owner), 'ttl' => intval($_records['ttl']), 'priority' => intval($_records['priority']) ); //print_r($record); $function = array( 'commit' => array( 'name' => $this->addRecordFunction, 'parameters' => array($record), 'logs' => array( 'success' => sprintf('Dns %s record under %s has been added', $_records['type'], $zone) ) ) ); $result = $this->SoapEngine->execute($function, $this->html); return (bool)$result; } } else { if ($this->html) { print "
Error: Invalid or missing record type.
"; } return false; } return true; } function getRecordKeys() { // Filter $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' => 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); $this->log_action('getRecords'); // Call function $result = $this->SoapEngine->soapclient->getRecords($Query); if ($this->checkLogSoapError($result, true)) { return false; } else { foreach ($result->records as $record) { $this->selectionKeys[] = array('id' => $record->id); } return true; } } function showRecord($record) { echo "

Record

"; printf("
", $_SERVER['PHP_SELF']); echo ""; printf( "
%s
", $record->name ); foreach (array_keys($this->Fields) as $item) { if (is_array($this->havePriority) && $item == 'priority' && !in_array($record->type, $this->havePriority)) { continue; } if ($this->Fields[$item]['name']) { $item_name = $this->Fields[$item]['name']; } else { $item_name = ucfirst($item); } if ($item == 'type') { $selected_type[$record->$item]='selected'; $select_box=sprintf(""; printf( "
%s
", $item_name, $select_box ); } elseif ($this->Fields[$item]['type'] == 'text') { printf( "
", $item_name, $item, $record->$item ); } else { if ($record->type == 'NAPTR' and $item == 'value') { $help_text = 'Priority field will be used for the preference part of the value'; } else { $help_text = ''; } printf( "
", $item_name, $item, $record->$item ); if ($help_text) { printf("%s", $help_text); } echo "
"; } } printf("", $record->id); $this->printFiltersToForm(); $this->printHiddenFormElements(); echo "
"; echo "
"; } function getRecord($id) { // Filter if (!$id) { print "Error in getRecord(): Missing record id"; return false; } $filter = array('id' => $id); // 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($this->getRecordsFunction); // Call function $result = call_user_func_array(array($this->SoapEngine->soapclient, $this->getRecordsFunction), array($Query)); if ($this->checkLogSoapError($result, true)) { return false; } else { if ($result->records[0]) { return $result->records[0]; } else { return false; } } } function updateRecord() { //print "

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); return (bool)$result; } function showTextBeforeCustomerSelection() { print _("Zone owner"); } } diff --git a/library/NGNPro/Records/GatewayRules.php b/library/NGNPro/Records/GatewayRules.php index a8a117e..01e3955 100644 --- a/library/NGNPro/Records/GatewayRules.php +++ b/library/NGNPro/Records/GatewayRules.php @@ -1,570 +1,572 @@ array('type'=>'integer','readonly' => true), 'gateway_id' => array('type'=>'integer','name' => 'Gateway'), 'prefix' => array('type'=>'string'), 'strip' => array('type'=>'integer'), 'prepend' => array('type'=>'string'), 'minLength' => array('type'=>'integer'), 'maxLength' => array('type'=>'integer') ); public function __construct($SoapEngine) { $this->filters = array( 'id' => trim($_REQUEST['id_filter']), 'gateway_id' => trim($_REQUEST['gateway_id_filter']), 'carrier_id' => trim($_REQUEST['carrier_id_filter']), 'prefix' => trim($_REQUEST['prefix_filter']), ); $this->sortElements = array( 'changeDate' => 'Change date', 'gateway' => 'Gateway', 'carrier' => 'Carrier', 'prefix' => 'Prefix' ); parent::__construct($SoapEngine); } function listRecords() { $this->getCarriers(); $this->showSeachForm(); // Insert credetials $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); // Filter $filter = array( 'id' => intval($this->filters['id']), 'gateway_id' => intval($this->filters['gateway_id']), 'carrier_id' => intval($this->filters['carrier_id']), 'prefix' => $this->filters['prefix'], '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'] = 'ASC'; $orderBy = array( 'attribute' => $this->sorting['sortBy'], 'direction' => $this->sorting['sortOrder'] ); // Compose query $Query = array( 'filter' => $filter, 'orderBy' => $orderBy, 'range' => $range ); $this->log_action('getGatewayRules'); $result = $this->SoapEngine->soapclient->getGatewayRules($Query); if ($this->checkLogSoapError($result, true)) { return false; } else { $this->rows = $result->total; 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->gateway_rules[$i]) break; $gateway_rule = $result->gateway_rules[$i]; $index = $this->next+$i+1; $base_url_data = array( 'service' => $this->SoapEngine->service, 'id_filter' => $gateway_rule->id, 'reseller_filter' => $gateway_rule->reseller ); $delete_url_data = array_merge( $base_url_data, array( 'action' => 'Delete', ) ); $customer_url_data = array( 'service' => sprintf('customers@%s', $this->SoapEngine->customer_engine), 'customer_filter' => $gateway_rule->reseller ); $carrier_url_data = array_merge( $base_url_data, array( 'service' => sprintf('pstn_carriers@%s', $this->SoapEngine->soapEngine), + 'id_filter' => $gateway_rule->carrier_id, ) ); $gateway_url_data = array_merge( $base_url_data, array( 'service' => sprintf('pstn_gateways@%s', $this->SoapEngine->soapEngine), + 'id_filter' => $gateway_rule->gateway_id, ) ); if ($_REQUEST['action'] == 'Delete' && $_REQUEST['id_filter'] == $gateway_rule->id) { $delete_url_data['confirm'] = 1; $actionText = "Confirm"; } else { $actionText = "Delete"; } $_delete_url = $this->buildUrl($delete_url_data); $_url = $this->buildUrl($base_url_data); $_customer_url = $this->buildUrl($customer_url_data); $_carrier_url = $this->buildUrl($carrier_url_data); $_gateway_url = $this->buildUrl($gateway_url_data); printf( " ", $index, $_customer_url, $gateway_rule->reseller, $_url, $gateway_rule->id, $_carrier_url, $gateway_rule->carrier, $gateway_rule->carrier_id, $_gateway_url, $gateway_rule->gateway, $gateway_rule->gateway_id, $gateway_rule->prefix, $gateway_rule->strip, $gateway_rule->prepend, $gateway_rule->minLength, $gateway_rule->maxLength, $gateway_rule->changeDate, $_delete_url, $actionText ); print ""; $i++; } } print "
Owner Rule Carrier Gateway Prefix Strip Prepend MinLength MaxLength Change date Actions
%s %s %s %s (%d) %s (%d) %s %s %s %s %s %s %s
"; if ($this->rows == 1) { $this->showRecord($gateway_rule); } else { $this->showPagination($maxrows); } return true; } } function showAddForm() { //if ($this->selectionActive) return; $this->getGateways(); if (!count($this->gateways)) { print "

Create a gateway first

"; return false; } printf("
", $_SERVER['PHP_SELF']); print <<< END
Gateway
Prefix
Strip
Prepend
Min length
Max length
END; $this->printHiddenFormElements(); print <<< END
END; } function addRecord($dictionary = array()) { if ($dictionary['gateway_id']) { $gateway_id = $dictionary['gateway_id']; } else { $gateway_id = trim($_REQUEST['gateway_id']); } if ($dictionary['prefix']) { $prefix = $dictionary['prefix']; } else { $prefix = trim($_REQUEST['prefix']); } if ($dictionary['strip']) { $strip = $dictionary['strip']; } else { $strip = trim($_REQUEST['strip']); } if ($dictionary['prepend']) { $prepend = $dictionary['prepend']; } else { $prepend = trim($_REQUEST['prepend']); } if ($dictionary['minLength']) { $minLength = $dictionary['minLength']; } else { $minLength = trim($_REQUEST['minLength']); } if ($dictionary['maxLength']) { $maxLength = $dictionary['maxLength']; } else { $maxLength = trim($_REQUEST['maxLength']); } if (!strlen($gateway_id)) { printf("

Error: Missing gateway id"); return false; } $rule = array( 'gateway_id' => intval($gateway_id), 'prefix' => $prefix, 'prepend' => $prepend, 'strip' => intval($strip), 'minLength' => intval($minLength), 'maxLength' => intval($maxLength) ); $function = array( 'commit' => array( 'name' => 'addGatewayRule', 'parameters' => array($rule), 'logs' => array('success' => sprintf('Gateway rule has been added')) ) ); unset($this->filters); return $this->SoapEngine->execute($function, $this->html); } function deleteRecord($dictionary = array()) { if (!$dictionary['confirm'] && !$_REQUEST['confirm']) { print "

Please press on Confirm to confirm the delete.

"; return true; } if ($dictionary['id']) { $id = $dictionary['id']; } else { $id = trim($this->filters['id']); } if (!strlen($id)) { print "

Error: missing rule id "; return false; } $function = array( 'commit' => array( 'name' => 'deleteGatewayRule', 'parameters' => array(intval($id)), 'logs' => array('success' => sprintf('Gateway rule %d has been deleted', $id)) ) ); unset($this->filters); return $this->SoapEngine->execute($function, $this->html); } function showSeachFormCustom() { printf( "

Rule
", $this->filters['id'] ); print <<< END "; printf( "
Gateway
", $this->filters['gateway_id'] ); printf( "
Prefix
", $this->filters['prefix'] ); } function showCustomerForm($name = 'customer_filter') { } function showTextBeforeCustomerSelection() { print "Owner"; } function showRecord($rule) { $this->getGateways(); print "

Rule

"; printf("
", $_SERVER['PHP_SELF']); print ""; foreach (array_keys($this->Fields) as $item) { if ($this->Fields[$item]['name']) { $item_name = $this->Fields[$item]['name']; } else { $item_name=ucfirst($item); } printf( "
", $item_name ); if ($this->Fields[$item]['readonly']) { printf( "
%s
", $item, $rule->$item, $rule->$item ); } else { if ($item == 'gateway_id') { printf("
"; } else { printf( "
", $item, $rule->$item ); } } print "
"; } printf("", $rule->reseller); $this->printFiltersToForm(); $this->printHiddenFormElements(); print <<< END
END; } function updateRecord() { //print "

Updating rule ..."; if (!$_REQUEST['id_form'] || !strlen($_REQUEST['reseller_filter'])) { return; } if (!$rule = $this->getRecord($_REQUEST['id_form'])) { return false; } foreach (array_keys($this->Fields) as $item) { $var_name = $item.'_form'; if ($this->Fields[$item]['type'] == 'integer') { $rule->$item = intval($_REQUEST[$var_name]); } else { $rule->$item = trim($_REQUEST[$var_name]); } } $function = array('commit' => array('name' => 'updateGatewayRule', 'parameters' => array($rule), 'logs' => array('success' => sprintf('Rule %d has been updated', $_REQUEST['id_form']))) ); $result = $this->SoapEngine->execute($function, $this->html); dprint_r($result); return (bool)$result; } function getRecord($id) { // Insert credetials $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); // Filter $filter = array('id' => intval($id)); // Range $range = array('start' => 0, 'count' => 1 ); // Order $this->sorting['sortBy'] = 'gateway'; $this->sorting['sortOrder'] = 'ASC'; $orderBy = array('attribute' => $this->sorting['sortBy'], 'direction' => $this->sorting['sortOrder'] ); // Compose query $Query = array('filter' => $filter, 'orderBy' => $orderBy, 'range' => $range ); // Call function $this->log_action('getGatewayRules'); $result = $this->SoapEngine->soapclient->getGatewayRules($Query); if ($this->checkLogSoapError($result, true)) { return false; } else { if ($result->gateway_rules[0]) { return $result->gateway_rules[0]; } else { return false; } } } } diff --git a/library/NGNPro/Records/Routes.php b/library/NGNPro/Records/Routes.php index 74058c0..d5522c5d 100644 --- a/library/NGNPro/Records/Routes.php +++ b/library/NGNPro/Records/Routes.php @@ -1,492 +1,528 @@ array('type'=>'integer', - 'readonly' => true), - 'carrier_id' => array('type'=>'integer','name'=>'Carrier'), - 'prefix' => array('type'=>'string'), - 'originator' => array('type'=>'string'), - 'priority' => array('type'=>'integer') - ); - - var $sortElements=array( - 'prefix' => 'Prefix', - 'priority' => 'Priority' - ); +class Routes extends Records +{ + var $carriers = array(); + + var $Fields = array( + 'id' => array( + 'type'=>'integer', + 'readonly' => true + ), + 'carrier_id' => array('type'=>'integer','name'=>'Carrier'), + 'prefix' => array('type'=>'string'), + 'originator' => array('type'=>'string'), + 'priority' => array('type'=>'integer') + ); + + var $sortElements = array( + 'prefix' => 'Prefix', + 'priority' => 'Priority' + ); public function __construct($SoapEngine) { $this->filters = array( 'prefix' => trim($_REQUEST['prefix_filter']), 'priority' => trim($_REQUEST['priority_filter']), 'carrier_id'=> trim($_REQUEST['carrier_id_filter']), 'reseller' => trim($_REQUEST['reseller_filter']), 'id' => trim($_REQUEST['id_filter']) ); parent::__construct($SoapEngine); } - function listRecords() { + function listRecords() + { $this->getCarriers(); $this->showSeachForm(); // Insert credetials $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); // Filter - $filter=array('prefix' => $this->filters['prefix'], - 'carrier_id' => intval($this->filters['carrier_id']), - 'reseller' => intval($this->filters['reseller']), - 'id' => intval($this->filters['id']) - ); + $filter = array( + 'prefix' => $this->filters['prefix'], + 'carrier_id' => intval($this->filters['carrier_id']), + 'reseller' => intval($this->filters['reseller']), + 'id' => intval($this->filters['id']) + ); // 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'] = 'prefix'; if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC'; - $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 + ); // Call function $this->log_action('getRoutes'); - $result = $this->SoapEngine->soapclient->getRoutes($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); + $result = $this->SoapEngine->soapclient->getRoutes($Query); + + if ($this->checkLogSoapError($result, true)) { return false; } else { - $this->rows = $result->total; - print " -

$this->rows records found
-

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

+

IdOwnerRouteCarrierGatewaysPrefixOriginatorPriorityChange dateActions
+ + + + + + + + + + + + + + +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) { - + while ($i < $maxrows) { if (!$result->routes[$i]) break; $route = $result->routes[$i]; - $index=$this->next+$i+1; + $index = $this->next+$i+1; - $_delete_url = $this->url.sprintf("&service=%s&action=Delete&id_filter=%d", - urlencode($this->SoapEngine->service), - urlencode($route->id) + $base_url_data = array( + 'service' => $this->SoapEngine->service, + 'id_filter' => $route->id, ); - if ($_REQUEST['action'] == 'Delete' && - $_REQUEST['id_filter'] == $route->id) { - $_delete_url .= "&confirm=1"; - $actionText = "Confirm"; - } else { - $actionText = "Delete"; - } - - $_url = $this->url.sprintf("&service=%s&id_filter=%d", - urlencode($this->SoapEngine->service), - urlencode($route->id) + $delete_url_data = array_merge( + $base_url_data, + array( + 'action' => 'Delete', + ) ); - $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", - urlencode($this->SoapEngine->customer_engine), - urlencode($route->reseller) + $customer_url_data = array( + 'service' => sprintf('customers@%s', $this->SoapEngine->customer_engine), + 'customer_filter' => $route->reseller ); - $_carrier_url = $this->url.sprintf("&service=pstn_carriers@%s&id_filter=%s", - urlencode($this->SoapEngine->soapEngine), - urlencode($route->carrier_id) + $carrier_url_data = array_merge( + $base_url_data, + array( + 'service' => sprintf('pstn_carriers@%s', $this->SoapEngine->soapEngine), + 'id_filter' => $route->carrier_id, + ) ); - $_gateway_url = $this->url.sprintf("&service=pstn_gateways@%s&carrier_id_filter=%s&reseller_filter=%s", - urlencode($this->SoapEngine->soapEngine), - urlencode($route->carrier_id), - urlencode($route->reseller) + $gateway_url_data = array( + 'service' => sprintf('pstn_gateways@%s', $this->SoapEngine->soapEngine), + 'carrier_id_filter' => $route->carrier_id, + 'reseller_filter' => $route->reseller ); - printf(" - - - - - - - - - - - - ", - $index, - $_customer_url, - $route->reseller, - $_url, - $route->id, - $_carrier_url, - $route->carrier, - $_gateway_url, - $route->prefix, - $route->originator, - $route->priority, - $route->changeDate, - $_delete_url, - $actionText + if ($_REQUEST['action'] == 'Delete' && + $_REQUEST['id_filter'] == $route->id) { + $delete_url_data['confirm'] = 1; + $actionText = "Confirm"; + } else { + $actionText = "Delete"; + } + + $_delete_url = $this->buildUrl($delete_url_data); + $_url = $this->buildUrl($base_url_data); + $_customer_url = $this->buildUrl($customer_url_data); + $_carrier_url = $this->buildUrl($carrier_url_data); + $_gateway_url = $this->buildUrl($gateway_url_data); + + printf( + " + + + + + + + + + + + + + ", + $index, + $_customer_url, + $route->reseller, + $_url, + $route->id, + $_carrier_url, + $route->carrier, + $_gateway_url, + $route->prefix, + $route->originator, + $route->priority, + $route->changeDate, + $_delete_url, + $actionText ); - printf(" - - "); + print ""; $i++; } } print "
IdOwnerRouteCarrierGatewaysPrefixOriginatorPriorityChange dateActions
%s%s%s%sGateways%s%s%s%s%s
%s%s%s%sGateways%s%s%s%s%s
"; if ($this->rows == 1) { $this->showRecord($route); } else { $this->showPagination($maxrows); } return true; } } - function showAddForm() { + function showAddForm() + { //if ($this->selectionActive) return; if (!count($this->carriers)) { print "

Create a carrier first"; return false; } - printf ("

",$_SERVER['PHP_SELF']); - - print " - - "; - - print "
"; - printf (" Carrier "); - print ""; + printf( + "
", + $_SERVER['PHP_SELF'] + ); - print " +
+ Carrier +
"); - - printf ("
Prefix
"); - printf ("
Originator
"); - printf ("
Priority
"); - + print <<< END + +
+ +
Prefix
+
Originator
+
Priority
+END; $this->printHiddenFormElements(); print "
"; } - function addRecord($dictionary=array()) { + function addRecord($dictionary = array()) + { if ($dictionary['prefix']) { $prefix = $dictionary['prefix']; } else { $prefix = trim($_REQUEST['prefix']); } if ($dictionary['carrier_id']) { $carrier_id = $dictionary['carrier_id']; } else { $carrier_id = trim($_REQUEST['carrier_id']); } if ($dictionary['originator']) { $originator = $dictionary['originator']; } else { $originator = trim($_REQUEST['originator']); } if ($dictionary['priority']) { $priority = $dictionary['priority']; } else { $priority = trim($_REQUEST['priority']); } if (!strlen($carrier_id)) { - printf ("

Error: Missing carrier id. "); + printf("

Error: Missing carrier id. "); return false; } - $route=array( - 'prefix' => $prefix, - 'originator' => $originator, - 'carrier_id' => intval($carrier_id), - 'priority' => intval($priority) - ); + $route = array( + 'prefix' => $prefix, + 'originator' => $originator, + 'carrier_id' => intval($carrier_id), + 'priority' => intval($priority) + ); - $routes=array($route); + $routes = array($route); - $function=array('commit' => array('name' => 'addRoutes', - 'parameters' => array($routes), - 'logs' => array('success' => sprintf('Route %s has been added',$prefix))) - ); + $function = array( + 'commit' => array( + 'name' => 'addRoutes', + 'parameters' => array($routes), + 'logs' => array('success' => sprintf('Route %s has been added', $prefix)) + ) + ); unset($this->filters); - return $this->SoapEngine->execute($function,$this->html); - + return $this->SoapEngine->execute($function, $this->html); } - function deleteRecord($dictionary=array()) { + function deleteRecord($dictionary = array()) + { if (!$dictionary['confirm'] && !$_REQUEST['confirm']) { print "

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

Error: missing route id. "; return false; } - $route=array('id'=> intval($id)); + $route = array('id'=> intval($id)); - $routes=array($route); + $routes = array($route); - $function=array('commit' => array('name' => 'deleteRoutes', - 'parameters' => array($routes), - 'logs' => array('success' => sprintf('Route %s has been deleted',$prefix))) - ); + $function = array( + 'commit' => array( + 'name' => 'deleteRoutes', + 'parameters' => array($routes), + 'logs' => array('success' => sprintf('Route %s has been deleted', $id)) + ) + ); unset($this->filters); - return $this->SoapEngine->execute($function,$this->html); + return $this->SoapEngine->execute($function, $this->html); } - function showSeachFormCustom() { - - printf ("

Route
",$this->filters['id']); - print " - +
+ ", + $this->filters['id'] + ); + print <<< END + "; - printf ("
Prefix
",$this->filters['prefix']); - + printf( + " +
+ Prefix +
+ ", + $this->filters['prefix'] + ); } - function showCustomerTextBox () { + function showCustomerTextBox() + { print "Owner"; $this->showResellerForm('reseller'); } - function showCustomerForm($name='customer_filter') { + function showCustomerForm($name = 'customer_filter') + { } - function showTextBeforeCustomerSelection() { + function showTextBeforeCustomerSelection() + { print "Owner"; } - function getRecord($id) { + function getRecord($id) + { // Insert credetials $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); // Filter - $filter=array('id' => intval($id)); + $filter = array('id' => intval($id)); // Range - $range=array('start' => 0, - 'count' => 1 - ); + $range = array( + 'start' => 0, + 'count' => 1 + ); // Order if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'prefix'; if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC'; - $orderBy = array('attribute' => $this->sorting['sortBy'], - 'direction' => $this->sorting['sortOrder'] - ); + $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 + ); // Call function $this->log_action('getRoutes'); - $result = $this->SoapEngine->soapclient->getRoutes($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); + $result = $this->SoapEngine->soapclient->getRoutes($Query); + + if ($this->checkLogSoapError($result, true)) { return false; } else { - if ($result->routes[0]){ + if ($result->routes[0]) { return $result->routes[0]; } else { return false; } } } - function showRecord($route) { - + function showRecord($route) + { print "

Route

"; - printf ("
",$_SERVER['PHP_SELF']); + printf("", $_SERVER['PHP_SELF']); print ""; 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); } - printf ("
- - ", - $item_name + printf( + " +
+ + ", + $item_name ); if ($this->Fields[$item]['readonly']) { - printf ("
%s
", - $item, - $route->$item, - $route->$item + printf( + "
%s
", + $item, + $route->$item, + $route->$item ); } else { if ($item == 'carrier_id') { - printf ("
", $item); + $selected_carrier[$route->$item] = 'selected'; foreach (array_keys($this->carriers) as $_carrier) { - printf ("
"); - + print "
"; } else { - printf ("
", - $item, - $route->$item + printf( + "
", + $item, + $route->$item ); } } print "
"; } - printf ("",$carier->id); + printf("", $route->id); $this->printFiltersToForm(); $this->printHiddenFormElements(); print "
"; print "
"; } - function updateRecord () { + function updateRecord() + { //print "

Updating route ..."; if (!$_REQUEST['id_filter']) return; if (!$route = $this->getRecord($_REQUEST['id_filter'])) { return false; } foreach (array_keys($this->Fields) as $item) { - $var_name=$item.'_form'; + $var_name = $item.'_form'; if ($this->Fields[$item]['type'] == 'integer') { $route->$item = intval($_REQUEST[$var_name]); } else { $route->$item = trim($_REQUEST[$var_name]); } } - $routes=array($route); + $routes = array($route); - $function=array('commit' => array('name' => 'updateRoutes', - 'parameters' => array($routes), - 'logs' => array('success' => sprintf('Route %d has been updated',$_REQUEST['id_filter']))) - ); - $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 = array( + 'commit' => array( + 'name' => 'updateRoutes', + 'parameters' => array($routes), + 'logs' => array('success' => sprintf('Route %d has been updated', $_REQUEST['id_filter'])) + ) + ); + return (bool)$this->SoapEngine->execute($function, $this->html); } } -