siteBuilder.php 38 KB

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