siteBuilder.php 37 KB

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