nextcloud.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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. 'domain' => $userName,
  364. )
  365. );
  366. } catch (\Exception $e) {
  367. logModuleCall(
  368. 'nextcloud',
  369. __FUNCTION__,
  370. $params,
  371. 'Error: could save username & password in database',
  372. $e->getMessage()
  373. );
  374. return 'Error: could save username & password in database';
  375. }
  376. if(nextcloudUpdateQuota($params) != 'success') {
  377. return 'Error: could not update addonQuota in database';
  378. };
  379. return 'success';
  380. } else {
  381. logModuleCall(
  382. 'nextcloud',
  383. __FUNCTION__,
  384. $params,
  385. 'Error: could not create user ' . $userName,
  386. $response
  387. );
  388. if ($response->ocs->meta->statuscode == '102') {
  389. return "Der Account konnte nicht erstellt werden. Es existiert bereits ein Account mit diesem Namen";
  390. } elseif ($response->ocs->meta->statuscode == '107') {
  391. return "Beim Erstellen des Accounts ist ein Fehler aufgetreten, der Fehler war: " . $response->ocs->meta->message;
  392. }
  393. }
  394. }
  395. /**
  396. * Set a nextcloud account to status inactive.
  397. *
  398. * Called when a suspension is requested. This is invoked automatically by WHMCS
  399. * when a product becomes overdue on payment or can be called manually by admin
  400. * user.
  401. *
  402. * @param array $params common module parameters
  403. *
  404. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  405. *
  406. * @return string 'success' or an error message
  407. */
  408. function nextcloud_SuspendAccount($params) {
  409. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'] . "/ocs/v1.php/cloud/users/" . $params['username'] . "/disable";
  410. $response = nextcloud_send($nextcloudURL, $params["serverusername"], $params["serverpassword"], "PUT", array() );
  411. if ($response === false) {
  412. return "Der Server kann nicht erreicht werden";
  413. }
  414. if ($response->ocs->meta->status == 'ok' && $response->ocs->meta->statuscode == '100') {
  415. return 'success';
  416. } else {
  417. logModuleCall(
  418. 'nextcloud',
  419. __FUNCTION__,
  420. $params,
  421. 'Error: could not suspend account ' . $params['username'],
  422. $response
  423. );
  424. return 'Der Account konnte nicht deaktiviert werden: ' . $params['username'];
  425. }
  426. }
  427. /**
  428. * Set a SeaFile account to status active.
  429. *
  430. * Called when an un-suspension is requested. This is invoked
  431. * automatically upon payment of an overdue invoice for a product, or
  432. * can be called manually by admin user.
  433. *
  434. * @param array $params common module parameters
  435. *
  436. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  437. *
  438. * @return string 'success' or an error message
  439. */
  440. function nextcloud_UnsuspendAccount($params) {
  441. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'] . "/ocs/v1.php/cloud/users/" . $params['username'] . "/enable";
  442. $response = nextcloud_send($nextcloudURL, $params["serverusername"], $params["serverpassword"], "PUT", array() );
  443. if ($response === false) {
  444. return "Der Server kann nicht erreicht werden";
  445. }
  446. if ($response->ocs->meta->status == 'ok' && $response->ocs->meta->statuscode == '100') {
  447. return 'success';
  448. } else {
  449. logModuleCall(
  450. 'nextcloud',
  451. __FUNCTION__,
  452. $params,
  453. 'Error: could not unsuspend account ' . $params['username'],
  454. $response
  455. );
  456. return 'Der Account konnte nicht reaktiviert werden: ' . $params['username'];
  457. }
  458. }
  459. /**
  460. * Removes a Nextcloud account.
  461. *
  462. * Called when a termination is requested. This can be invoked automatically for
  463. * overdue products if enabled, or requested manually by an admin 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 nextcloud_TerminateAccount($params) {
  472. $nextcloudURL = $params['serverhttpprefix'] . '://' . $params['serverhostname'] . ':' . $params['serverport'] . "/ocs/v1.php/cloud/users/" . $params['username'];
  473. $response = nextcloud_send($nextcloudURL, $params["serverusername"], $params["serverpassword"], "DELETE", array() );
  474. if ($response === false) {
  475. return "Der Server kann nicht erreicht werden";
  476. }
  477. if ($response->ocs->meta->status == 'ok' && $response->ocs->meta->statuscode == '100') {
  478. return 'success';
  479. } else {
  480. logModuleCall(
  481. 'nextcloud',
  482. __FUNCTION__,
  483. $params,
  484. 'Error: could not delete account ' . $params['username'],
  485. $response
  486. );
  487. return 'Der Account konnte nicht gelöscht werden: ' . $params['username'];
  488. }
  489. }
  490. function nextcloud_send($href, $username, $password, $action, $post = array()) {
  491. $postdata = http_build_query($post);
  492. $ch = curl_init();
  493. if (strtoupper($action) == 'POST') {
  494. curl_setopt($ch, CURLOPT_POST, true);
  495. if ($postdata) {
  496. curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  497. }
  498. }
  499. if (strtoupper($action) == 'PUT') {
  500. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
  501. if ($postdata) {
  502. curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  503. }
  504. }
  505. if (strtoupper($action) == 'GET') {
  506. curl_setopt($ch, CURLOPT_HTTPGET, true);
  507. }
  508. if (strtoupper($action) == 'DELETE') {
  509. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
  510. }
  511. curl_setopt($ch, CURLOPT_URL, $href);
  512. curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
  513. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  514. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json","OCS-APIRequest: true",'content-type: application/x-www-form-urlencoded'));
  515. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  516. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  517. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  518. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  519. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  520. $result_json = curl_exec($ch);
  521. $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  522. curl_close($ch);
  523. if ($httpcode >= 200 && $httpcode < 300) {
  524. $result_bom = nextcloud_remove_utf8bom($result_json);
  525. $result = json_decode($result_bom);
  526. return($result);
  527. } else {
  528. error_log("NextCloud Module nextcloud_send(): Error while executing " . $href . " the result code was: " . $httpcode);
  529. logModuleCall(
  530. 'nextcloud',
  531. __FUNCTION__,
  532. $result_json,
  533. 'nextcloud_send: Error: error in response',
  534. $response
  535. );
  536. return false;
  537. }
  538. }
  539. function nextcloud_remove_utf8bom($text) {
  540. $bom = pack('H*', 'EFBBBF');
  541. $text = preg_replace("/^$bom/", '', $text);
  542. return $text;
  543. }
  544. /**
  545. * server side password check
  546. *
  547. * recheck the client side password check
  548. * in case that the client side check has been disabled
  549. *
  550. * @param string $pwd password
  551. *
  552. * @return string missing features or null if the password matches our needs
  553. */
  554. function nextcloudCheckPassword($pwd) {
  555. if (strlen($pwd) < 8) {
  556. return 'Das das Passwort ist zu kurz. Es werden mind. 8 Zeichen benötigt';
  557. }
  558. if (!preg_match('#[0-9]+#', $pwd)) {
  559. return 'Das Passwort muss mindestens eine Zahl enthalten';
  560. }
  561. if (!preg_match('#[A-Z]+#', $pwd)) {
  562. return 'Das Passwort muss mindestens einen Grossbuchstaben (A-Z) enthalten';
  563. }
  564. if (!preg_match('#[a-z]+#', $pwd)) {
  565. return 'Das Passwort muss mindestens einen Kleinbuchstaben (a-z) enthalten';
  566. }
  567. if (!preg_match('#[^\w]+#', $pwd)) {
  568. return 'Das Passwort muss mindestens ein Sonderzeichen (.,-:=) enthalten';
  569. }
  570. return null;
  571. }
  572. /**
  573. * Perform an update of customfields to prevent downgrades.
  574. *
  575. * Called in changePackage or createAccount functions.
  576. *
  577. * @param array $params common module parameters
  578. *
  579. * @return *success* or an error
  580. */
  581. function nextcloudUpdateQuota($params) {
  582. if(isset($params['configoptions']['addonQuota'])) {
  583. $addonQuota = $params['configoptions']['addonQuota'] ? $params['configoptions']['addonQuota'] : 0 ;
  584. $newAddQuota = $params['configoptions']['newAddQuota'] ? $params['configoptions']['newAddQuota'] : 0;
  585. $addonQuota = $addonQuota + $newAddQuota;
  586. $addonQuotaFieldIDObj = Capsule::table('tblproductconfigoptions')
  587. ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
  588. ->where('tblhostingconfigoptions.relid', '=', $params['serviceid'])
  589. ->where('tblproductconfigoptions.optionname', 'like', 'addonQuota%')
  590. ->select('tblhostingconfigoptions.id', 'tblproductconfigoptions.qtymaximum')
  591. ->get();
  592. if($addonQuota > $addonQuotaFieldIDObj[0]->qtymaximum) {
  593. logModuleCall(
  594. 'seafile',
  595. __FUNCTION__,
  596. $params,
  597. 'Info: someone is trying to exceed the maximum size',
  598. ''
  599. );
  600. $addonQuota = $addonQuotaFieldIDObj[0]->qtymaximum;
  601. }
  602. try {
  603. $updateAddonQuota = Capsule::table('tblhostingconfigoptions')
  604. ->where('id', $addonQuotaFieldIDObj[0]->id)
  605. ->update(
  606. [
  607. 'qty' => $addonQuota,
  608. ]
  609. );
  610. } catch (\Exception $e) {
  611. logModuleCall(
  612. 'nextcloud',
  613. __FUNCTION__,
  614. $updateAddonQuota,
  615. 'Error: could not save addonOuota in database.',
  616. $e->getMessage()
  617. );
  618. return 'Error: could not save addonOuota in database.';
  619. }
  620. $newAddQuotaFieldIDObj = Capsule::table('tblproductconfigoptions')
  621. ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
  622. ->where('tblhostingconfigoptions.relid', '=', $params['serviceid'])
  623. ->where('tblproductconfigoptions.optionname', 'like', 'newAddQuota%')
  624. ->select('tblhostingconfigoptions.id')
  625. ->get();
  626. try {
  627. $updateNewAddQuota = Capsule::table('tblhostingconfigoptions')
  628. ->where('id', $newAddQuotaFieldIDObj[0]->id)
  629. ->update(
  630. [
  631. 'qty' => '0',
  632. ]
  633. );
  634. } catch (\Exception $e) {
  635. logModuleCall(
  636. 'nextcloud',
  637. __FUNCTION__,
  638. $updateNewAddQuota,
  639. 'Error: could not reset newAddOuota in database.',
  640. $e->getMessage()
  641. );
  642. return 'Error: could not reset newAddOuota in database.';
  643. }
  644. }
  645. return 'success';
  646. }
  647. ?>