From a84340eb4d0c5d9308f8850cf450a23a20a85210 Mon Sep 17 00:00:00 2001 From: Liam <dovahkiin454@gmail.com> Date: Sat, 25 Jul 2015 02:09:06 -0500 Subject: [PATCH] General fixes to code, as requested --- contrib/cozaepp-cli | 75 ++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 45 deletions(-) diff --git a/contrib/cozaepp-cli b/contrib/cozaepp-cli index 5433a97..a0f5548 100755 --- a/contrib/cozaepp-cli +++ b/contrib/cozaepp-cli @@ -40,25 +40,9 @@ # Set the path below to the dbconnect.php file of your WHMCS installation. $dbconnpath = dirname(__FILE__) . '/../dbconnect.php'; -# Internals -$_help = <<<EOD -usage: {$argv[0]} [--help|-h] <command> [<args>] - -Available commands are: - changepassword Change ZACR account password. - -EOD; -$_setup = <<<EOD -This script requires you to specify the path to the dbconnect.php file in your WHMCS installation. - -Open the file and change the variable \$dbconnpath to suit your environment. - -{$_help} -EOD; - -// Validate dbconnpath -if (!file_exists($dbconnpath)) { - die($_setup); +// Function that displays help +function _displayHelp() { + echo "usage: {$argv[0]} [--help|-h] <command> [<args>]\n\nAvailable commands are:\n\n changepassword Change ZACR account password."; } // This file brings in a few constants we need @@ -70,16 +54,12 @@ set_include_path($include_path . PATH_SEPARATOR . get_include_path()); // Include EPP stuff we need require_once 'cozaepp.php'; -if (!function_exists('_cozaepp_Client')) { - die($_setup); -} - // Additional functions we need require_once ROOTDIR . '/includes/functions.php'; // Include registrar functions aswell require_once ROOTDIR . '/includes/registrarfunctions.php'; - +// Changes old password to given new password for the specified SLD function changePassword($sld, $current_password, $new_password) { // Grab module parameters @@ -89,29 +69,29 @@ function changePassword($sld, $current_password, $new_password) $client = _cozaepp_Client($sld); $result = $client->request(' - <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"> - <command> - <login> - <clID>'.$params['Username'].'</clID> - <pw>'.$current_password.'</pw> - <newPW>'.$new_password.'</newPW> - <options> - <version>1.0</version> - <lang>en</lang> - </options> - <svcs> - <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI> - <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI> - </svcs> - </login> - </command> - </epp>'); +<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"> + <command> + <login> + <clID>'.$params['Username'].'</clID> + <pw>'.$current_password.'</pw> + <newPW>'.$new_password.'</newPW> + <options> + <version>1.0</version> + <lang>en</lang> + </options> + <svcs> + <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI> + <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI> + </svcs> + </login> + </command> +</epp>'); $doc= new DOMDocument(); $doc->loadXML($result); $coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code'); $msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue; - if($coderes != '1000') { + if ($coderes != '1000') { $values["error"] = "ChangePassword($sld): Code ($coderes) $msg"; return $values; } @@ -138,10 +118,12 @@ switch ($_command) { $res = changePassword($argv['2'], $argv['3'], $argv['4']); break; case '-h': + exit(0); case '--help': - case 'help': + exit(0); default: - echo $_help; + exit(1); + _displayHelp(); break; } @@ -156,4 +138,7 @@ if (is_array($res)) { } else { echo "\033[1;31mError: Unexpected result from command call\033[1;0m\n\n"; var_dump($res); -} \ No newline at end of file +} + + + -- GitLab