seafile.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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. $clientInfo['basequota'] = $params['configoption1'] ? $params['configoption1'] : 1;
  185. $clientInfo['addonquota'] = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0;
  186. $clientInfo['userquota'] = $clientInfo['basequota'] + $clientInfo['addonquota'];
  187. $clientInfo['mailaddress'] = $params['username'];
  188. $clientInfo['webmailurl'] = $seafileURL;
  189. $clientInfo['zimbraserver'] = parse_url($clientInfo['webmailurl'], PHP_URL_HOST);
  190. $clientinfo['url'] = $seafileURL;
  191. $clientinfo['user'] = $user;
  192. $clientinfo['mobile1'] = $app;
  193. $clientinfo['mobile2'] = $google;
  194. $clientinfo['winclient'] = $winClient;
  195. $clientinfo['macclient'] = $macClient;
  196. $clientinfo['linClient'] = $linClient;
  197. $clientinfo['stitle'] = $params['model']['product']['name'];
  198. return array(
  199. 'tabOverviewReplacementTemplate' => 'clientarea',
  200. 'vars' => $clientInfo,
  201. );
  202. }
  203. /**
  204. * Change the password for a SeaFile account.
  205. *
  206. * Called when a password change is requested. This can occur either due to a
  207. * client requesting it via the client area or an admin requesting it from the
  208. * admin side.
  209. *
  210. * This option is only available to client end users when the product is in an
  211. * active status.
  212. *
  213. * @param array $params common module parameters
  214. *
  215. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  216. *
  217. * @return string 'success' or an error message
  218. */
  219. function seafile_ChangePassword($params) {
  220. $checkPassword = seafileCheckPassword($params['password']);
  221. if ($checkPassword != null) {
  222. return $checkPassword;
  223. }
  224. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  225. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  226. $response = $seafileAPI->login();
  227. if (isset($response['error_msg'])) {
  228. logModuleCall(
  229. 'seafile',
  230. __FUNCTION__,
  231. $params,
  232. 'Error: could not login to ' . $seafileURL,
  233. $response
  234. );
  235. return 'Error: could not login to ' . $seafileURL;
  236. }
  237. $userAccount = $seafileAPI->getAccount($params['username']);
  238. if(isset($userAccount['error_msg'])) {
  239. logModuleCall(
  240. 'seafile',
  241. __FUNCTION__,
  242. $params,
  243. 'Error: could not find account for: ' . $params['username'],
  244. $userAccount
  245. );
  246. return 'Error: could not find account for: ' . $params['username'];
  247. }
  248. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'password' => $params['password']));
  249. if(isset($result['error_msg'])) {
  250. logModuleCall(
  251. 'seafile',
  252. __FUNCTION__,
  253. $params,
  254. 'Error: could not change password for: ' . $params['username'],
  255. $result
  256. );
  257. return 'Error: could not change password for: ' . $params['username'];
  258. }
  259. return 'success';
  260. }
  261. /**
  262. * Set a new quota of a SeaFile account.
  263. *
  264. * Called to apply a quota change of the service. It
  265. * is called to provision upgrade or downgrade orders, as well as being
  266. * able to be invoked manually by an admin user.
  267. *
  268. * This same function is called for upgrades and downgrades of both
  269. * products and configurable options.
  270. *
  271. * @param array $params common module parameters
  272. *
  273. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  274. *
  275. * @return string 'success' or an error message
  276. */
  277. function seafile_ChangePackage($params) {
  278. $quota = $params['configoption1'] ? $params['configoption1'] : 1;
  279. $addonQuota = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0;
  280. $newAddQuota = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
  281. $accountQuota = ($quota + $addonQuota + $newAddQuota);
  282. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  283. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  284. $response = $seafileAPI->login();
  285. if (isset($response['error_msg'])) {
  286. logModuleCall(
  287. 'seafile',
  288. __FUNCTION__,
  289. $params,
  290. 'Error: could not login to ' . $seafileURL,
  291. $response
  292. );
  293. return 'Error: could not login to ' . $seafileURL;
  294. }
  295. $userAccount = $seafileAPI->getAccount($params['username']);
  296. if(isset($userAccount['error_msg'])) {
  297. logModuleCall(
  298. 'seafile',
  299. __FUNCTION__,
  300. $params,
  301. 'Error: could not find account ' . $params['username'],
  302. $userAccount
  303. );
  304. return 'Error: could not find account ' . $params['username'];
  305. }
  306. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'quota_total' => $accountQuota * 1024));
  307. if(isset($result['error_msg'])) {
  308. logModuleCall(
  309. 'seafile',
  310. __FUNCTION__,
  311. $params,
  312. 'Error: could not update quota for ' . $userAccount['email'],
  313. $result
  314. );
  315. return 'Error: could not update quota for ' . $userAccount['email'];
  316. } elseif ($result['quota_total'] != ($accountQuota * 1048576)) {
  317. logModuleCall(
  318. 'seafile',
  319. __FUNCTION__,
  320. $params,
  321. 'Error: quota for ' . $userAccount['email'] . ' not updated',
  322. $result
  323. );
  324. return 'Error: quota for ' . $userAccount['email'] . ' not updated';
  325. }
  326. try {
  327. Capsule::table('tblhosting')
  328. ->where('id', '=', $params['serviceid'])
  329. ->update(
  330. array(
  331. 'disklimit' => $userAccount['quota_total'] / 1024,
  332. )
  333. );
  334. } catch (Exception $e) {
  335. logModuleCall(
  336. 'seafile',
  337. __FUNCTION__,
  338. $params,
  339. 'Error: could not update quota in database',
  340. $e->getMessage()
  341. );
  342. return 'Error: could not update quota in database';
  343. }
  344. if(seafileUpdateQuota($params) != 'success') {
  345. return 'Error: could not update addonQuota in database';
  346. };
  347. return 'success';
  348. }
  349. /**
  350. * Provision a new instance of a SeaFile account.
  351. *
  352. * Attempt to provision a new SeaFile account. This is
  353. * called any time provisioning is requested inside of WHMCS. Depending upon the
  354. * configuration, this can be any of:
  355. * * When a new order is placed
  356. * * When an invoice for a new order is paid
  357. * * Upon manual request by an admin user
  358. *
  359. * @param array $params common module parameters
  360. *
  361. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  362. *
  363. * @return string 'success' or an error message
  364. */
  365. function seafile_CreateAccount($params) {
  366. $firstName = $params['customfields']['firstname'];
  367. $lastName = $params['customfields']['lastname'];
  368. $loginEMail = $params['customfields']['login'];
  369. $loginPassword = $params['customfields']['password'];
  370. $baseQuota = $params['configoption1'];
  371. $addonQuota = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0;
  372. $newAddQuota = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
  373. //error_log( print_r($params,true) );
  374. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  375. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  376. $response = $seafileAPI->login();
  377. if (isset($response['error_msg'])) {
  378. logModuleCall(
  379. 'seafile',
  380. __FUNCTION__,
  381. $params,
  382. 'Error: could not login to ' . $seafileURL,
  383. $response
  384. );
  385. return 'Error: could not login to ' . $seafileURL;
  386. }
  387. $existingAccount = $seafileAPI->getAccount($loginEMail);
  388. if(!isset($existingAccount['error_msg'])) {
  389. return 'Error: account already exists ' . $loginEMail;
  390. }
  391. $accountQuota = ($baseQuota + $addonQuota + $newAddQuota) * 1024;
  392. $newAccount = array();
  393. $newAccount['email'] = $loginEMail;
  394. $newAccount['name'] = $firstName . ' ' . $lastName;
  395. $newAccount['isActive'] = 1;
  396. $newAccount['isStaff'] = 0;
  397. $newAccount['password'] = $loginPassword;
  398. $newAccount['note'] = 'Account created from WHCMS for client ' . $params['userid'];
  399. $newAccount['quota_total'] = $accountQuota;
  400. error_log("Seafile:Create Account for " . $loginEMail . " with " . $accountQuota . "MB");
  401. $result = $seafileAPI->createAccount($newAccount);
  402. if(isset($result['error_msg'])) {
  403. logModuleCall(
  404. 'seafile',
  405. __FUNCTION__,
  406. $params,
  407. 'Error: could not create account ' . $loginEMail,
  408. $result
  409. );
  410. return 'Error: could not create account ' . $loginEMail;
  411. }
  412. try {
  413. Capsule::table('tblhosting')
  414. ->where('id', '=', $params['serviceid'])
  415. ->update(
  416. array(
  417. 'username' => $loginEMail,
  418. 'password' => $params['customfields']['password'],
  419. 'disklimit' => $accountQuota,
  420. 'diskusage' => 0,
  421. )
  422. );
  423. } catch (\Exception $e) {
  424. logModuleCall(
  425. 'seafile',
  426. __FUNCTION__,
  427. $params,
  428. 'Error: could save username & password in database',
  429. $e->getMessage()
  430. );
  431. return 'Error: could save username & password in database';
  432. }
  433. if(seafileUpdateQuota($params) != 'success') {
  434. return 'Error: could not update addonQuota in database';
  435. };
  436. return 'success';
  437. }
  438. /**
  439. * Set a SeaFile account to status inactive.
  440. *
  441. * Called when a suspension is requested. This is invoked automatically by WHMCS
  442. * when a product becomes overdue on payment or can be called manually by admin
  443. * user.
  444. *
  445. * @param array $params common module parameters
  446. *
  447. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  448. *
  449. * @return string 'success' or an error message
  450. */
  451. function seafile_SuspendAccount($params) {
  452. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  453. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  454. $response = $seafileAPI->login();
  455. if (isset($response['error_msg'])) {
  456. logModuleCall(
  457. 'seafile',
  458. __FUNCTION__,
  459. $params,
  460. 'Error: could not login to ' . $seafileURL,
  461. $response
  462. );
  463. return 'Error: could not login to ' . $seafileURL;
  464. }
  465. $userAccount = $seafileAPI->getAccount($params['username']);
  466. if(isset($userAccount['error_msg'])) {
  467. logModuleCall(
  468. 'seafile',
  469. __FUNCTION__,
  470. $params,
  471. 'Error: could not find account ' . $params['username'],
  472. $userAccount
  473. );
  474. return 'Error: could not find account ' . $params['username'];
  475. }
  476. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'is_active' => 0));
  477. if(isset($result['error_msg'])) {
  478. logModuleCall(
  479. 'seafile',
  480. __FUNCTION__,
  481. $params,
  482. 'Error: could not suspend ' . $params['username'],
  483. $result
  484. );
  485. return 'Error: could not suspend ' . $params['username'];
  486. } elseif ($result['update_status_tip'] != 'Edit succeeded') {
  487. logModuleCall(
  488. 'seafile',
  489. __FUNCTION__,
  490. $params,
  491. 'Error: ' . $params['username'] . ' not deactivated',
  492. $result
  493. );
  494. return 'Error: ' . $params['username'] . ' not deactivated';
  495. }
  496. return 'success';
  497. }
  498. /**
  499. * Set a SeaFile account to status active.
  500. *
  501. * Called when an un-suspension is requested. This is invoked
  502. * automatically upon payment of an overdue invoice for a product, or
  503. * can be called manually by admin user.
  504. *
  505. * @param array $params common module parameters
  506. *
  507. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  508. *
  509. * @return string 'success' or an error message
  510. */
  511. function seafile_UnsuspendAccount($params) {
  512. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  513. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  514. $response = $seafileAPI->login();
  515. if (isset($response['error_msg'])) {
  516. logModuleCall(
  517. 'seafile',
  518. __FUNCTION__,
  519. $params,
  520. 'Error: could not login to ' . $seafileURL,
  521. $response
  522. );
  523. return 'Error: could not login to ' . $seafileURL;
  524. }
  525. $userAccount = $seafileAPI->getAccount($params['username']);
  526. if(isset($userAccount['error_msg'])) {
  527. logModuleCall(
  528. 'seafile',
  529. __FUNCTION__,
  530. $params,
  531. 'Error: could not find account ' . $params['username'],
  532. $userAccount
  533. );
  534. return 'Error: could not find account ' . $params['username'];
  535. }
  536. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'is_active' => 1));
  537. if(isset($result['error_msg'])) {
  538. logModuleCall(
  539. 'seafile',
  540. __FUNCTION__,
  541. $params,
  542. 'Error: could not suspend ' . $params['username'],
  543. $result
  544. );
  545. return 'Error: could not suspend ' . $params['username'];
  546. } elseif ($result['update_status_tip'] != 'Edit succeeded') {
  547. logModuleCall(
  548. 'seafile',
  549. __FUNCTION__,
  550. $params,
  551. 'Error: ' . $params['username'] . ' not activated',
  552. $result
  553. );
  554. return 'Error: ' . $params['username'] . ' not activated';
  555. }
  556. return 'success';
  557. }
  558. /**
  559. * Removes a SeaFile account.
  560. *
  561. * Called when a termination is requested. This can be invoked automatically for
  562. * overdue products if enabled, or requested manually by an admin user.
  563. *
  564. * @param array $params common module parameters
  565. *
  566. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  567. *
  568. * @return string 'success' or an error message
  569. */
  570. function seafile_TerminateAccount($params) {
  571. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  572. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  573. $response = $seafileAPI->login();
  574. if (isset($response['error_msg'])) {
  575. logModuleCall(
  576. 'seafile',
  577. __FUNCTION__,
  578. $params,
  579. 'Error: could not login to ' . $seafileURL,
  580. $response
  581. );
  582. return 'Error: could not login to ' . $seafileURL;
  583. }
  584. $existingAccount = $seafileAPI->getAccount($params['username']);
  585. if(isset($existingAccount['error_msg'])) {
  586. logModuleCall(
  587. 'seafile',
  588. __FUNCTION__,
  589. $params,
  590. 'Error: could not find account ' . $params['username'],
  591. ''
  592. );
  593. return 'Error: could not find account ' . $params['username'];
  594. }
  595. //if ($existingAccount['is_active'] == 1) {
  596. // return 'Account '. $params['username'] . ' is active, suspend account first!';
  597. //}
  598. $result = $seafileAPI->deleteAccount($params['username']);
  599. if($result != true) {
  600. logModuleCall(
  601. 'seafile',
  602. __FUNCTION__,
  603. $params,
  604. 'Error: could not remove ' . $params['username'],
  605. $seafileAPI
  606. );
  607. return 'Error: could not remove ' . $params['username'];
  608. }
  609. return 'success';
  610. }
  611. /**
  612. * server side password check
  613. *
  614. * recheck the client side password check
  615. * in case that the client side check has been disabled
  616. *
  617. * @param string $pwd password
  618. *
  619. * @return string missing features or null if the password matches our needs
  620. */
  621. function seafileCheckPassword($pwd) {
  622. if (strlen($pwd) < 8) {
  623. return 'Das das Passwort ist zu kurz. Es werden mind. 8 Zeichen benötigt';
  624. }
  625. if (!preg_match('#[0-9]+#', $pwd)) {
  626. return 'Das Passwort muss mindestens eine Zahl enthalten';
  627. }
  628. if (!preg_match('#[A-Z]+#', $pwd)) {
  629. return 'Das Passwort muss mindestens einen Grossbuchstaben (A-Z) enthalten';
  630. }
  631. if (!preg_match('#[a-z]+#', $pwd)) {
  632. return 'Das Passwort muss mindestens einen Kleinbuchstaben (a-z) enthalten';
  633. }
  634. if (!preg_match('#[^\w]+#', $pwd)) {
  635. return 'Das Passwort muss mindestens ein Sonderzeichen (.,-:=) enthalten';
  636. }
  637. return null;
  638. }
  639. /**
  640. * Perform an update of customfields to prevent downgrades.
  641. *
  642. * Called in changePackage or createAccount functions.
  643. *
  644. * @param array $params common module parameters
  645. *
  646. * @return *success* or an error
  647. */
  648. function seafileUpdateQuota($params) {
  649. if(isset($params['configoptions']['addonQuota'])) {
  650. $addonQuota = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0 ;
  651. $newAddQuota = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
  652. $addonQuota = $addonQuota + $newAddQuota;
  653. $addonQuotaFieldIDObj = Capsule::table('tblproductconfigoptions')
  654. ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
  655. ->where('tblhostingconfigoptions.relid', '=', $params['serviceid'])
  656. ->where('tblproductconfigoptions.optionname', 'like', 'addonQuota%')
  657. ->select('tblhostingconfigoptions.id', 'tblproductconfigoptions.qtymaximum')
  658. ->get();
  659. if($addonQuota > $addonQuotaFieldIDObj[0]->qtymaximum) {
  660. logModuleCall(
  661. 'seafile',
  662. __FUNCTION__,
  663. $params,
  664. 'Info: someone is trying to exceed the maximum size',
  665. ''
  666. );
  667. $addonQuota = $addonQuotaFieldIDObj[0]->qtymaximum;
  668. }
  669. try {
  670. $updateAddonQuota = Capsule::table('tblhostingconfigoptions')
  671. ->where('id', $addonQuotaFieldIDObj[0]->id)
  672. ->update(
  673. [
  674. 'qty' => $addonQuota,
  675. ]
  676. );
  677. } catch (\Exception $e) {
  678. logModuleCall(
  679. 'seafile',
  680. __FUNCTION__,
  681. $updateAddonQuota,
  682. 'Error: could not save addonOuota in database.',
  683. $e->getMessage()
  684. );
  685. return 'Error: could not save addonOuota in database.';
  686. }
  687. $newAddQuotaFieldIDObj = Capsule::table('tblproductconfigoptions')
  688. ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
  689. ->where('tblhostingconfigoptions.relid', '=', $params['serviceid'])
  690. ->where('tblproductconfigoptions.optionname', 'like', 'newAddQuota%')
  691. ->select('tblhostingconfigoptions.id')
  692. ->get();
  693. try {
  694. $updateNewAddQuota = Capsule::table('tblhostingconfigoptions')
  695. ->where('id', $newAddQuotaFieldIDObj[0]->id)
  696. ->update(
  697. [
  698. 'qty' => '0',
  699. ]
  700. );
  701. } catch (\Exception $e) {
  702. logModuleCall(
  703. 'seafile',
  704. __FUNCTION__,
  705. $updateNewAddQuota,
  706. 'Error: could not reset newAddOuota in database.',
  707. $e->getMessage()
  708. );
  709. return 'Error: could not reset newAddOuota in database.';
  710. }
  711. }
  712. return 'success';
  713. }
  714. ?>