seafile.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  68. $response = $seafileAPI->login();
  69. if (isset($response['error_msg'])) {
  70. logModuleCall(
  71. 'seafile',
  72. __FUNCTION__,
  73. $params,
  74. 'Error: could not login to ' . $seafileURL,
  75. $response
  76. );
  77. return array(
  78. 'success' => false,
  79. 'error' => 'Error: could not login to ' . $seafileURL,
  80. );
  81. }
  82. return array(
  83. 'success' => true,
  84. 'error' => '',
  85. );
  86. }
  87. /**
  88. * Usage Update
  89. *
  90. * Important: Runs daily per server not per product
  91. * Run Manually: /admin/reports.php?report=disk_usage_summary&action=updatestats
  92. * @param array $params common module parameters
  93. *
  94. * @see https://developers.whmcs.com/provisioning-modules/usage-update/
  95. */
  96. function seafile_UsageUpdate($params) {
  97. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  98. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  99. $response = $seafileAPI->login();
  100. if (isset($response['error_msg'])) {
  101. logModuleCall(
  102. 'seafile',
  103. __FUNCTION__,
  104. $params,
  105. 'Error: could not login to ' . $seafileURL,
  106. $response
  107. );
  108. return 'Error: could not login to ' . $seafileURL;
  109. }
  110. $servicesObj = Capsule::table('tblhosting')
  111. ->select('*')
  112. ->where('server', '=', $params['serverid'])
  113. ->where('domainstatus', '=', 'Active')
  114. ->get();
  115. foreach((array)$servicesObj as $serviceObj) {
  116. $service = get_object_vars($serviceObj[0]);
  117. $accountInfo = $seafileAPI->getAccount($service['username']);
  118. if(!isset($accountInfo['error_msg'])) {
  119. try {
  120. Capsule::table('tblhosting')
  121. ->where('id', '=', $service['id'])
  122. ->update(
  123. array(
  124. 'diskusage' => round($accountInfo['quota_usage'] / 1000000,2),
  125. 'disklimit' => round($accountInfo['quota_total'],2),
  126. 'lastupdate' => Capsule::raw('now()')
  127. )
  128. );
  129. } catch (Exception $e) {
  130. logModuleCall(
  131. 'seafile',
  132. __FUNCTION__,
  133. $params,
  134. 'Error: could update usage information for ' . $service['username'],
  135. $e->getMessage()
  136. );
  137. }
  138. }
  139. }
  140. }
  141. /**
  142. * Client area output logic handling.
  143. *
  144. * This function is used to define module specific client area output. It should
  145. * return an array consisting of a template file and optional additional
  146. * template variables to make available to that template.
  147. *
  148. * The template file you return can be one of two types:
  149. *
  150. * * tabOverviewModuleOutputTemplate - The output of the template provided here
  151. * will be displayed as part of the default product/service client area
  152. * product overview page.
  153. *
  154. * * tabOverviewReplacementTemplate - Alternatively using this option allows you
  155. * to entirely take control of the product/service overview page within the
  156. * client area.
  157. *
  158. * Whichever option you choose, extra template variables are defined in the same
  159. * way. This demonstrates the use of the full replacement.
  160. *
  161. * Please Note: Using tabOverviewReplacementTemplate means you should display
  162. * the standard information such as pricing and billing details in your custom
  163. * template or they will not be visible to the end user.
  164. *
  165. * @param array $params common module parameters
  166. *
  167. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  168. *
  169. * @return array
  170. */
  171. function seafile_ClientArea($params) {
  172. switch ($params['serverport']) {
  173. case '80':
  174. case '443':
  175. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'];
  176. break;
  177. default:
  178. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  179. break;
  180. };
  181. $user = $params['username'];
  182. $app = 'https://itunes.apple.com/cn/app/seafile-pro/id639202512?l=en&mt=8';
  183. $google = 'https://play.google.com/store/apps/details?id=com.seafile.seadroid2';
  184. $driveWin = 'https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seadrive-2.0.5-en.msi';
  185. $winClient = 'https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-7.0.9-en.msi';
  186. $macClient = 'https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-client-7.0.9.dmg';
  187. $driveMac = 'https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seadrive-2.0.5.dmg';
  188. $linClient = 'https://download.seafile.com/published/seafile-user-manual/syncing_client/install_linux_client.md';
  189. $langObj = Capsule::table('tblconfiguration')
  190. ->select('value')
  191. ->where('setting', '=', 'Language')
  192. ->get();
  193. $lla = $_SESSION['Language'] ? trim($_SESSION['Language']) : strtolower($langObj[0]->value);
  194. $slang = array();
  195. include_once dirname(__FILE__).'/lang/'.$lla.'.php';
  196. return array(
  197. 'tabOverviewReplacementTemplate' => 'clientarea',
  198. 'vars' => array_merge(
  199. array(
  200. 'url' => $seafileURL,
  201. 'user' => $user,
  202. 'mobile1' => $app,
  203. 'mobile2' => $google,
  204. 'drivewin' => $driveWin,
  205. 'winclient' => $winClient,
  206. 'macclient' => $macClient,
  207. 'drivemac' => $driveMac,
  208. 'linClient' => $linClient,
  209. ),
  210. $slang,
  211. $params
  212. ),
  213. );
  214. }
  215. /**
  216. * Change the password for a SeaFile account.
  217. *
  218. * Called when a password change is requested. This can occur either due to a
  219. * client requesting it via the client area or an admin requesting it from the
  220. * admin side.
  221. *
  222. * This option is only available to client end users when the product is in an
  223. * active status.
  224. *
  225. * @param array $params common module parameters
  226. *
  227. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  228. *
  229. * @return string 'success' or an error message
  230. */
  231. function seafile_ChangePassword($params) {
  232. $checkPassword = seafileCheckPassword($params['password']);
  233. if ($checkPassword != null) {
  234. return $checkPassword;
  235. }
  236. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  237. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  238. $response = $seafileAPI->login();
  239. if (isset($response['error_msg'])) {
  240. logModuleCall(
  241. 'seafile',
  242. __FUNCTION__,
  243. $params,
  244. 'Error: could not login to ' . $seafileURL,
  245. $response
  246. );
  247. return 'Error: could not login to ' . $seafileURL;
  248. }
  249. $userAccount = $seafileAPI->getAccount($params['username']);
  250. if(isset($userAccount['error_msg'])) {
  251. logModuleCall(
  252. 'seafile',
  253. __FUNCTION__,
  254. $params,
  255. 'Error: could not find account for: ' . $params['username'],
  256. $userAccount
  257. );
  258. return 'Error: could not find account for: ' . $params['username'];
  259. }
  260. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'password' => $params['password']));
  261. if(isset($result['error_msg'])) {
  262. logModuleCall(
  263. 'seafile',
  264. __FUNCTION__,
  265. $params,
  266. 'Error: could not change password for: ' . $params['username'],
  267. $result
  268. );
  269. return 'Error: could not change password for: ' . $params['username'];
  270. }
  271. return 'success';
  272. }
  273. /**
  274. * Set a new quota of a SeaFile account.
  275. *
  276. * Called to apply a quota change of the service. It
  277. * is called to provision upgrade or downgrade orders, as well as being
  278. * able to be invoked manually by an admin user.
  279. *
  280. * This same function is called for upgrades and downgrades of both
  281. * products and configurable options.
  282. *
  283. * @param array $params common module parameters
  284. *
  285. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  286. *
  287. * @return string 'success' or an error message
  288. */
  289. function seafile_ChangePackage($params) {
  290. $addonQuota = $params['configoptions']['addonQuota'];
  291. $quota = $params['configoption1'] ? $params['configoption1'] : 1;
  292. $accountQuota = ($quota + $addonQuota) * 1000;
  293. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  294. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  295. $response = $seafileAPI->login();
  296. if (isset($response['error_msg'])) {
  297. logModuleCall(
  298. 'seafile',
  299. __FUNCTION__,
  300. $params,
  301. 'Error: could not login to ' . $seafileURL,
  302. $response
  303. );
  304. return 'Error: could not login to ' . $seafileURL;
  305. }
  306. $userAccount = $seafileAPI->getAccount($params['username']);
  307. if(isset($userAccount['error_msg'])) {
  308. logModuleCall(
  309. 'seafile',
  310. __FUNCTION__,
  311. $params,
  312. 'Error: could not find account ' . $params['username'],
  313. $userAccount
  314. );
  315. return 'Error: could not find account ' . $params['username'];
  316. }
  317. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'quota_total' => $accountQuota));
  318. if(isset($result['error_msg'])) {
  319. logModuleCall(
  320. 'seafile',
  321. __FUNCTION__,
  322. $params,
  323. 'Error: could not update quota for ' . $userAccount['email'],
  324. $result
  325. );
  326. return 'Error: could not update quota for ' . $userAccount['email'];
  327. } elseif ($result['quota_total'] != ($accountQuota * 1000000)) {
  328. logModuleCall(
  329. 'seafile',
  330. __FUNCTION__,
  331. $params,
  332. 'Error: quota for ' . $userAccount['email'] . ' not updated',
  333. $result
  334. );
  335. return 'Error: quota for ' . $userAccount['email'] . ' not updated';
  336. }
  337. try {
  338. Capsule::table('tblhosting')
  339. ->where('id', '=', $params['serviceid'])
  340. ->update(
  341. array(
  342. 'disklimit' => $userAccount['quota_total'],
  343. )
  344. );
  345. } catch (Exception $e) {
  346. logModuleCall(
  347. 'seafile',
  348. __FUNCTION__,
  349. $params,
  350. 'Error: could not update quota in database',
  351. $e->getMessage()
  352. );
  353. return 'Error: could not update quota in database';
  354. }
  355. return 'success';
  356. }
  357. /**
  358. * Provision a new instance of a SeaFile account.
  359. *
  360. * Attempt to provision a new SeaFile account. This is
  361. * called any time provisioning is requested inside of WHMCS. Depending upon the
  362. * configuration, this can be any of:
  363. * * When a new order is placed
  364. * * When an invoice for a new order is paid
  365. * * Upon manual request by an admin user
  366. *
  367. * @param array $params common module parameters
  368. *
  369. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  370. *
  371. * @return string 'success' or an error message
  372. */
  373. function seafile_CreateAccount($params) {
  374. $firstName = $params['customfields']['firstname'];
  375. $lastName = $params['customfields']['lastname'];
  376. $loginEMail = $params['customfields']['login'];
  377. $loginPassword = $params['customfields']['password'];
  378. $addonQuota = $params['configoptions']['addonQuota'];
  379. $quota = $params['configoption1'] ? $params['configoption1'] : 1;
  380. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  381. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  382. $response = $seafileAPI->login();
  383. if (isset($response['error_msg'])) {
  384. logModuleCall(
  385. 'seafile',
  386. __FUNCTION__,
  387. $params,
  388. 'Error: could not login to ' . $seafileURL,
  389. $response
  390. );
  391. return 'Error: could not login to ' . $seafileURL;
  392. }
  393. $existingAccount = $seafileAPI->getAccount($loginEMail);
  394. if(!isset($existingAccount['error_msg'])) {
  395. return 'Error: account already exists ' . $loginEMail;
  396. }
  397. $accountQuota = ($quota + $addonQuota) * 1000;
  398. $newAccount = array();
  399. $newAccount['email'] = $loginEMail;
  400. $newAccount['name'] = $firstName . ' ' . $lastName;
  401. $newAccount['isActive'] = 1;
  402. $newAccount['isStaff'] = 0;
  403. $newAccount['password'] = $loginPassword;
  404. $newAccount['note'] = 'Account created from WHCMS for client ' . $params['userid'];
  405. $newAccount['quota_total'] = $accountQuota;
  406. $result = $seafileAPI->createAccount($newAccount);
  407. if(isset($result['error_msg'])) {
  408. logModuleCall(
  409. 'seafile',
  410. __FUNCTION__,
  411. $params,
  412. 'Error: could not create account ' . $loginEMail,
  413. $result
  414. );
  415. return 'Error: could not create account ' . $loginEMail;
  416. }
  417. try {
  418. Capsule::table('tblhosting')
  419. ->where('id', '=', $params['serviceid'])
  420. ->update(
  421. array(
  422. 'username' => $loginEMail,
  423. 'password' => $params['customfields']['password'],
  424. 'disklimit' => $accountQuota,
  425. 'diskusage' => 0,
  426. 'domain' => $loginEMail,
  427. )
  428. );
  429. } catch (\Exception $e) {
  430. logModuleCall(
  431. 'seafile',
  432. __FUNCTION__,
  433. $params,
  434. 'Error: could save account in database',
  435. $e->getMessage()
  436. );
  437. return 'Error: could save account in database';
  438. }
  439. return 'success';
  440. }
  441. /**
  442. * Set a SeaFile account to status inactive.
  443. *
  444. * Called when a suspension is requested. This is invoked automatically by WHMCS
  445. * when a product becomes overdue on payment or can be called manually by admin
  446. * user.
  447. *
  448. * @param array $params common module parameters
  449. *
  450. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  451. *
  452. * @return string 'success' or an error message
  453. */
  454. function seafile_SuspendAccount($params) {
  455. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  456. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  457. $response = $seafileAPI->login();
  458. if (isset($response['error_msg'])) {
  459. logModuleCall(
  460. 'seafile',
  461. __FUNCTION__,
  462. $params,
  463. 'Error: could not login to ' . $seafileURL,
  464. $response
  465. );
  466. return 'Error: could not login to ' . $seafileURL;
  467. }
  468. $userAccount = $seafileAPI->getAccount($params['username']);
  469. if(isset($userAccount['error_msg'])) {
  470. logModuleCall(
  471. 'seafile',
  472. __FUNCTION__,
  473. $params,
  474. 'Error: could not find account ' . $params['username'],
  475. $userAccount
  476. );
  477. return 'Error: could not find account ' . $params['username'];
  478. }
  479. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'is_active' => 0));
  480. if(isset($result['error_msg'])) {
  481. logModuleCall(
  482. 'seafile',
  483. __FUNCTION__,
  484. $params,
  485. 'Error: could not suspend ' . $params['username'],
  486. $result
  487. );
  488. return 'Error: could not suspend ' . $params['username'];
  489. } elseif ($result['update_status_tip'] != 'Edit succeeded') {
  490. logModuleCall(
  491. 'seafile',
  492. __FUNCTION__,
  493. $params,
  494. 'Error: ' . $params['username'] . ' not deactivated',
  495. $result
  496. );
  497. return 'Error: ' . $params['username'] . ' not deactivated';
  498. }
  499. return 'success';
  500. }
  501. /**
  502. * Set a SeaFile account to status active.
  503. *
  504. * Called when an un-suspension is requested. This is invoked
  505. * automatically upon payment of an overdue invoice for a product, or
  506. * can be called manually by admin user.
  507. *
  508. * @param array $params common module parameters
  509. *
  510. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  511. *
  512. * @return string 'success' or an error message
  513. */
  514. function seafile_UnsuspendAccount($params) {
  515. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  516. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  517. $response = $seafileAPI->login();
  518. if (isset($response['error_msg'])) {
  519. logModuleCall(
  520. 'seafile',
  521. __FUNCTION__,
  522. $params,
  523. 'Error: could not login to ' . $seafileURL,
  524. $response
  525. );
  526. return 'Error: could not login to ' . $seafileURL;
  527. }
  528. $userAccount = $seafileAPI->getAccount($params['username']);
  529. if(isset($userAccount['error_msg'])) {
  530. logModuleCall(
  531. 'seafile',
  532. __FUNCTION__,
  533. $params,
  534. 'Error: could not find account ' . $params['username'],
  535. $userAccount
  536. );
  537. return 'Error: could not find account ' . $params['username'];
  538. }
  539. $result = $seafileAPI->modifyAccount(array('email' => $userAccount['email'], 'is_active' => 1));
  540. if(isset($result['error_msg'])) {
  541. logModuleCall(
  542. 'seafile',
  543. __FUNCTION__,
  544. $params,
  545. 'Error: could not suspend ' . $params['username'],
  546. $result
  547. );
  548. return 'Error: could not suspend ' . $params['username'];
  549. } elseif ($result['update_status_tip'] != 'Edit succeeded') {
  550. logModuleCall(
  551. 'seafile',
  552. __FUNCTION__,
  553. $params,
  554. 'Error: ' . $params['username'] . ' not activated',
  555. $result
  556. );
  557. return 'Error: ' . $params['username'] . ' not activated';
  558. }
  559. return 'success';
  560. }
  561. /**
  562. * Removes a SeaFile account.
  563. *
  564. * Called when a termination is requested. This can be invoked automatically for
  565. * overdue products if enabled, or requested manually by an admin user.
  566. *
  567. * @param array $params common module parameters
  568. *
  569. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  570. *
  571. * @return string 'success' or an error message
  572. */
  573. function seafile_TerminateAccount($params) {
  574. $seafileURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  575. $seafileAPI = new Sf_Admin($seafileURL,$params['serverusername'],$params['serverpassword']);
  576. $response = $seafileAPI->login();
  577. if (isset($response['error_msg'])) {
  578. logModuleCall(
  579. 'seafile',
  580. __FUNCTION__,
  581. $params,
  582. 'Error: could not login to ' . $seafileURL,
  583. $response
  584. );
  585. return 'Error: could not login to ' . $seafileURL;
  586. }
  587. $existingAccount = $seafileAPI->getAccount($params['username']);
  588. if(isset($existingAccount['error_msg'])) {
  589. logModuleCall(
  590. 'seafile',
  591. __FUNCTION__,
  592. $params,
  593. 'Error: could not find account ' . $params['username'],
  594. ''
  595. );
  596. return 'Error: could not find account ' . $params['username'];
  597. }
  598. if ($existingAccount['is_active'] == 1) {
  599. return 'Account '. $params['username'] . ' is active, suspend account first!';
  600. }
  601. $result = $seafileAPI->deleteAccount($params['username']);
  602. if($result != true) {
  603. logModuleCall(
  604. 'seafile',
  605. __FUNCTION__,
  606. $params,
  607. 'Error: could not remove ' . $params['username'],
  608. $seafileAPI
  609. );
  610. return 'Error: could not remove ' . $params['username'];
  611. }
  612. return 'success';
  613. }
  614. /**
  615. * server side password check
  616. *
  617. * recheck the client side password check
  618. * in case that the client side check has been disabled
  619. *
  620. * @param string $pwd password
  621. *
  622. * @return string missing features or null if the password matches our needs
  623. */
  624. function seafileCheckPassword($pwd) {
  625. if (strlen($pwd) < 8) {
  626. return 'Das das Passwort ist zu kurz. Es werden mind. 8 Zeichen benötigt';
  627. }
  628. if (!preg_match('#[0-9]+#', $pwd)) {
  629. return 'Das Passwort muss mindestens eine Zahl enthalten';
  630. }
  631. if (!preg_match('#[A-Z]+#', $pwd)) {
  632. return 'Das Passwort muss mindestens einen Grossbuchstaben (A-Z) enthalten';
  633. }
  634. if (!preg_match('#[a-z]+#', $pwd)) {
  635. return 'Das Passwort muss mindestens einen Kleinbuchstaben (a-z) enthalten';
  636. }
  637. if (!preg_match('#[^\w]+#', $pwd)) {
  638. return 'Das Passwort muss mindestens ein Sonderzeichen (.,-:=) enthalten';
  639. }
  640. return null;
  641. }
  642. ?>