[Work on Dns records port Adrian Georgescu **20080629185727] hunk ./library/ngnpro_client.php 192 - /* hunk ./library/ngnpro_client.php 206 - */ - hunk ./library/ngnpro_client.php 1395 + + function print_w($obj) { + print "
\n";
+        print_r($obj);
+        print "
\n"; + } + hunk ./library/ngnpro_client.php 2138 - hunk ./library/ngnpro_client.php 2184 - //print "
";
-            //print_r($result->accounts);
-
hunk ./library/ngnpro_client.php 6118
+                                 'id'           => trim($_REQUEST['id_filter']),
hunk ./library/ngnpro_client.php 6125
+
hunk ./library/ngnpro_client.php 6134
+                      'id'       => $this->filters['id'],
hunk ./library/ngnpro_client.php 6168
+        //$this->print_w($result);
+
hunk ./library/ngnpro_client.php 6180
-             if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') {
+            if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') {
hunk ./library/ngnpro_client.php 6193
-                ";
-                print "
hunk ./library/ngnpro_client.php 6194
+                Id
hunk ./library/ngnpro_client.php 6196
-                Name
-                Type
+                Name
+                Type
hunk ./library/ngnpro_client.php 6200
-                Info
+                Priority
hunk ./library/ngnpro_client.php 6204
-                ";
-                print "
hunk ./library/ngnpro_client.php 6226
-                    //print"
";
-                    //print_r($record);
hunk ./library/ngnpro_client.php 6235
-                    $j=1;
-
-                    $_url = $this->url.sprintf("&service=%s&action=Delete&name_filter=%s&zone_filter=%s",
+                    $_url = $this->url.sprintf("&service=%s&action=Delete&name_filter=%s&zone_filter=%s&id_filter=%s",
hunk ./library/ngnpro_client.php 6237
-                    urlencode($record->id->name),
-                    urlencode($record->id->zone)
+                    urlencode($record->name),
+                    urlencode($record->zone),
+                    urlencode($record->id)
hunk ./library/ngnpro_client.php 6243
-                        $_REQUEST['name_filter'] == $record->id->name &&
-                        $_REQUEST['zone_filter'] == $record->id->zone) {
+                        $_REQUEST['id_filter'] == $record->id) {
hunk ./library/ngnpro_client.php 6250
-                    $_number_url = $this->url.sprintf("&service=%s&id_filter=%s",
-                    urlencode($this->SoapEngine->service),
-                    urlencode($record->id)
-                    );
-
hunk ./library/ngnpro_client.php 6272
-                    if (strlen($record->id->name)) {
-                        $name=$record->id->name.'.'.$record->id->zone;
+                    if (strlen($record->name)) {
+                        $name=$record->name.'.'.$record->zone;
hunk ./library/ngnpro_client.php 6275
-                        $name=$record->id->zone;
+                        $name=$record->zone;
hunk ./library/ngnpro_client.php 6281
-                    Zone
-                    %s
hunk ./library/ngnpro_client.php 6282
+                    Zone
+                    %s
+                    %s
hunk ./library/ngnpro_client.php 6298
+                    $record->id,
hunk ./library/ngnpro_client.php 6303
-
hunk ./library/ngnpro_client.php 6304
-                    $record->info,
+                    $record->priority,
hunk ./library/ngnpro_client.php 6330
-        printf (" Name ",$_REQUEST['name_filter']);
-        printf (" Type ",$_REQUEST['name_filter']);
+
+        $selected_zone[$_REQUEST['zone_filter']]='selected';
+        print ".";
hunk ./library/ngnpro_client.php 6341
+        printf (" Type ",$_REQUEST['name']);
-        print "";
-
-        print "
hunk ./library/ngnpro_client.php 6411
-        printf (" ",$_REQUEST['value']);
+        printf (" Name");
+
+        printf (" ",$_REQUEST['name']);
+
+        if ($_REQUEST['zone']) {
+            $selected_zone[$_REQUEST['zone']]='selected';
+        } else if ($_zone=$this->getLoginProperty('dns_records_last_zone')) {
+            $selected_zone[$_zone]='selected';
+        }
+
+        print ".";
+
+        printf (" Value",$_REQUEST['value']);
hunk ./library/ngnpro_client.php 6488
+        if ($dictionary['name']) {
+            $name = $dictionary['name'];
+        } else {
+            $name = trim($_REQUEST['name']);
+        }
+
hunk ./library/ngnpro_client.php 6501
-        if ($dictionary['name']) {
-            $name = $dictionary['name'];
+        if (!strlen($zone)) {
+            printf ("

Error: Missing zone name. "); + return false; + } + + if ($dictionary['type']) { + $type = $dictionary['type']; hunk ./library/ngnpro_client.php 6509 - $name = trim($_REQUEST['name']); + $type = trim($_REQUEST['type']); hunk ./library/ngnpro_client.php 6512 - if (!strlen($zone)) { - printf ("

Error: Missing zone name. "); + if (!strlen($type) || !in_array($type,$this->recordTypes)) { + printf ("

Error: Invalid or missing record type. "); + return false; + } + + if ($dictionary['value']) { + $value = $dictionary['value']; + } else { + $value = trim($_REQUEST['value']); + } + + if (!strlen($value)) { + printf ("

Error: Missing record value. "); hunk ./library/ngnpro_client.php 6550 - if ($dictionary['info']) { - $info = $dictionary['info']; - } else { - $info = trim($_REQUEST['info']); - } - - if ($dictionary['value']) { - $value = $dictionary['value']; - } else { - $value = trim($_REQUEST['value']); - } - - if (!strlen($value)) { - printf ("

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

Error: Invalid or missing record type. "); - return false; - } - - $record=array('id' => array('name'=>$name, - 'zone'=>$zone), - 'value' => $value, - 'ttl' => $ttl, + $record=array('name' => trim($name), + 'zone' => trim($zone), hunk ./library/ngnpro_client.php 6553 - 'owner' => $owner, - 'info' => $info - ); + 'value' => trim($value), + 'ttl' => intval($ttl), + 'priority' => intval($priority), + 'owner' => intval($owner) + ); hunk ./library/ngnpro_client.php 6591 - $filter=array('number' => $this->filters['number'], - 'tld' => $this->filters['tld'], + $filter=array( + 'id' => $this->filters['id'], + 'zone' => $this->filters['zone'], + 'name' => $this->filters['name'], hunk ./library/ngnpro_client.php 6596 - 'mapto' => $this->filters['mapto'], + 'value' => $this->filters['value'], hunk ./library/ngnpro_client.php 6601 + hunk ./library/ngnpro_client.php 6625 - $result = $this->SoapEngine->soapclient->getNumbers($Query); + $result = $this->SoapEngine->soapclient->getRecords($Query); hunk ./library/ngnpro_client.php 6634 - foreach ($result->numbers as $number) { - $this->selectionKeys[]=array('number' => $number->id->number, - 'tld' => $number->id->tld); + foreach ($result->records as $record) { + $this->selectionKeys[]=array('id' => $record->id); hunk ./library/ngnpro_client.php 6779 - function getRecord($record) { + function getRecord($id) { + // Filter + if (!$id) { + print "Error in getRecord(): Missing record id"; + return false; + } + + $filter=array('id' => $id); + + // Range + $range=array('start' => 0, + 'count' => 1 + ); + + // Order + $orderBy = array('attribute' => 'changeDate', + 'direction' => 'DESC' + ); + + // Compose query + $Query=array('filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); hunk ./library/ngnpro_client.php 6805 - $result = $this->SoapEngine->soapclient->getRecords($filter); + $result = $this->SoapEngine->soapclient->getRecords($Query); hunk ./library/ngnpro_client.php 6814 - return $result; + if ($result->records[0]){ + return $result->records[0]; + } else { + return false; + } hunk ./library/ngnpro_client.php 6827 - $record=array('number' => $_REQUEST['number_filter'], - 'tld' => $_REQUEST['tld_filter'] - ); - - if (!$number = $this->getRecord($record)) { + if (!$record = $this->getRecord($_REQUEST['id_filter'])) { hunk ./library/ngnpro_client.php 6843 - //print_r($number); + //print_r($record); hunk ./library/ngnpro_client.php 6846 - 'logs' => array('success' => sprintf('ENUM number +%s under %s has been updated',$enumid['number'],$enumid['tld']))), + 'logs' => array('success' => sprintf('Record %s has been updated',$_REQUEST['id_filter']))), hunk ./library/ngnpro_client.php 7063 + hunk ./library/ngnpro_client.php 11969 + $this->SoapEngine->execute($function,$this->html); + } + } + } + + print ""; + } +} + +class DnsRecordsActions extends Actions { + var $actions=array( + 'delete' => 'Delete Dns records', + 'changettl' => 'Change TTL to:', + 'changeowner' => 'Change owner to:' + ); + + function DnsRecordsActions(&$SoapEngine) { + $this->Actions(&$SoapEngine); + } + + 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(); + print "
  1. "; + //printf ("Performing action=%s on key=%s",$action,$key['id']); + + if ($action=='delete') { + + $function=array('commit' => array('name' => 'deleteRecord', + 'parameters' => array($key['id']), + 'logs' => array('success' => sprintf('Dns record %s has been deleted',$key['id']) + ) + ) + + ); + + $this->SoapEngine->execute($function,$this->html); + } else if ($action == 'changettl') { + $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); + $record = $this->SoapEngine->soapclient->getRecord($key['id']); + + if (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); + + $function=array('commit' => array('name' => 'updateRecord', + 'parameters' => array($record), + 'logs' => array('success' => sprintf('TTL for Dns record %d has been set to %d',$key['id'],intval($sub_action_parameter)) + ) + ) + + ); + $this->SoapEngine->execute($function,$this->html); + } + } else if ($action == 'changeowner') { + $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); + $record = $this->SoapEngine->soapclient->getRecord($key['id']); + + if (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->owner=intval($sub_action_parameter); + } else { + printf ("Error: Owner '%s' must be numeric",$sub_action_parameter); + continue; + } + + $function=array('commit' => array('name' => 'updateRecord', + 'parameters' => array($record), + 'logs' => array('success' => sprintf('Owne for Dns record %d has been set to %d',$key['id'],intval($sub_action_parameter)) + ) + ) + ); +