seafile.php 25 KB

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