siteBuilder.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. <?php
  2. /**
  3. * WHMCS siteBuilder Provisioning Module
  4. *
  5. * Provisioning for User Account on the siteBuilder Server
  6. *
  7. * @see https://centos-webpanel.com/
  8. * @copyright Copyright (c) Thurdata GmbH 2022
  9. * @license GPL
  10. */
  11. use WHMCS\Database\Capsule;
  12. require_once 'Net/DNS2.php';
  13. require_once(__DIR__ . '/api/sitebuilder.php');
  14. if (!defined('WHMCS')) {
  15. die('This file cannot be accessed directly');
  16. }
  17. /**
  18. * Define siteBuilder product metadata parameters.
  19. *
  20. * @see https://developers.whmcs.com/provisioning-modules/meta-data-params/
  21. *
  22. * @return array
  23. */
  24. function siteBuilder_MetaData() {
  25. return array(
  26. 'DisplayName' => 'ThurData SiteBuilder Provisioning',
  27. 'APIVersion' => '1.2',
  28. 'DefaultNonSSLPort' => '80',
  29. 'DefaultSSLPort' => '443',
  30. 'RequiresServer' => true,
  31. 'ServiceSingleSignOnLabel' => 'Login to siteBuilder',
  32. 'AdminSingleSignOnLabel' => 'Login to siteBuilder Admin'
  33. );
  34. }
  35. function siteBuilder_ConfigOptions() {
  36. siteBuilderCreateTables();
  37. return ["BuilderURL" => [
  38. "FriendlyName" => "Builder URL", # Full Builder URL (prefix//hostname:port/)
  39. "Type" => "text", # Text Box
  40. "Size" => "25", # Defines the Field Width
  41. "Description" => "Full Builder URL (prefix//hostname:port/)",
  42. "Default" => "https://builder.thurdata.ch/",
  43. ],
  44. ];
  45. }
  46. /**
  47. * Test connection to a siteBuilder server with the given server parameters.
  48. *
  49. * Allows an admin user to verify that an API connection can be
  50. * successfully made with the given configuration parameters for a
  51. * server.
  52. *
  53. * When defined in a module, a test connection button will appear
  54. * alongside the server type dropdown when adding or editing an
  55. * existing server.
  56. *
  57. * @param array $params common module parameters
  58. *
  59. * @see https://developers.whmcs.com/provisioning-modules/module-parameters/
  60. *
  61. * @return array
  62. */
  63. function siteBuilder_Testconnection($params) {
  64. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  65. $response = $siteBuilder->ping($params['serverusername'], $params['serverpassword']);
  66. if($response['response']['answer'] == 'pong') {
  67. return array(
  68. 'success' => true,
  69. 'error' => '',
  70. );
  71. }
  72. return array(
  73. 'success' => false,
  74. 'error' => $response,
  75. );
  76. }
  77. /**
  78. * Provision a new account of a siteBuilder server.
  79. *
  80. * Attempt to provision a new siteBuilder account. This is
  81. * called any time provisioning is requested inside of WHMCS. Depending upon the
  82. * configuration, this can be any of:
  83. * * When a new order is placed
  84. * * When an invoice for a new order is paid
  85. * * Upon manual request by an admin user
  86. *
  87. * @param array $params common module parameters
  88. *
  89. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  90. *
  91. * @return string 'success' or an error message
  92. */
  93. function siteBuilder_CreateAccount($params) {
  94. $username = strtolower(substr($params['clientsdetails']['firstname'],0,2) . substr($params['clientsdetails']['lastname'],0,3)) . $params['serviceid'];
  95. $userdomain = $params['domain'];
  96. try {
  97. Capsule::table('tblhosting')
  98. ->where('id', '=', $params['serviceid'])
  99. ->update(
  100. array(
  101. 'username' => $username,
  102. 'domain' => $userdomain,
  103. )
  104. );
  105. } catch (\Exception $e) {
  106. logModuleCall(
  107. 'siteBuilder',
  108. __FUNCTION__,
  109. $params,
  110. 'Error: could save username & domain in database',
  111. $e->getMessage()
  112. );
  113. return 'Error: could save username & password in database';
  114. }
  115. try {
  116. Capsule::table('sitePro_acc')
  117. ->insert(
  118. array(
  119. 'account' => $username,
  120. 'pid' => $params['serviceid'],
  121. 'enabled' => true,
  122. )
  123. );
  124. } catch (\Exception $e) {
  125. logModuleCall(
  126. 'siteBuilder',
  127. __FUNCTION__,
  128. $params,
  129. 'Error: could save username & serviceid in database',
  130. $e->getMessage()
  131. );
  132. return 'Error: could save username & serviceid in database';
  133. }
  134. try {
  135. Capsule::table('sitePro_dom')
  136. ->insert(
  137. array(
  138. 'relid' => $params['serviceid'],
  139. 'domain' => $userdomain,
  140. 'enabled' => true,
  141. )
  142. );
  143. } catch (\Exception $e) {
  144. logModuleCall(
  145. 'siteBuilder',
  146. __FUNCTION__,
  147. $params,
  148. 'Error: could save domain & serviceid in database',
  149. $e->getMessage()
  150. );
  151. return 'Error: could save domain & serviceid in database';
  152. }
  153. if ($params["server"] == 1) {
  154. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  155. $response = $siteBuilder->deployDev($username, $domain, $params['serverusername'], $params['serverpassword']);
  156. }
  157. if($response['status'] != '200') {
  158. return 'Error: ' . $response['response'];
  159. }
  160. return 'success';
  161. }
  162. /**
  163. * Removes a siteBuilder account.
  164. *
  165. * Called when a termination is requested. This can be invoked automatically for
  166. * overdue products if enabled, or requested manually by an admin user.
  167. *
  168. * @param array $params common module parameters
  169. *
  170. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  171. *
  172. * @return string 'success' or an error message
  173. */
  174. function siteBuilder_TerminateAccount($params) {
  175. try {
  176. Capsule::table('sitePro_dom')
  177. ->where('relid',$params['serviceid'])
  178. ->delete();
  179. } catch (\Exception $e) {
  180. logModuleCall(
  181. 'siteBuilder',
  182. __FUNCTION__,
  183. $params,
  184. 'Error: could remove domains from database',
  185. $e->getMessage()
  186. );
  187. return 'Error: could remove domains from database';
  188. }
  189. try {
  190. Capsule::table('sitePro_acc')
  191. ->where('account',$params['username'])
  192. ->delete();
  193. } catch (\Exception $e) {
  194. logModuleCall(
  195. 'siteBuilder',
  196. __FUNCTION__,
  197. $params,
  198. 'Error: could remove account from database',
  199. $e->getMessage()
  200. );
  201. return 'Error: could remove account from database';
  202. }
  203. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  204. $response = $siteBuilder->terminate($params['domain'],$params['username']);
  205. if($response['status'] != '200') {
  206. return 'Error: ' . $response['response'];
  207. }
  208. return 'success';
  209. }
  210. /**
  211. * Set a siteBuilder account to status inactive.
  212. *
  213. * Called when a suspension is requested. This is invoked automatically by WHMCS
  214. * when a product becomes overdue on payment or can be called manually by admin
  215. * user.
  216. *
  217. * @param array $params common module parameters
  218. *
  219. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  220. *
  221. * @return string 'success' or an error message
  222. */
  223. function siteBuilder_SuspendAccount($params) {
  224. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  225. $status = $siteBuilder->isprodenabled($params['domain'],$params['username']);
  226. if($status['status'] != '200') {
  227. return 'Error: ' . $status['error_msg'];
  228. }
  229. if($response['response']['isenabled'] == 'YES'){
  230. $response = $siteBuilder->disableprod($params['domain'],$params['username']);
  231. if($response['status'] != '200') {
  232. return 'Error: ' . $response['error_msg'];
  233. }
  234. }
  235. try {
  236. Capsule::table('sitePro_acc')
  237. ->where('account',$params['username'])
  238. ->update(array(
  239. 'enabled' => false,
  240. ));
  241. } catch (\Exception $e) {
  242. logModuleCall(
  243. 'siteBuilder',
  244. __FUNCTION__,
  245. $params,
  246. 'Error: could remove account from database',
  247. $e->getMessage()
  248. );
  249. return 'Error: could remove account from database';
  250. }
  251. return 'success';
  252. }
  253. /**
  254. * Set a siteBuilder account to status active.
  255. *
  256. * Called when an un-suspension is requested. This is invoked
  257. * automatically upon payment of an overdue invoice for a product, or
  258. * can be called manually by admin user.
  259. *
  260. * @param array $params common module parameters
  261. *
  262. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  263. *
  264. * @return string 'success' or an error message
  265. */
  266. function siteBuilder_UnsuspendAccount($params) {
  267. try {
  268. Capsule::table('sitePro_acc')
  269. ->where('account',$params['username'])
  270. ->update(array(
  271. 'enabled' => true,
  272. ));
  273. } catch (\Exception $e) {
  274. logModuleCall(
  275. 'siteBuilder',
  276. __FUNCTION__,
  277. $params,
  278. 'Error: could remove account from database',
  279. $e->getMessage()
  280. );
  281. return 'Error: could remove account from database';
  282. }
  283. return 'success';
  284. }
  285. /**
  286. * Client area output logic handling.
  287. *
  288. * This function is used to define module specific client area output. It should
  289. * return an array consisting of a template file and optional additional
  290. * template variables to make available to that template.
  291. *
  292. * @param array $params common module parameters
  293. *
  294. * @see https://developers.whmcs.com/provisioning-modules/client-area-output/
  295. *
  296. * @return array
  297. */
  298. function siteBuilder_ClientArea($params) {
  299. $clientInfo = array('moduleclientarea' => '1');
  300. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  301. $response = $siteBuilder->getSSLDays($params['domain'],$params['username']);
  302. if($response['status'] == 'OK') {
  303. $sslSites = array();
  304. foreach($response['msj'] as $sslSite) {
  305. $sslSites[$sslSite['ssl']] = array(
  306. 'auotssl' => $sslSite['autossl'],
  307. 'expire' => $sslSite['exp'],
  308. );
  309. }
  310. }
  311. $response = $siteBuilder->getAccount($params['username']);
  312. if($response['status'] != 'OK') {
  313. logModuleCall(
  314. 'siteBuilder',
  315. __FUNCTION__,
  316. $params,
  317. 'debug',
  318. $response
  319. );
  320. }
  321. if(siteBuilderCheckLimit($params,'domains')){
  322. $clientInfo['domainlimit'] = 1;
  323. } else {
  324. $clientInfo['domainlimit'] = 0;
  325. };
  326. if(siteBuilderCheckLimit($params,'subdomins')){
  327. $clientInfo['subdomainlimit'] = 1;
  328. } else {
  329. $clientInfo['subdomainlimit'] = 0;
  330. };
  331. $clientInfo['db_max'] = $response['result']['account_info']['db_max'];
  332. $clientInfo['db_used'] = $response['result']['account_info']['db_used'];
  333. $clientInfo['ftp_accounts'] = $response['result']['account_info']['ftp_accounts'];
  334. $clientInfo['ftp_accounts_used'] = $response['result']['account_info']['ftp_accounts_used'];
  335. $clientInfo['addons_domains'] = $response['result']['account_info']['addons_domains'];
  336. $clientInfo['addons_domains_used'] = $response['result']['account_info']['addons_domains_used'];
  337. $clientInfo['sub_domains'] = $response['result']['account_info']['sub_domains'];
  338. $clientInfo['sub_domains_used'] = $response['result']['account_info']['sub_domains_used'];
  339. $clientInfo['space_usage'] = $response['result']['account_info']['space_usage'];
  340. $clientInfo['space_disk'] = $response['result']['account_info']['space_disk'];
  341. $clientInfo['bandwidth_used'] = $response['result']['account_info']['bandwidth_used'];
  342. $clientInfo['bandwidth'] = $response['result']['account_info']['bandwidth'];
  343. $domains = $response['result']['domains'];
  344. $subDomains = $response['result']['subdomins'];
  345. $clientInfo['domains'] = array();
  346. foreach($domains as $domain) {
  347. if($domain['path'] == '/home/' . $params['username'] . '/public_html') {
  348. $clientInfo['mgmtDomain'] = $domain['domain'];
  349. $clientInfo['mgmtEmail'] = $domain['email'];
  350. } else {
  351. $domain['relpath'] = str_replace('/home/' . $params['username'], '~', $domain['path']);
  352. if(array_key_exists($domain['domain'], $sslSites)) {
  353. $domain['ssl'] = 1;
  354. $domain['sslexpire'] = $sslSites[$domain['domain']]['expire'];
  355. $domain['autossl'] = $sslSites[$domain['domain']]['auotssl'];
  356. }
  357. if(siteBuilderCheckA($domain['domain'],$params['serverip'],$params['configoption5']) == 1) {
  358. $domain['DNS'] = 1;
  359. }
  360. $domain['domainNS'] = siteBuilderCheckSOA($domain['domain'],$params['configoption5']);
  361. $domain['subdomains'] = array();
  362. foreach($subDomains as $subDomain) {
  363. if($subDomain['domain'] == $domain['domain']) {
  364. $subFQDN = $subDomain['subdomain'] . '.' . $subDomain['domain'];
  365. $subDomain['relpath'] = str_replace('/home/' . $params['username'], '~', $subDomain['path']);
  366. if(array_key_exists($subFQDN, $sslSites)) {
  367. $subDomain['ssl'] = 1;
  368. $subDomain['sslexpire'] = $sslSites[$subFQDN]['expire'];
  369. $subDomain['autossl'] = $sslSites[$subFQDN]['auotssl'];
  370. } else {
  371. unset($subDomain['ssl']);
  372. unset($subDomain['sslexpire']);
  373. unset($subDomain['autossl']);
  374. }
  375. if(siteBuilderCheckA($subFQDN,$params['serverip'],$params['configoption5']) == 1) {
  376. $subDomain['DNS'] = 1;
  377. } else {
  378. unset($subDomain['DNS']);
  379. }
  380. array_push($domain['subdomains'], $subDomain);
  381. }
  382. }
  383. array_push($clientInfo['domains'], $domain);
  384. }
  385. }
  386. return array(
  387. 'tabOverviewReplacementTemplate' => 'clientarea',
  388. 'vars' => $clientInfo,
  389. );
  390. }
  391. /**
  392. * Perform single sign-on for a siteBuilder account.
  393. *
  394. * When successful, returns a URL to which the user should be redirected.
  395. *
  396. * @param array $params common module parameters
  397. *
  398. * @see https://developers.whmcs.com/provisioning-modules/single-sign-on/
  399. *
  400. * @return array
  401. */
  402. function siteBuilder_ServiceSingleSignOn($params) {
  403. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  404. $response = $siteBuilder->getLoginLink($params['username']);
  405. if($response['status'] == 'OK') {
  406. $link = $response['msj']['details'];
  407. $linkautologin = $link[0]['url'];
  408. return array(
  409. 'success' => true,
  410. 'redirectTo' => $linkautologin,
  411. );
  412. } else {
  413. return array(
  414. 'success' => false,
  415. 'redirectTo' => '',
  416. );
  417. }
  418. }
  419. /**
  420. * Change the password for a siteBuilder account.
  421. *
  422. * Called when a password change is requested. This can occur either due to a
  423. * client requesting it via the client area or an admin requesting it from the
  424. * admin side.
  425. *
  426. * This option is only available to client end users when the product is in an
  427. * active status.
  428. *
  429. * @param array $params common module parameters
  430. *
  431. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  432. *
  433. * @return string "success" or an error message
  434. */
  435. function siteBuilder_ChangePassword($params) {
  436. $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
  437. $response = $siteBuilder->changePass(array('user' => $params['username'], 'password' => $params['password']));
  438. if($response['status'] != 'OK') {
  439. return 'Error: ' . $response['error_msg'];
  440. }
  441. return 'success';
  442. }
  443. /**
  444. * Upgrade or downgrade a siteBuilder account by package.
  445. *
  446. * Called to apply any change in product assignment or parameters. It
  447. * is called to provision upgrade or downgrade orders, as well as being
  448. * able to be invoked manually by an admin user.
  449. *
  450. * This same function is called for upgrades and downgrades of both
  451. * products and configurable options.
  452. *
  453. * @param array $params common module parameters
  454. *
  455. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  456. *
  457. * @return string "success" or an error message
  458. */
  459. function siteBuilder_ChangePackage($params) {
  460. $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
  461. $data = array(
  462. 'user' => $params['username'],
  463. 'email' => $params['clientsdetails']['email'],
  464. 'package' => $params['configoption1'],
  465. 'inode' => (int) $params["configoption2"],
  466. 'openfiles' => (int) $params["configoption3"],
  467. 'processes' => (int) $params["configoption4"],
  468. 'server_ips'=> $params["serverip"],
  469. );
  470. $response = $siteBuilder->modifyAccount($data);
  471. if($response['status'] != 'OK') {
  472. return 'Error: ' . $response['error_msg'];
  473. }
  474. return 'success';
  475. }
  476. /**
  477. * Usage Update
  478. *
  479. * Important: Runs daily per server not per product
  480. * Run Manually: /admin/reports.php?report=disk_usage_summary&action=updatestats
  481. * @param array $params common module parameters
  482. *
  483. * @see https://developers.whmcs.com/provisioning-modules/usage-update/
  484. */
  485. function siteBuilder_UsageUpdate($params) {
  486. $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
  487. $response = $siteBuilder->getAllAccounts();
  488. if($response['status'] == 'OK'){
  489. $results = $response['msj'];
  490. for($i = 0; $i < count($results); $i++){
  491. if($results[$i]['diskusage'] == '') {
  492. $diskusage = 0;
  493. } else {
  494. $diskusage = trim($results[$i]['diskusage']);
  495. }
  496. if($results[$i]['disklimit'] == '') {
  497. $disklimit = 0;
  498. } else {
  499. $disklimit = trim($results[$i]['disklimit']);
  500. }
  501. if($results[$i]['bandwidth'] == '') {
  502. $bandwidth = 0;
  503. } else {
  504. $bandwidth =trim($results[$i]['bandwidth']);
  505. }
  506. if($results[$i]['bwlimit'] == '') {
  507. $bwlimit = 0;
  508. } else {
  509. $bwlimit = trim($results[$i]['bwlimit']);
  510. }
  511. $domain = trim($results[$i]['domain']);
  512. try {
  513. \WHMCS\Database\Capsule::table('tblhosting')
  514. ->where('server', $params['serverid'])
  515. ->where('domain', $domain)
  516. ->update([
  517. 'diskusage' => $diskusage,
  518. 'disklimit' => $disklimit,
  519. 'bwusage' => $bandwidth,
  520. 'bwlimit' => $bwlimit,
  521. 'lastupdate' => date('Y-m-d H:i:S'),
  522. ]);
  523. } catch (\Exception $e) {
  524. logActivity('ERROR: Unable to update server usage: ' . $e->getMessage());
  525. }
  526. }
  527. }
  528. }
  529. /**
  530. * Additional actions a client user can invoke.
  531. *
  532. * Define additional actions a client user can perform for an instance of a
  533. * product/service.
  534. *
  535. * Any actions you define here will be automatically displayed in the available
  536. * list of actions within the client area.
  537. *
  538. * @return array
  539. */
  540. function siteBuilder_ClientAreaCustomButtonArray ($params) {
  541. if(siteBuilderCheckLimit($params, 'domains')) {
  542. return array();
  543. }
  544. return array(
  545. 'Neue Domain' => 'newDomain',
  546. );
  547. }
  548. /**
  549. * Additional actions a client user can invoke.
  550. *
  551. * Define additional actions a client user is allowed to perform for an instance of a
  552. * product/service.
  553. *
  554. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  555. *
  556. * @return array
  557. */
  558. function siteBuilder_ClientAreaAllowedFunctions() {
  559. return array(
  560. "Enable SSL" => "enableSSL",
  561. "Renew SSL" => "renewSSL",
  562. "Set DNS" => "setDNS",
  563. "Unset DNS" => "unsetDNS",
  564. "Confirm Enable SSL" => "enableSSLConfirm",
  565. "Confirm Renew SSL" => "renewSSLConfirm",
  566. "Confirm Set DNS" => "setDNSConfirm",
  567. "Confirm Unset DNS" => "unsetDNSConfirm",
  568. "Info DNS" => "infoDNS",
  569. "Info SSL" => "infoSSL",
  570. "Add Domain" => "addDomain",
  571. "new Domain" => "newDomain",
  572. "Add Subdomain" => "addSubdomain",
  573. "New Subdomain" => "newSubdomain",
  574. "Confirm Delete Domain" => "delDomainConfirm",
  575. "Delete Domain" => "delDomain",
  576. "Confirm Delete Subdomain" => "delSubdomainConfirm",
  577. "Delete Subdomain" => "delSubdomain",
  578. );
  579. }
  580. /**
  581. * Opens a form to add a new domain.
  582. *
  583. * @param array $params common module parameters
  584. *
  585. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  586. *
  587. * @return array template information
  588. */
  589. function siteBuilder_newDomain($params) {
  590. return array(
  591. 'breadcrumb' => array(
  592. 'clientarea.php?action=productdetails&id=' . $params['serviceid'] . '&modop=custom&a=newDomain' => 'Neue Domain',
  593. ),
  594. 'templatefile' => 'siteBuilder_add_domain',
  595. );
  596. }
  597. /**
  598. * Adds a new domain to a siteBuilder account.
  599. *
  600. * @param array $params common module parameters
  601. *
  602. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  603. *
  604. * @return string "success" or an error message
  605. */
  606. function siteBuilder_addDomain($params) {
  607. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  608. return 'Error: invalid domain name';
  609. }
  610. if(siteBuilderCheckLimit($params, 'domains')) {
  611. return 'Error: domain limit exceeded';
  612. }
  613. $vars['user'] = $params['username'];
  614. $vars['name'] = $_POST['d'];
  615. $vars['type'] = 'domain';
  616. $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
  617. $response = $siteBuilder->addDomain($vars);
  618. if($response['status'] != 'OK') {
  619. return 'Error: ' . $response['error_msg'];
  620. }
  621. return 'success';
  622. }
  623. /**
  624. * Opens a form to add a new subdomain to a domain.
  625. *
  626. * @param array $params common module parameters
  627. *
  628. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  629. *
  630. * @return array template information
  631. */
  632. function siteBuilder_newSubdomain($params) {
  633. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  634. return 'Error: invalid domain name';
  635. }
  636. return array(
  637. 'breadcrumb' => array(
  638. 'clientarea.php?action=productdetails&id=' . $params['serviceid'] . '&modop=custom&a=newSubdomain' => 'Neue Subdomain',
  639. ),
  640. 'templatefile' => 'siteBuilder_add_subdomain',
  641. 'vars' => array(
  642. 'domainselected' => $_POST['d'],
  643. ),
  644. );
  645. }
  646. /**
  647. * Adds a new subdomain to domain of a siteBuilder account.
  648. *
  649. * @param array $params common module parameters
  650. *
  651. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  652. *
  653. * @return string "success" or an error message
  654. */
  655. function siteBuilder_addSubdomain($params) {
  656. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  657. return 'Error: invalid domain name';
  658. }
  659. if(!filter_var($_POST['s'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  660. return 'Error: invalid subdomain name';
  661. }
  662. if($_POST['s'] == 'www') {
  663. return 'Error: default Subdomain www wurde bereits automatisch erstellt' ;
  664. }
  665. if(siteBuilderCheckLimit($params, 'subdomins')) {
  666. return 'Error: subdomain limit exceeded';
  667. }
  668. $vars['user'] = $params['username'];
  669. $vars['name'] = $_POST['s'] . '.' . $_POST['d'];
  670. $vars['type'] = 'subdomain';
  671. $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
  672. $response = $siteBuilder->addDomain($vars);
  673. if($response['status'] != 'OK') {
  674. return 'Error: ' . $response['error_msg'];
  675. }
  676. return 'success';
  677. }
  678. /**
  679. * Opens a form to delete a domain from a siteBuilder account.
  680. *
  681. * @param array $params common module parameters
  682. *
  683. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  684. *
  685. * @return array template information
  686. */
  687. function siteBuilder_delDomainConfirm($params) {
  688. return array(
  689. 'templatefile' => 'siteBuilder_del_domain_confirm',
  690. 'vars' => array(
  691. 'deldomain' => $_POST['d'],
  692. ),
  693. );
  694. }
  695. /**
  696. * Removes a domain from a siteBuilder account.
  697. *
  698. * @param array $params common module parameters
  699. *
  700. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  701. *
  702. * @return string "success" or an error message
  703. */
  704. function siteBuilder_delDomain($params) {
  705. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  706. return 'Error: invalid domain name';
  707. }
  708. $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
  709. $response = $siteBuilder->getAccount($params['username']);
  710. if($response['status'] != 'OK') {
  711. logModuleCall(
  712. 'siteBuilder',
  713. __FUNCTION__,
  714. $params,
  715. 'debug',
  716. $response
  717. );
  718. }
  719. $domains = $response['result']['domains'];
  720. $clientdomains = array();
  721. foreach($domains as $domain){
  722. if($domain['domain'] != $params['domain']) {
  723. array_push($clientdomains, $domain['domain']);
  724. }
  725. }
  726. if(!in_array($_POST['d'], $clientdomains)) {
  727. logModuleCall(
  728. 'siteBuilder',
  729. __FUNCTION__,
  730. $_POST,
  731. 'POST DATA VIOLATION',
  732. $params
  733. );
  734. return 'Error: ' . $_POST['d'] . ' not in client domains';
  735. }
  736. // do delete domain
  737. $vars['user'] = $params['username'];
  738. $vars['name'] = $_POST['d'];
  739. $vars['type'] = 'domain';
  740. $response = $siteBuilder->deleteDomain($vars);
  741. if($response['status'] != 'OK') {
  742. return 'Error: ' . $response['error_msg'];
  743. }
  744. return 'success';
  745. }
  746. /**
  747. * Opens a form to delete a subdomain from domain of a siteBuilder account.
  748. *
  749. * @param array $params common module parameters
  750. *
  751. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  752. *
  753. * @return array template information
  754. */
  755. function siteBuilder_delSubdomainConfirm($params) {
  756. return array(
  757. 'templatefile' => 'siteBuilder_del_subdomain_confirm',
  758. 'vars' => array(
  759. 'delsubdomain' => $_POST['d'],
  760. ),
  761. );
  762. }
  763. /**
  764. * Removes a subdomain from a domain of a siteBuilder account.
  765. *
  766. * @param array $params common module parameters
  767. *
  768. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  769. *
  770. * @return string "success" or an error message
  771. */
  772. function siteBuilder_delSubdomain($params) {
  773. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  774. return 'Error: invalid domain name';
  775. }
  776. $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
  777. $response = $siteBuilder->getAccount($params['username']);
  778. if($response['status'] != 'OK') {
  779. logModuleCall(
  780. 'siteBuilder',
  781. __FUNCTION__,
  782. $params,
  783. 'debug',
  784. $response
  785. );
  786. }
  787. $subdomains = $response['result']['subdomins'];
  788. $clientsubdomains = array();
  789. foreach($subdomains as $subdomain){
  790. if($subdomain['domain'] != $params['domain']) {
  791. array_push($clientsubdomains, $subdomain['subdomain'] . "." . $subdomain['domain']);
  792. }
  793. }
  794. if(!in_array($_POST['d'], $clientsubdomains)) {
  795. logModuleCall(
  796. 'siteBuilder',
  797. __FUNCTION__,
  798. $_POST,
  799. 'POST DATA VIOLATION',
  800. $params
  801. );
  802. return 'Error: ' . $_POST['d'] . ' not in client subdomains';
  803. }
  804. // do delete subdomain
  805. $vars['user'] = $params['username'];
  806. $vars['name'] = $_POST['d'];
  807. $vars['type'] = 'subdomain';
  808. $response = $siteBuilder->deleteDomain($vars);
  809. if($response['status'] != 'OK') {
  810. return 'Error: ' . $response['error_msg'];
  811. }
  812. return 'success';
  813. }
  814. /**
  815. * Opens a form to enable SSL for a subdomain or domain of a siteBuilder account.
  816. *
  817. * @param array $params common module parameters
  818. *
  819. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  820. *
  821. * @return array template information
  822. */
  823. function siteBuilder_enableSSLConfirm($params) {
  824. return array(
  825. 'templatefile' => 'siteBuilder_enable_SSL_confirm',
  826. 'vars' => array(
  827. 'SSLdomain' => $_POST['d'],
  828. ),
  829. );
  830. }
  831. /**
  832. * Aktivate siteBuilder AutoSSL for a subdomain or domain of a siteBuilder account.
  833. *
  834. * @param array $params common module parameters
  835. *
  836. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  837. *
  838. * @return string "success" or an error message
  839. */
  840. function siteBuilder_enableSSL($params) {
  841. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  842. return 'Error: invalid domain name';
  843. }
  844. $vars['user'] = $params['username'];
  845. $vars['name'] = $_POST['d'];
  846. $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
  847. $response = $siteBuilder->addAutoSSL($vars);
  848. if($response['status'] != 'OK') {
  849. return 'Error: ' . $response['error_msg'];
  850. }
  851. return 'success';
  852. }
  853. /**
  854. * Opens a form to renew a SSL certificate for a subdomain or domain of a siteBuilder account.
  855. *
  856. * @param array $params common module parameters
  857. *
  858. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  859. *
  860. * @return array template information
  861. */
  862. function siteBuilder_renewSSLConfirm($params) {
  863. return array(
  864. 'templatefile' => 'siteBuilder_renew_SSL_confirm',
  865. 'vars' => array(
  866. 'SSLdomain' => $_POST['d'],
  867. ),
  868. );
  869. }
  870. /**
  871. * Renews a SSL certificate for a subdomain or domain of a siteBuilder account.
  872. *
  873. * @param array $params common module parameters
  874. *
  875. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  876. *
  877. * @return string "success" or an error message
  878. */
  879. function siteBuilder_renewSSL($params) {
  880. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  881. return 'Error: invalid domain name';
  882. }
  883. $vars['user'] = $params['username'];
  884. $vars['name'] = $_POST['d'];
  885. $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
  886. $response = $siteBuilder->updateAutoSSL($vars);
  887. if($response['status'] != 'OK') {
  888. return 'Error: ' . $response['error_msg'];
  889. }
  890. return 'success';
  891. }
  892. /**
  893. * Opens a form to set a DNS record for a subdomain or domain of a siteBuilder account.
  894. *
  895. * @param array $params common module parameters
  896. *
  897. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  898. *
  899. * @return array template information
  900. */
  901. function siteBuilder_setDNSConfirm($params) {
  902. if(isset($_POST['s'])){
  903. return array(
  904. 'templatefile' => 'siteBuilder_set_DNS_confirm',
  905. 'vars' => array(
  906. 'DNSdomain' => $_POST['d'],
  907. 'DNSsubdomain' => $_POST['s'],
  908. ),
  909. );
  910. }
  911. return array(
  912. 'templatefile' => 'siteBuilder_set_DNS_confirm',
  913. 'vars' => array(
  914. 'DNSdomain' => $_POST['d'],
  915. ),
  916. );
  917. }
  918. /**
  919. * Opens a form to unsset a DNS record for a subdomain or domain of a siteBuilder account.
  920. *
  921. * @param array $params common module parameters
  922. *
  923. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  924. *
  925. * @return array template information
  926. */
  927. function siteBuilder_unsetDNSConfirm($params) {
  928. if(isset($_POST['s'])){
  929. return array(
  930. 'templatefile' => 'siteBuilder_unset_DNS_confirm',
  931. 'vars' => array(
  932. 'DNSdomain' => $_POST['d'],
  933. 'DNSsubdomain' => $_POST['s'],
  934. ),
  935. );
  936. }
  937. return array(
  938. 'templatefile' => 'siteBuilder_unset_DNS_confirm',
  939. 'vars' => array(
  940. 'DNSdomain' => $_POST['d'],
  941. ),
  942. );
  943. }
  944. /**
  945. * Update a DNS zone for a domain setting a new record for a domain or subdomain of a siteBuilder account.
  946. *
  947. * @param array $params common module parameters
  948. *
  949. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  950. *
  951. * @return string "success" or an error message
  952. */
  953. function siteBuilder_setDNS($params) {
  954. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  955. return 'Error: invalid domain name';
  956. }
  957. $domainName = $_POST['d'];
  958. $zoneRecords = array();
  959. if(isset($_POST['s'])){
  960. if(!filter_var($_POST['s'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  961. return 'Error: invalid subdomain name';
  962. }
  963. $hostName = $_POST['s'] . '.' . $domainName . '.';
  964. $newRecord = array(
  965. 'line' => $hostName.'|A|0',
  966. 'name' => $hostName,
  967. 'type' => 'A',
  968. 'class' => 'IN',
  969. 'data' => array(
  970. 'address' => $params['serverip'],
  971. ),
  972. );
  973. array_push($zoneRecords, $newRecord);
  974. } else {
  975. $hostName = $domainName . '.';
  976. $domainRecord = array(
  977. 'line' => $hostName.'|A|0',
  978. 'name' => $hostName,
  979. 'type' => 'A',
  980. 'class' => 'IN',
  981. 'data' => array(
  982. 'address' => $params['serverip'],
  983. ),
  984. );
  985. array_push($zoneRecords, $domainRecord);
  986. $wwwRecord = array(
  987. 'line' => 'www'.$hostName.'|A|0',
  988. 'name' => 'www'.$hostName,
  989. 'type' => 'A',
  990. 'class' => 'IN',
  991. 'data' => array(
  992. 'address' => $params['serverip'],
  993. ),
  994. );
  995. array_push($zoneRecords, $wwwRecord);
  996. }
  997. $zoneIDcollection = Capsule::table('dns_manager2_zone')
  998. ->select('id')
  999. ->where('name', '=', $domainName)
  1000. ->where('clientid', '=', $params['userid'])
  1001. ->get();
  1002. $zoneIDobj = $zoneIDcollection[0];
  1003. $zoneID = $zoneIDobj->{'id'};
  1004. if(!isset($zoneID)) {
  1005. return 'Error: Zone for domain ' . $domainName . ' or not owned by client';
  1006. }
  1007. $dnsZone = localAPI('dnsmanager', array( 'dnsaction' => 'getZone', 'zone_id' => $zoneID));
  1008. foreach($dnsZone['data']->records as $record) {
  1009. if(($record->name != $hostName) || ($record->type != 'A' && $record->type != 'CNAME')) {
  1010. array_push($zoneRecords, $record);
  1011. };
  1012. }
  1013. $result = localAPI('dnsmanager' ,
  1014. array(
  1015. 'dnsaction' => 'updateZone',
  1016. 'zone_id' => $zoneID,
  1017. 'records' => $zoneRecords,
  1018. )
  1019. );
  1020. if($result['result'] != 'success') {
  1021. return 'Error: ' . $result['message'];
  1022. }
  1023. return 'success';
  1024. }
  1025. /**
  1026. * Removing a DNS record for a domain or subdomain of a siteBuilder account.
  1027. *
  1028. * @param array $params common module parameters
  1029. *
  1030. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  1031. *
  1032. * @return string "success" or an error message
  1033. */
  1034. function siteBuilder_unsetDNS($params) {
  1035. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  1036. return 'Error: invalid domain name';
  1037. }
  1038. $domainName = $_POST['d'];
  1039. $zoneRecords = array();
  1040. if(isset($_POST['s'])){
  1041. if(!filter_var($_POST['s'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  1042. return 'Error: invalid subdomain name';
  1043. }
  1044. $hostName = $_POST['s'] . '.' . $domainName . '.';
  1045. } else {
  1046. $hostName = $domainName . '.';
  1047. }
  1048. $zoneIDcollection = Capsule::table('dns_manager2_zone')
  1049. ->select('id')
  1050. ->where('name', '=', $domainName)
  1051. ->where('clientid', '=', $params['userid'])
  1052. ->get();
  1053. $zoneIDobj = $zoneIDcollection[0];
  1054. $zoneID = $zoneIDobj->{'id'};
  1055. if(!isset($zoneID)) {
  1056. return 'Error: Zone for domain ' . $domainName . ' or not owned by client';
  1057. }
  1058. $dnsZone = localAPI('dnsmanager', array( 'dnsaction' => 'getZone', 'zone_id' => $zoneID));
  1059. foreach($dnsZone['data']->records as $record) {
  1060. if(($record->name != $hostName) || ($record->type != 'A' && $record->type != 'CNAME')) {
  1061. array_push($zoneRecords, $record);
  1062. };
  1063. }
  1064. $result = localAPI('dnsmanager' ,
  1065. array(
  1066. 'dnsaction' => 'updateZone',
  1067. 'zone_id' => $zoneID,
  1068. 'records' => $zoneRecords,
  1069. )
  1070. );
  1071. if($result['result'] != 'success') {
  1072. return 'Error: ' . $result['message'];
  1073. }
  1074. return 'success';
  1075. }
  1076. /**
  1077. * Opens a form to inform about the DNS status of a subdomain or domain of a siteBuilder account.
  1078. *
  1079. * @param array $params common module parameters
  1080. *
  1081. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  1082. *
  1083. * @return array template information
  1084. */
  1085. function siteBuilder_infoDNS($params) {
  1086. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  1087. return 'Error: invalid domain name';
  1088. }
  1089. $siteBuildernameserver = siteBuilderCheckSOA($_POST['d'],$params['configoption5']);
  1090. return array(
  1091. 'templatefile' => 'siteBuilder_help_dns',
  1092. 'vars' => array(
  1093. 'infodomain' => $_POST['d'],
  1094. 'siteBuildernameserver' => $siteBuildernameserver,
  1095. ),
  1096. );
  1097. }
  1098. /**
  1099. * Opens a form to inform about the SSL status of a subdomain or domain of a siteBuilder account.
  1100. *
  1101. * @param array $params common module parameters
  1102. *
  1103. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  1104. *
  1105. * @return array template information
  1106. */
  1107. function siteBuilder_infoSSL($params) {
  1108. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  1109. return 'Error: invalid domain name';
  1110. }
  1111. return array(
  1112. 'templatefile' => 'siteBuilder_help_ssl',
  1113. 'vars' => array(
  1114. 'infodomain' => $_POST['d'],
  1115. ),
  1116. );
  1117. }
  1118. /**
  1119. * Ask nameservers for a IP adress of a given host.
  1120. *
  1121. * @param string $host hostname
  1122. * @param string $serverIP siteBuilder server IP
  1123. * @param string $nameserverIP polled name server IP
  1124. * @param int $recurse optional -> used to follow CNAME responses
  1125. *
  1126. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  1127. *
  1128. * @return bool
  1129. */
  1130. function siteBuilderCheckA($host, $serverIP, $nameserverIP, $recurse = 0) {
  1131. if($recurse > 3) {
  1132. return false;
  1133. }
  1134. $nameserver = array($nameserverIP);
  1135. # try NS1
  1136. $resolver = new Net_DNS2_Resolver(array('nameservers' => $nameserver));
  1137. try {
  1138. $result = $resolver->query($host, 'A');
  1139. } catch(Net_DNS2_Exception $e) {
  1140. # try default nameserver
  1141. $resolver = new Net_DNS2_Resolver();
  1142. try {
  1143. $result = $resolver->query($host, 'A');
  1144. } catch(Net_DNS2_Exception $e) {
  1145. logModuleCall(
  1146. 'siteBuilder',
  1147. __FUNCTION__,
  1148. $e,
  1149. 'DNS lookup exception',
  1150. $e->getMessage()
  1151. );
  1152. return false;
  1153. }
  1154. }
  1155. $hostA = $result->answer;
  1156. if($hostA[0]->type == 'CNAME') {
  1157. if(siteBuilderCheckA($hostA[0]->cname, $serverIP, $nameserverIP, $recurse++)) {
  1158. return true;
  1159. }
  1160. }
  1161. if($hostA[0]->type == 'A') {
  1162. if($hostA[0]->address == $serverIP){
  1163. return true;
  1164. }
  1165. }
  1166. return false;
  1167. }
  1168. /**
  1169. * Ask nameservers for the authority of a domain.
  1170. *
  1171. * @param string $domain domain name
  1172. * @param string $nameserverIP polled name server IP
  1173. * @param string $nameserverName name of the own namesever
  1174. *
  1175. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  1176. *
  1177. * @return string 'none' -> not registered, 'self' -> registered at own or the name of an other responsible nameserver
  1178. */
  1179. function siteBuilderCheckSOA($domain, $nameserverIP) {
  1180. $nameserver = array($nameserverIP);
  1181. # try NS1
  1182. $resolver = new Net_DNS2_Resolver(array('nameservers' => $nameserver));
  1183. try {
  1184. $result = $resolver->query($domain, 'SOA');
  1185. return 'self';
  1186. } catch(Net_DNS2_Exception $e) {
  1187. # try default NS
  1188. $resolver = new Net_DNS2_Resolver();
  1189. try {
  1190. $result = $resolver->query($domain, 'SOA');
  1191. } catch(Net_DNS2_Exception $e) {
  1192. return 'none';
  1193. }
  1194. }
  1195. return $result->answer[0]->mname;
  1196. }
  1197. /**
  1198. * Check limits for a service of an account .
  1199. *
  1200. * @param array $params common module parameters
  1201. * @param string $type domains|subdomins
  1202. *
  1203. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  1204. *
  1205. * @return bool true -> limit reached, false -> limit not reached
  1206. */
  1207. function siteBuilderCheckLimit($params, $type) {
  1208. $siteBuilder = new siteBuilder_Admin($params['serverhostname'], $params['serveraccesshash']);
  1209. $response = $siteBuilder->getQuota($params['username']);
  1210. if($response[$type]['sw'] < 1) {
  1211. return true;
  1212. }
  1213. return false;
  1214. }
  1215. /**
  1216. * Returns API Url .
  1217. *
  1218. * @param string $params common module parameters
  1219. * @param string $user
  1220. * @param string $params common module parameters
  1221. *
  1222. * @return string $apiUrl
  1223. */
  1224. function getSiteBuilderApiURL($params) {
  1225. $httpPrefix = $params['serversecure'] ? 'https://' : 'http://';
  1226. $serverPort = $params['serverport'] ? ':' . $params['serverport'] . '/' : '/';
  1227. return $httpPrefix . $params['serverhostname'] . $serverPort;
  1228. }
  1229. function siteBuilderCreateTables() {
  1230. // Create a new table.
  1231. if (!Capsule::schema()->hasTable('sitePro_acc')) {
  1232. try {
  1233. Capsule::schema()->create(
  1234. 'sitePro_acc',
  1235. function ($table) {
  1236. /** @var \Illuminate\Database\Schema\Blueprint $table */
  1237. $table->increments('id');
  1238. $table->string('account');
  1239. $table->integer('pid');
  1240. $table->boolean('enabled');
  1241. }
  1242. );
  1243. } catch (\Exception $e) {
  1244. echo "Unable to create sitePro_acc: {$e->getMessage()}";
  1245. }
  1246. }
  1247. if (!Capsule::schema()->hasTable('sitePro_dom')) {
  1248. try {
  1249. Capsule::schema()->create(
  1250. 'sitePro_dom',
  1251. function ($table) {
  1252. /** @var \Illuminate\Database\Schema\Blueprint $table */
  1253. $table->increments('id');
  1254. $table->integer('relid');
  1255. $table->string('domain');
  1256. $table->boolean('enabled');
  1257. }
  1258. );
  1259. } catch (\Exception $e) {
  1260. echo "Unable to create sitePro_dom: {$e->getMessage()}";
  1261. }
  1262. }
  1263. }