seafile.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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. 'domain' => $loginEMail,
  422. )
  423. );
  424. } catch (\Exception $e) {
  425. logModuleCall(
  426. 'seafile',
  427. __FUNCTION__,
  428. $params,
  429. 'Error: could save username & password in database',
  430. $e->getMessage()
  431. );
  432. return 'Error: could save username & password in database';
  433. }
  434. if(seafileUpdateQuota($params) != 'success') {
  435. return 'Error: could not update addonQuota in database';
  436. };
  437. return 'success';
  438. }
  439. /**
  440. * Set a SeaFile account to status inactive.
  441. *
  442. * Called when a suspension is requested. This is invoked automatically by WHMCS
  443. * when a product becomes overdue on payment or can be called manually by admin
  444. * user.
  445. *
  446. * @param array $params common module parameters
  447. *
  448. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  449. *
  450. * @return string 'success' or an error message
  451. */
  452. function seafile_SuspendAccount($params) {
  453. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  454. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  455. $response = $seafileAPI->login();
  456. if (isset($response['error_msg'])) {
  457. logModuleCall(
  458. 'seafile',
  459. __FUNCTION__,
  460. $params,
  461. 'Error: could not login to ' . $seafileURL,
  462. $response
  463. );
  464. return 'Error: could not login to ' . $seafileURL;
  465. }
  466. $userAccount = $seafileAPI->getAccount($params['username']);
  467. if(isset($userAccount['error_msg'])) {
  468. logModuleCall(
  469. 'seafile',
  470. __FUNCTION__,
  471. $params,
  472. 'Error: could not find account ' . $params['username'],
  473. $userAccount
  474. );
  475. return 'Error: could not find account ' . $params['username'];
  476. }
  477. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'is_active' => 0));
  478. if(isset($result['error_msg'])) {
  479. logModuleCall(
  480. 'seafile',
  481. __FUNCTION__,
  482. $params,
  483. 'Error: could not suspend ' . $params['username'],
  484. $result
  485. );
  486. return 'Error: could not suspend ' . $params['username'];
  487. } elseif ($result['update_status_tip'] != 'Edit succeeded') {
  488. logModuleCall(
  489. 'seafile',
  490. __FUNCTION__,
  491. $params,
  492. 'Error: ' . $params['username'] . ' not deactivated',
  493. $result
  494. );
  495. return 'Error: ' . $params['username'] . ' not deactivated';
  496. }
  497. return 'success';
  498. }
  499. /**
  500. * Set a SeaFile account to status active.
  501. *
  502. * Called when an un-suspension is requested. This is invoked
  503. * automatically upon payment of an overdue invoice for a product, or
  504. * can be called manually by admin user.
  505. *
  506. * @param array $params common module parameters
  507. *
  508. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  509. *
  510. * @return string 'success' or an error message
  511. */
  512. function seafile_UnsuspendAccount($params) {
  513. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  514. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  515. $response = $seafileAPI->login();
  516. if (isset($response['error_msg'])) {
  517. logModuleCall(
  518. 'seafile',
  519. __FUNCTION__,
  520. $params,
  521. 'Error: could not login to ' . $seafileURL,
  522. $response
  523. );
  524. return 'Error: could not login to ' . $seafileURL;
  525. }
  526. $userAccount = $seafileAPI->getAccount($params['username']);
  527. if(isset($userAccount['error_msg'])) {
  528. logModuleCall(
  529. 'seafile',
  530. __FUNCTION__,
  531. $params,
  532. 'Error: could not find account ' . $params['username'],
  533. $userAccount
  534. );
  535. return 'Error: could not find account ' . $params['username'];
  536. }
  537. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'is_active' => 1));
  538. if(isset($result['error_msg'])) {
  539. logModuleCall(
  540. 'seafile',
  541. __FUNCTION__,
  542. $params,
  543. 'Error: could not suspend ' . $params['username'],
  544. $result
  545. );
  546. return 'Error: could not suspend ' . $params['username'];
  547. } elseif ($result['update_status_tip'] != 'Edit succeeded') {
  548. logModuleCall(
  549. 'seafile',
  550. __FUNCTION__,
  551. $params,
  552. 'Error: ' . $params['username'] . ' not activated',
  553. $result
  554. );
  555. return 'Error: ' . $params['username'] . ' not activated';
  556. }
  557. return 'success';
  558. }
  559. /**
  560. * Removes a SeaFile account.
  561. *
  562. * Called when a termination is requested. This can be invoked automatically for
  563. * overdue products if enabled, or requested manually by an admin user.
  564. *
  565. * @param array $params common module parameters
  566. *
  567. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  568. *
  569. * @return string 'success' or an error message
  570. */
  571. function seafile_TerminateAccount($params) {
  572. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  573. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  574. $response = $seafileAPI->login();
  575. if (isset($response['error_msg'])) {
  576. logModuleCall(
  577. 'seafile',
  578. __FUNCTION__,
  579. $params,
  580. 'Error: could not login to ' . $seafileURL,
  581. $response
  582. );
  583. return 'Error: could not login to ' . $seafileURL;
  584. }
  585. $existingAccount = $seafileAPI->getAccount($params['username']);
  586. if(isset($existingAccount['error_msg'])) {
  587. logModuleCall(
  588. 'seafile',
  589. __FUNCTION__,
  590. $params,
  591. 'Error: could not find account ' . $params['username'],
  592. ''
  593. );
  594. return 'Error: could not find account ' . $params['username'];
  595. }
  596. //if ($existingAccount['is_active'] == 1) {
  597. // return 'Account '. $params['username'] . ' is active, suspend account first!';
  598. //}
  599. $result = $seafileAPI->deleteAccount($params['username']);
  600. if($result != true) {
  601. logModuleCall(
  602. 'seafile',
  603. __FUNCTION__,
  604. $params,
  605. 'Error: could not remove ' . $params['username'],
  606. $seafileAPI
  607. );
  608. return 'Error: could not remove ' . $params['username'];
  609. }
  610. return 'success';
  611. }
  612. /**
  613. * server side password check
  614. *
  615. * recheck the client side password check
  616. * in case that the client side check has been disabled
  617. *
  618. * @param string $pwd password
  619. *
  620. * @return string missing features or null if the password matches our needs
  621. */
  622. function seafileCheckPassword($pwd) {
  623. if (strlen($pwd) < 8) {
  624. return 'Das das Passwort ist zu kurz. Es werden mind. 8 Zeichen benötigt';
  625. }
  626. if (!preg_match('#[0-9]+#', $pwd)) {
  627. return 'Das Passwort muss mindestens eine Zahl enthalten';
  628. }
  629. if (!preg_match('#[A-Z]+#', $pwd)) {
  630. return 'Das Passwort muss mindestens einen Grossbuchstaben (A-Z) enthalten';
  631. }
  632. if (!preg_match('#[a-z]+#', $pwd)) {
  633. return 'Das Passwort muss mindestens einen Kleinbuchstaben (a-z) enthalten';
  634. }
  635. if (!preg_match('#[^\w]+#', $pwd)) {
  636. return 'Das Passwort muss mindestens ein Sonderzeichen (.,-:=) enthalten';
  637. }
  638. return null;
  639. }
  640. /**
  641. * Perform an update of customfields to prevent downgrades.
  642. *
  643. * Called in changePackage or createAccount functions.
  644. *
  645. * @param array $params common module parameters
  646. *
  647. * @return *success* or an error
  648. */
  649. function seafileUpdateQuota($params) {
  650. if(isset($params['configoptions']['addonQuota'])) {
  651. $addonQuota = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0 ;
  652. $newAddQuota = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
  653. $addonQuota = $addonQuota + $newAddQuota;
  654. $addonQuotaFieldIDObj = Capsule::table('tblproductconfigoptions')
  655. ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
  656. ->where('tblhostingconfigoptions.relid', '=', $params['serviceid'])
  657. ->where('tblproductconfigoptions.optionname', 'like', 'addonQuota%')
  658. ->select('tblhostingconfigoptions.id', 'tblproductconfigoptions.qtymaximum')
  659. ->get();
  660. if($addonQuota > $addonQuotaFieldIDObj[0]->qtymaximum) {
  661. logModuleCall(
  662. 'seafile',
  663. __FUNCTION__,
  664. $params,
  665. 'Info: someone is trying to exceed the maximum size',
  666. ''
  667. );
  668. $addonQuota = $addonQuotaFieldIDObj[0]->qtymaximum;
  669. }
  670. try {
  671. $updateAddonQuota = Capsule::table('tblhostingconfigoptions')
  672. ->where('id', $addonQuotaFieldIDObj[0]->id)
  673. ->update(
  674. [
  675. 'qty' => $addonQuota,
  676. ]
  677. );
  678. } catch (\Exception $e) {
  679. logModuleCall(
  680. 'seafile',
  681. __FUNCTION__,
  682. $updateAddonQuota,
  683. 'Error: could not save addonOuota in database.',
  684. $e->getMessage()
  685. );
  686. return 'Error: could not save addonOuota in database.';
  687. }
  688. $newAddQuotaFieldIDObj = Capsule::table('tblproductconfigoptions')
  689. ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
  690. ->where('tblhostingconfigoptions.relid', '=', $params['serviceid'])
  691. ->where('tblproductconfigoptions.optionname', 'like', 'newAddQuota%')
  692. ->select('tblhostingconfigoptions.id')
  693. ->get();
  694. try {
  695. $updateNewAddQuota = Capsule::table('tblhostingconfigoptions')
  696. ->where('id', $newAddQuotaFieldIDObj[0]->id)
  697. ->update(
  698. [
  699. 'qty' => '0',
  700. ]
  701. );
  702. } catch (\Exception $e) {
  703. logModuleCall(
  704. 'seafile',
  705. __FUNCTION__,
  706. $updateNewAddQuota,
  707. 'Error: could not reset newAddOuota in database.',
  708. $e->getMessage()
  709. );
  710. return 'Error: could not reset newAddOuota in database.';
  711. }
  712. }
  713. return 'success';
  714. }
  715. ?>