|
|
@@ -0,0 +1,338 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+/**
|
|
|
+ * WHMCS Zimbra Provisioning Module
|
|
|
+ *
|
|
|
+ * Provisioning for private user accounts on the Zimbra Server
|
|
|
+ *
|
|
|
+ * @see https://www.zimbra.com
|
|
|
+ * @copyright Copyright (c) Thurdata GmbH 2020
|
|
|
+ * @license GPL
|
|
|
+ */
|
|
|
+
|
|
|
+if (!defined("WHMCS")) {
|
|
|
+ die("This file cannot be accessed directly");
|
|
|
+}
|
|
|
+require_once dirname(__FILE__) . '/zimbraSingle.inc';
|
|
|
+
|
|
|
+function zimbraSingle_TestConnection($params)
|
|
|
+{
|
|
|
+ $auth = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
|
|
|
+ $login = $auth->login();
|
|
|
+ if(is_a($login, "Exception")) {
|
|
|
+ logModuleCall(
|
|
|
+ 'zimbrasingle',
|
|
|
+ __FUNCTION__,
|
|
|
+ $params,
|
|
|
+ "Connection test to " . $params['serverip'] . " failed: Cannot login",
|
|
|
+ $login->getMessage()
|
|
|
+ );
|
|
|
+ return array(
|
|
|
+ 'success' => false,
|
|
|
+ 'error' => "Connection test to " . $params['serverip'] . " failed, the error was: " . $login->getMessage(),
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return array(
|
|
|
+ 'success' => true,
|
|
|
+ 'error' => '',
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function zimbraSingle_UsageUpdate($params)
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function zimbraSingle_ClientArea($params)
|
|
|
+{
|
|
|
+
|
|
|
+ // error_log(print_r($params,true));
|
|
|
+ # error_log("CLIENT-AREA");
|
|
|
+ # $zimbraSingleURL = buildzimbraSingleURL($params);
|
|
|
+ # $user = $params['username'];
|
|
|
+
|
|
|
+ # $result0 = select_query("tblconfiguration","value" , array('setting' => 'Language'));
|
|
|
+ # $data0 = mysql_fetch_array($result0);
|
|
|
+ # $lla = ($_SESSION['Language']) ? trim($_SESSION['Language']) : strtolower($data0[0]);
|
|
|
+
|
|
|
+ # $slang = array();
|
|
|
+ # include_once dirname(__FILE__).'/lang/'.$lla.'.php';
|
|
|
+
|
|
|
+ # return array(
|
|
|
+ # 'templatefile' => 'clientside',
|
|
|
+ # 'vars' => array_merge(array(
|
|
|
+ # 'url' => $seafileURL,
|
|
|
+ # 'user' => $user,
|
|
|
+ # 'mobile1' => $app,
|
|
|
+ # 'mobile2' => $google,
|
|
|
+ # 'drivewin' => $driveWin,
|
|
|
+ # 'winclient' => $winClient,
|
|
|
+ # 'macclient' => $macClient,
|
|
|
+ # 'drivemac' => $driveMac,
|
|
|
+ # 'linClient' => $linClient,
|
|
|
+ # ), $slang, $params),
|
|
|
+ # );
|
|
|
+}
|
|
|
+
|
|
|
+function zimbraSingle_ClientAreaCustomButtonArray()
|
|
|
+{
|
|
|
+ $buttonarray = array(
|
|
|
+ "Reset Password" => "ClientPassword",
|
|
|
+ );
|
|
|
+ return $buttonarray;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function zimbraSingle_ChangePassword($params)
|
|
|
+{
|
|
|
+ # if (strcmp($params['status'],"Active") !== 0) {
|
|
|
+ # return "Der Dienst ist gesperrt, das Passwort kann daher nicht geändert werden";
|
|
|
+ # }
|
|
|
+ # $loginPassword = $params["customfields"]["Passwort"];
|
|
|
+ # $checkPassword = checkPassword($loginPassword);
|
|
|
+ # if ($checkPassword != null) {
|
|
|
+ # return $checkPassword;
|
|
|
+ # }
|
|
|
+ # $fieldID = getCustomFieldIDFor($params,"Passwort");
|
|
|
+ #
|
|
|
+ # $seafileURL = buildSeafileURL($params);
|
|
|
+ # $apiuser = getSeafileAdminUser($params);
|
|
|
+ # $apipass = getSeafileAdminPassword($params);
|
|
|
+ #
|
|
|
+ # $seafileAPI = new SeafileAPI($seafileURL,$apiuser,$apipass);
|
|
|
+ # if ($seafileAPI->login() != true) {
|
|
|
+ # logModuleCall(
|
|
|
+ # 'seafile',
|
|
|
+ # __FUNCTION__,
|
|
|
+ # $params,
|
|
|
+ # "Cannot login to " . $seafileURL,
|
|
|
+ # ""
|
|
|
+ # );
|
|
|
+ # return "Login to " . $seafileURL . " fehlgeschlagen. Bitte den Administrator informieren.\n";
|
|
|
+ # }
|
|
|
+ #
|
|
|
+ # $userAccount = $seafileAPI->getAccountByEMail($params['username']);
|
|
|
+ # if ($userAccount != null) {
|
|
|
+ # $userAccount->password = $loginPassword;
|
|
|
+ # try {
|
|
|
+ # $result = $seafileAPI->updateAccount($userAccount);
|
|
|
+ # if ($result != true) {
|
|
|
+ # logModuleCall(
|
|
|
+ # 'seafile',
|
|
|
+ # __FUNCTION__,
|
|
|
+ # $params,
|
|
|
+ # "Cannot change password for " . $userAccount->email . ": Unknown error",
|
|
|
+ # ""
|
|
|
+ # );
|
|
|
+ # return "Das Passwort konnte nicht aktualisiert werden. Unbekannter Fehler.";
|
|
|
+ # } else {
|
|
|
+ # update_query( "tblcustomfieldsvalues",array( "value" => $loginPassword,"updated_at"=> "now()", ),array("id" => $fieldID) );
|
|
|
+ # logModuleCall(
|
|
|
+ # 'seafile',
|
|
|
+ # __FUNCTION__,
|
|
|
+ # $params,
|
|
|
+ # "Changed password for " . $userAccount->email,
|
|
|
+ # ""
|
|
|
+ # );
|
|
|
+ # return 'success';
|
|
|
+ # }
|
|
|
+ # } catch (Exception $exe) {
|
|
|
+ # logModuleCall(
|
|
|
+ # 'seafile',
|
|
|
+ # __FUNCTION__,
|
|
|
+ # $params,
|
|
|
+ # "Cannot change password for " . $userAccount->email . ", the error was " . $exe->getMessage(),
|
|
|
+ # $exe->getTraceAsString()
|
|
|
+ # );
|
|
|
+ # return "Fehler beim Update des Passworts, der Fehler war: " . $exe->getMessage();
|
|
|
+ # }
|
|
|
+ # } else {
|
|
|
+ # logModuleCall(
|
|
|
+ # 'seafile',
|
|
|
+ # __FUNCTION__,
|
|
|
+ # $params,
|
|
|
+ # "Changed password for " . $userAccount->email,
|
|
|
+ # ""
|
|
|
+ # );
|
|
|
+ # return "Konnte den Account " . $params['username'] . " auf dem Server nicht finden";
|
|
|
+ # }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function zimbraSingle_ClientPassword($params)
|
|
|
+{
|
|
|
+ /* if (strcmp($params['status'],"Active") !== 0) {
|
|
|
+ return "Der Dienst ist gesperrt, das Passwort kann daher nicht geändert werden";
|
|
|
+ }
|
|
|
+ $password1 = $_POST['password1'];
|
|
|
+ $password2 = $_POST['password2'];
|
|
|
+
|
|
|
+ if (empty($password1) == true || empty($password2) == true) {
|
|
|
+ return "Bitte beide Passwörter zuerst ausfüllen";
|
|
|
+ }
|
|
|
+ if (strcmp($password1,$password2) !== 0) {
|
|
|
+ return "Die Passwörter stimmen nicht überein";
|
|
|
+ }
|
|
|
+
|
|
|
+ $checkPassword = checkPassword($password1);
|
|
|
+ if ($checkPassword != null) {
|
|
|
+ return $checkPassword;
|
|
|
+ }
|
|
|
+ $fieldID = getCustomFieldIDFor($params,"Passwort");
|
|
|
+
|
|
|
+ $seafileURL = buildSeafileURL($params);
|
|
|
+ $apiuser = getSeafileAdminUser($params);
|
|
|
+ $apipass = getSeafileAdminPassword($params);
|
|
|
+
|
|
|
+ $seafileAPI = new SeafileAPI($seafileURL,$apiuser,$apipass);
|
|
|
+ if ($seafileAPI->login() != true) {
|
|
|
+ logModuleCall(
|
|
|
+ 'seafile',
|
|
|
+ __FUNCTION__,
|
|
|
+ $params,
|
|
|
+ "Cannot login to " . $seafileURL,
|
|
|
+ ""
|
|
|
+ );
|
|
|
+ return "Login to " . $seafileURL . " fehlgeschlagen. Bitte den Administrator informieren.\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ $userAccount = $seafileAPI->getAccountByEMail($params['username']);
|
|
|
+ if ($userAccount != null) {
|
|
|
+ $userAccount->password = $password1;
|
|
|
+ try {
|
|
|
+ $result = $seafileAPI->updateAccount($userAccount);
|
|
|
+ if ($result != true) {
|
|
|
+ return "Das Passwort konnte nicht aktualisiert werden. Unbekannter Fehler.";
|
|
|
+ } else {
|
|
|
+ update_query( "tblcustomfieldsvalues",array( "value" => $password1,"updated_at"=> "now()", ),array("id" => $fieldID) );
|
|
|
+ return 'success';
|
|
|
+ }
|
|
|
+ } catch (Exception $exe) {
|
|
|
+ logModuleCall(
|
|
|
+ 'seafile',
|
|
|
+ __FUNCTION__,
|
|
|
+ $params,
|
|
|
+ "Cannot change password for " . $userAccount->email . ", the error was " . $exe->getMessage(),
|
|
|
+ $exe->getTraceAsString()
|
|
|
+ );
|
|
|
+ return "Fehler beim Update des Passworts, der Fehler war: " . $exe->getMessage();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ logModuleCall(
|
|
|
+ 'seafile',
|
|
|
+ __FUNCTION__,
|
|
|
+ $params,
|
|
|
+ "Cannot find the Account " . $params['username'],
|
|
|
+ ""
|
|
|
+ );
|
|
|
+ return "Konnte den Account " . $params['username'] . " nicht finden";
|
|
|
+ } */
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function zimbraSingle_CreateAccount($params)
|
|
|
+{
|
|
|
+ $response = zimbraSingleCreateAccount($params['customfields']);
|
|
|
+ if($response) {
|
|
|
+ return 'success';
|
|
|
+ }
|
|
|
+ return 'Error creating account';
|
|
|
+}
|
|
|
+
|
|
|
+function zimbraSingle_SuspendAccount($params)
|
|
|
+{
|
|
|
+ $response = zimbraSingleSuspendAccount($params['customfields']);
|
|
|
+ if($response) {
|
|
|
+ return 'success';
|
|
|
+ }
|
|
|
+ return 'Error suspending account';
|
|
|
+}
|
|
|
+
|
|
|
+function zimbraSingle_UnsuspendAccount($params)
|
|
|
+{
|
|
|
+ $response = zimbraSingleUnsuspendAccount($params['customfields']);
|
|
|
+ if($response) {
|
|
|
+ return 'success';
|
|
|
+ }
|
|
|
+ return 'Error unsuspending account';
|
|
|
+}
|
|
|
+
|
|
|
+function zimbraSingle_TerminateAccount($params)
|
|
|
+{
|
|
|
+ return zimbraSingleDeleteAccount($params['customfields']);
|
|
|
+}
|
|
|
+
|
|
|
+function zimbraSingle_genUsername($name)
|
|
|
+{
|
|
|
+ /* $namelen = strlen($name);
|
|
|
+ $result = select_query("tblhosting","COUNT(*)",array("username" => $name));
|
|
|
+ $data = mysql_fetch_array($result);
|
|
|
+ $username_exists = $data[0];
|
|
|
+ $suffix=0;
|
|
|
+
|
|
|
+ while ($username_exists > 0) {
|
|
|
+ $suffix++;
|
|
|
+ $name = substr($name,0,$namelen).$suffix;
|
|
|
+
|
|
|
+ $result = select_query( "tblhosting", "COUNT(*)", array( "username" => $name ) );
|
|
|
+ $data = mysql_fetch_array($result);
|
|
|
+
|
|
|
+ $username_exists = $data[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $name; */
|
|
|
+}
|
|
|
+
|
|
|
+function zimbraSingle_getCustomFieldIDFor($params, $fieldName)
|
|
|
+{
|
|
|
+ $Client = Client::find($params['userid']);
|
|
|
+ $clientFields = $Client->customFieldValues;
|
|
|
+
|
|
|
+ foreach ($Client->services as $service) {
|
|
|
+ //print "ServiceID: " . $service->id . " ?= " . $params['serviceid'] . " <br />";
|
|
|
+ // print nl2br(print_r($service,true));
|
|
|
+ if ($service->packageid == $params['packageid']) {
|
|
|
+ //print " => PackageID found <br />";
|
|
|
+ $serviceFields = $service->customFieldValues;
|
|
|
+ //print nl2br(print_r($serviceFields,true));
|
|
|
+ foreach ($serviceFields as $field) {
|
|
|
+ //print " ===> " . $field->customField->fieldName . " : " . $field->id . "</br />";
|
|
|
+ //print " Field: " . $field->customField->fieldName . " ?= Search Field Name: " . $fieldName . " ? " . strcmp($field->customField->fieldName,$fieldName) . " : " . $field->id . " : " . $field->fieldid . "<br />";
|
|
|
+ if (strcmp($field->customField->fieldName, $fieldName) == 0) {
|
|
|
+ return $field->id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ **** TESTING METHODS ****
|
|
|
+ Please do not remove this lines
|
|
|
+
|
|
|
+ // run through customfields
|
|
|
+ foreach($clientFields AS $field){
|
|
|
+ $HTML .= "Field ".$field->customField->fieldName.": ".$field->value."<br>";
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+
|
|
|
+ $HTML .= "Service custom fields";
|
|
|
+ foreach($Client->services as $service) {
|
|
|
+ $HTML .= "----------------------------------------------------------<br />";
|
|
|
+ $HTML .= nl2br(print_r($service,true));
|
|
|
+ $HTML .= "----------------------------------------------------------<br />";
|
|
|
+ $ServiceFields = $service->customFieldValues;
|
|
|
+ foreach($ServiceFields as $field) {
|
|
|
+ //$HTML .= "Service field ".$field->customField->fieldName . ": ".$field->value."<br>";
|
|
|
+ //$HTML .= "----------------------------------------------------------<br />";
|
|
|
+ //$HTML .= nl2br(print_r($field,true));
|
|
|
+ //$HTML .= "Service field ".$field->customField->fieldName . "( FieldID: " . $field->fieldid . "/ ID: " . $field->id . "/ RelID:" . $field->relid . ") : " . $field->value . "<br>";
|
|
|
+ //$HTML .= "----------------------------------------------------------<br />";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+}
|
|
|
+
|