siteBuilder.php 38 KB

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