andre 5 лет назад
Родитель
Сommit
1c8b7c2e7a
2 измененных файлов с 60 добавлено и 8 удалено
  1. 52 0
      zimbraAddressAvailable.php
  2. 8 8
      zimbraAddressCheck.php

+ 52 - 0
zimbraAddressAvailable.php

@@ -0,0 +1,52 @@
+<?php
+$allowed_host = 'admin.seecure.ch';
+$host = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
+if(substr($host, 0 - strlen($allowed_host)) != $allowed_host) {
+  die("This file cannot be accessed directly");
+}
+
+use WHMCS\Database\Capsule;
+define("CLIENTAREA", true);
+require_once(__DIR__ . '/../../../init.php');
+require_once(ROOTDIR . '/includes/dbfunctions.php');
+require_once dirname(__FILE__) . '/zimbraSingle.inc';
+
+$whmcs = App::self();
+$productID = $_GET['pid'];
+$accessData = array('zimbraServer' => '', 'adminUser' => '', 'adminPass' => '');
+$serverIDObj = Capsule::table('tblhosting')
+	->select('server')
+	->where('id', '=', $productID)
+	->get();
+$serverID = $serverIDObj[0]->server;
+$server = Capsule::table('tblservers')
+	->select('ipaddress', 'username', 'password')
+	->where('id', '=', $serverID)
+	->where('active', '=', 1)
+	->get();
+$accessData['zimbraServer'] = $server[0]->ipaddress;
+$accessData['adminUser'] = $server[0]->username;
+$adminPassCrypt = $server[0]->password;
+$adminPassDecrypt = localAPI('DecryptPassword', array('password2' => $adminPassCrypt));
+if ($adminPassDecrypt['result'] == 'success') {
+	$accessData['adminPass'] = $adminPassDecrypt['password'];
+}
+$api = new Zm_Auth($accessData['zimbraServer'], $accessData['adminUser'], $accessData['adminPass'], "admin");
+$login = $api->login();
+if(is_a($login, "Exception")) {
+	logModuleCall(
+		'zimbrasingle',
+		__FUNCTION__,
+		$params,
+		"Error : cannot login to " . $accessData['zimbraServer'],
+		"$login->getMessage()"
+	);
+	exit();
+} else {
+	$apiAccountManager = new Zm_Account($api);
+		if( $apiAccountManager->accountExists($account_name)) {
+		echo 'no';
+	} else {
+		echo 'yes';
+	}
+}

+ 8 - 8
zimbraAddressCheck.php

@@ -1,18 +1,18 @@
 <?php
 $allowed_host = 'admin.seecure.ch';
 $host = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
+
 if(substr($host, 0 - strlen($allowed_host)) != $allowed_host) {
   die("This file cannot be accessed directly");
 }
+require_once("api/Zm/Auth.php");
+require_once("api/Zm/Account.php");
 
-define("CLIENTAREA", true);
-require_once(__DIR__ . '/../../../init.php');
-require_once(ROOTDIR . '/includes/dbfunctions.php');
-require_once dirname(__FILE__) . '/zimbraSingle.inc';
-
-$whmcs = App::self();
-$whmcs->set_req_var('id', $_GET['pid']);
-if(zimbraSingleDoesEMailExist($_GET['name'], $_GET['domain'])) {
+$account_name = $_GET['name'] . "@" .  $_GET['domain'];
+$api = new Zm_Auth('192.168.16.225', 'admin@thurdata.local', 'Technics2312', "admin");
+$login = $api->login();
+$apiAccountManager = new Zm_Account($api);
+if( $apiAccountManager->accountExists($account_name)) {
 	echo 'no';
 } else {
 	echo 'yes';