siteBuilder.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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. require_once(__DIR__ . '/api/SiteProApiClient.php');
  15. if (!defined('WHMCS')) {
  16. die('This file cannot be accessed directly');
  17. }
  18. /**
  19. * Define siteBuilder product metadata parameters.
  20. *
  21. * @see https://developers.whmcs.com/provisioning-modules/meta-data-params/
  22. *
  23. * @return array
  24. */
  25. function siteBuilder_MetaData() {
  26. return array(
  27. 'DisplayName' => 'ThurData SiteBuilder Provisioning',
  28. 'APIVersion' => '1.2',
  29. 'DefaultNonSSLPort' => '80',
  30. 'DefaultSSLPort' => '443',
  31. 'RequiresServer' => true,
  32. 'ServiceSingleSignOnLabel' => 'Login to siteBuilder',
  33. 'AdminSingleSignOnLabel' => 'Login to siteBuilder Admin'
  34. );
  35. }
  36. function siteBuilder_ConfigOptions() {
  37. siteBuilderCreateTables();
  38. return ["BuilderURL" => [
  39. "FriendlyName" => "Builder URL", # Full Builder URL (prefix//hostname:port/)
  40. "Type" => "text", # Text Box
  41. "Size" => "25", # Defines the Field Width
  42. "Description" => "Full Builder URL (prefix//hostname:port/)",
  43. "Default" => "https://builder.thurdata.ch/",
  44. ],
  45. ];
  46. }
  47. /**
  48. * Test connection to a siteBuilder 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 siteBuilder_Testconnection($params) {
  65. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  66. $response = $siteBuilder->ping($params['serverusername'], $params['serverpassword']);
  67. if($response['response']['answer'] == 'pong') {
  68. return array(
  69. 'success' => true,
  70. 'error' => '',
  71. );
  72. }
  73. return array(
  74. 'success' => false,
  75. 'error' => $response,
  76. );
  77. }
  78. /**
  79. * Provision a new account of a siteBuilder server.
  80. *
  81. * Attempt to provision a new siteBuilder account. This is
  82. * called any time provisioning is requested inside of WHMCS. Depending upon the
  83. * configuration, this can be any of:
  84. * * When a new order is placed
  85. * * When an invoice for a new order is paid
  86. * * Upon manual request by an admin user
  87. *
  88. * @param array $params common module parameters
  89. *
  90. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  91. *
  92. * @return string 'success' or an error message
  93. */
  94. function siteBuilder_CreateAccount($params) {
  95. $username = strtolower(substr($params['clientsdetails']['firstname'],0,2) . substr($params['clientsdetails']['lastname'],0,3)) . $params['serviceid'];
  96. $userdomain = $params['domain'];
  97. try {
  98. Capsule::table('tblhosting')
  99. ->where('id', '=', $params['serviceid'])
  100. ->update(
  101. array(
  102. 'username' => $username,
  103. 'domain' => $userdomain,
  104. )
  105. );
  106. } catch (\Exception $e) {
  107. logModuleCall(
  108. 'siteBuilder',
  109. __FUNCTION__,
  110. $params,
  111. 'Error: could save username & domain in database',
  112. $e->getMessage()
  113. );
  114. return 'Error: could save username & password in database';
  115. }
  116. try {
  117. Capsule::table('sitePro_acc')
  118. ->insert(
  119. array(
  120. 'account' => $username,
  121. 'pid' => $params['serviceid'],
  122. 'enabled' => true,
  123. )
  124. );
  125. } catch (\Exception $e) {
  126. logModuleCall(
  127. 'siteBuilder',
  128. __FUNCTION__,
  129. $params,
  130. 'Error: could save username & serviceid in database',
  131. $e->getMessage()
  132. );
  133. return 'Error: could save username & serviceid in database';
  134. }
  135. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  136. $response = $siteBuilder->create($params['username'], $params['domain'], $params['serverusername'], $params['serverpassword']);
  137. if($response['status'] != '200') {
  138. return 'Error: ' . $response['response'];
  139. }
  140. $response = $siteBuilder->init($params['username'], $params['domain'], $params['serverusername'], $params['serverpassword']);
  141. if($response['status'] != '200') {
  142. return 'Error: ' . $response['response'];
  143. }
  144. return 'success';
  145. }
  146. /**
  147. * Removes a siteBuilder account.
  148. *
  149. * Called when a termination is requested. This can be invoked automatically for
  150. * overdue products if enabled, or requested manually by an admin user.
  151. *
  152. * @param array $params common module parameters
  153. *
  154. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  155. *
  156. * @return string 'success' or an error message
  157. */
  158. function siteBuilder_TerminateAccount($params) {
  159. try {
  160. $active = Capsule::table('sitePro_acc')
  161. ->where('account',$params['username'])
  162. ->value('enabled');
  163. } catch (\Exception $e) {
  164. logModuleCall(
  165. 'siteBuilder',
  166. __FUNCTION__,
  167. $params,
  168. 'Error: could fetch account from database',
  169. $e->getMessage()
  170. );
  171. return 'Error: could fetch account from database';
  172. }
  173. if($active == true) {
  174. return 'Error: Account is active, please suspend account first';
  175. }
  176. // undeploy all related sites
  177. $sites = getSites($params['serviceid']);
  178. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  179. if(!empty($sites)) {
  180. foreach($sites as $site) {
  181. /* $response = $siteBuilder->undeploy($params['username'], $site, $params['serverusername'], $params['serverpassword']);
  182. if($response['status'] != '200') {
  183. return 'Error: ' . $response['response'];
  184. } */
  185. logModuleCall(
  186. 'siteBuilder',
  187. __FUNCTION__,
  188. $params,
  189. 'debug',
  190. $site
  191. );
  192. }
  193. try {
  194. Capsule::table('sitePro_site')
  195. ->where('relid',$params['serviceid'])
  196. ->delete();
  197. } catch (\Exception $e) {
  198. logModuleCall(
  199. 'siteBuilder',
  200. __FUNCTION__,
  201. $params,
  202. 'Error: could remove domains from database',
  203. $e->getMessage()
  204. );
  205. return 'Error: could remove domains from database';
  206. }
  207. }
  208. // terminate account
  209. $response = $siteBuilder->terminate($params['username'], $params['domain']);
  210. if($response['status'] != '200') {
  211. return 'Error: ' . $response['response'];
  212. }
  213. try {
  214. Capsule::table('sitePro_acc')
  215. ->where('account',$params['username'])
  216. ->delete();
  217. } catch (\Exception $e) {
  218. logModuleCall(
  219. 'siteBuilder',
  220. __FUNCTION__,
  221. $params,
  222. 'Error: could remove account from database',
  223. $e->getMessage()
  224. );
  225. return 'Error: could remove account from database';
  226. }
  227. return 'success';
  228. }
  229. /**
  230. * Set a siteBuilder account to status inactive.
  231. *
  232. * Called when a suspension is requested. This is invoked automatically by WHMCS
  233. * when a product becomes overdue on payment or can be called manually by admin
  234. * user.
  235. *
  236. * @param array $params common module parameters
  237. *
  238. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  239. *
  240. * @return string 'success' or an error message
  241. */
  242. function siteBuilder_SuspendAccount($params) {
  243. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  244. $status = $siteBuilder->isenabled($params['username'],$params['domain']);
  245. if($status['status'] != '200') {
  246. return 'Error: ' . $status['error_msg'];
  247. }
  248. if($response['response']['isenabled'] == 'YES'){
  249. $response = $siteBuilder->disable($params['username'],$params['domain']);
  250. if($response['status'] != '200') {
  251. return 'Error: ' . $response['error_msg'];
  252. }
  253. }
  254. try {
  255. Capsule::table('sitePro_acc')
  256. ->where('account',$params['username'])
  257. ->update(array(
  258. 'enabled' => false,
  259. ));
  260. } catch (\Exception $e) {
  261. logModuleCall(
  262. 'siteBuilder',
  263. __FUNCTION__,
  264. $params,
  265. 'Error: could not disable account in database',
  266. $e->getMessage()
  267. );
  268. return 'Error: could not disable account in database';
  269. }
  270. // disable all sites but not change status in DB for restoring
  271. $sites = getSites($params['serviceid']);
  272. if(!empty($sites)) {
  273. foreach($sites as $site) {
  274. /* $response = $siteBuilder->disable($params['username'], $site, $params['serverusername'], $params['serverpassword']);
  275. if($response['status'] != '200') {
  276. return 'Error: ' . $response['response'];
  277. } */
  278. logModuleCall(
  279. 'siteBuilder',
  280. __FUNCTION__,
  281. $params,
  282. 'debug',
  283. $site
  284. );
  285. }
  286. }
  287. return 'success';
  288. }
  289. /**
  290. * Set a siteBuilder account to status active.
  291. *
  292. * Called when an un-suspension is requested. This is invoked
  293. * automatically upon payment of an overdue invoice for a product, or
  294. * can be called manually by admin user.
  295. *
  296. * @param array $params common module parameters
  297. *
  298. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  299. *
  300. * @return string 'success' or an error message
  301. */
  302. function siteBuilder_UnsuspendAccount($params) {
  303. try {
  304. Capsule::table('sitePro_acc')
  305. ->where('account',$params['username'])
  306. ->update(array(
  307. 'enabled' => true,
  308. ));
  309. } catch (\Exception $e) {
  310. logModuleCall(
  311. 'siteBuilder',
  312. __FUNCTION__,
  313. $params,
  314. 'Error: could update account in database',
  315. $e->getMessage()
  316. );
  317. return 'Error: could update account in database';
  318. }
  319. // enable active sites
  320. $sites = getSites($params['serviceid']);
  321. if(!empty($sites)) {
  322. foreach($sites as $site) {
  323. /* $response = $siteBuilder->enable($params['username'], $site, $params['serverusername'], $params['serverpassword']);
  324. if($response['status'] != '200') {
  325. return 'Error: ' . $response['response'];
  326. } */
  327. logModuleCall(
  328. 'siteBuilder',
  329. __FUNCTION__,
  330. $params,
  331. 'debug',
  332. $site
  333. );
  334. }
  335. }
  336. return 'success';
  337. }
  338. /**
  339. * Client area output logic handling.
  340. *
  341. * This function is used to define module specific client area output. It should
  342. * return an array consisting of a template file and optional additional
  343. * template variables to make available to that template.
  344. *
  345. * @param array $params common module parameters
  346. *
  347. * @see https://developers.whmcs.com/provisioning-modules/client-area-output/
  348. *
  349. * @return array
  350. */
  351. function siteBuilder_ClientArea($params) {
  352. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  353. $clientInfo = array('moduleclientarea' => '1');
  354. $clientInfo['domain'] = $params['domain'];
  355. $accountObj = Capsule::table('sitePro_acc')
  356. ->where('pid', $params['serviceid'])
  357. ->get();
  358. $sitesObj = Capsule::table('sitePro_site')
  359. ->where('relid', $params['serviceid'])
  360. ->get();
  361. $clientInfo['sites'] = [];
  362. $sslProd = 0;
  363. $sslDev = 0;
  364. foreach($sitesObj as $site){
  365. $response = $siteBuilder->getSSLDays($site->name, $params['username']);
  366. if($response['status'] == '200') {
  367. $sslProd = $response['response']['ssl_remaining'];
  368. }
  369. $response = $siteBuilder->getSSLDays('dev.' . $site->name, $params['username']);
  370. if($response['status'] == '200') {
  371. $sslDev = $response['response']['ssl_remaining'];
  372. }
  373. array_push($clientInfo['sites'],['name' => $site->name, 'sslProd' => $sslProd, 'sslDev' => $sslDev]);
  374. }
  375. return array(
  376. 'tabOverviewReplacementTemplate' => 'clientarea',
  377. 'vars' => $clientInfo,
  378. );
  379. }
  380. /**
  381. * Perform single sign-on for a siteBuilder account.
  382. *
  383. * When successful, returns a URL to which the user should be redirected.
  384. *
  385. * @param array $params common module parameters
  386. *
  387. * @see https://developers.whmcs.com/provisioning-modules/single-sign-on/
  388. *
  389. * @return array
  390. */
  391. function siteBuilder_ServiceSingleSignOn($params) {
  392. }
  393. /**
  394. * Upgrade or downgrade a siteBuilder account by package.
  395. *
  396. * Called to apply any change in product assignment or parameters. It
  397. * is called to provision upgrade or downgrade orders, as well as being
  398. * able to be invoked manually by an admin user.
  399. *
  400. * This same function is called for upgrades and downgrades of both
  401. * products and configurable options.
  402. *
  403. * @param array $params common module parameters
  404. *
  405. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  406. *
  407. * @return string "success" or an error message
  408. */
  409. function siteBuilder_ChangePackage($params) {
  410. return 'success';
  411. }
  412. /**
  413. * Usage Update
  414. *
  415. * Important: Runs daily per server not per product
  416. * Run Manually: /admin/reports.php?report=disk_usage_summary&action=updatestats
  417. * @param array $params common module parameters
  418. *
  419. * @see https://developers.whmcs.com/provisioning-modules/usage-update/
  420. */
  421. function siteBuilder_UsageUpdate($params) {
  422. }
  423. /**
  424. * Additional actions a client user can invoke.
  425. *
  426. * Define additional actions a client user can perform for an instance of a
  427. * product/service.
  428. *
  429. * Any actions you define here will be automatically displayed in the available
  430. * list of actions within the client area.
  431. *
  432. * @return array
  433. */
  434. function siteBuilder_ClientAreaCustomButtonArray ($params) {
  435. return array(
  436. 'Neue Webseite' => 'newSite',
  437. );
  438. }
  439. /**
  440. * Additional actions a client user can invoke.
  441. *
  442. * Define additional actions a client user is allowed to perform for an instance of a
  443. * product/service.
  444. *
  445. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  446. *
  447. * @return array
  448. */
  449. function siteBuilder_ClientAreaAllowedFunctions() {
  450. return array(
  451. "Add Site" => "addSite",
  452. "new Site" => "newSite",
  453. "Confirm Delete Site" => "delSiteConfirm",
  454. "Delete Site" => "delSite",
  455. "Edit Site" => "editSite",
  456. 'Conform Revert Site' => 'revSiteConfirm',
  457. 'Revert Site' => 'revSite',
  458. 'Publish Site' => 'pubSite',
  459. 'Activate Prod' => 'enableProd',
  460. 'Deactivate Prod' => 'disableProd'
  461. );
  462. }
  463. /**
  464. * Opens a form to add a new domain.
  465. *
  466. * @param array $params common module parameters
  467. *
  468. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  469. *
  470. * @return array template information
  471. */
  472. function siteBuilder_newSite($params) {
  473. return array(
  474. 'breadcrumb' => array(
  475. 'clientarea.php?action=productdetails&id=' . $params['serviceid'] . '&modop=custom&a=newSite' => 'Neue Webseite',
  476. ),
  477. 'templatefile' => 'siteBuilder_new_site',
  478. );
  479. }
  480. /**
  481. * Adds a new domain to a siteBuilder account.
  482. *
  483. * @param array $params common module parameters
  484. *
  485. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  486. *
  487. * @return string "success" or an error message
  488. */
  489. function siteBuilder_addSite($params) {
  490. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  491. return 'Error: invalid site name';
  492. }
  493. $site = $_POST['d'] . '.' . $params['domain'];
  494. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  495. $response = $siteBuilder->deployDev($params['username'], $site, $params['serverusername'], $params['serverpassword']);
  496. if($response['status'] != '200') {
  497. return 'Error: ' . $response['response'];
  498. }
  499. try {
  500. Capsule::table('sitePro_site')
  501. ->insert(
  502. array(
  503. 'relid' => $params['serviceid'],
  504. 'name' => $site,
  505. 'enabled' => false,
  506. )
  507. );
  508. } catch (\Exception $e) {
  509. logModuleCall(
  510. 'siteBuilder',
  511. __FUNCTION__,
  512. $params,
  513. 'Error: could save site & serviceid in database',
  514. $e->getMessage()
  515. );
  516. return 'Error: could save site & serviceid in database';
  517. }
  518. return 'success';
  519. }
  520. function siteBuilder_editSite($params) {
  521. if(!filter_var($_POST['s'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  522. return 'Error: invalid site name';
  523. }
  524. $site = $_POST['s'];
  525. $api = new SiteProApiClient('https://builder.thurdata.ch/api/', 'apikey0', '993yVHwC05TLsx2JI2XFlAhkkPUxR6JbQUYbI.a5HiRtmNV9');
  526. // use this for enterprise licenses and change 'your-bulder-domain.com' to your builder domain
  527. //$api = new SiteProApiClient('http://your-bulder-domain.com/api/', 'your_api_username', 'your_api_password');
  528. try {
  529. // this call is used to open builder, so you need to set correct parameters to represent users website you want to open
  530. // this data usually comes from your user/hosting manager system
  531. $res = $api->remoteCall('requestLogin', array(
  532. 'type' => 'internal', // (required) 'internal'
  533. 'domain' => $site, // (required) domain of the user website you want to edit
  534. 'lang' => 'de', // (optional) 2-letter language code, set language code you whant builder to open in
  535. 'apiUrl' => '/deployDev', // (required) API endpoint URL
  536. 'resellerClientAccountId' => $params['serviceid'], // (required) ID of website/user in your system
  537. // 'username' => 'example_user', // (optional) authorization username to be used with API endpoint
  538. // 'password' => 'example_password', // (optional) authorization password to be used with API endpoint
  539. ));
  540. if (!$res || !is_object($res)) {
  541. logModuleCall(
  542. 'siteBuilder',
  543. __FUNCTION__,
  544. $params,
  545. 'Error: Response format error',
  546. $res
  547. );
  548. return 'Error: Response format error';
  549. } else if (isset($res->url) && $res->url) {
  550. logModuleCall(
  551. 'siteBuilder',
  552. __FUNCTION__,
  553. $params,
  554. 'Debug',
  555. $res
  556. );
  557. // on success redirect to builder URL
  558. // header('Location: '.$res->url, true);
  559. // exit();
  560. } else {
  561. logModuleCall(
  562. 'siteBuilder',
  563. __FUNCTION__,
  564. $params,
  565. 'Error: Unknown error',
  566. $res
  567. );
  568. return 'Error: Unknown error';
  569. }
  570. } catch (\Exception $e) {
  571. logModuleCall(
  572. 'siteBuilder',
  573. __FUNCTION__,
  574. $params,
  575. 'Error: Request error',
  576. $e->getMessage()
  577. );
  578. return 'Error: Request error';
  579. }
  580. return 'success';
  581. }
  582. /**
  583. * Opens a form to delete a domain from a siteBuilder account.
  584. *
  585. * @param array $params common module parameters
  586. *
  587. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  588. *
  589. * @return array template information
  590. */
  591. function siteBuilder_delSiteConfirm($params) {
  592. return array(
  593. 'templatefile' => 'siteBuilder_del_site_confirm',
  594. 'vars' => array(
  595. 'delsite' => $_POST['s'],
  596. ),
  597. );
  598. }
  599. /**
  600. * Removes a domain from a siteBuilder account.
  601. *
  602. * @param array $params common module parameters
  603. *
  604. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  605. *
  606. * @return string "success" or an error message
  607. */
  608. function siteBuilder_delSite($params) {
  609. if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  610. return 'Error: invalid domain name';
  611. }
  612. return 'success';
  613. }
  614. /**
  615. * Opens a form to delete a domain from a siteBuilder account.
  616. *
  617. * @param array $params common module parameters
  618. *
  619. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  620. *
  621. * @return array template information
  622. */
  623. function siteBuilder_revSiteConfirm($params) {
  624. return array(
  625. 'templatefile' => 'siteBuilder_rev_site_confirm',
  626. 'vars' => array(
  627. 'delSite' => $_POST['s'],
  628. ),
  629. );
  630. }
  631. /**
  632. * Revert all Changes of the development Site.
  633. *
  634. * @param array $params common module parameters
  635. *
  636. * @see https://developers.whmcs.com/provisioning-modules/supported-functions/
  637. *
  638. * @return string "success" or an error message
  639. */
  640. function siteBuilder_revSite($params) {
  641. if(!filter_var($_POST['s'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){
  642. return 'Error: invalid site name';
  643. }
  644. $site = $_POST['s'];
  645. $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']);
  646. $response = $siteBuilder->revertDev($params['username'], $site, $params['serverusername'], $params['serverpassword']);
  647. if($response['status'] != '200') {
  648. return 'Error: ' . $response['response'];
  649. }
  650. return 'success';
  651. }
  652. /**
  653. * Returns API Url .
  654. *
  655. * @param string $params common module parameters
  656. * @param string $user
  657. * @param string $params common module parameters
  658. *
  659. * @return string $apiUrl
  660. */
  661. function getSiteBuilderApiURL($params) {
  662. $httpPrefix = $params['serversecure'] ? 'https://' : 'http://';
  663. $serverPort = $params['serverport'] ? ':' . $params['serverport'] . '/' : '/';
  664. return $httpPrefix . $params['serverhostname'] . $serverPort;
  665. }
  666. function getSites($serviceID) {
  667. try {
  668. $sites = Capsule::table('sitePro_site')
  669. ->where('relid',$serviceID)
  670. ->value('name');
  671. } catch (\Exception $e) {
  672. logModuleCall(
  673. 'siteBuilder',
  674. __FUNCTION__,
  675. $params,
  676. 'Error: could fetch sites from database',
  677. $e->getMessage()
  678. );
  679. return 'Error: could fetch sites from database';
  680. }
  681. return $sites;
  682. }
  683. function siteBuilderCreateTables() {
  684. // Create a new table.
  685. if (!Capsule::schema()->hasTable('sitePro_acc')) {
  686. try {
  687. Capsule::schema()->create(
  688. 'sitePro_acc',
  689. function ($table) {
  690. /** @var \Illuminate\Database\Schema\Blueprint $table */
  691. $table->increments('id');
  692. $table->string('account');
  693. $table->integer('pid');
  694. $table->boolean('enabled');
  695. }
  696. );
  697. } catch (\Exception $e) {
  698. echo "Unable to create sitePro_acc: {$e->getMessage()}";
  699. }
  700. }
  701. if (!Capsule::schema()->hasTable('sitePro_site')) {
  702. try {
  703. Capsule::schema()->create(
  704. 'sitePro_site',
  705. function ($table) {
  706. /** @var \Illuminate\Database\Schema\Blueprint $table */
  707. $table->increments('id');
  708. $table->integer('relid');
  709. $table->string('name');
  710. $table->boolean('enabled');
  711. }
  712. );
  713. } catch (\Exception $e) {
  714. echo "Unable to create sitePro_site: {$e->getMessage()}";
  715. }
  716. }
  717. }