diff --git a/modules/addons/awit_cozaepp/awit_cozaepp.php b/modules/addons/awit_cozaepp/awit_cozaepp.php new file mode 100644 index 0000000000000000000000000000000000000000..bf848e66738d5820ca9febea957139e105abdf40 --- /dev/null +++ b/modules/addons/awit_cozaepp/awit_cozaepp.php @@ -0,0 +1,297 @@ +<?php +/** + * AWIT COZAEPP - COZA EPP Module + * Copyright (c) 2014, AllWorldIT + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +// Make sure we not being accssed directly +if (!defined("WHMCS")) + die("This file cannot be accessed directly"); + +// Our global supported field list +$AWIT_COZAEPP_SUPPORTED_FIELDS = array( + "max_items" +); + +// Addon configuration +function awit_cozaepp_config() +{ + + // Configuration + $configarray = array( + "name" => "AWIT COZAEPP", + "description" => "This module is to facilitate displaying of epp messages.", + "version" => "0.1", + "author" => "AllWorldIT", + "language" => "english", + "fields" => array( + // Admin User + "max_items" => array ( + "FriendlyName" => "Items Per Page", + "Description" => "Amount of items to list per page", + "Type" => "text", "Size" => "30", + "Default" => "100" + ), + ) + ); + + return $configarray; +} + + + +function awit_cozaepp_get_config_custom_fields() +{ + global $AWIT_COZAEPP_SUPPORTED_FIELDS; + + // Query modules table + $table = "tbladdonmodules"; + $fields = "setting,value"; + $where = array( 'module' => 'awit_cozaepp' ); + $result = select_query($table,$fields,$where); + + // Filter out the settings we need + $custom_fields = array(); + while ($row = mysql_fetch_array($result)) { + // Check in our global list + if (in_array($row['setting'],$AWIT_COZAEPP_SUPPORTED_FIELDS)) { + $custom_fields[$row['setting']] = $row['value']; + } + } + + return $custom_fields; +} + + + +function _awit_cozaepp_getMaxItems() +{ + $customFields = awit_cozaepp_get_config_custom_fields(); + return $customFields['max_items']; +} + + + +// Addon activation +function awit_cozaepp_activate() +{ + + // Create Custom DB Table + $result = mysql_query(" + CREATE TABLE `mod_awit_cozaepp_messages` ( + `id` INT( 1 ) NOT NULL AUTO_INCREMENT PRIMARY KEY, + `created` DATETIME NOT NULL, + `code` VARCHAR(10) NOT NULL, + `message` TEXT NOT NULL + ) + "); + + // Return Result + if (!$result) { + return array("status" => "error", "description"=>"There was a problem activating the module."); + } else { + return array("status" => "success","description" =>"Open module configuration for configuration options."); + } + +} + + + +function awit_cozaepp_deactivate() +{ + // Remove custom tables + $result1 = mysql_query(" + DROP TABLE `mod_awit_cozaepp_messages` + "); + + if (!$result) { + return array("status"=>"error","description"=>"There was an error deactivating the module."); + } else { + return array("status"=>"success","description"=>"Module has been deactivated."); + } + +} + + + +// Addon output +function awit_cozaepp_output($vars) +{ + // Check if we have to display all records + if (isset($_POST['button']) && $_POST['button'] == 'Display All') { + $whereClause = ''; + + } else if (!empty($_POST['date_to']) && !empty($_POST['date_from'])) { + + // Default dates + try { + $dateTo = new DateTime($_POST['date_to']); + $dateTo = $dateTo->format('Y-m-d'); + + $dateFrom = new DateTime($_POST['date_from']); + $dateFrom = $dateFrom->format('Y-m-d'); + } catch (Exception $ex) { + // Catching exception against valid date + + $dateFrom = new DateTime(date("Y-m-d")); + $dateFrom = $dateFrom->format('Y-m-d'); + + $dateFrom->modify('+1 day'); + $dateTo = $dateTo->format('Y-m-d'); + } + + $whereClause = "WHERE Date(created) >= Date('".mysql_real_escape_string($dateFrom)."') + AND Date(created) <= Date('".mysql_real_escape_string($dateTo)."')"; + } + + // Make link to use + $link = $vars['modulelink']; + + // Fancy date picker + echo ' + <script> + $(function() { + $( "#date_from" ).datepicker({ + dateFormat: "yy-mm-dd", + constrainInput: true + }); + $( "#date_to" ).datepicker({ + dateFormat: "yy-mm-dd", + constrainInput: true + }); + }); + </script> + '; + + // Date search fields + echo "<p>Select a start and end date and hit search.</p>"; + echo "<form action='$link' method='post'>"; + echo "<input id='date_from' type='text' value='$dateFrom' name='date_from' />"; + echo "<input id='date_to' type='text' value='$dateTo' name='date_to' />"; + echo "<input type='submit' name='button' value='Search' />"; + echo "<input type='submit' name='button' value='Display All' />"; + echo "<br /><br />"; + + $orderClause = 'ORDER BY created DESC'; + + // Max amount of records to show per page + $recordMax = _awit_cozaepp_getMaxItems(); + + // Validation + if (!is_numeric($recordMax)) { + $recordMax = 100; + } + + // Setting page number + if (isset($_GET['page'])) { + $page = $_GET['page']; + } else if (isset($_POST['page'])) { + $page = $_POST['page']; + } + + // Ensuring valid page number + if ($page < 1) { + $page = 1; + } + // Pagination button handler + if (isset($_POST['prevPage'])) { + // Prev Page + $page = ($page > 1)? ($page - 1) : 1; + + } else if (isset($_POST['nextPage'])) { + // Next Page + $page = $page + 1; + } + + $recordCurrent = intval(abs($recordMax * $page)) - $recordMax; + + $limitClause = "LIMIT $recordCurrent, $recordMax"; + + // Query the database, getting the total amount of records + $result = mysql_query(sprintf(" + SELECT + COUNT(*) AS cnt + FROM + mod_awit_cozaepp_messages + %s %s + ", + $whereClause, + $orderClause + )); + + $row = mysql_fetch_array($result); + $totalRecords = $row['cnt']; + $lastPage = ceil($totalRecords / $recordMax); + + // Query the database + $result = mysql_query(sprintf(" + SELECT + * + FROM + mod_awit_cozaepp_messages + %s %s %s + ", + $whereClause, + $orderClause, + $limitClause + )); + + // Loop through results and genenrate form + $includeForm = 0; + while ($row = mysql_fetch_array($result)) { + // Open form + if (!$includeForm) { + $includeForm = 1; + + echo '<div class="tablebg">'; + echo '<table id="epp-message-log" class="datatable" width="100%" border="0" cellspacing="1" cellpadding="3">'; + echo "<tr>"; + echo "<th>Timestamp</th>"; + echo "<th>Code</th>"; + echo "<th>Message</th>"; + echo "</tr>"; + } + + echo "<tr>"; + echo "<td>".$row['created']."</td>"; + echo "<td>".$row['code']."</td>"; + echo "<td>".$row['message']."</td>"; + echo "</tr>"; + } + + // Close form + if ($includeForm) { + echo "<tr><td colspan='5'>"; + if ($page >= $lastPage) { + echo "<button name='prevPage'> << Previous Page </button> Page $page"; + } else if ($page == 1) { + echo " Page $page <button name='nextPage'> Next Page >> </button>"; + } else { + echo "<button name='prevPage'> << Previous Page </button> Page $page"; + echo "<button name='nextPage'> Next Page >> </button>"; + } + + echo "</td></tr>"; + echo "</table><br>"; + echo "<input type='hidden' name='page' value='$page'>"; + echo "</form>"; + echo "</div>"; + } else { + echo "<p>No logs yet for selected period..</p>"; + } + +} diff --git a/modules/addons/awit_cozaepp/lang/english.php b/modules/addons/awit_cozaepp/lang/english.php new file mode 100644 index 0000000000000000000000000000000000000000..2723a4abb5282d174bda1d8e7cd63eb05bf31046 --- /dev/null +++ b/modules/addons/awit_cozaepp/lang/english.php @@ -0,0 +1,7 @@ +<?php + +$_ADDONLANG['intro'] = "AWIT COZAEPP Module"; +$_ADDONLANG['description'] = "This module is to facilitate displaying of epp messages."; +$_ADDONLANG['documentation'] = "Pending.."; + +?> diff --git a/modules/registrars/cozaepp/cozaepp.php b/modules/registrars/cozaepp/cozaepp.php index 56cdbf2c14aa7eee5a5e4d8df3a6b3a77fad4311..867d160aa305a33887a4a1fcbee11d5816bb07f1 100644 --- a/modules/registrars/cozaepp/cozaepp.php +++ b/modules/registrars/cozaepp/cozaepp.php @@ -51,13 +51,13 @@ function cozaepp_getConfigArray() { } function cozaepp_AdminCustomButtonArray() { - $buttonarray = array( - "Approve Transfer" => "ApproveTransfer", - "Cancel Transfer Request" => "CancelTransferRequest", - "Reject Transfer" => "RejectTransfer", - "Recreate Contact" => "RecreateContact", - ); - return $buttonarray; + $buttonarray = array( + "Approve Transfer" => "ApproveTransfer", + "Cancel Transfer Request" => "CancelTransferRequest", + "Reject Transfer" => "RejectTransfer", + "Recreate Contact" => "RecreateContact", + ); + return $buttonarray; } # Function to return current nameservers @@ -866,7 +866,7 @@ function cozaepp_SaveContactDetails($params) { # Registrant details $registrant_name = $params["contactdetails"]["Registrant"]["Contact Name"]; $registrant_org = $params["contactdetails"]["Registrant"]["Organisation"]; - $registrant_address1 = $params["contactdetails"]["Registrant"]["Address line 1"]; + $registrant_address1 = $params["contactdetails"]["Registrant"]["Address line 1"]; $registrant_address2 = $params["contactdetails"]["Registrant"]["Address line 2"]; $registrant_town = $params["contactdetails"]["Registrant"]["TownCity"]; $registrant_state = $params["contactdetails"]["Registrant"]["State"]; @@ -1065,21 +1065,21 @@ function cozaepp_ModifyNameserver($params) { # Modify nameserver $request = $client->request($xml = ' <epp:epp xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> - <epp:command> - <epp:update> - <domain:update> - <domain:name>'.$sld.'.'.$tld.'</domain:name> - <domain:add> - <domain:ns> - <domain:hostAttr> - <domain:hostName>'.$nameserver.'</domain:hostName> - <domain:hostAddr ip="v4">'.$newipaddress.'</domain:hostAddr> - </domain:hostAttr> - </domain:ns> - </domain:add> - </domain:update> - </epp:update> - </epp:command> + <epp:command> + <epp:update> + <domain:update> + <domain:name>'.$sld.'.'.$tld.'</domain:name> + <domain:add> + <domain:ns> + <domain:hostAttr> + <domain:hostName>'.$nameserver.'</domain:hostName> + <domain:hostAddr ip="v4">'.$newipaddress.'</domain:hostAddr> + </domain:hostAttr> + </domain:ns> + </domain:add> + </domain:update> + </epp:update> + </epp:command> </epp:epp> '); # Parse XML result @@ -1122,26 +1122,26 @@ function cozaepp_DeleteNameserver($params) { try { $client = _cozaepp_Client(); - # If we were given hostname. blow away all of the stuff behind it and allow us to remove hostname + # If we were given hostname. blow away all of the stuff behind it and allow us to remove hostname $nameserver = preg_replace('/\.\.\S+/','',$nameserver); # Delete nameserver $request = $client->request($xml = ' <epp:epp xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> - <epp:command> - <epp:update> - <domain:update> - <domain:name>'.$sld.'.'.$tld.'</domain:name> - <domain:rem> - <domain:ns> - <domain:hostAttr> - <domain:hostName>'.$nameserver.'</domain:hostName> - </domain:hostAttr> - </domain:ns> - </domain:rem> - </domain:update> - </epp:update> - </epp:command> + <epp:command> + <epp:update> + <domain:update> + <domain:name>'.$sld.'.'.$tld.'</domain:name> + <domain:rem> + <domain:ns> + <domain:hostAttr> + <domain:hostName>'.$nameserver.'</domain:hostName> + </domain:hostAttr> + </domain:ns> + </domain:rem> + </domain:update> + </epp:update> + </epp:command> </epp:epp> '); # Parse XML result @@ -1366,31 +1366,31 @@ function cozaepp_RecreateContact($params) { $request = $client->request($xml = ' <epp:epp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:contact="urn:ietf:params:xml:ns:contact-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd"> - <epp:command> - <epp:create> - <contact:create xsi:schemaLocation="urn:ietf:params:xml:ns:contact-1.0 contact-1.0.xsd"> - <contact:id>'.$registrant.'</contact:id> - <contact:postalInfo type="loc"> - <contact:name>'.$contact["Registrant"]["Contact Name"].'</contact:name> - <contact:org>'.$contact["Registrant"]["Organisation"].'</contact:org> - <contact:addr> - <contact:street>'.$contact["Registrant"]["Address line 1"].'</contact:street> - <contact:street>'.$contact["Registrant"]["Address line 2"].'</contact:street> - <contact:city>'.$contact["Registrant"]["TownCity"].'</contact:city> - <contact:sp>'.$contact["Registrant"]["State"].'</contact:sp> - <contact:pc>'.$contact["Registrant"]["Zip code"].'</contact:pc> - <contact:cc>'.$contact["Registrant"]["Country Code"].'</contact:cc> - </contact:addr> - </contact:postalInfo> - <contact:voice>'.$contact["Registrant"]["Phone"].'</contact:voice> - <contact:fax></contact:fax> - <contact:email>'.$contact["Registrant"]["Email"].'</contact:email> - <contact:authInfo> - <contact:pw>AxA8AjXbAH'.rand().rand().'</contact:pw> - </contact:authInfo> - </contact:create> - </epp:create> - </epp:command> + <epp:command> + <epp:create> + <contact:create xsi:schemaLocation="urn:ietf:params:xml:ns:contact-1.0 contact-1.0.xsd"> + <contact:id>'.$registrant.'</contact:id> + <contact:postalInfo type="loc"> + <contact:name>'.$contact["Registrant"]["Contact Name"].'</contact:name> + <contact:org>'.$contact["Registrant"]["Organisation"].'</contact:org> + <contact:addr> + <contact:street>'.$contact["Registrant"]["Address line 1"].'</contact:street> + <contact:street>'.$contact["Registrant"]["Address line 2"].'</contact:street> + <contact:city>'.$contact["Registrant"]["TownCity"].'</contact:city> + <contact:sp>'.$contact["Registrant"]["State"].'</contact:sp> + <contact:pc>'.$contact["Registrant"]["Zip code"].'</contact:pc> + <contact:cc>'.$contact["Registrant"]["Country Code"].'</contact:cc> + </contact:addr> + </contact:postalInfo> + <contact:voice>'.$contact["Registrant"]["Phone"].'</contact:voice> + <contact:fax></contact:fax> + <contact:email>'.$contact["Registrant"]["Email"].'</contact:email> + <contact:authInfo> + <contact:pw>AxA8AjXbAH'.rand().rand().'</contact:pw> + </contact:authInfo> + </contact:create> + </epp:create> + </epp:command> </epp:epp> '); @@ -1494,8 +1494,8 @@ function cozaepp_Sync($params) { } else if ($coderes == '1000') { # Code 1000, success if ( - $doc->getElementsByTagName('infData') && - $doc->getElementsByTagName('infData')->item(0)->getElementsByTagName('ns')->item(0) && + $doc->getElementsByTagName('infData') && + $doc->getElementsByTagName('infData')->item(0)->getElementsByTagName('ns')->item(0) && $doc->getElementsByTagName('infData')->item(0)->getElementsByTagName('clID') ) { $owningRegistrar = $doc->getElementsByTagName('infData')->item(0)->getElementsByTagName('clID')->item(0)->nodeValue; @@ -1602,13 +1602,13 @@ function cozaepp_ApproveTransfer($params) { # Grab domain info $request = $client->request($xml = ' <epp:epp xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> - <epp:command> - <epp:transfer op="approve"> - <domain:transfer> - <domain:name>'.$sld.'.'.$tld.'</domain:name> - </domain:transfer> - </epp:transfer> - </epp:command> + <epp:command> + <epp:transfer op="approve"> + <domain:transfer> + <domain:name>'.$sld.'.'.$tld.'</domain:name> + </domain:transfer> + </epp:transfer> + </epp:command> </epp:epp> '); @@ -1728,4 +1728,3 @@ function cozaepp_RejectTransfer($params) { return $values; } -?> diff --git a/modules/registrars/cozaepp/cozaepppoll.php b/modules/registrars/cozaepp/cozaepppoll.php index a55d03b0d0a0d2d371905396d29d7704c8b9af48..498b5aeb29e1e4e0154cdb828bb43c16d085f1ba 100644 --- a/modules/registrars/cozaepp/cozaepppoll.php +++ b/modules/registrars/cozaepp/cozaepppoll.php @@ -84,6 +84,34 @@ try { $msgs = $doc->getElementsByTagName('msg'); for ($m = 0; $m < $msgs->length; $m++) { echo "CODE: $coderes, MESSAGE: '".$msgs->item($m)->textContent."'\n"; + + // Messages to ignore + $ignored = array( + 'Command completed successfully; ack to dequeue', + 'Command completed successfully; no messages' + ); + + // Logging message + if (!in_array(trim($msgs->item($m)->textContent), $ignored)) { + $message = mysql_real_escape_string(trim($msgs->item($m)->textContent)); + $result = mysql_query(" + INSERT INTO mod_awit_cozaepp_messages + ( + created, + code, + message + ) + VALUES + ( + now(), + '$coderes', + '$message' + ) + "); + if (mysql_error($result)) { + echo "ERROR: couldn't log epp message: " . mysql_error($result); + } + } } # This is the last one @@ -119,8 +147,3 @@ try { exit; } - - - - -?>