nextcloud.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. if (!defined('WHMCS')) {
  13. die('This file cannot be accessed directly'); }
  14. function nextcloud_MetaData() {
  15. return array(
  16. 'DisplayName' => 'Nextcloud Provisioning',
  17. 'APIVersion' => '1.2',
  18. 'DefaultNonSSLPort' => '80',
  19. 'DefaultSSLPort' => '443',
  20. 'RequiresServer' => true,
  21. 'ServiceSingleSignOnLabel' => 'Login to Nextcloud',
  22. 'AdminSingleSignOnLabel' => 'Login to Nextcloud Admin',
  23. 'ListAccountsUniqueIdentifierDisplayName' => 'Domain',
  24. 'ListAccountsUniqueIdentifierField' => 'domain',
  25. 'ListAccountsProductField' => 'configoption1',
  26. );
  27. }
  28. /**
  29. * Define SeaFile product configuration options.
  30. *
  31. * @see https://developers.whmcs.com/provisioning-modules/config-options/
  32. *
  33. * @return array
  34. */
  35. function nextcloud_ConfigOptions() {
  36. $configarray = array(
  37. 'quota' => array(
  38. 'Type' => 'text',
  39. 'Description' => 'Basis User-Quota für dieses Produkt in GB',
  40. 'Default' => '10',
  41. 'Size' => '15',
  42. 'FriendlyName' => 'User Quota',
  43. ),
  44. );
  45. return $configarray;
  46. }
  47. /**
  48. * Test connection to a Nextcloud server with the given server parameters.
  49. *
  50. * Allows an admin user to verify that an API connection can be
  51. * successfully made with the given configuration parameters for a
  52. * server.
  53. *
  54. * When defined in a module, a Test Connection button will appear
  55. * alongside the Server Type dropdown when adding or editing an
  56. * existing server.
  57. *
  58. * @param array $params common module parameters
  59. *
  60. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  61. *
  62. * @return array
  63. */
  64. function nextcloud_TestConnection($params) {
  65. error_log("Nextcloud TestConnection: " . $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport']);
  66. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'] . "/ocs/v1.php/cloud/capabilities";
  67. $response = nextcloud_send($nextcloudURL,$params['serverusername'],$params['serverpassword'],"GET");
  68. if ($response === false) {
  69. return array(
  70. 'success' => false,
  71. 'error' => 'Error: cannot communicate with server ' . $nextcloudURL,
  72. );
  73. }
  74. if ($response->ocs->meta->status == 'ok') {
  75. return array(
  76. 'success' => true,
  77. 'error' => '',
  78. );
  79. } else {
  80. if (isset($response->ocs->meta->message)) {
  81. logModuleCall(
  82. 'nextcloud',
  83. __FUNCTION__,
  84. $params,
  85. 'Error: could not login to ' . $nextcloudURL,
  86. $response
  87. );
  88. }
  89. return array(
  90. 'success' => false,
  91. 'error' => 'Error: could not login to ' . $nextcloudURL,
  92. );
  93. }
  94. }
  95. /**
  96. * Usage Update
  97. *
  98. * Important: Runs daily per server not per product
  99. * Run Manually: /admin/reports.php?report=disk_usage_summary&action=updatestats
  100. * @param array $params common module parameters
  101. *
  102. * @see https://developers.whmcs.com/provisioning-modules/usage-update/
  103. */
  104. function nextcloud_UsageUpdate($params) {
  105. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'] . "/ocs/v1.php/cloud/users/";
  106. $nextcloudTestURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'] . "/ocs/v1.php/cloud/capabilities";
  107. $response = nextcloud_send($nextcloudTestURL, $params['serverusername'],$params['serverpassword'],"GET");
  108. if ($response === false) {
  109. return "Cannot communicate with server: " . $nextcloudURL;
  110. }
  111. if ($response->ocs->meta->status !== 'ok') {
  112. if (isset($response->ocs->meta->message)) {
  113. logModuleCall(
  114. 'nextcloud',
  115. __FUNCTION__,
  116. $params,
  117. 'Error: could not login to ' . $nextcloudURL,
  118. $response
  119. );
  120. }
  121. return 'Error: could not login to ' . $nextcloudURL;
  122. }
  123. $servicesObj = Capsule::table('tblhosting')
  124. ->select('*')
  125. ->where('server', '=', $params['serverid'])
  126. ->where('domainstatus', '=', 'Active')
  127. ->get();
  128. foreach((array)$servicesObj as $serviceObj) {
  129. $service = get_object_vars($serviceObj[0]);
  130. $response = nextcloud_send($nextcloudURL . "/" . $service['username'], $params['serverusername'],$params['serverpassword'],"GET");
  131. $freeMegaBytes = round($response->ocs->data->quota->free / 1048576,2);
  132. $usedMegaBytes = round($response->ocs->data->quota->used / 1048576,2);
  133. $quotaMegaBytes = round($response->ocs->data->quota->quota / 1048576,2);
  134. if ($response->ocs->meta->status == 'ok') {
  135. try {
  136. Capsule::table('tblhosting')
  137. ->where('id', '=', $service['id'])
  138. ->update(
  139. array(
  140. 'diskusage' => $usedMegaBytes,
  141. 'disklimit' => $quotaMegaBytes,
  142. 'lastupdate' => Capsule::raw('now()')
  143. )
  144. );
  145. } catch (Exception $e) {
  146. logModuleCall(
  147. 'nextcloud',
  148. __FUNCTION__,
  149. $params,
  150. 'Error: could update usage information for ' . $service['username'],
  151. $response->ocs->meta->message
  152. );
  153. }
  154. } else {
  155. logModuleCall(
  156. 'nextcloud',
  157. __FUNCTION__,
  158. $params,
  159. 'Error: could update usage information for ' . $service['username'],
  160. $response->ocs->meta->message
  161. );
  162. }
  163. }
  164. }
  165. /**
  166. * Client area output logic handling.
  167. *
  168. * This function is used to define module specific client area output. It should
  169. * return an array consisting of a template file and optional additional
  170. * template variables to make available to that template.
  171. *
  172. * The template file you return can be one of two types:
  173. *
  174. * * tabOverviewModuleOutputTemplate - The output of the template provided here
  175. * will be displayed as part of the default product/service client area
  176. * product overview page.
  177. *
  178. * * tabOverviewReplacementTemplate - Alternatively using this option allows you
  179. * to entirely take control of the product/service overview page within the
  180. * client area.
  181. *
  182. * Whichever option you choose, extra template variables are defined in the same
  183. * way. This demonstrates the use of the full replacement.
  184. *
  185. * Please Note: Using tabOverviewReplacementTemplate means you should display
  186. * the standard information such as pricing and billing details in your custom
  187. * template or they will not be visible to the end user.
  188. *
  189. * @param array $params common module parameters
  190. *
  191. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  192. *
  193. * @return array
  194. */
  195. function nextcloud_ClientArea($params) {
  196. switch ($params['serverport']) {
  197. case '80':
  198. case '443':
  199. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'];
  200. break;
  201. default:
  202. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'];
  203. break;
  204. };
  205. $clientInfo['basequota'] = $params['configoption1'] ? $params['configoption1'] : 1;
  206. $clientInfo['addonquota'] = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0;
  207. $clientInfo['userquota'] = $clientInfo['basequota'] + $clientInfo['addonquota'];
  208. $clientInfo['mailaddress'] = $params['username'];
  209. $clientInfo['webmailurl'] = $nextcloudURL;
  210. $clientInfo['zimbraserver'] = parse_url($clientInfo['webmailurl'], PHP_URL_HOST);
  211. $clientinfo['url'] = $nextcloudURL;
  212. $clientinfo['user'] = $user;
  213. $clientinfo['mobile1'] = $app;
  214. $clientinfo['mobile2'] = $google;
  215. $clientinfo['winclient'] = $winClient;
  216. $clientinfo['macclient'] = $macClient;
  217. $clientinfo['linClient'] = $linClient;
  218. $clientinfo['stitle'] = $params['model']['product']['name'];
  219. return array(
  220. 'tabOverviewReplacementTemplate' => 'clientarea',
  221. 'vars' => $clientInfo,
  222. );
  223. }
  224. /**
  225. * Change the password for a SeaFile account.
  226. *
  227. * Called when a password change is requested. This can occur either due to a
  228. * client requesting it via the client area or an admin requesting it from the
  229. * admin side.
  230. *
  231. * This option is only available to client end users when the product is in an
  232. * active status.
  233. *
  234. * @param array $params common module parameters
  235. *
  236. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  237. *
  238. * @return string 'success' or an error message
  239. */
  240. function nextcloud_ChangePassword($params) {
  241. $checkPassword = nextcloudCheckPassword($params['password']);
  242. if ($checkPassword != null) {
  243. return $checkPassword;
  244. }
  245. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'] . "/ocs/v1.php/cloud/users/" . $params['username'];
  246. $post = array('key' => 'password', 'value' => $params["password"]);
  247. $response = nextcloud_send($nextcloudURL, $params["serverusername"], $params["serverpassword"], "PUT", $post);
  248. if ($response === false) {
  249. return "Der Server kann nicht erreicht werden";
  250. }
  251. if ($response->ocs->meta->status == 'ok') {
  252. return 'success';
  253. } else {
  254. if ($response->ocs->meta->statuscode == '107') {
  255. return 'Das Passwort entspricht nicht den Grundanforderungen von Nextcloud';
  256. } else {
  257. return 'Das Passwort konnte nicht geändert werden. Der Fehlercode war: ' . $response->ocs->meta->statuscode;
  258. }
  259. }
  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 nextcloud_ChangePackage($params) {
  278. $addonQuota = $params['configoptions']['addonQuota'];
  279. $quota = $params['configoption1'] ? $params['configoption1'] : 1;
  280. $accountQuota = ($quota + $addonQuota);
  281. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'] . "/ocs/v1.php/cloud/users/" . $params['username'];
  282. $post = array('key' => 'quota', 'value' => $accountQuota . "MB");
  283. $response = nextcloud_send($nextcloudURL, $params["serverusername"], $params["serverpassword"], "PUT", $post);
  284. if ($response === false) {
  285. return "Der Server kann nicht erreicht werden";
  286. }
  287. if ($response->ocs->meta->status == 'ok') {
  288. try {
  289. Capsule::table('tblhosting')
  290. ->where('id', '=', $params['serviceid'])
  291. ->update(
  292. array(
  293. 'disklimit' => $userAccount['quota_total'],
  294. )
  295. );
  296. } catch (Exception $e) {
  297. logModuleCall(
  298. 'nextcloud',
  299. __FUNCTION__,
  300. $params,
  301. 'Error: could not update quota in database',
  302. $e->getMessage()
  303. );
  304. return 'Error: could not update quota in database';
  305. }
  306. if(nextcloudUpdateQuota($params) != 'success') {
  307. return 'Error: could not update addonQuota in database';
  308. };
  309. return 'success';
  310. } else {
  311. return 'Der Account konnte nicht modifiziert werden. Der Fehlercode war: ' . $response->ocs->meta->statuscode;
  312. }
  313. }
  314. /**
  315. * Provision a new instance of a NextCloud account.
  316. *
  317. * Attempt to provision a new NextCloud account. This is
  318. * called any time provisioning is requested inside of WHMCS. Depending upon the
  319. * configuration, this can be any of:
  320. * * When a new order is placed
  321. * * When an invoice for a new order is paid
  322. * * Upon manual request by an admin user
  323. *
  324. * @param array $params common module parameters
  325. *
  326. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  327. *
  328. * @return string 'success' or an error message
  329. */
  330. function nextcloud_CreateAccount($params) {
  331. $userName = $params['customfields']['username'];
  332. $firstName = $params['customfields']['firstname'];
  333. $lastName = $params['customfields']['lastname'];
  334. $loginEMail = $params['customfields']['email'];
  335. $loginPassword = $params['customfields']['password'];
  336. $addonQuota = $params['configoptions']['addonQuota'];
  337. $baseQuota = $params['configoption1'] ? $params['configoption1'] : 1;
  338. $addonQuota = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0;
  339. $newAddQuota = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
  340. $accountQuota = $baseQuota + $addonQuota + $newAddQuota;
  341. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'] . "/ocs/v1.php/cloud/users";
  342. $post = array(
  343. 'userid' => $userName,
  344. 'password' => $loginPassword,
  345. 'email' => $loginEMail,
  346. 'displayName' => $firstName . " " . $lastName,
  347. 'quota' => $accountQuota . "GB"
  348. );
  349. $response = nextcloud_send($nextcloudURL, $params["serverusername"], $params["serverpassword"], "POST", $post);
  350. if ($response === false) {
  351. return "Der Server kann nicht erreicht werden";
  352. }
  353. if ($response->ocs->meta->status == 'ok' && $response->ocs->meta->statuscode == '100') {
  354. try {
  355. Capsule::table('tblhosting')
  356. ->where('id', '=', $params['serviceid'])
  357. ->update(
  358. array(
  359. 'username' => $userName,
  360. 'password' => $loginPassword,
  361. 'disklimit' => $accountQuota * 1024,
  362. 'diskusage' => 0,
  363. )
  364. );
  365. } catch (\Exception $e) {
  366. logModuleCall(
  367. 'nextcloud',
  368. __FUNCTION__,
  369. $params,
  370. 'Error: could save username & password in database',
  371. $e->getMessage()
  372. );
  373. return 'Error: could save username & password in database';
  374. }
  375. if(nextcloudUpdateQuota($params) != 'success') {
  376. return 'Error: could not update addonQuota in database';
  377. };
  378. return 'success';
  379. } else {
  380. logModuleCall(
  381. 'nextcloud',
  382. __FUNCTION__,
  383. $params,
  384. 'Error: could not create user ' . $userName,
  385. $response
  386. );
  387. if ($response->ocs->meta->statuscode == '102') {
  388. return "Der Account konnte nicht erstellt werden. Es existiert bereits ein Account mit diesem Namen";
  389. } elseif ($response->ocs->meta->statuscode == '107') {
  390. return "Beim Erstellen des Accounts ist ein Fehler aufgetreten, der Fehler war: " . $response->ocs->meta->message;
  391. }
  392. }
  393. }
  394. /**
  395. * Set a nextcloud account to status inactive.
  396. *
  397. * Called when a suspension is requested. This is invoked automatically by WHMCS
  398. * when a product becomes overdue on payment or can be called manually by admin
  399. * user.
  400. *
  401. * @param array $params common module parameters
  402. *
  403. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  404. *
  405. * @return string 'success' or an error message
  406. */
  407. function nextcloud_SuspendAccount($params) {
  408. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'] . "/ocs/v1.php/cloud/users/" . $params['username'] . "/disable";
  409. $response = nextcloud_send($nextcloudURL, $params["serverusername"], $params["serverpassword"], "PUT", array() );
  410. if ($response === false) {
  411. return "Der Server kann nicht erreicht werden";
  412. }
  413. if ($response->ocs->meta->status == 'ok' && $response->ocs->meta->statuscode == '100') {
  414. return 'success';
  415. } else {
  416. logModuleCall(
  417. 'nextcloud',
  418. __FUNCTION__,
  419. $params,
  420. 'Error: could not suspend account ' . $params['username'],
  421. $response
  422. );
  423. return 'Der Account konnte nicht deaktiviert werden: ' . $params['username'];
  424. }
  425. }
  426. /**
  427. * Set a SeaFile account to status active.
  428. *
  429. * Called when an un-suspension is requested. This is invoked
  430. * automatically upon payment of an overdue invoice for a product, or
  431. * can be called manually by admin user.
  432. *
  433. * @param array $params common module parameters
  434. *
  435. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  436. *
  437. * @return string 'success' or an error message
  438. */
  439. function nextcloud_UnsuspendAccount($params) {
  440. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'] . "/ocs/v1.php/cloud/users/" . $params['username'] . "/enable";
  441. $response = nextcloud_send($nextcloudURL, $params["serverusername"], $params["serverpassword"], "PUT", array() );
  442. if ($response === false) {
  443. return "Der Server kann nicht erreicht werden";
  444. }
  445. if ($response->ocs->meta->status == 'ok' && $response->ocs->meta->statuscode == '100') {
  446. return 'success';
  447. } else {
  448. logModuleCall(
  449. 'nextcloud',
  450. __FUNCTION__,
  451. $params,
  452. 'Error: could not unsuspend account ' . $params['username'],
  453. $response
  454. );
  455. return 'Der Account konnte nicht reaktiviert werden: ' . $params['username'];
  456. }
  457. }
  458. /**
  459. * Removes a Nextcloud account.
  460. *
  461. * Called when a termination is requested. This can be invoked automatically for
  462. * overdue products if enabled, or requested manually by an admin user.
  463. *
  464. * @param array $params common module parameters
  465. *
  466. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  467. *
  468. * @return string 'success' or an error message
  469. */
  470. function nextcloud_TerminateAccount($params) {
  471. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'] . "/ocs/v1.php/cloud/users/" . $params['username'];
  472. $response = nextcloud_send($nextcloudURL, $params["serverusername"], $params["serverpassword"], "DELETE", array() );
  473. if ($response === false) {
  474. return "Der Server kann nicht erreicht werden";
  475. }
  476. if ($response->ocs->meta->status == 'ok' && $response->ocs->meta->statuscode == '100') {
  477. return 'success';
  478. } else {
  479. logModuleCall(
  480. 'nextcloud',
  481. __FUNCTION__,
  482. $params,
  483. 'Error: could not delete account ' . $params['username'],
  484. $response
  485. );
  486. return 'Der Account konnte nicht gelöscht werden: ' . $params['username'];
  487. }
  488. }
  489. function nextcloud_send($href, $username, $password, $action, $post = array()) {
  490. $postdata = http_build_query($post);
  491. $ch = curl_init();
  492. if (strtoupper($action) == 'POST') {
  493. curl_setopt($ch, CURLOPT_POST, true);
  494. if ($postdata) {
  495. curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  496. }
  497. }
  498. if (strtoupper($action) == 'PUT') {
  499. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
  500. if ($postdata) {
  501. curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  502. }
  503. }
  504. if (strtoupper($action) == 'GET') {
  505. curl_setopt($ch, CURLOPT_HTTPGET, true);
  506. }
  507. if (strtoupper($action) == 'DELETE') {
  508. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
  509. }
  510. curl_setopt($ch, CURLOPT_URL, $href);
  511. curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
  512. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  513. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json","OCS-APIRequest: true",'content-type: application/x-www-form-urlencoded'));
  514. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  515. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  516. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  517. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  518. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  519. $result_json = curl_exec($ch);
  520. $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  521. curl_close($ch);
  522. if ($httpcode >= 200 && $httpcode < 300) {
  523. $result_bom = nextcloud_remove_utf8bom($result_json);
  524. $result = json_decode($result_bom);
  525. return($result);
  526. } else {
  527. error_log("NextCloud Module nextcloud_send(): Error while executing " . $href . " the result code was: " . $httpcode);
  528. logModuleCall(
  529. 'nextcloud',
  530. __FUNCTION__,
  531. $result_json,
  532. 'nextcloud_send: Error: error in response',
  533. $response
  534. );
  535. return false;
  536. }
  537. }
  538. function nextcloud_remove_utf8bom($text) {
  539. $bom = pack('H*', 'EFBBBF');
  540. $text = preg_replace("/^$bom/", '', $text);
  541. return $text;
  542. }
  543. /**
  544. * server side password check
  545. *
  546. * recheck the client side password check
  547. * in case that the client side check has been disabled
  548. *
  549. * @param string $pwd password
  550. *
  551. * @return string missing features or null if the password matches our needs
  552. */
  553. function nextcloudCheckPassword($pwd) {
  554. if (strlen($pwd) < 8) {
  555. return 'Das das Passwort ist zu kurz. Es werden mind. 8 Zeichen benötigt';
  556. }
  557. if (!preg_match('#[0-9]+#', $pwd)) {
  558. return 'Das Passwort muss mindestens eine Zahl enthalten';
  559. }
  560. if (!preg_match('#[A-Z]+#', $pwd)) {
  561. return 'Das Passwort muss mindestens einen Grossbuchstaben (A-Z) enthalten';
  562. }
  563. if (!preg_match('#[a-z]+#', $pwd)) {
  564. return 'Das Passwort muss mindestens einen Kleinbuchstaben (a-z) enthalten';
  565. }
  566. if (!preg_match('#[^\w]+#', $pwd)) {
  567. return 'Das Passwort muss mindestens ein Sonderzeichen (.,-:=) enthalten';
  568. }
  569. return null;
  570. }
  571. /**
  572. * Perform an update of customfields to prevent downgrades.
  573. *
  574. * Called in changePackage or createAccount functions.
  575. *
  576. * @param array $params common module parameters
  577. *
  578. * @return *success* or an error
  579. */
  580. function nextcloudUpdateQuota($params) {
  581. if(isset($params['configoptions']['addonQuota'])) {
  582. $addonQuota = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0 ;
  583. $newAddQuota = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
  584. $addonQuota = $addonQuota + $newAddQuota;
  585. $addonQuotaFieldIDObj = Capsule::table('tblproductconfigoptions')
  586. ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
  587. ->where('tblhostingconfigoptions.relid', '=', $params['serviceid'])
  588. ->where('tblproductconfigoptions.optionname', 'like', 'addonQuota%')
  589. ->select('tblhostingconfigoptions.id', 'tblproductconfigoptions.qtymaximum')
  590. ->get();
  591. if($addonQuota > $addonQuotaFieldIDObj[0]->qtymaximum) {
  592. logModuleCall(
  593. 'seafile',
  594. __FUNCTION__,
  595. $params,
  596. 'Info: someone is trying to exceed the maximum size',
  597. ''
  598. );
  599. $addonQuota = $addonQuotaFieldIDObj[0]->qtymaximum;
  600. }
  601. try {
  602. $updateAddonQuota = Capsule::table('tblhostingconfigoptions')
  603. ->where('id', $addonQuotaFieldIDObj[0]->id)
  604. ->update(
  605. [
  606. 'qty' => $addonQuota,
  607. ]
  608. );
  609. } catch (\Exception $e) {
  610. logModuleCall(
  611. 'nextcloud',
  612. __FUNCTION__,
  613. $updateAddonQuota,
  614. 'Error: could not save addonOuota in database.',
  615. $e->getMessage()
  616. );
  617. return 'Error: could not save addonOuota in database.';
  618. }
  619. $newAddQuotaFieldIDObj = Capsule::table('tblproductconfigoptions')
  620. ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
  621. ->where('tblhostingconfigoptions.relid', '=', $params['serviceid'])
  622. ->where('tblproductconfigoptions.optionname', 'like', 'newAddQuota%')
  623. ->select('tblhostingconfigoptions.id')
  624. ->get();
  625. try {
  626. $updateNewAddQuota = Capsule::table('tblhostingconfigoptions')
  627. ->where('id', $newAddQuotaFieldIDObj[0]->id)
  628. ->update(
  629. [
  630. 'qty' => '0',
  631. ]
  632. );
  633. } catch (\Exception $e) {
  634. logModuleCall(
  635. 'nextcloud',
  636. __FUNCTION__,
  637. $updateNewAddQuota,
  638. 'Error: could not reset newAddOuota in database.',
  639. $e->getMessage()
  640. );
  641. return 'Error: could not reset newAddOuota in database.';
  642. }
  643. }
  644. return 'success';
  645. }
  646. ?>