seafile.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. 'templatefile' => 'clientside',
  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. )
  425. );
  426. } catch (\Exception $e) {
  427. logModuleCall(
  428. 'seafile',
  429. __FUNCTION__,
  430. $params,
  431. 'Error: could save username & password in database',
  432. $e->getMessage()
  433. );
  434. return 'Error: could save username & password 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. ?>