diff --git a/library/NGNPro/Actions/Customers.php b/library/NGNPro/Actions/Customers.php index 037baa3..50a4de4 100644 --- a/library/NGNPro/Actions/Customers.php +++ b/library/NGNPro/Actions/Customers.php @@ -1,39 +1,34 @@ 'Delete customers' ); - public function __construct($SoapEngine, $login_credentials) + public function execute($selectionKeys, $action, $sub_action_parameter) { - parent::__construct($SoapEngine, $login_credentials); - } - - function execute($selectionKeys,$action,$sub_action_parameter) { - - if (!in_array($action,array_keys($this->actions))) { + if (!in_array($action, array_keys($this->actions))) { print "Error: Invalid action $action"; return false; } print "
    "; foreach($selectionKeys as $key) { flush(); print "
  1. "; 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); } } print "
"; } } diff --git a/library/NGNPro/Actions/DnsRecords.php b/library/NGNPro/Actions/DnsRecords.php index 3177461..cf24c8f 100644 --- a/library/NGNPro/Actions/DnsRecords.php +++ b/library/NGNPro/Actions/DnsRecords.php @@ -1,130 +1,126 @@ 'Change TTL to:', 'changepriority' => 'Change Priority to:', 'changevalue' => 'Change value to:', 'delete' => 'Delete records' ); - public function __construct($SoapEngine, $login_credentials) + public function execute($selectionKeys, $action, $sub_action_parameter) { - parent::__construct($SoapEngine, $login_credentials); - } - - function execute($selectionKeys, $action, $sub_action_parameter) { - if (!in_array($action,array_keys($this->actions))) { + if (!in_array($action, array_keys($this->actions))) { print "Error: Invalid action $action"; return false; } print "
    "; foreach($selectionKeys as $key) { flush(); print "
  1. "; //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') { $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); break; } else { if (!is_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); } } else if ($action == 'changepriority') { $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); 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); 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); } } else if ($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); break; } else { $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); } } } print "
"; } } diff --git a/library/NGNPro/Actions/DnsZones.php b/library/NGNPro/Actions/DnsZones.php index 13c48fa..30a5b83 100644 --- a/library/NGNPro/Actions/DnsZones.php +++ b/library/NGNPro/Actions/DnsZones.php @@ -1,334 +1,330 @@ '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 __construct($SoapEngine, $login_credentials) + public function execute($selectionKeys, $action, $sub_action_parameter) { - parent::__construct($SoapEngine, $login_credentials); - } - - function execute($selectionKeys,$action,$sub_action_parameter) { - if (!in_array($action,array_keys($this->actions))) { + if (!in_array($action, array_keys($this->actions))) { print "Error: Invalid action $action"; return false; } if ($action!='export') { print "
    "; } else { $exported_data=array('dns_zones'=>array()); $export_customers=array(); } foreach($selectionKeys as $key) { flush(); if ($action!='export') { print "
  1. "; } //printf ("Performing action=%s on key=%s",$action,$key['name']); 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') { // 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); 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); return false; } else { $exported_data['dns_records'] = objectToArray($result->records); } } else if ($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); break; } else { if (!is_numeric($sub_action_parameter)) { printf ("Error: TTL '%s' must be numeric",$sub_action_parameter); continue; } $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); } } else if ($action == 'changeexpire') { $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); break; } else { if (!is_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); } } else if ($action == 'changeminimum') { $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); break; } else { if (!is_numeric($sub_action_parameter)) { printf ("Error: Minimum '%s' must be numeric",$sub_action_parameter); continue; } $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); } } else if ($action == 'addnsrecord') { $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); break; } else { $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); } } else if ($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); break; } else { $new_servers=array(); foreach ($zone->nameservers as $_ns) { if ($_ns == $sub_action_parameter) continue; $new_servers[]=$_ns; } $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); } } else if ($action == 'changeretry') { $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); break; } else { if (!is_numeric($sub_action_parameter)) { printf ("Error: Retry '%s' must be numeric",$sub_action_parameter); continue; } $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); } } else if ($action == 'changeinfo') { $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); break; } else { $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); } } } if ($action!='export') { print "
"; } else { // Filter foreach ($export_customers as $customer) { $filter=array( 'customer' => intval($customer), ); // Compose query $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); 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 4481740..a8903fa 100644 --- a/library/NGNPro/Actions/EnumMappings.php +++ b/library/NGNPro/Actions/EnumMappings.php @@ -1,165 +1,161 @@ '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' ); - public function __construct($SoapEngine, $login_credentials) + public function execute($selectionKeys, $action, $sub_action_parameter) { - parent::__construct($SoapEngine, $login_credentials); - } - - function execute($selectionKeys,$action,$sub_action_parameter) { - if (!in_array($action,array_keys($this->actions))) { + if (!in_array($action, array_keys($this->actions))) { print "Error: Invalid action $action"; return false; } print "
    "; foreach($selectionKeys as $key) { flush(); print "
  1. "; $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') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getNumber'); $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); break; } else { if (!is_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; } $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); } } else if ($action == 'changeowner') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getNumber'); $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); break; } else { $new_mappings=array(); foreach ($number->mappings as $_mapping) { $new_mappings[]=$_mapping; } $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); 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); } } else if ($action == 'changeinfo') { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getNumber'); $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); 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); } } } print "
"; } } diff --git a/library/NGNPro/Actions/SipAccounts.php b/library/NGNPro/Actions/SipAccounts.php index 45b8785..331f4be 100644 --- a/library/NGNPro/Actions/SipAccounts.php +++ b/library/NGNPro/Actions/SipAccounts.php @@ -1,544 +1,541 @@ '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:' ); - function SipAccountsActions($SoapEngine, $login_credentials) { - $this->Actions($SoapEngine, $login_credentials); - } - - function execute($selectionKeys,$action,$sub_action_parameter) { - if (!in_array($action,array_keys($this->actions))) { + 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) { flush(); //printf ("Performing action=%s on key=%s",$action,$key); $account=array('username' => $key['username'], 'domain' => $key['domain'] ); printf ("
  1. %s@%s",$key['username'],$key['domain']); 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') { $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') { if (!strlen($sub_action_parameter)) { 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') { $this->log_action('addToGroup'); if (!strlen($sub_action_parameter)) { 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') { $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') { $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') { $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') { $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') { $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); 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(); $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); } } else if ($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); break; } else { 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); } } else if ($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); 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(); $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); } } else if ($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); 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_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); } else { 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); } } else if ($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); 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_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); } } else if ($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); 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_numeric($sub_action_parameter)) { $result->rpid=$sub_action_parameter.$result->rpid; } else { 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); } } else if ($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); 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_numeric($sub_action_parameter)) { $result->customer=intval($sub_action_parameter); } else { 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); } } else if ($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); 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_numeric($sub_action_parameter)) { $result->owner=intval($sub_action_parameter); } else { 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); } } else if ($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); break; } else { 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); } } else if ($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); break; } else { 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); } } else if ($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); break; } else { 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); } } else if ($action=='addbalance') { if (!is_numeric($sub_action_parameter)) { 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); break; } if (!$result->prepaid) { 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); } } print "
"; } } diff --git a/library/NGNPro/Actions/SipAliases.php b/library/NGNPro/Actions/SipAliases.php index 6504b22..11177de 100644 --- a/library/NGNPro/Actions/SipAliases.php +++ b/library/NGNPro/Actions/SipAliases.php @@ -1,46 +1,41 @@ 'Delete SIP aliases' ); - public function __construct($SoapEngine, $login_credentials) + public function execute($selectionKeys, $action, $sub_action_parameter) { - parent::__construct($SoapEngine, $login_credentials); - } - - function execute($selectionKeys, $action, $sub_action_parameter) - { - if (!in_array($action,array_keys($this->actions))) { + if (!in_array($action, array_keys($this->actions))) { print "Error: Invalid action $action"; return false; } print "
    "; foreach($selectionKeys as $key) { print "
  1. "; flush(); //printf ("Performing action=%s on key=%s",$action,$key); $alias=array('username' => $key['username'], '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); } } print "
"; } }