| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- <?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 />";
- }
- }
- */
- }
|