seafile.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. <?php
  2. /**
  3. * WHMCS Seafile Provisioning Module
  4. *
  5. * Provisioning for User Account on the Seafile Server
  6. *
  7. * @see https://www.seafile.com
  8. * @copyright Copyright (c) Thurdata GmbH 2020
  9. * @license GPL
  10. */
  11. use WHMCS\Database\Capsule;
  12. require_once(__DIR__ . '/api/Sf/Admin.php');
  13. if (!defined('WHMCS')) {
  14. die('This file cannot be accessed directly'); }
  15. function seafile_MetaData() {
  16. return array(
  17. 'DisplayName' => 'Seafile Provisioning',
  18. 'APIVersion' => '1.2',
  19. 'DefaultNonSSLPort' => '8000',
  20. 'DefaultSSLPort' => '443',
  21. 'RequiresServer' => true,
  22. 'ServiceSingleSignOnLabel' => 'Login to Seafile',
  23. 'AdminSingleSignOnLabel' => 'Login to Seafile Admin',
  24. 'ListAccountsUniqueIdentifierDisplayName' => 'Domain',
  25. 'ListAccountsUniqueIdentifierField' => 'domain',
  26. 'ListAccountsProductField' => 'configoption1',
  27. );
  28. }
  29. /**
  30. * Define SeaFile product configuration options.
  31. *
  32. * @see https://developers.whmcs.com/provisioning-modules/config-options/
  33. *
  34. * @return array
  35. */
  36. function seafile_ConfigOptions() {
  37. $configarray = array(
  38. 'quota' => array(
  39. 'Type' => 'text',
  40. 'Description' => 'Basis User-Quota für dieses Produkt in GB',
  41. 'Default' => '10',
  42. 'Size' => '15',
  43. 'FriendlyName' => 'User Quota',
  44. ),
  45. );
  46. return $configarray;
  47. }
  48. /**
  49. * Test connection to a SeaFile server with the given server parameters.
  50. *
  51. * Allows an admin user to verify that an API connection can be
  52. * successfully made with the given configuration parameters for a
  53. * server.
  54. *
  55. * When defined in a module, a Test Connection button will appear
  56. * alongside the Server Type dropdown when adding or editing an
  57. * existing server.
  58. *
  59. * @param array $params common module parameters
  60. *
  61. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  62. *
  63. * @return array
  64. */
  65. function seafile_TestConnection($params) {
  66. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  67. error_log("Seafile:TestConnection: " . $seafileURL);
  68. //error_log(" -> " . $params['serverusername'] . " " . $params['serverpassword']);
  69. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  70. $response = $seafileAPI->login();
  71. if (isset($response['error_msg'])) {
  72. logModuleCall(
  73. 'seafile',
  74. __FUNCTION__,
  75. $params,
  76. 'Error: could not login to ' . $seafileURL,
  77. $response
  78. );
  79. return array(
  80. 'success' => false,
  81. 'error' => 'Error: could not login to ' . $seafileURL,
  82. );
  83. }
  84. return array(
  85. 'success' => true,
  86. 'error' => '',
  87. );
  88. }
  89. /**
  90. * Usage Update
  91. *
  92. * Important: Runs daily per server not per product
  93. * Run Manually: /admin/reports.php?report=disk_usage_summary&action=updatestats
  94. * @param array $params common module parameters
  95. *
  96. * @see https://developers.whmcs.com/provisioning-modules/usage-update/
  97. */
  98. function seafile_UsageUpdate($params) {
  99. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  100. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  101. $response = $seafileAPI->login();
  102. if (isset($response['error_msg'])) {
  103. logModuleCall(
  104. 'seafile',
  105. __FUNCTION__,
  106. $params,
  107. 'Error: could not login to ' . $seafileURL,
  108. $response
  109. );
  110. return 'Error: could not login to ' . $seafileURL;
  111. }
  112. $servicesObj = Capsule::table('tblhosting')
  113. ->select('*')
  114. ->where('server', '=', $params['serverid'])
  115. ->where('domainstatus', '=', 'Active')
  116. ->get();
  117. foreach((array)$servicesObj as $serviceObj) {
  118. $service = get_object_vars($serviceObj[0]);
  119. $accountInfo = $seafileAPI->getAccount($service['username']);
  120. error_log("Seafile Module: Updating Disk Usage for: " . $accountInfo . " : " . round($accountInfo['quota_usage'] / 1000000,2) . "/" . round($accountInfo['quota_total'] / 1000000,2));
  121. if(!isset($accountInfo['error_msg'])) {
  122. try {
  123. Capsule::table('tblhosting')
  124. ->where('id', '=', $service['id'])
  125. ->update(
  126. array(
  127. 'diskusage' => round($accountInfo['quota_usage'] / 1000000,2),
  128. 'disklimit' => round($accountInfo['quota_total'] / 1000000,2),
  129. 'lastupdate' => Capsule::raw('now()')
  130. )
  131. );
  132. } catch (Exception $e) {
  133. logModuleCall(
  134. 'seafile',
  135. __FUNCTION__,
  136. $params,
  137. 'Error: could update usage information for ' . $service['username'],
  138. $e->getMessage()
  139. );
  140. }
  141. }
  142. }
  143. }
  144. /**
  145. * Client area output logic handling.
  146. *
  147. * This function is used to define module specific client area output. It should
  148. * return an array consisting of a template file and optional additional
  149. * template variables to make available to that template.
  150. *
  151. * The template file you return can be one of two types:
  152. *
  153. * * tabOverviewModuleOutputTemplate - The output of the template provided here
  154. * will be displayed as part of the default product/service client area
  155. * product overview page.
  156. *
  157. * * tabOverviewReplacementTemplate - Alternatively using this option allows you
  158. * to entirely take control of the product/service overview page within the
  159. * client area.
  160. *
  161. * Whichever option you choose, extra template variables are defined in the same
  162. * way. This demonstrates the use of the full replacement.
  163. *
  164. * Please Note: Using tabOverviewReplacementTemplate means you should display
  165. * the standard information such as pricing and billing details in your custom
  166. * template or they will not be visible to the end user.
  167. *
  168. * @param array $params common module parameters
  169. *
  170. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  171. *
  172. * @return array
  173. */
  174. function seafile_ClientArea($params) {
  175. switch ($params['serverport']) {
  176. case '80':
  177. case '443':
  178. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'];
  179. break;
  180. default:
  181. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  182. break;
  183. };
  184. $app = 'https://itunes.apple.com/cn/app/seafile-pro/id639202512?l=en&mt=8';
  185. $google = 'https://play.google.com/store/apps/details?id=com.seafile.seadroid2';
  186. $driveWin = 'https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seadrive-2.0.5-en.msi';
  187. $winClient = 'https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-7.0.9-en.msi';
  188. $macClient = 'https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-client-7.0.9.dmg';
  189. $driveMac = 'https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seadrive-2.0.5.dmg';
  190. $linClient = 'https://download.seafile.com/published/seafile-user-manual/syncing_client/install_linux_client.md';
  191. $clientInfo['basequota'] = $params['configoption1'] ? $params['configoption1'] : 1;
  192. $clientInfo['addonquota'] = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0;
  193. $clientInfo['userquota'] = $clientInfo['basequota'] + $clientInfo['addonquota'];
  194. $clientInfo['mailaddress'] = $params['username'];
  195. $clientinfo['stitle'] = $params['model']['product']['name'];
  196. $langObj = Capsule::table('tblconfiguration')
  197. ->select('value')
  198. ->where('setting', '=', 'Language')
  199. ->get();
  200. $lla = $_SESSION['Language'] ? trim($_SESSION['Language']) : strtolower($langObj[0]->value);
  201. $slang = array();
  202. include_once dirname(__FILE__).'/lang/'.$lla.'.php';
  203. return array(
  204. 'tabOverviewReplacementTemplate' => 'clientarea',
  205. 'vars' => array_merge(
  206. array(
  207. 'url' => $seafileURL,
  208. 'mobile1' => $app,
  209. 'mobile2' => $google,
  210. 'drivewin' => $driveWin,
  211. 'winclient' => $winClient,
  212. 'macclient' => $macClient,
  213. 'drivemac' => $driveMac,
  214. 'linClient' => $linClient,
  215. ),
  216. $slang,
  217. $clientInfo
  218. ),
  219. );
  220. }
  221. /**
  222. * Change the password for a SeaFile account.
  223. *
  224. * Called when a password change is requested. This can occur either due to a
  225. * client requesting it via the client area or an admin requesting it from the
  226. * admin side.
  227. *
  228. * This option is only available to client end users when the product is in an
  229. * active status.
  230. *
  231. * @param array $params common module parameters
  232. *
  233. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  234. *
  235. * @return string 'success' or an error message
  236. */
  237. function seafile_ChangePassword($params) {
  238. $checkPassword = seafileCheckPassword($params['password']);
  239. if ($checkPassword != null) {
  240. return $checkPassword;
  241. }
  242. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  243. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  244. $response = $seafileAPI->login();
  245. if (isset($response['error_msg'])) {
  246. logModuleCall(
  247. 'seafile',
  248. __FUNCTION__,
  249. $params,
  250. 'Error: could not login to ' . $seafileURL,
  251. $response
  252. );
  253. return 'Error: could not login to ' . $seafileURL;
  254. }
  255. $userAccount = $seafileAPI->getAccount($params['username']);
  256. if(isset($userAccount['error_msg'])) {
  257. logModuleCall(
  258. 'seafile',
  259. __FUNCTION__,
  260. $params,
  261. 'Error: could not find account for: ' . $params['username'],
  262. $userAccount
  263. );
  264. return 'Error: could not find account for: ' . $params['username'];
  265. }
  266. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'password' => $params['password']));
  267. if(isset($result['error_msg'])) {
  268. logModuleCall(
  269. 'seafile',
  270. __FUNCTION__,
  271. $params,
  272. 'Error: could not change password for: ' . $params['username'],
  273. $result
  274. );
  275. return 'Error: could not change password for: ' . $params['username'];
  276. }
  277. return 'success';
  278. }
  279. /**
  280. * Set a new quota of a SeaFile account.
  281. *
  282. * Called to apply a quota change of the service. It
  283. * is called to provision upgrade or downgrade orders, as well as being
  284. * able to be invoked manually by an admin user.
  285. *
  286. * This same function is called for upgrades and downgrades of both
  287. * products and configurable options.
  288. *
  289. * @param array $params common module parameters
  290. *
  291. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  292. *
  293. * @return string 'success' or an error message
  294. */
  295. function seafile_ChangePackage($params) {
  296. $quota = $params['configoption1'] ? $params['configoption1'] : 1;
  297. $addonQuota = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0;
  298. $newAddQuota = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
  299. $accountQuota = ($quota + $addonQuota + $newAddQuota);
  300. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  301. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  302. $response = $seafileAPI->login();
  303. if (isset($response['error_msg'])) {
  304. logModuleCall(
  305. 'seafile',
  306. __FUNCTION__,
  307. $params,
  308. 'Error: could not login to ' . $seafileURL,
  309. $response
  310. );
  311. return 'Error: could not login to ' . $seafileURL;
  312. }
  313. $userAccount = $seafileAPI->getAccount($params['username']);
  314. if(isset($userAccount['error_msg'])) {
  315. logModuleCall(
  316. 'seafile',
  317. __FUNCTION__,
  318. $params,
  319. 'Error: could not find account ' . $params['username'],
  320. $userAccount
  321. );
  322. return 'Error: could not find account ' . $params['username'];
  323. }
  324. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'quota_total' => $accountQuota * 1024));
  325. if(isset($result['error_msg'])) {
  326. logModuleCall(
  327. 'seafile',
  328. __FUNCTION__,
  329. $params,
  330. 'Error: could not update quota for ' . $userAccount['email'],
  331. $result
  332. );
  333. return 'Error: could not update quota for ' . $userAccount['email'];
  334. } elseif ($result['quota_total'] != ($accountQuota * 1048576)) {
  335. logModuleCall(
  336. 'seafile',
  337. __FUNCTION__,
  338. $params,
  339. 'Error: quota for ' . $userAccount['email'] . ' not updated',
  340. $result
  341. );
  342. return 'Error: quota for ' . $userAccount['email'] . ' not updated';
  343. }
  344. try {
  345. Capsule::table('tblhosting')
  346. ->where('id', '=', $params['serviceid'])
  347. ->update(
  348. array(
  349. 'disklimit' => $userAccount['quota_total'] / 1024,
  350. )
  351. );
  352. } catch (Exception $e) {
  353. logModuleCall(
  354. 'seafile',
  355. __FUNCTION__,
  356. $params,
  357. 'Error: could not update quota in database',
  358. $e->getMessage()
  359. );
  360. return 'Error: could not update quota in database';
  361. }
  362. if(seafileUpdateQuota($params) != 'success') {
  363. return 'Error: could not update addonQuota in database';
  364. };
  365. return 'success';
  366. }
  367. /**
  368. * Provision a new instance of a SeaFile account.
  369. *
  370. * Attempt to provision a new SeaFile account. This is
  371. * called any time provisioning is requested inside of WHMCS. Depending upon the
  372. * configuration, this can be any of:
  373. * * When a new order is placed
  374. * * When an invoice for a new order is paid
  375. * * Upon manual request by an admin user
  376. *
  377. * @param array $params common module parameters
  378. *
  379. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  380. *
  381. * @return string 'success' or an error message
  382. */
  383. function seafile_CreateAccount($params) {
  384. $firstName = $params['customfields']['firstname'];
  385. $lastName = $params['customfields']['lastname'];
  386. $loginEMail = $params['customfields']['login'];
  387. $loginPassword = $params['customfields']['password'];
  388. $baseQuota = $params['configoption1'];
  389. $addonQuota = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0;
  390. $newAddQuota = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
  391. //error_log( print_r($params,true) );
  392. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  393. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  394. $response = $seafileAPI->login();
  395. if (isset($response['error_msg'])) {
  396. logModuleCall(
  397. 'seafile',
  398. __FUNCTION__,
  399. $params,
  400. 'Error: could not login to ' . $seafileURL,
  401. $response
  402. );
  403. return 'Error: could not login to ' . $seafileURL;
  404. }
  405. $existingAccount = $seafileAPI->getAccount($loginEMail);
  406. if(!isset($existingAccount['error_msg'])) {
  407. return 'Error: account already exists ' . $loginEMail;
  408. }
  409. $accountQuota = ($baseQuota + $addonQuota + $newAddQuota) * 1024;
  410. $newAccount = array();
  411. $newAccount['email'] = $loginEMail;
  412. $newAccount['name'] = $firstName . ' ' . $lastName;
  413. $newAccount['isActive'] = 1;
  414. $newAccount['isStaff'] = 0;
  415. $newAccount['password'] = $loginPassword;
  416. $newAccount['note'] = 'Account created from WHCMS for client ' . $params['userid'];
  417. $newAccount['quota_total'] = $accountQuota;
  418. error_log("Seafile:Create Account for " . $loginEMail . " with " . $accountQuota . "MB");
  419. $result = $seafileAPI->createAccount($newAccount);
  420. if(isset($result['error_msg'])) {
  421. logModuleCall(
  422. 'seafile',
  423. __FUNCTION__,
  424. $params,
  425. 'Error: could not create account ' . $loginEMail,
  426. $result
  427. );
  428. return 'Error: could not create account ' . $loginEMail;
  429. }
  430. try {
  431. Capsule::table('tblhosting')
  432. ->where('id', '=', $params['serviceid'])
  433. ->update(
  434. array(
  435. 'username' => $loginEMail,
  436. 'password' => $params['customfields']['password'],
  437. 'disklimit' => $accountQuota,
  438. 'diskusage' => 0,
  439. 'domain' => $loginEMail,
  440. )
  441. );
  442. } catch (\Exception $e) {
  443. logModuleCall(
  444. 'seafile',
  445. __FUNCTION__,
  446. $params,
  447. 'Error: could save username & password in database',
  448. $e->getMessage()
  449. );
  450. return 'Error: could save username & password in database';
  451. }
  452. if(seafileUpdateQuota($params) != 'success') {
  453. return 'Error: could not update addonQuota in database';
  454. };
  455. return 'success';
  456. }
  457. /**
  458. * Set a SeaFile account to status inactive.
  459. *
  460. * Called when a suspension is requested. This is invoked automatically by WHMCS
  461. * when a product becomes overdue on payment or can be called manually by admin
  462. * user.
  463. *
  464. * @param array $params common module parameters
  465. *
  466. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  467. *
  468. * @return string 'success' or an error message
  469. */
  470. function seafile_SuspendAccount($params) {
  471. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  472. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  473. $response = $seafileAPI->login();
  474. if (isset($response['error_msg'])) {
  475. logModuleCall(
  476. 'seafile',
  477. __FUNCTION__,
  478. $params,
  479. 'Error: could not login to ' . $seafileURL,
  480. $response
  481. );
  482. return 'Error: could not login to ' . $seafileURL;
  483. }
  484. $userAccount = $seafileAPI->getAccount($params['username']);
  485. if(isset($userAccount['error_msg'])) {
  486. logModuleCall(
  487. 'seafile',
  488. __FUNCTION__,
  489. $params,
  490. 'Error: could not find account ' . $params['username'],
  491. $userAccount
  492. );
  493. return 'Error: could not find account ' . $params['username'];
  494. }
  495. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'is_active' => 0));
  496. if(isset($result['error_msg'])) {
  497. logModuleCall(
  498. 'seafile',
  499. __FUNCTION__,
  500. $params,
  501. 'Error: could not suspend ' . $params['username'],
  502. $result
  503. );
  504. return 'Error: could not suspend ' . $params['username'];
  505. } elseif ($result['update_status_tip'] != 'Edit succeeded') {
  506. logModuleCall(
  507. 'seafile',
  508. __FUNCTION__,
  509. $params,
  510. 'Error: ' . $params['username'] . ' not deactivated',
  511. $result
  512. );
  513. return 'Error: ' . $params['username'] . ' not deactivated';
  514. }
  515. return 'success';
  516. }
  517. /**
  518. * Set a SeaFile account to status active.
  519. *
  520. * Called when an un-suspension is requested. This is invoked
  521. * automatically upon payment of an overdue invoice for a product, or
  522. * can be called manually by admin user.
  523. *
  524. * @param array $params common module parameters
  525. *
  526. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  527. *
  528. * @return string 'success' or an error message
  529. */
  530. function seafile_UnsuspendAccount($params) {
  531. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  532. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  533. $response = $seafileAPI->login();
  534. if (isset($response['error_msg'])) {
  535. logModuleCall(
  536. 'seafile',
  537. __FUNCTION__,
  538. $params,
  539. 'Error: could not login to ' . $seafileURL,
  540. $response
  541. );
  542. return 'Error: could not login to ' . $seafileURL;
  543. }
  544. $userAccount = $seafileAPI->getAccount($params['username']);
  545. if(isset($userAccount['error_msg'])) {
  546. logModuleCall(
  547. 'seafile',
  548. __FUNCTION__,
  549. $params,
  550. 'Error: could not find account ' . $params['username'],
  551. $userAccount
  552. );
  553. return 'Error: could not find account ' . $params['username'];
  554. }
  555. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'is_active' => 1));
  556. if(isset($result['error_msg'])) {
  557. logModuleCall(
  558. 'seafile',
  559. __FUNCTION__,
  560. $params,
  561. 'Error: could not suspend ' . $params['username'],
  562. $result
  563. );
  564. return 'Error: could not suspend ' . $params['username'];
  565. } elseif ($result['update_status_tip'] != 'Edit succeeded') {
  566. logModuleCall(
  567. 'seafile',
  568. __FUNCTION__,
  569. $params,
  570. 'Error: ' . $params['username'] . ' not activated',
  571. $result
  572. );
  573. return 'Error: ' . $params['username'] . ' not activated';
  574. }
  575. return 'success';
  576. }
  577. /**
  578. * Removes a SeaFile account.
  579. *
  580. * Called when a termination is requested. This can be invoked automatically for
  581. * overdue products if enabled, or requested manually by an admin user.
  582. *
  583. * @param array $params common module parameters
  584. *
  585. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  586. *
  587. * @return string 'success' or an error message
  588. */
  589. function seafile_TerminateAccount($params) {
  590. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  591. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  592. $response = $seafileAPI->login();
  593. if (isset($response['error_msg'])) {
  594. logModuleCall(
  595. 'seafile',
  596. __FUNCTION__,
  597. $params,
  598. 'Error: could not login to ' . $seafileURL,
  599. $response
  600. );
  601. return 'Error: could not login to ' . $seafileURL;
  602. }
  603. $existingAccount = $seafileAPI->getAccount($params['username']);
  604. if(isset($existingAccount['error_msg'])) {
  605. logModuleCall(
  606. 'seafile',
  607. __FUNCTION__,
  608. $params,
  609. 'Error: could not find account ' . $params['username'],
  610. ''
  611. );
  612. return 'Error: could not find account ' . $params['username'];
  613. }
  614. //if ($existingAccount['is_active'] == 1) {
  615. // return 'Account '. $params['username'] . ' is active, suspend account first!';
  616. //}
  617. $result = $seafileAPI->deleteAccount($params['username']);
  618. if($result != true) {
  619. logModuleCall(
  620. 'seafile',
  621. __FUNCTION__,
  622. $params,
  623. 'Error: could not remove ' . $params['username'],
  624. $seafileAPI
  625. );
  626. return 'Error: could not remove ' . $params['username'];
  627. }
  628. return 'success';
  629. }
  630. /**
  631. * server side password check
  632. *
  633. * recheck the client side password check
  634. * in case that the client side check has been disabled
  635. *
  636. * @param string $pwd password
  637. *
  638. * @return string missing features or null if the password matches our needs
  639. */
  640. function seafileCheckPassword($pwd) {
  641. if (strlen($pwd) < 8) {
  642. return 'Das das Passwort ist zu kurz. Es werden mind. 8 Zeichen benötigt';
  643. }
  644. if (!preg_match('#[0-9]+#', $pwd)) {
  645. return 'Das Passwort muss mindestens eine Zahl enthalten';
  646. }
  647. if (!preg_match('#[A-Z]+#', $pwd)) {
  648. return 'Das Passwort muss mindestens einen Grossbuchstaben (A-Z) enthalten';
  649. }
  650. if (!preg_match('#[a-z]+#', $pwd)) {
  651. return 'Das Passwort muss mindestens einen Kleinbuchstaben (a-z) enthalten';
  652. }
  653. if (!preg_match('#[^\w]+#', $pwd)) {
  654. return 'Das Passwort muss mindestens ein Sonderzeichen (.,-:=) enthalten';
  655. }
  656. return null;
  657. }
  658. /**
  659. * Perform an update of customfields to prevent downgrades.
  660. *
  661. * Called in changePackage or createAccount functions.
  662. *
  663. * @param array $params common module parameters
  664. *
  665. * @return *success* or an error
  666. */
  667. function seafileUpdateQuota($params) {
  668. if(isset($params['configoptions']['addonQuota'])) {
  669. $addonQuota = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0 ;
  670. $newAddQuota = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
  671. $addonQuota = $addonQuota + $newAddQuota;
  672. $addonQuotaFieldIDObj = Capsule::table('tblproductconfigoptions')
  673. ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
  674. ->where('tblhostingconfigoptions.relid', '=', $params['serviceid'])
  675. ->where('tblproductconfigoptions.optionname', 'like', 'addonQuota%')
  676. ->select('tblhostingconfigoptions.id', 'tblproductconfigoptions.qtymaximum')
  677. ->get();
  678. if($addonQuota > $addonQuotaFieldIDObj[0]->qtymaximum) {
  679. logModuleCall(
  680. 'seafile',
  681. __FUNCTION__,
  682. $params,
  683. 'Info: someone is trying to exceed the maximum size',
  684. ''
  685. );
  686. $addonQuota = $addonQuotaFieldIDObj[0]->qtymaximum;
  687. }
  688. try {
  689. $updateAddonQuota = Capsule::table('tblhostingconfigoptions')
  690. ->where('id', $addonQuotaFieldIDObj[0]->id)
  691. ->update(
  692. [
  693. 'qty' => $addonQuota,
  694. ]
  695. );
  696. } catch (\Exception $e) {
  697. logModuleCall(
  698. 'seafile',
  699. __FUNCTION__,
  700. $updateAddonQuota,
  701. 'Error: could not save addonOuota in database.',
  702. $e->getMessage()
  703. );
  704. return 'Error: could not save addonOuota in database.';
  705. }
  706. $newAddQuotaFieldIDObj = Capsule::table('tblproductconfigoptions')
  707. ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
  708. ->where('tblhostingconfigoptions.relid', '=', $params['serviceid'])
  709. ->where('tblproductconfigoptions.optionname', 'like', 'newAddQuota%')
  710. ->select('tblhostingconfigoptions.id')
  711. ->get();
  712. try {
  713. $updateNewAddQuota = Capsule::table('tblhostingconfigoptions')
  714. ->where('id', $newAddQuotaFieldIDObj[0]->id)
  715. ->update(
  716. [
  717. 'qty' => '0',
  718. ]
  719. );
  720. } catch (\Exception $e) {
  721. logModuleCall(
  722. 'seafile',
  723. __FUNCTION__,
  724. $updateNewAddQuota,
  725. 'Error: could not reset newAddOuota in database.',
  726. $e->getMessage()
  727. );
  728. return 'Error: could not reset newAddOuota in database.';
  729. }
  730. }
  731. return 'success';
  732. }
  733. ?>