From eb2192701bde12cac1a66f6fa9ce81623ebd0ecd Mon Sep 17 00:00:00 2001
From: Scott Barr <scott@barr.co.za>
Date: Wed, 1 Oct 2014 14:49:22 +0200
Subject: [PATCH] The module requires that the account password is the same
 across all SLD servers.

Added a command line script that allows the user to specify the current
account password for a server and change it to something else by sending
the EPP registry a newPW command on login.

Example usage: ./zacr-cli changepassword org.za <currentpass> <newpass>

Signed-off-by: Scott Barr <scott@barr.co.za>
---
 contrib/zacr-cli | 159 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 159 insertions(+)
 create mode 100755 contrib/zacr-cli

diff --git a/contrib/zacr-cli b/contrib/zacr-cli
new file mode 100755
index 0000000..ba15e0a
--- /dev/null
+++ b/contrib/zacr-cli
@@ -0,0 +1,159 @@
+#!/usr/bin/env php
+<?php
+# Copyright (c) 2012-2013, 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/>.
+
+
+# Official Website:
+# http://devlabs.linuxassist.net/projects/whmcs-coza-epp
+
+# Lead developer:
+# Nigel Kukard <nkukard@lbsd.net>
+
+
+# ! ! P L E A S E   N O T E  ! !
+
+# * If you make changes to this file, please consider contributing
+#   anything useful back to the community. Don't be a sour prick.
+
+# * If you find this module useful please consider making a
+#   donation to support modules like this.
+
+
+# WHMCS hosting, theming, module development, payment gateway
+# integration, customizations and consulting all available from
+# http://allworldit.com
+
+# ! ! CONFIGURATION REQUIRED ! !
+# 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);
+}
+
+// This file brings in a few constants we need
+require_once $dbconnpath;
+
+// Setup include dir
+$include_path = ROOTDIR . '/modules/registrars/zacr';
+set_include_path($include_path . PATH_SEPARATOR . get_include_path());
+// Include EPP stuff we need
+require_once 'zacr.php';
+
+if (!function_exists('_zacr_Client')) {
+	die($_setup);
+}
+
+// Additional functions we need
+require_once ROOTDIR . '/includes/functions.php';
+// Include registrar functions aswell
+require_once ROOTDIR . '/includes/registrarfunctions.php';
+
+
+function changePassword($sld, $current_password, $new_password)
+{
+	// Grab module parameters
+	$params = getregistrarconfigoptions('zacr');
+
+	try {
+		$client = _zacr_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>');
+
+		$doc= new DOMDocument();
+		$doc->loadXML($result);
+		$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
+		$msg = $doc->getElementsByTagName('msg')->item(0)->nodeValue;
+		if($coderes != '1000') {
+			$values["error"] = "ChangePassword($sld): Code ($coderes) $msg";
+			return $values;
+		}
+
+		$values['status'] = $msg;
+
+	} catch (Exception $e) {
+		$values["error"] = 'changePassword/EPP: '.$e->getMessage();
+		return $values;
+	}
+
+	return $values;
+}
+
+$_command = strtolower($argv[1]);
+switch ($_command) {
+	case 'changepassword':
+		if (empty($argv['2']) || empty($argv['3']) || empty($argv['4'])) {
+			echo "\033[1;31mError: changepassword expects 3 arguments.\033[1;0m\n\n";
+			echo "{$argv[0]} changepassword <sld> <current password> <new password>\n\n";
+			exit(1);
+		}
+
+		$res = changePassword($argv['2'], $argv['3'], $argv['4']);
+		break;
+	case '-h':
+	case '--help':
+	case 'help':
+	default:
+		echo $_help;
+		break;
+}
+
+if (is_array($res)) {
+	if (array_key_exists('error', $res)) {
+		echo $res['error'];
+		exit(2);
+	} elseif (array_key_exists('status', $res)) {
+		echo $res['status'];
+		exit(0);
+	}
+} 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