siteBuilder.php 37 KB

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