diff --git a/library/NGNPro/Actions/Customers.php b/library/NGNPro/Actions/Customers.php index 50a4de4..71ac289 100644 --- a/library/NGNPro/Actions/Customers.php +++ b/library/NGNPro/Actions/Customers.php @@ -1,34 +1,39 @@ 'Delete customers' +class CustomersActions extends Actions +{ + public $actions = array( + 'delete' => 'Delete customers' ); public function execute($selectionKeys, $action, $sub_action_parameter) { if (!in_array($action, array_keys($this->actions))) { print "Error: Invalid action $action"; return false; } print "
    "; - foreach($selectionKeys as $key) { + foreach ($selectionKeys as $key) { flush(); print "
  1. "; - if ($action=='delete') { + if ($action == 'delete') { $this->log_action('deleteAccount'); - $function=array('commit' => array('name' => 'deleteAccount', - 'parameters' => array(intval($key)), - 'logs' => array('success' => sprintf('Customer id %s has been deleted',$key))) - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'deleteAccount', + 'parameters' => array(intval($key)), + 'logs' => array( + 'success' => sprintf('Customer id %s has been deleted', $key) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } } print "
"; } } - diff --git a/library/NGNPro/Actions/DnsRecords.php b/library/NGNPro/Actions/DnsRecords.php index cf24c8f..8b7cd81 100644 --- a/library/NGNPro/Actions/DnsRecords.php +++ b/library/NGNPro/Actions/DnsRecords.php @@ -1,126 +1,122 @@ 'Change TTL to:', 'changepriority' => 'Change Priority to:', 'changevalue' => 'Change value to:', 'delete' => 'Delete records' ); public function execute($selectionKeys, $action, $sub_action_parameter) { if (!in_array($action, array_keys($this->actions))) { print "Error: Invalid action $action"; return false; } print "
    "; - foreach($selectionKeys as $key) { + foreach ($selectionKeys as $key) { flush(); print "
  1. "; - //printf ("Performing action=%s on key=%s",$action,$key['id']); + //printf ("Performing action=%s on key=%s",$action, $key['id']); if ($action=='delete') { $this->log_action('deleteRecord'); - $function=array('commit' => array('name' => 'deleteRecord', - 'parameters' => array(intval($key['id'])), - 'logs' => array('success' => sprintf('Record %d has been deleted',$key['id']) - ) - ) - - ); - - $this->SoapEngine->execute($function,$this->html); - } else if ($action == 'changettl') { + $function=array( + 'commit' => array( + 'name' => 'deleteRecord', + 'parameters' => array(intval($key['id'])), + 'logs' => array( + 'success' => sprintf('Record %d has been deleted', $key['id']) + ) + ) + ); + + $this->SoapEngine->execute($function, $this->html); + } elseif ($action == 'changettl') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getRecord'); - $record = $this->SoapEngine->soapclient->getRecord($key['id']); + $record = $this->SoapEngine->soapclient->getRecord($key['id']); - if ((new PEAR)->isError($record)) { - $error_msg = $record->getMessage(); - $error_fault= $record->getFault(); - $error_code = $record->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($record)) { break; } else { - if (!is_numeric($sub_action_parameter)) { - printf ("Error: TTL '%s' must be numeric",$sub_action_parameter); + printf("Error: TTL '%s' must be numeric", $sub_action_parameter); continue; } $record->ttl=intval($sub_action_parameter); $this->log_action('updateRecord'); - $function=array('commit' => array('name' => 'updateRecord', - 'parameters' => array($record), - 'logs' => array('success' => sprintf('TTL for record %d has been set to %d',$key['id'],intval($sub_action_parameter)) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function=array('commit' => array( + 'name' => 'updateRecord', + 'parameters' => array($record), + 'logs' => array( + 'success' => sprintf('TTL for record %d has been set to %d', $key['id'], intval($sub_action_parameter)) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action == 'changepriority') { + } elseif ($action == 'changepriority') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getRecord'); - $record = $this->SoapEngine->soapclient->getRecord($key['id']); + $record = $this->SoapEngine->soapclient->getRecord($key['id']); - if ((new PEAR)->isError($record)) { - $error_msg = $record->getMessage(); - $error_fault= $record->getFault(); - $error_code = $record->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($record)) { break; } else { if (is_numeric($sub_action_parameter)) { $record->priority=intval($sub_action_parameter); } else { - printf ("Error: Priority '%s' must be numeric",$sub_action_parameter); + printf("Error: Priority '%s' must be numeric", $sub_action_parameter); continue; } $this->log_action('updateRecord'); - $function=array('commit' => array('name' => 'updateRecord', - 'parameters' => array($record), - 'logs' => array('success' => sprintf('Priority for record %d has been set to %d',$key['id'],intval($sub_action_parameter)) - ) - ) - ); - - $this->SoapEngine->execute($function,$this->html); + $function=array( + 'commit' => array( + 'name' => 'updateRecord', + 'parameters' => array($record), + 'logs' => array( + 'success' => sprintf('Priority for record %d has been set to %d',$key['id'],intval($sub_action_parameter)) + ) + ) + ); + + $this->SoapEngine->execute($function, $this->html); } - } else if ($action == 'changevalue') { + } elseif ($action == 'changevalue') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getRecord'); $record = $this->SoapEngine->soapclient->getRecord($key['id']); - if ((new PEAR)->isError($record)) { - $error_msg = $record->getMessage(); - $error_fault= $record->getFault(); - $error_code = $record->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($record)) { break; } else { - $record->value=$sub_action_parameter; + $record->value=$sub_action_parameter; $this->log_action('updateRecord'); - $function=array('commit' => array('name' => 'updateRecord', - 'parameters' => array($record), - 'logs' => array('success' => sprintf('Value of record %d has been set to %s',$key['id'],$sub_action_parameter) - ) - ) - ); - - $this->SoapEngine->execute($function,$this->html); + $function=array( + 'commit' => array( + 'name' => 'updateRecord', + 'parameters' => array($record), + 'logs' => array( + 'success' => sprintf('Value of record %d has been set to %s',$key['id'], $sub_action_parameter) + ) + ) + ); + + $this->SoapEngine->execute($function, $this->html); } } } print "
"; } } - diff --git a/library/NGNPro/Actions/DnsZones.php b/library/NGNPro/Actions/DnsZones.php index 30a5b83..2c7c389 100644 --- a/library/NGNPro/Actions/DnsZones.php +++ b/library/NGNPro/Actions/DnsZones.php @@ -1,330 +1,322 @@ 'Change TTL to:', - 'changeexpire' => 'Change Expire to:', - 'changeminimum' => 'Change Minimum to:', - 'changeretry' => 'Change Retry to:', - 'changeinfo' => 'Change Info to:', - 'addnsrecord' => 'Add name server:', - 'removensrecord' => 'Remove name server:', - 'delete' => 'Delete zones', - 'export' => 'Export zones' - ); +class DnsZonesActions extends Actions +{ + public $sub_action_parameter_size = 50; + + public $actions = array( + 'changettl' => 'Change TTL to:', + 'changeexpire' => 'Change Expire to:', + 'changeminimum' => 'Change Minimum to:', + 'changeretry' => 'Change Retry to:', + 'changeinfo' => 'Change Info to:', + 'addnsrecord' => 'Add name server:', + 'removensrecord' => 'Remove name server:', + 'delete' => 'Delete zones', + 'export' => 'Export zones' + ); public function execute($selectionKeys, $action, $sub_action_parameter) { if (!in_array($action, array_keys($this->actions))) { print "Error: Invalid action $action"; return false; } - if ($action!='export') { + if ($action != 'export') { print "
    "; } else { - $exported_data=array('dns_zones'=>array()); - $export_customers=array(); + $exported_data = array('dns_zones'=>array()); + $export_customers = array(); } - foreach($selectionKeys as $key) { + foreach ($selectionKeys as $key) { flush(); - if ($action!='export') { + if ($action!='export') { print "
  1. "; } - //printf ("Performing action=%s on key=%s",$action,$key['name']); + //printf ("Performing action=%s on key=%s",$action, $key['name']); - if ($action=='delete') { + if ($action == 'delete') { $this->log_action('deleteZone'); - $function=array('commit' => array('name' => 'deleteZone', - 'parameters' => array($key['name']), - 'logs' => array('success' => sprintf('Zone %s has been deleted',$key['name']) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); - } else if ($action=='export') { + $function=array( + 'commit' => array( + 'name' => 'deleteZone', + 'parameters' => array($key['name']), + 'logs' => array( + 'success' => sprintf('Zone %s has been deleted', $key['name']) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); + } elseif ($action=='export') { // Filter $filter=array( 'zone' => $key['name'] ); $range = array('start' => 0,'count' => 5000); // Compose query $Query=array('filter' => $filter, 'range' => $range ); $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getZone'); - $result = $this->SoapEngine->soapclient->getZone($key['name']); - 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->getZone($key['name']); + if ($this->checkLogSoapError($result, true)) { return false; } else { if (!in_array($result->customer, $export_customers)) { $export_customers[]=$result->customer; } if (!in_array($result->reseller, $export_customers)) { $export_customers[]=$result->reseller; } $exported_data['dns_zones'][] = objectToArray($result); } $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getRecords'); // Call function - $result = call_user_func_array(array($this->SoapEngine->soapclient,'getRecords'),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); + $result = call_user_func_array(array($this->SoapEngine->soapclient,'getRecords'), array($Query)); + + if ($this->checkLogSoapError($result, true)) { return false; } else { $exported_data['dns_records'] = objectToArray($result->records); } - } else if ($action == 'changettl') { + } elseif ($action == 'changettl') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getZone'); $zone = $this->SoapEngine->soapclient->getZone($key['name']); - if ((new PEAR)->isError($zone)) { - $error_msg = $zone->getMessage(); - $error_fault= $zone->getFault(); - $error_code = $zone->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($zone)) { break; } else { - if (!is_numeric($sub_action_parameter)) { - printf ("Error: TTL '%s' must be numeric",$sub_action_parameter); + printf("Error: TTL '%s' must be numeric", $sub_action_parameter); continue; } - $zone->ttl=intval($sub_action_parameter); + $zone->ttl = intval($sub_action_parameter); $this->log_action('updateZone'); - $function=array('commit' => array('name' => 'updateZone', - 'parameters' => array($zone), - 'logs' => array('success' => sprintf('TTL for zone %s has been set to %d',$key['name'],intval($sub_action_parameter)) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateZone', + 'parameters' => array($zone), + 'logs' => array( + 'success' => sprintf( + 'TTL for zone %s has been set to %d', + $key['name'], + intval($sub_action_parameter) + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action == 'changeexpire') { + } elseif ($action == 'changeexpire') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getZone'); - $zone = $this->SoapEngine->soapclient->getZone($key['name']); + $zone = $this->SoapEngine->soapclient->getZone($key['name']); - if ((new PEAR)->isError($zone)) { - $error_msg = $zone->getMessage(); - $error_fault= $zone->getFault(); - $error_code = $zone->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($zone)) { break; } else { - if (!is_numeric($sub_action_parameter)) { - printf ("Error: Expire '%s' must be numeric",$sub_action_parameter); + printf("Error: Expire '%s' must be numeric", $sub_action_parameter); continue; } $zone->expire=intval($sub_action_parameter); $this->log_action('updateZone'); - $function=array('commit' => array('name' => 'updateZone', - 'parameters' => array($zone), - 'logs' => array('success' => sprintf('Expire for zone %s has been set to %d',$key['name'],intval($sub_action_parameter)) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateZone', + 'parameters' => array($zone), + 'logs' => array( + 'success' => sprintf( + 'Expire for zone %s has been set to %d', + $key['name'], + intval($sub_action_parameter) + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action == 'changeminimum') { + } elseif ($action == 'changeminimum') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getZone'); - $zone = $this->SoapEngine->soapclient->getZone($key['name']); + $zone = $this->SoapEngine->soapclient->getZone($key['name']); - if ((new PEAR)->isError($zone)) { - $error_msg = $zone->getMessage(); - $error_fault= $zone->getFault(); - $error_code = $zone->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($zone)) { break; } else { - if (!is_numeric($sub_action_parameter)) { - printf ("Error: Minimum '%s' must be numeric",$sub_action_parameter); + printf("Error: Minimum '%s' must be numeric", $sub_action_parameter); continue; } - $zone->minimum=intval($sub_action_parameter); + $zone->minimum = intval($sub_action_parameter); $this->log_action('updateZone'); - $function=array('commit' => array('name' => 'updateZone', - 'parameters' => array($zone), - 'logs' => array('success' => sprintf('Minimum for zone %s has been set to %d',$key['name'],intval($sub_action_parameter)) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateZone', + 'parameters' => array($zone), + 'logs' => array( + 'success' => sprintf( + 'Minimum for zone %s has been set to %d', + $key['name'], + intval($sub_action_parameter) + ) + ) + ) + + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action == 'addnsrecord') { + } elseif ($action == 'addnsrecord') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getZone'); - $zone = $this->SoapEngine->soapclient->getZone($key['name']); + $zone = $this->SoapEngine->soapclient->getZone($key['name']); - if ((new PEAR)->isError($zone)) { - $error_msg = $zone->getMessage(); - $error_fault= $zone->getFault(); - $error_code = $zone->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($zone)) { break; } else { - - $zone->nameservers[]=$sub_action_parameter; - $zone->nameservers=array_unique($zone->nameservers); + $zone->nameservers[] = $sub_action_parameter; + $zone->nameservers = array_unique($zone->nameservers); $this->log_action('updateZone'); - $function=array('commit' => array('name' => 'updateZone', - 'parameters' => array($zone), - 'logs' => array('success' => sprintf('Added NS record %s for zone %s',$sub_action_parameter,$key['name']) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateZone', + 'parameters' => array($zone), + 'logs' => array( + 'success' => sprintf('Added NS record %s for zone %s',$sub_action_parameter, $key['name']) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action == 'removensrecord') { + } elseif ($action == 'removensrecord') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getZone'); $zone = $this->SoapEngine->soapclient->getZone($key['name']); - if ((new PEAR)->isError($zone)) { - $error_msg = $zone->getMessage(); - $error_fault= $zone->getFault(); - $error_code = $zone->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($zone)) { break; } else { - $new_servers=array(); - foreach ($zone->nameservers as $_ns) { + $new_servers = array(); + foreach ($zone->nameservers as $_ns) { if ($_ns == $sub_action_parameter) continue; $new_servers[]=$_ns; } - $zone->nameservers=array_unique($new_servers); + $zone->nameservers = array_unique($new_servers); $this->log_action('updateZone'); - $function=array('commit' => array('name' => 'updateZone', - 'parameters' => array($zone), - 'logs' => array('success' => sprintf('NS record %s removed from zone %s',$sub_action_parameter,$key['name']) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateZone', + 'parameters' => array($zone), + 'logs' => array( + 'success' => sprintf( + 'NS record %s removed from zone %s', + $sub_action_parameter, + $key['name'] + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action == 'changeretry') { + } elseif ($action == 'changeretry') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getZone'); - $zone = $this->SoapEngine->soapclient->getZone($key['name']); + $zone = $this->SoapEngine->soapclient->getZone($key['name']); - if ((new PEAR)->isError($zone)) { - $error_msg = $zone->getMessage(); - $error_fault= $zone->getFault(); - $error_code = $zone->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($zone)) { break; } else { - if (!is_numeric($sub_action_parameter)) { - printf ("Error: Retry '%s' must be numeric",$sub_action_parameter); + printf("Error: Retry '%s' must be numeric", $sub_action_parameter); continue; } - $zone->retry=intval($sub_action_parameter); + $zone->retry = intval($sub_action_parameter); $this->log_action('updateZone'); - $function=array('commit' => array('name' => 'updateZone', - 'parameters' => array($zone), - 'logs' => array('success' => sprintf('Retry for zone %s has been set to %d',$key['name'],intval($sub_action_parameter)) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateZone', + 'parameters' => array($zone), + 'logs' => array( + 'success' => sprintf( + 'Retry for zone %s has been set to %d', + $key['name'], + intval($sub_action_parameter) + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action == 'changeinfo') { + } elseif ($action == 'changeinfo') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getZone'); - $zone = $this->SoapEngine->soapclient->getZone($key['name']); + $zone = $this->SoapEngine->soapclient->getZone($key['name']); - if ((new PEAR)->isError($zone)) { - $error_msg = $zone->getMessage(); - $error_fault= $zone->getFault(); - $error_code = $zone->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($zone)) { break; } else { - $zone->info=$sub_action_parameter; + $zone->info = $sub_action_parameter; $this->log_action('updateZone'); - $function=array('commit' => array('name' => 'updateZone', - 'parameters' => array($zone), - 'logs' => array('success' => sprintf('Info for zone %s has been set to %s',$key['name'],$sub_action_parameter) - ) - ) - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateZone', + 'parameters' => array($zone), + 'logs' => array( + 'success' => sprintf('Info for zone %s has been set to %s',$key['name'], $sub_action_parameter) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } } } - if ($action!='export') { + if ($action != 'export') { print "
"; } else { // Filter foreach ($export_customers as $customer) { - $filter=array( - 'customer' => intval($customer), - ); + $filter = array( + 'customer' => intval($customer), + ); // Compose query - $Query=array('filter' => $filter - ); + $Query = array( + 'filter' => $filter + ); // Insert credetials $this->SoapEngine->soapclientCustomers->addHeader($this->SoapEngine->SoapAuth); $this->getCustomers('getZone'); // Call function $result = $this->SoapEngine->soapclientCustomers->getCustomers($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); + if ($this->checkLogSoapError($result, true)) { return false; } else { $exported_data['customers'] = objectToArray($result->accounts); } } print_r(json_encode($exported_data)); } } } diff --git a/library/NGNPro/Actions/EnumMappings.php b/library/NGNPro/Actions/EnumMappings.php index a8903fa..5d7f88c 100644 --- a/library/NGNPro/Actions/EnumMappings.php +++ b/library/NGNPro/Actions/EnumMappings.php @@ -1,161 +1,178 @@ 'Change TTL to:', - 'changeowner' => 'Change owner to:', - 'changeinfo' => 'Change info to:', - 'delete' => 'Delete ENUM mappings' - ); - - var $mapping_fields=array('id' => 'integer', - 'type' => 'text', - 'mapto' => 'text', - 'priority' => 'integer', - 'ttl' => 'integer' - ); +class EnumMappingsActions extends Actions +{ + public $actions = array( + 'changettl' => 'Change TTL to:', + 'changeowner' => 'Change owner to:', + 'changeinfo' => 'Change info to:', + 'delete' => 'Delete ENUM mappings' + ); + + public $mapping_fields = array( + 'id' => 'integer', + 'type' => 'text', + 'mapto' => 'text', + 'priority' => 'integer', + 'ttl' => 'integer' + ); public function execute($selectionKeys, $action, $sub_action_parameter) { if (!in_array($action, array_keys($this->actions))) { print "Error: Invalid action $action"; return false; } print "
    "; - foreach($selectionKeys as $key) { + foreach ($selectionKeys as $key) { flush(); print "
  1. "; - $enum_id=array('number' => $key['number'], - 'tld' => $key['tld'] - ); + $enum_id=array( + 'number' => $key['number'], + 'tld' => $key['tld'] + ); if ($action=='delete') { - - //printf ("Performing action=%s on key=%s",$action,$key); - $function=array('commit' => array('name' => 'deleteNumber', - 'parameters' => array($enum_id), - 'logs' => array('success' => sprintf('ENUM number +%s under %s has been deleted',$key['number'],$key['tld']) - ) - ) - - ); - - $this->SoapEngine->execute($function,$this->html); - } else if ($action == 'changettl') { + //printf ("Performing action=%s on key=%s",$action, $key); + $function=array( + 'commit' => array( + 'name' => 'deleteNumber', + 'parameters' => array($enum_id), + 'logs' => array( + 'success' => sprintf( + 'ENUM number +%s under %s has been deleted', + $key['number'], + $key['tld'] + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); + } elseif ($action == 'changettl') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getNumber'); - $number = $this->SoapEngine->soapclient->getNumber($enum_id); + $number = $this->SoapEngine->soapclient->getNumber($enum_id); - if ((new PEAR)->isError($number)) { - $error_msg = $number->getMessage(); - $error_fault= $number->getFault(); - $error_code = $number->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($number)) { break; } else { if (!is_numeric($sub_action_parameter)) { - printf ("Error: TTL '%s' must be numeric",$sub_action_parameter); + printf("Error: TTL '%s' must be numeric", $sub_action_parameter); continue; } $new_mappings=array(); foreach ($number->mappings as $_mapping) { foreach (array_keys($this->mapping_fields) as $field) { if ($field == 'ttl') { $new_mapping[$field]=intval($sub_action_parameter); } else { if ($this->mapping_fields[$field] == 'integer') { $new_mapping[$field]=intval($_mapping->$field); } else { $new_mapping[$field]=$_mapping->$field; } } } - $new_mappings[]=$new_mapping; + $new_mappings[] = $new_mapping; } - $number->mappings=$new_mappings; + $number->mappings = $new_mappings; $this->log_action('updateNumber'); - $function=array('commit' => array('name' => 'updateNumber', - 'parameters' => array($number), - 'logs' => array('success' => sprintf('ENUM number %s@%s TTL has been set to %d',$key['number'],$key['tld'],intval($sub_action_parameter)) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateNumber', + 'parameters' => array($number), + 'logs' => array( + 'success' => sprintf( + 'ENUM number %s@%s TTL has been set to %d', + $key['number'], + $key['tld'], + intval($sub_action_parameter) + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action == 'changeowner') { + } elseif ($action == 'changeowner') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getNumber'); - $number = $this->SoapEngine->soapclient->getNumber($enum_id); + $number = $this->SoapEngine->soapclient->getNumber($enum_id); - if ((new PEAR)->isError($number)) { - $error_msg = $number->getMessage(); - $error_fault= $number->getFault(); - $error_code = $number->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($number)) { break; } else { $new_mappings=array(); foreach ($number->mappings as $_mapping) { - $new_mappings[]=$_mapping; + $new_mappings[] = $_mapping; } - $number->mappings=$new_mappings; + $number->mappings = $new_mappings; if (is_numeric($sub_action_parameter)) { $number->owner=intval($sub_action_parameter); } else { - printf ("Error: Owner '%s' must be numeric",$sub_action_parameter); + printf("Error: Owner '%s' must be numeric", $sub_action_parameter); continue; } $this->log_action('updateNumber'); - $function=array('commit' => array('name' => 'updateNumber', - 'parameters' => array($number), - 'logs' => array('success' => sprintf('ENUM number %s@%s owner has been set to %d',$key['number'],$key['tld'],intval($sub_action_parameter)) - ) - ) - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateNumber', + 'parameters' => array($number), + 'logs' => array( + 'success' => sprintf( + 'ENUM number %s@%s owner has been set to %d', + $key['number'], + $key['tld'], + intval($sub_action_parameter) + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action == 'changeinfo') { + } elseif ($action == 'changeinfo') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getNumber'); - $number = $this->SoapEngine->soapclient->getNumber($enum_id); + $number = $this->SoapEngine->soapclient->getNumber($enum_id); - if ((new PEAR)->isError($number)) { - $error_msg = $number->getMessage(); - $error_fault= $number->getFault(); - $error_code = $number->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($number)) { break; } else { $new_mappings=array(); foreach ($number->mappings as $_mapping) { $new_mappings[]=$_mapping; } $number->mappings=$new_mappings; $number->info=trim($sub_action_parameter); $this->log_action('updateNumber'); - $function=array('commit' => array('name' => 'updateNumber', - 'parameters' => array($number), - 'logs' => array('success' => sprintf('ENUM number %s@%s info has been set to %s',$key['number'],$key['tld'],trim($sub_action_parameter)) - ) - ) - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array('name' => 'updateNumber', + 'parameters' => array($number), + 'logs' => array( + 'success' => sprintf( + 'ENUM number %s@%s info has been set to %s', + $key['number'], + $key['tld'], + trim($sub_action_parameter) + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } } } print "
"; } } diff --git a/library/NGNPro/Actions/SipAccounts.php b/library/NGNPro/Actions/SipAccounts.php index 331f4be..f39c458 100644 --- a/library/NGNPro/Actions/SipAccounts.php +++ b/library/NGNPro/Actions/SipAccounts.php @@ -1,541 +1,627 @@ 'Block SIP accounts', - 'deblock' => 'Deblock SIP accounts', - 'enable_pstn' => 'Enable access to PSTN for the SIP accounts', - 'disable_pstn' => 'Disable access to PSTN for the SIP accounts', - 'deblock_quota' => 'Deblock SIP accounts blocked by quota', - 'prepaid' => 'Make SIP accounts prepaid', - 'postpaid' => 'Make SIP accounts postpaid', - 'delete' => 'Delete SIP accounts', - 'setquota' => 'Set quota of SIP account to:', - 'rpidasusername' => 'Set PSTN caller ID as the username', - 'prefixtorpid' => 'Add to PSTN caller ID this prefix:', - 'rmdsfromrpid' => 'Remove from PSTN caller ID digits:', - 'addtogroup' => 'Add SIP accounts to group:', - 'removefromgroup'=> 'Remove SIP accounts from group:', - 'addbalance' => 'Add to prepaid balance value:', - 'changeowner' => 'Change owner to:', - 'changefirstname'=> 'Change first name to:', - 'changelastname' => 'Change last name to:', - 'changepassword' => 'Change password to:' - ); +class SipAccountsActions extends Actions +{ + public $actions = array( + 'block' => 'Block SIP accounts', + 'deblock' => 'Deblock SIP accounts', + 'enable_pstn' => 'Enable access to PSTN for the SIP accounts', + 'disable_pstn' => 'Disable access to PSTN for the SIP accounts', + 'deblock_quota' => 'Deblock SIP accounts blocked by quota', + 'prepaid' => 'Make SIP accounts prepaid', + 'postpaid' => 'Make SIP accounts postpaid', + 'delete' => 'Delete SIP accounts', + 'setquota' => 'Set quota of SIP account to:', + 'rpidasusername' => 'Set PSTN caller ID as the username', + 'prefixtorpid' => 'Add to PSTN caller ID this prefix:', + 'rmdsfromrpid' => 'Remove from PSTN caller ID digits:', + 'addtogroup' => 'Add SIP accounts to group:', + 'removefromgroup'=> 'Remove SIP accounts from group:', + 'addbalance' => 'Add to prepaid balance value:', + 'changeowner' => 'Change owner to:', + 'changefirstname'=> 'Change first name to:', + 'changelastname' => 'Change last name to:', + 'changepassword' => 'Change password to:' + ); public function execute($selectionKeys, $action, $sub_action_parameter) { if (!in_array($action, array_keys($this->actions))) { print "Error: Invalid action $action"; return false; } print "
    "; - foreach($selectionKeys as $key) { - + foreach ($selectionKeys as $key) { flush(); - //printf ("Performing action=%s on key=%s",$action,$key); + //printf ("Performing action=%s on key=%s",$action, $key); - $account=array('username' => $key['username'], - 'domain' => $key['domain'] - ); + $account = array('username' => $key['username'], + 'domain' => $key['domain'] + ); - printf ("
  1. %s@%s",$key['username'],$key['domain']); + printf("
  2. %s@%s", $key['username'], $key['domain']); - if ($action=='block') { + if ($action == 'block') { $this->log_action('addToGroup'); - $function=array('commit' => array('name' => 'addToGroup', - 'parameters' => array($account,'blocked'), - 'logs' => array('success' => sprintf('SIP account %s@%s has been blocked',$key['username'],$key['domain']) - ) - ) - - ); - - $this->SoapEngine->execute($function,$this->html); - } else if ($action=='deblock') { + $function = array( + 'commit' => array( + 'name' => 'addToGroup', + 'parameters' => array($account,'blocked'), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s has been blocked', + $key['username'], + $key['domain'] + ) + ) + ) + ); + + $this->SoapEngine->execute($function, $this->html); + } elseif ($action == 'deblock') { $this->log_action('removeFromGroup'); - $function=array('commit' => array('name' => 'removeFromGroup', - 'parameters' => array($account,'blocked'), - 'logs' => array('success' => sprintf('SIP account %s@%s has been de-blocked',$key['username'],$key['domain']) - ) - ) - - ); - - $this->SoapEngine->execute($function,$this->html); - } else if ($action=='removefromgroup') { + $function = array( + 'commit' => array( + 'name' => 'removeFromGroup', + 'parameters' => array($account,'blocked'), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s has been de-blocked', + $key['username'], + $key['domain'] + ) + ) + ) + ); + + $this->SoapEngine->execute($function, $this->html); + } elseif ($action == 'removefromgroup') { if (!strlen($sub_action_parameter)) { - printf ("Error: you must enter a group name"); + printf("Error: you must enter a group name"); break; } $this->log_action('removeFromGroup'); - $function=array('commit' => array('name' => 'removeFromGroup', - 'parameters' => array($account,$sub_action_parameter), - 'logs' => array('success' => sprintf('SIP account %s@%s has been removed from group %s',$key['username'],$key['domain'],$sub_action_parameter) - ) - ) - - ); - - $this->SoapEngine->execute($function,$this->html); - } else if ($action=='addtogroup') { + $function = array( + 'commit' => array( + 'name' => 'removeFromGroup', + 'parameters' => array($account,$sub_action_parameter), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s has been removed from group %s', + $key['username'], + $key['domain'], + $sub_action_parameter + ) + ) + ) + ); + + $this->SoapEngine->execute($function, $this->html); + } elseif ($action=='addtogroup') { $this->log_action('addToGroup'); if (!strlen($sub_action_parameter)) { - printf ("Error: you must enter a group name"); + printf("Error: you must enter a group name"); break; } - $function=array('commit' => array('name' => 'addToGroup', - 'parameters' => array($account,$sub_action_parameter), - 'logs' => array('success' => sprintf('SIP account %s@%s is now in group %s',$key['username'],$key['domain'],$sub_action_parameter) - ) - ) - - ); - - $this->SoapEngine->execute($function,$this->html); - } else if ($action=='deblock_quota') { + $function = array( + 'commit' => array( + 'name' => 'addToGroup', + 'parameters' => array($account,$sub_action_parameter), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s is now in group %s', + $key['username'], + $key['domain'], + $sub_action_parameter + ) + ) + ) + ); + + $this->SoapEngine->execute($function, $this->html); + } elseif ($action=='deblock_quota') { $this->log_action('removeFromGroup'); - $function=array('commit' => array('name' => 'removeFromGroup', - 'parameters' => array($account,'quota'), - 'logs' => array('success' => sprintf('SIP account %s@%s has been deblocked from quota',$key['username'],$key['domain']) - ) - ) - - ); - - $this->SoapEngine->execute($function,$this->html); - } else if ($action=='disable_pstn') { + $function = array( + 'commit' => array( + 'name' => 'removeFromGroup', + 'parameters' => array($account,'quota'), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s has been deblocked from quota', + $key['username'], + $key['domain'] + ) + ) + ) + ); + + $this->SoapEngine->execute($function, $this->html); + } elseif ($action=='disable_pstn') { $this->log_action('removeFromGroup'); - $function=array('commit' => array('name' => 'removeFromGroup', - 'parameters' => array($account,'free-pstn'), - 'logs' => array('success' => sprintf('SIP account %s@%s has no access to the PSTN',$key['username'],$key['domain']) - ) - ) - - ); - - $this->SoapEngine->execute($function,$this->html); - } else if ($action=='enable_pstn') { + $function = array( + 'commit' => array( + 'name' => 'removeFromGroup', + 'parameters' => array($account,'free-pstn'), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s has no access to the PSTN', + $key['username'], + $key['domain'] + ) + ) + ) + ); + + $this->SoapEngine->execute($function, $this->html); + } elseif ($action=='enable_pstn') { $this->log_action('addToGroup'); - $function=array('commit' => array('name' => 'addToGroup', - 'parameters' => array($account,'free-pstn'), - 'logs' => array('success' => sprintf('SIP account %s@%s has access to the PSTN',$key['username'],$key['domain']) - ) - ) - - ); - - $this->SoapEngine->execute($function,$this->html); - } else if ($action=='delete') { + $function = array( + 'commit' => array( + 'name' => 'addToGroup', + 'parameters' => array($account,'free-pstn'), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s has access to the PSTN', + $key['username'], + $key['domain'] + ) + ) + ) + ); + + $this->SoapEngine->execute($function, $this->html); + } elseif ($action=='delete') { $this->log_action('deleteAccount'); - $function=array('commit' => array('name' => 'deleteAccount', - 'parameters' => array($account), - 'logs' => array('success' => sprintf('SIP account %s@%s has been deleted',$key['username'],$key['domain']) - ) - ) - - ); - - $this->SoapEngine->execute($function,$this->html); - } else if ($action=='prepaid') { + $function = array( + 'commit' => array( + 'name' => 'deleteAccount', + 'parameters' => array($account), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s has been deleted', + $key['username'], + $key['domain'] + ) + ) + ) + ); + + $this->SoapEngine->execute($function, $this->html); + } elseif ($action=='prepaid') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccount'); $result = $this->SoapEngine->soapclient->getAccount($account); - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($result)) { break; } else { //print_r($result); // Sanitize data types due to PHP bugs - if (!is_array($result->properties)) $result->properties=array(); - if (!is_array($result->groups)) $result->groups=array(); + if (!is_array($result->properties)) $result->properties = array(); + if (!is_array($result->groups)) $result->groups = array(); $result->quota = intval($result->quota); $result->answerTimeout = intval($result->answerTimeout); $result->prepaid=1; $this->log_action('updateAccount'); - $function=array('commit' => array('name' => 'updateAccount', - 'parameters' => array($result), - 'logs' => array('success' => sprintf('SIP account %s@%s is now prepaid',$key['username'],$key['domain']) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateAccount', + 'parameters' => array($result), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s is now prepaid', + $key['username'], + $key['domain'] + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action=='postpaid') { + } elseif ($action=='postpaid') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccount'); $result = $this->SoapEngine->soapclient->getAccount($account); - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($result)) { break; } else { - if (!is_array($result->properties)) $result->properties=array(); - if (!is_array($result->groups)) $result->groups=array(); + if (!is_array($result->properties)) $result->properties = array(); + if (!is_array($result->groups)) $result->groups = array(); $result->quota = intval($result->quota); $result->answerTimeout = intval($result->answerTimeout); $result->prepaid=0; $this->log_action('updateAccount'); - $function=array('commit' => array('name' => 'updateAccount', - 'parameters' => array($result), - 'logs' => array('success' => sprintf('SIP account %s@%s is now postpaid',$key['username'],$key['domain']) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateAccount', + 'parameters' => array($result), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s is now postpaid', + $key['username'], + $key['domain'] + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action=='setquota') { + } elseif ($action=='setquota') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccount'); $result = $this->SoapEngine->soapclient->getAccount($account); - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($result)) { break; } else { //print_r($result); // Sanitize data types due to PHP bugs - if (!is_array($result->properties)) $result->properties=array(); - if (!is_array($result->groups)) $result->groups=array(); + if (!is_array($result->properties)) $result->properties = array(); + if (!is_array($result->groups)) $result->groups = array(); $result->quota = intval($sub_action_parameter); $result->answerTimeout = intval($result->answerTimeout); $this->log_action('updateAccount'); - $function=array('commit' => array('name' => 'updateAccount', - 'parameters' => array($result), - 'logs' => array('success' => sprintf('SIP account %s@%s has quota set to %s',$key['username'],$key['domain'],$sub_action_parameter) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateAccount', + 'parameters' => array($result), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s has quota set to %s', + $key['username'], + $key['domain'], + $sub_action_parameter + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action=='rmdsfromrpid') { + } elseif ($action=='rmdsfromrpid') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccount'); $result = $this->SoapEngine->soapclient->getAccount($account); - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($result)) { break; } else { //print_r($result); // Sanitize data types due to PHP bugs - if (!is_array($result->properties)) $result->properties=array(); - if (!is_array($result->groups)) $result->groups=array(); + if (!is_array($result->properties)) $result->properties = array(); + if (!is_array($result->groups)) $result->groups = array(); if (is_numeric($sub_action_parameter) && strlen($result->rpid) > $sub_action_parameter) { - printf("%s %s",$result->rpid,$sub_action_parameter); - $result->rpid=substr($result->rpid,$sub_action_parameter); - printf("%s %s",$result->rpid,$sub_action_parameter); + printf("%s %s", $result->rpid, $sub_action_parameter); + $result->rpid = substr($result->rpid, $sub_action_parameter); + printf("%s %s", $result->rpid, $sub_action_parameter); } else { - printf ("Error: '%s' must be numeric and less than caller if length",$sub_action_parameter); + printf( + "Error: '%s' must be numeric and less than caller if length", + $sub_action_parameter + ); continue; } $result->quota = intval($result->quota); $result->answerTimeout = intval($result->answerTimeout); $this->log_action('updateAccount'); - $function=array('commit' => array('name' => 'updateAccount', - 'parameters' => array($result), - 'logs' => array('success' => sprintf('SIP account %s@%s has PSTN caller ID set to %s',$key['username'],$key['domain'],$result->rpid) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateAccount', + 'parameters' => array($result), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s has PSTN caller ID set to %s', + $key['username'], + $key['domain'], + $result->rpid + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action=='rpidasusername') { + } elseif ($action=='rpidasusername') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccount'); $result = $this->SoapEngine->soapclient->getAccount($account); - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($result)) { break; } else { //print_r($result); // Sanitize data types due to PHP bugs - if (!is_array($result->properties)) $result->properties=array(); - if (!is_array($result->groups)) $result->groups=array(); + if (!is_array($result->properties)) $result->properties = array(); + if (!is_array($result->groups)) $result->groups = array(); if (is_numeric($key['username'])) $result->rpid=$key['username']; $result->quota = intval($result->quota); $result->answerTimeout = intval($result->answerTimeout); $this->log_action('updateAccount'); - $function=array('commit' => array('name' => 'updateAccount', - 'parameters' => array($result), - 'logs' => array('success' => sprintf('SIP account %s@%s has PSTN caller ID set to %s',$key['username'],$key['domain'],$key['username']) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateAccount', + 'parameters' => array($result), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s has PSTN caller ID set to %s', + $key['username'], + $key['domain'], + $key['username'] + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action=='prefixtorpid') { + } elseif ($action=='prefixtorpid') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccount'); $result = $this->SoapEngine->soapclient->getAccount($account); - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($result)) { break; } else { //print_r($result); // Sanitize data types due to PHP bugs - if (!is_array($result->properties)) $result->properties=array(); - if (!is_array($result->groups)) $result->groups=array(); + if (!is_array($result->properties)) $result->properties = array(); + if (!is_array($result->groups)) $result->groups = array(); if (is_numeric($sub_action_parameter)) { $result->rpid=$sub_action_parameter.$result->rpid; } else { - printf ("Error: '%s' must be numeric",$sub_action_parameter); + printf("Error: '%s' must be numeric", $sub_action_parameter); continue; } $result->quota = intval($result->quota); $result->answerTimeout = intval($result->answerTimeout); $this->log_action('updateAccount'); - $function=array('commit' => array('name' => 'updateAccount', - 'parameters' => array($result), - 'logs' => array('success' => sprintf('SIP account %s@%s has PSTN caller ID set to %s ',$key['username'],$key['domain'],$result->rpid) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateAccount', + 'parameters' => array($result), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s has PSTN caller ID set to %s ', + $key['username'], + $key['domain'], + $result->rpid + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action=='changecustomer') { + } elseif ($action=='changecustomer') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccount'); $result = $this->SoapEngine->soapclient->getAccount($account); - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($result)) { break; } else { //print_r($result); // Sanitize data types due to PHP bugs - if (!is_array($result->properties)) $result->properties=array(); - if (!is_array($result->groups)) $result->groups=array(); + if (!is_array($result->properties)) $result->properties = array(); + if (!is_array($result->groups)) $result->groups = array(); if (is_numeric($sub_action_parameter)) { - $result->customer=intval($sub_action_parameter); + $result->customer = intval($sub_action_parameter); } else { - printf ("Error: '%s' must be numeric",$sub_action_parameter); + printf("Error: '%s' must be numeric", $sub_action_parameter); continue; } $result->quota = intval($result->quota); $result->answerTimeout = intval($result->answerTimeout); $this->log_action('updateAccount'); - $function=array('commit' => array('name' => 'updateAccount', - 'parameters' => array($result), - 'logs' => array('success' => sprintf('SIP account %s@%s has customer set to %s ',$key['username'],$key['domain'],$result->customer) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateAccount', + 'parameters' => array($result), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s has customer set to %s ', + $key['username'], + $key['domain'], + $result->customer + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action=='changeowner') { + } elseif ($action=='changeowner') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccount'); $result = $this->SoapEngine->soapclient->getAccount($account); - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($result)) { break; } else { //print_r($result); // Sanitize data types due to PHP bugs - if (!is_array($result->properties)) $result->properties=array(); - if (!is_array($result->groups)) $result->groups=array(); + if (!is_array($result->properties)) $result->properties = array(); + if (!is_array($result->groups)) $result->groups = array(); if (is_numeric($sub_action_parameter)) { - $result->owner=intval($sub_action_parameter); + $result->owner = intval($sub_action_parameter); } else { - printf ("Error: '%s' must be numeric",$sub_action_parameter); + printf("Error: '%s' must be numeric", $sub_action_parameter); continue; } $result->quota = intval($result->quota); $result->answerTimeout = intval($result->answerTimeout); $this->log_action('updateAccount'); - $function=array('commit' => array('name' => 'updateAccount', - 'parameters' => array($result), - 'logs' => array('success' => sprintf('SIP account %s@%s has owner set to %s ',$key['username'],$key['domain'],$result->owner) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateAccount', + 'parameters' => array($result), + 'logs' => array( + 'success' => sprintf('SIP account %s@%s has owner set to %s ', + $key['username'], + $key['domain'], + $result->owner + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action=='changefirstname') { + } elseif ($action=='changefirstname') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccount'); $result = $this->SoapEngine->soapclient->getAccount($account); - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($result)) { break; } else { - - if (!is_array($result->properties)) $result->properties=array(); - if (!is_array($result->groups)) $result->groups=array(); - $result->firstName=trim($sub_action_parameter); + if (!is_array($result->properties)) $result->properties = array(); + if (!is_array($result->groups)) $result->groups = array(); + $result->firstName = trim($sub_action_parameter); $result->quota = intval($result->quota); $result->answerTimeout = intval($result->answerTimeout); $this->log_action('updateAccount'); - $function=array('commit' => array('name' => 'updateAccount', - 'parameters' => array($result), - 'logs' => array('success' => sprintf('SIP account %s@%s first name has been set to %s ',$key['username'],$key['domain'],$result->firstName) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateAccount', + 'parameters' => array($result), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s first name has been set to %s ', + $key['username'], + $key['domain'], + $result->firstName + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action=='changelastname') { + } elseif ($action=='changelastname') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccount'); $result = $this->SoapEngine->soapclient->getAccount($account); - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($result)) { break; } else { - - if (!is_array($result->properties)) $result->properties=array(); - if (!is_array($result->groups)) $result->groups=array(); - $result->lastName=trim($sub_action_parameter); + if (!is_array($result->properties)) $result->properties = array(); + if (!is_array($result->groups)) $result->groups = array(); + $result->lastName = trim($sub_action_parameter); $result->quota = intval($result->quota); $result->answerTimeout = intval($result->answerTimeout); $this->log_action('updateAccount'); - $function=array('commit' => array('name' => 'updateAccount', - 'parameters' => array($result), - 'logs' => array('success' => sprintf('SIP account %s@%s last name has been set to %s ',$key['username'],$key['domain'],$result->lastName) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateAccount', + 'parameters' => array($result), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s last name has been set to %s ', + $key['username'], + $key['domain'], + $result->lastName + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action=='changepassword') { + } elseif ($action=='changepassword') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccount'); $result = $this->SoapEngine->soapclient->getAccount($account); - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($result)) { break; } else { - - if (!is_array($result->properties)) $result->properties=array(); - if (!is_array($result->groups)) $result->groups=array(); - $result->password=trim($sub_action_parameter); + if (!is_array($result->properties)) $result->properties = array(); + if (!is_array($result->groups)) $result->groups = array(); + $result->password = trim($sub_action_parameter); $result->quota = intval($result->quota); $result->answerTimeout = intval($result->answerTimeout); $this->log_action('updateAccount'); - $function=array('commit' => array('name' => 'updateAccount', - 'parameters' => array($result), - 'logs' => array('success' => sprintf('Password for SIP account %s@%s has been changed',$key['username'],$key['domain']) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'updateAccount', + 'parameters' => array($result), + 'logs' => array( + 'success' => sprintf( + 'Password for SIP account %s@%s has been changed', + $key['username'], + $key['domain'] + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } - } else if ($action=='addbalance') { + } elseif ($action=='addbalance') { if (!is_numeric($sub_action_parameter)) { - printf ("Error: you must enter a positive balance"); + printf("Error: you must enter a positive balance"); break; } $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccount'); $result = $this->SoapEngine->soapclient->getAccount($account); - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - printf ("Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + if ($this->checkLogSoapError($result)) { break; } if (!$result->prepaid) { - printf ("Info: SIP account %s@%s is not prepaid, no action performed",$key['username'],$key['domain']); + printf( + "Info: SIP account %s@%s is not prepaid, no action performed", + $key['username'], + $key['domain'] + ); continue; } $this->log_action('addBalance'); - $function=array('commit' => array('name' => 'addBalance', - 'parameters' => array($account,$sub_action_parameter), - 'logs' => array('success' => sprintf('SIP account %s@%s balance has been increased with %s',$key['username'],$key['domain'],$sub_action_parameter) - ) - ) - - ); - $this->SoapEngine->execute($function,$this->html); + $function = array( + 'commit' => array( + 'name' => 'addBalance', + 'parameters' => array($account, $sub_action_parameter), + 'logs' => array( + 'success' => sprintf( + 'SIP account %s@%s balance has been increased with %s', + $key['username'], + $key['domain'], + $sub_action_parameter + ) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } } print "
"; } } - diff --git a/library/NGNPro/Actions/SipAliases.php b/library/NGNPro/Actions/SipAliases.php index 11177de..786d2a2 100644 --- a/library/NGNPro/Actions/SipAliases.php +++ b/library/NGNPro/Actions/SipAliases.php @@ -1,41 +1,43 @@ 'Delete SIP aliases' ); public function execute($selectionKeys, $action, $sub_action_parameter) { if (!in_array($action, array_keys($this->actions))) { print "Error: Invalid action $action"; return false; } print "
    "; - foreach($selectionKeys as $key) { + foreach ($selectionKeys as $key) { print "
  1. "; flush(); //printf ("Performing action=%s on key=%s",$action,$key); $alias=array('username' => $key['username'], - 'domain' => $key['domain'] - ); + 'domain' => $key['domain'] + ); if ($action=='delete') { $this->log_action('deleteAlias'); - $function=array('commit' => array('name' => 'deleteAlias', - 'parameters' => array($alias), - 'logs' => array('success' => sprintf('SIP alias %s@%s has been deleted',$key['username'],$key['domain']) - ) - ) - ); - $this->SoapEngine->execute($function,$this->html); + $function=array( + 'commit' => array( + 'name' => 'deleteAlias', + 'parameters' => array($alias), + 'logs' => array( + 'success' => sprintf('SIP alias %s@%s has been deleted', $key['username'], $key['domain']) + ) + ) + ); + $this->SoapEngine->execute($function, $this->html); } } print "
"; - } }