PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/provision/PLESK_RELOADED_7_5.php

https://github.com/ntws/agilebill
PHP | 938 lines | 694 code | 135 blank | 109 comment | 46 complexity | 70dac05cd3e415000f03e11aacad808e MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0
  1. <?php
  2. /**
  3. * AgileBill - Open Billing Software
  4. *
  5. * This body of work is free software; you can redistribute it and/or
  6. * modify it under the terms of the Open AgileBill License
  7. * License as published at http://www.agileco.com/agilebill/license1-4.txt
  8. *
  9. * For questions, help, comments, discussion, etc., please join the
  10. * Agileco community forums at http://forum.agileco.com/
  11. *
  12. * @link http://www.agileco.com/
  13. * @copyright 2004-2008 Agileco, LLC.
  14. * @license http://www.agileco.com/agilebill/license1-4.txt
  15. * @author Tony Landis <tony@agileco.com>
  16. * @package AgileBill
  17. * @version 1.4.93
  18. */
  19. /*
  20. * Vars available from server config:
  21. *
  22. * host
  23. * port
  24. * user
  25. * pass
  26. *
  27. *
  28. * Vars from service config:
  29. *
  30. * package
  31. *
  32. */
  33. class plgn_prov_PLESK_RELOADED_7_5
  34. {
  35. function plgn_prov_PLESK_RELOADED_7_5()
  36. {
  37. $this->name = 'PLESK_RELOADED_7_5';
  38. $this->task_based = false;
  39. $this->remote_based = true;
  40. # PSA STUFF:
  41. $this->psapath = "enterprise/control/agent.php";
  42. $this->proto = "1.3.1.0";
  43. }
  44. # add new service
  45. function p_new()
  46. {
  47. # get the common server class and set login details
  48. include_once(PATH_MODULES.'host_server/host_server.inc.php');
  49. $host = new host_server;
  50. if($this->service['host_username'] == '' || $this->service['host_password'] == '')
  51. {
  52. # set the limits
  53. $pass_len = 10;
  54. $user_len = 12;
  55. # Generate a new username/login:
  56. $domain = $this->service['domain_name'].$this->service['domain_tld'];
  57. # set the username
  58. $username = trim($domain);
  59. $username = eregi_replace("[-_\.]", "", $username);
  60. if(strlen($username) < $user_len)
  61. {
  62. $rand = md5(md5($username).time());
  63. $diff = $user_len - strlen($username);
  64. $username = $username . substr($rand, 0, $diff);
  65. }
  66. else
  67. {
  68. $rand = md5(microtime().md5($username).microtime());
  69. $username = substr($username, 0, $user_len-5);
  70. $username = $username . substr($rand, 0, 5);
  71. }
  72. # Set the password
  73. $password = substr(md5(md5(time()).$domain.$username), 0, 10);
  74. # Set the user/pass for the XML queries
  75. $this->login['username'] = $username;
  76. $this->login['password'] = $password;
  77. } else {
  78. # Validate
  79. $this->login['username'] = $this->service['host_username'];
  80. $this->login['password'] = $this->service['host_password'];
  81. }
  82. # get ip address
  83. if ($this->plugin_data['ip_based'] == '1') {
  84. $this->ip = $host->useipaddress($this->service, $this->server);
  85. } else {
  86. $this->ip = $this->server['name_based_ip'];
  87. }
  88. ####################################################
  89. ### Assemble the XML for the account creation: ####
  90. $data =<<<EOF
  91. <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  92. <packet version="{$this->proto}">
  93. <client>
  94. <add>
  95. <gen_info>
  96. <pname>{$this->account['first_name']} {$this->account['last_name']} ({$this->login['username']})</pname>
  97. <login>{$this->login['username']}</login>
  98. <passwd>{$this->login['password']}</passwd>
  99. <email>{$this->account['email']}</email>
  100. <pcode>00000</pcode>
  101. <country>US</country>
  102. <status>0</status>
  103. <phone>18005551212</phone>
  104. </gen_info>
  105. <limits>
  106. <max_webapps>{$this->plugin_data['max_webapps']}</max_webapps>
  107. <max_maillists>{$this->plugin_data['max_maillists']}</max_maillists>
  108. <max_resp>{$this->plugin_data['max_resp']}</max_resp>
  109. <max_mg>{$this->plugin_data['max_mg']}</max_mg>
  110. <max_redir>{$this->plugin_data['max_redir']}</max_redir>
  111. <mbox_quota>{$this->plugin_data['mbox_quota']}</mbox_quota>
  112. <max_box>{$this->plugin_data['max_box']}</max_box>
  113. <max_db>{$this->plugin_data['max_db']}</max_db>
  114. <max_wu>{$this->plugin_data['max_wu']}</max_wu>
  115. <max_traffic>{$this->plugin_data['max_traffic']}</max_traffic>
  116. <disk_space>{$this->plugin_data['disk_space']}</disk_space>
  117. <max_subdom>{$this->plugin_data['max_subdom']}</max_subdom>
  118. <max_dom>{$this->plugin_data['max_dom']}</max_dom>
  119. </limits>
  120. </add>
  121. </client>
  122. </packet>
  123. EOF;
  124. # Connect & get response:
  125. $result = $this->connect(
  126. $this->server_cfg['host'],
  127. $this->server_cfg['port'],
  128. $this->server_cfg['user'],
  129. $this->server_cfg['pass'],
  130. $data
  131. );
  132. # Debug:
  133. $this->debug($data, $result);
  134. # Get the account id
  135. $cl_id = $this->getid($result);
  136. ################################################
  137. ### SET CLIENT PERMISSIONS & ADD IP TO POOL: ###
  138. # Loop through the values below and convert to true or false:
  139. $tf_arr = Array (
  140. 'create_domains', 'manage_phosting', 'manage_sh_access', 'manage_not_chroot_shell', 'manage_quota', 'manage_subdomains',
  141. 'manage_log', 'manage_anonftp', 'manage_crontab', 'site_builder', 'change_limits', 'manage_dns',
  142. 'manage_webapps', 'manage_maillists', 'manage_drweb', 'make_dumps',
  143. 'fp', 'fp_auth', 'fp_ssl', 'ssl', 'shell', 'php', 'ssi', 'cgi',
  144. 'mod_perl', 'mod_python', 'asp', 'asp_dot_net', 'coldfusion', 'webstat',
  145. 'errdocs', 'at_domains'
  146. );
  147. for($i=0; $i<count($tf_arr); $i++) {
  148. if($this->plugin_data["$tf_arr[$i]"] == 1)
  149. $this->plugin_data["$tf_arr[$i]"] = 'true';
  150. else
  151. $this->plugin_data["$tf_arr[$i]"] = 'false';
  152. }
  153. $data =<<<EOF
  154. <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  155. <packet version="{$this->proto}">
  156. <client>
  157. <set>
  158. <filter>
  159. <id>$cl_id</id>
  160. </filter>
  161. <values>
  162. <permissions>
  163. <create_domains>{$this->plugin_data['create_domains']}</create_domains>
  164. <manage_phosting>false</manage_phosting>
  165. <manage_sh_access>{$this->plugin_data['manage_sh_access']}</manage_sh_access>
  166. <manage_not_chroot_shell>{$this->plugin_data['manage_not_chroot_shell']}</manage_not_chroot_shell>
  167. <manage_quota>{$this->plugin_data['manage_quota']}</manage_quota>
  168. <manage_subdomains>{$this->plugin_data['manage_subdomains']}</manage_subdomains>
  169. <manage_log>{$this->plugin_data['manage_log']}</manage_log>
  170. <manage_anonftp>{$this->plugin_data['manage_anonftp']}</manage_anonftp>
  171. <manage_crontab>{$this->plugin_data['manage_crontab']}</manage_crontab>
  172. <site_builder>{$this->plugin_data['site_builder']}</site_builder>
  173. <change_limits>{$this->plugin_data['change_limits']}</change_limits>
  174. <manage_dns>{$this->plugin_data['manage_dns']}</manage_dns>
  175. <manage_webapps>{$this->plugin_data['manage_webapps']}</manage_webapps>
  176. <manage_maillists>{$this->plugin_data['manage_maillists']}</manage_maillists>
  177. <manage_drweb>{$this->plugin_data['manage_drweb']}</manage_drweb>
  178. <make_dumps>{$this->plugin_data['make_dumps']}</make_dumps>
  179. </permissions>
  180. </values>
  181. </set>
  182. <ippool_add_ip>
  183. <client_id>$cl_id</client_id>
  184. <ip_address>{$this->ip}</ip_address>
  185. </ippool_add_ip>
  186. </client>
  187. </packet>
  188. EOF;
  189. # Connect & get response:
  190. $result = $this->connect(
  191. $this->server_cfg['host'],
  192. $this->server_cfg['port'],
  193. $this->server_cfg['user'],
  194. $this->server_cfg['pass'],
  195. $data
  196. );
  197. # Debug:
  198. $this->debug($data, $result);
  199. # Calculate limits
  200. @$ftp_quota = ceil($this->plugin_data['ftp_quota']) *1024*1024;
  201. @$disk_space = ceil($this->plugin_data['disk_space']) *1024*1024;
  202. @$max_traffic= ceil($this->plugin_data['max_traffic']) *1024*1024;
  203. @$mbox_quota = ceil($this->plugin_data['mbox_quota']) *1024;
  204. if($this->plugin_data['shell'] == 1)
  205. $shell = 'true';
  206. else
  207. $shell = '/bin/false';
  208. ###################################
  209. ### ADD NEW DOMAIN AND LIMITS: ###
  210. $data =<<<EOF
  211. <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  212. <packet version="{$this->proto}">
  213. <domain>
  214. <add>
  215. <gen_setup>
  216. <name>{$this->service['domain_name']}.{$this->service['domain_tld']}</name>
  217. <client_id>$cl_id</client_id>
  218. <ip_address>{$this->ip}</ip_address>
  219. <htype>vrt_hst</htype>
  220. <status />
  221. </gen_setup>
  222. <hosting>
  223. <vrt_hst>
  224. <ip_address>{$this->ip}</ip_address>
  225. <ftp_login>{$this->login['username']}</ftp_login>
  226. <ftp_password>{$this->login['password']}</ftp_password>
  227. <ftp_quota>{$ftp_quota}</ftp_quota>
  228. <fp>{$this->plugin_data['fp']}</fp>
  229. <fp_ssl>{$this->plugin_data['fp_ssl']}</fp_ssl>
  230. <fp_auth>{$this->plugin_data['fp_auth']}</fp_auth>
  231. <fp_admin_login>{$this->login['username']}</fp_admin_login>
  232. <fp_admin_password>{$this->login['password']}</fp_admin_password>
  233. <ssl>{$this->plugin_data['ssl']}</ssl>
  234. <shell>{$shell}</shell>
  235. <php>{$this->plugin_data['php']}</php>
  236. <ssi>{$this->plugin_data['ssi']}</ssi>
  237. <cgi>{$this->plugin_data['cgi']}</cgi>
  238. <mod_perl>{$this->plugin_data['mod_perl']}</mod_perl>
  239. <mod_python>{$this->plugin_data['mod_python']}</mod_python>
  240. <asp>{$this->plugin_data['asp']}</asp>
  241. <asp_dot_net>{$this->plugin_data['asp_dot_net']}</asp_dot_net>
  242. <coldfusion>{$this->plugin_data['coldfusion']}</coldfusion>
  243. <webstat>{$this->plugin_data['webstat']}</webstat>
  244. <errdocs>{$this->plugin_data['errdocs']}</errdocs>
  245. <at_domains>{$this->plugin_data['at_domains']}</at_domains>
  246. </vrt_hst>
  247. </hosting>
  248. <limits>
  249. <max_subdom>{$this->plugin_data['max_subdom']}</max_subdom>
  250. <disk_space>{$disk_space}</disk_space>
  251. <max_traffic>{$max_traffic}</max_traffic>
  252. <max_wu>{$this->plugin_data['max_wu']}</max_wu>
  253. <max_db>{$this->plugin_data['max_db']}</max_db>
  254. <max_box>{$this->plugin_data['max_box']}</max_box>
  255. <mbox_quota>{$mbox_quota}</mbox_quota>
  256. <max_redir>{$this->plugin_data['max_redir']}</max_redir>
  257. <max_mg>{$this->plugin_data['max_mg']}</max_mg>
  258. <max_resp>{$this->plugin_data['max_resp']}</max_resp>
  259. <max_maillists>{$this->plugin_data['max_maillists']}</max_maillists>
  260. <max_webapps>{$this->plugin_data['max_webapps']}</max_webapps>
  261. </limits>
  262. <prefs>
  263. <www>true</www>
  264. </prefs>
  265. </add>
  266. </domain>
  267. </packet>
  268. EOF;
  269. # Connect & get response:
  270. $result = $this->connect(
  271. $this->server_cfg['host'],
  272. $this->server_cfg['port'],
  273. $this->server_cfg['user'],
  274. $this->server_cfg['pass'],
  275. $data
  276. );
  277. # Debug:
  278. $this->debug($data, $result);
  279. # Get the account id
  280. if(!$domain_id = $this->getid($result)) {
  281. return false;
  282. } else {
  283. $db = &DB();
  284. $id = $this->service_id;
  285. $sql = "SELECT * FROM ".AGILE_DB_PREFIX."service WHERE id = $id";
  286. $rs = $db->Execute($sql);
  287. $plugin_data = unserialize($rs->fields['host_provision_plugin_data']);
  288. $plugin_data['account_id'] = $cl_id;
  289. $plugin_data['domain_id'] = $domain_id;
  290. $insert = Array ( 'host_provision_plugin_data' => serialize($plugin_data),
  291. 'host_username' => $this->login['username'],
  292. 'host_password' => $this->login['password']);
  293. $sql = $db->GetUpdateSQL($rs, $insert);
  294. $result = $db->Execute($sql);
  295. if ($result === false) {
  296. global $C_debug;
  297. $C_debug->error('PLESK_RELOADED_7_5.php','plgn_prov_PLESK_RELOADED_7_5 :: p_new()', $db->ErrorMsg(). "\r\n\r\n". $sql);
  298. }
  299. # send the user the details
  300. include_once(PATH_MODULES.'email_template/email_template.inc.php');
  301. $email = new email_template;
  302. $email->send('host_new_user', $this->account['id'], $this->service_id, '', '');
  303. }
  304. return true;
  305. }
  306. # edit service
  307. function p_edit()
  308. {
  309. ## Get the IP
  310. if(!empty($this->service['host_ip']))
  311. $this->ip = $this->service['host_ip'];
  312. else
  313. $this->ip = $this->server['name_based_ip'];
  314. ################################################
  315. ### SET CLIENT LOGIN
  316. $data =<<<EOF
  317. <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  318. <packet version="{$this->proto}">
  319. <client>
  320. <set>
  321. <filter>
  322. <id>{$this->plugin_data['account_id']}</id>
  323. </filter>
  324. <values>
  325. <gen_info>
  326. <login>{$this->service['host_username']}</login>
  327. <passwd>{$this->service['host_password']}</passwd>
  328. </gen_info>
  329. </values>
  330. </set>
  331. </client>
  332. </packet>
  333. EOF;
  334. # Connect & get response:
  335. $result = $this->connect(
  336. $this->server_cfg['host'],
  337. $this->server_cfg['port'],
  338. $this->server_cfg['user'],
  339. $this->server_cfg['pass'],
  340. $data
  341. );
  342. # Debug:
  343. $this->debug($data, $result);
  344. ################################################
  345. ### SET CLIENT PERMISSIONS & ADD IP TO POOL: ###
  346. # Loop through the values below and convert to true or false:
  347. $tf_arr = Array (
  348. 'create_domains', 'manage_phosting', 'manage_sh_access', 'manage_not_chroot_shell', 'manage_quota', 'manage_subdomains',
  349. 'manage_log', 'manage_anonftp', 'manage_crontab', 'site_builder', 'change_limits', 'manage_dns',
  350. 'manage_webapps', 'manage_maillists', 'manage_drweb', 'make_dumps',
  351. 'fp', 'fp_ssl', 'ssl', 'shell', 'php', 'ssi', 'cgi',
  352. 'mod_perl', 'mod_python', 'asp', 'asp_dot_net', 'coldfusion', 'webstat',
  353. 'errdocs', 'at_domains'
  354. );
  355. for($i=0; $i<count($tf_arr); $i++) {
  356. if($this->plugin_data["$tf_arr[$i]"] == 1)
  357. $this->plugin_data["$tf_arr[$i]"] = 'true';
  358. else
  359. $this->plugin_data["$tf_arr[$i]"] = 'false';
  360. }
  361. $data =<<<EOF
  362. <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  363. <packet version="{$this->proto}">
  364. <client>
  365. <set>
  366. <filter>
  367. <id>{$this->plugin_data['account_id']}</id>
  368. </filter>
  369. <values>
  370. <permissions>
  371. <create_domains>{$this->plugin_data['create_domains']}</create_domains>
  372. <manage_phosting>{$this->plugin_data['manage_phosting']}</manage_phosting>
  373. <manage_sh_access>{$this->plugin_data['manage_sh_access']}</manage_sh_access>
  374. <manage_not_chroot_shell>{$this->plugin_data['manage_not_chroot_shell']}</manage_not_chroot_shell>
  375. <manage_quota>{$this->plugin_data['manage_quota']}</manage_quota>
  376. <manage_subdomains>{$this->plugin_data['manage_subdomains']}</manage_subdomains>
  377. <manage_log>{$this->plugin_data['manage_log']}</manage_log>
  378. <manage_anonftp>{$this->plugin_data['manage_anonftp']}</manage_anonftp>
  379. <manage_crontab>{$this->plugin_data['manage_crontab']}</manage_crontab>
  380. <site_builder>{$this->plugin_data['site_builder']}</site_builder>
  381. <change_limits>{$this->plugin_data['change_limits']}</change_limits>
  382. <manage_dns>{$this->plugin_data['manage_dns']}</manage_dns>
  383. <manage_webapps>{$this->plugin_data['manage_webapps']}</manage_webapps>
  384. <manage_maillists>{$this->plugin_data['manage_maillists']}</manage_maillists>
  385. <manage_drweb>{$this->plugin_data['manage_drweb']}</manage_drweb>
  386. <make_dumps>{$this->plugin_data['make_dumps']}</make_dumps>
  387. </permissions>
  388. </values>
  389. </set>
  390. <ippool_add_ip>
  391. <client_id>{$this->plugin_data['account_id']}</client_id>
  392. <ip_address>{$this->ip}</ip_address>
  393. </ippool_add_ip>
  394. </client>
  395. </packet>
  396. EOF;
  397. # Connect & get response:
  398. $result = $this->connect(
  399. $this->server_cfg['host'],
  400. $this->server_cfg['port'],
  401. $this->server_cfg['user'],
  402. $this->server_cfg['pass'],
  403. $data
  404. );
  405. # Debug:
  406. $this->debug($data, $result);
  407. ### Edit the domain settings:
  408. $data =<<<EOF
  409. <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  410. <packet version="{$this->proto}">
  411. <domain>
  412. <set>
  413. <filter>
  414. <id>{$this->plugin_data['domain_id']}</id>
  415. </filter>
  416. <values>
  417. <gen_setup>
  418. <status>16</status>
  419. <name>{$this->service['domain_name']}.{$this->service['domain_tld']}</name>
  420. </gen_setup>
  421. </values>
  422. </set>
  423. </domain>
  424. </packet>
  425. EOF;
  426. # Calculate limits
  427. @$ftp_quota = ceil($this->plugin_data['ftp_quota']) *1024*1024;
  428. @$disk_space = ceil($this->plugin_data['disk_space']) *1024*1024;
  429. @$max_traffic= ceil($this->plugin_data['max_traffic']) *1024*1024;
  430. @$mbox_quota = ceil($this->plugin_data['mbox_quota']) *1024;
  431. if($this->plugin_data['shell'] == 1)
  432. $shell = 'true';
  433. else
  434. $shell = '/bin/false';
  435. $data =<<<EOF
  436. <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  437. <packet version="{$this->proto}">
  438. <domain>
  439. <set>
  440. <filter>
  441. <id>{$this->plugin_data['domain_id']}</id>
  442. </filter>
  443. <values>
  444. <gen_setup>
  445. <status>0</status>
  446. <name>{$this->service['domain_name']}.{$this->service['domain_tld']}</name>
  447. </gen_setup>
  448. <hosting>
  449. <vrt_hst>
  450. <ip_address>{$this->ip}</ip_address>
  451. <ftp_login>{$this->service['host_username']}</ftp_login>
  452. <ftp_password>{$this->service['host_password']}</ftp_password>
  453. <ftp_quota>{$ftp_quota}</ftp_quota>
  454. <fp>{$this->plugin_data['fp']}</fp>
  455. <fp_ssl>{$this->plugin_data['fp_ssl']}</fp_ssl>
  456. <fp_auth>{$this->plugin_data['fp_auth']}</fp_auth>
  457. <fp_admin_login>{$this->service['host_username']}</fp_admin_login>
  458. <fp_admin_password>{$this->service['host_password']}</fp_admin_password>
  459. <ssl>{$this->plugin_data['ssl']}</ssl>
  460. <shell>{$shell}</shell>
  461. <php>{$this->plugin_data['php']}</php>
  462. <ssi>{$this->plugin_data['ssi']}</ssi>
  463. <cgi>{$this->plugin_data['cgi']}</cgi>
  464. <mod_perl>{$this->plugin_data['mod_perl']}</mod_perl>
  465. <mod_python>{$this->plugin_data['mod_python']}</mod_python>
  466. <asp>{$this->plugin_data['asp']}</asp>
  467. <asp_dot_net>{$this->plugin_data['asp_dot_net']}</asp_dot_net>
  468. <coldfusion>{$this->plugin_data['coldfusion']}</coldfusion>
  469. <webstat>{$this->plugin_data['webstat']}</webstat>
  470. <errdocs>{$this->plugin_data['errdocs']}</errdocs>
  471. <at_domains>{$this->plugin_data['at_domains']}</at_domains>
  472. </vrt_hst>
  473. </hosting>
  474. <limits>
  475. <max_subdom>{$this->plugin_data['max_subdom']}</max_subdom>
  476. <disk_space>{$disk_space}</disk_space>
  477. <max_traffic>{$max_traffic}</max_traffic>
  478. <max_wu>{$this->plugin_data['max_wu']}</max_wu>
  479. <max_db>{$this->plugin_data['max_db']}</max_db>
  480. <max_box>{$this->plugin_data['max_box']}</max_box>
  481. <mbox_quota>{$mbox_quota}</mbox_quota>
  482. <max_redir>{$this->plugin_data['max_redir']}</max_redir>
  483. <max_mg>{$this->plugin_data['max_mg']}</max_mg>
  484. <max_resp>{$this->plugin_data['max_resp']}</max_resp>
  485. <max_maillists>{$this->plugin_data['max_maillists']}</max_maillists>
  486. <max_webapps>{$this->plugin_data['max_webapps']}</max_webapps>
  487. </limits>
  488. </values>
  489. </set>
  490. </domain>
  491. </packet>
  492. EOF;
  493. # Connect & get response:
  494. $result = $this->connect(
  495. $this->server_cfg['host'],
  496. $this->server_cfg['port'],
  497. $this->server_cfg['user'],
  498. $this->server_cfg['pass'],
  499. $data
  500. );
  501. # Debug:
  502. $this->debug($data, $result);
  503. if(!empty($result))
  504. return true;
  505. else
  506. return false;
  507. }
  508. # activate service
  509. function p_inactive()
  510. {
  511. $data =<<<EOF
  512. <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  513. <packet version="{$this->proto}">
  514. <client>
  515. <set>
  516. <filter>
  517. <id>{$this->plugin_data['account_id']}</id>
  518. </filter>
  519. <values>
  520. <gen_info>
  521. <status>16</status>
  522. </gen_info>
  523. </values>
  524. </set>
  525. </client>
  526. </packet>
  527. EOF;
  528. # Connect & get response:
  529. $result = $this->connect(
  530. $this->server_cfg['host'],
  531. $this->server_cfg['port'],
  532. $this->server_cfg['user'],
  533. $this->server_cfg['pass'],
  534. $data
  535. );
  536. # Debug:
  537. $this->debug($data, $result);
  538. $data =<<<EOF
  539. <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  540. <packet version="{$this->proto}">
  541. <domain>
  542. <set>
  543. <filter>
  544. <id>{$this->plugin_data['domain_id']}</id>
  545. </filter>
  546. <values>
  547. <gen_setup>
  548. <status>16</status>
  549. </gen_setup>
  550. </values>
  551. </set>
  552. </domain>
  553. </packet>
  554. EOF;
  555. # Connect & get response:
  556. $result = $this->connect(
  557. $this->server_cfg['host'],
  558. $this->server_cfg['port'],
  559. $this->server_cfg['user'],
  560. $this->server_cfg['pass'],
  561. $data
  562. );
  563. # Debug:
  564. $this->debug($data, $result);
  565. if(!empty($result))
  566. return true;
  567. else
  568. return false;
  569. }
  570. # deactivate service
  571. function p_active()
  572. {
  573. $data =<<<EOF
  574. <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  575. <packet version="{$this->proto}">
  576. <client>
  577. <set>
  578. <filter>
  579. <id>{$this->plugin_data['account_id']}</id>
  580. </filter>
  581. <values>
  582. <gen_info>
  583. <status>0</status>
  584. </gen_info>
  585. </values>
  586. </set>
  587. </client>
  588. </packet>
  589. EOF;
  590. # Connect & get response:
  591. $result = $this->connect(
  592. $this->server_cfg['host'],
  593. $this->server_cfg['port'],
  594. $this->server_cfg['user'],
  595. $this->server_cfg['pass'],
  596. $data
  597. );
  598. # Debug:
  599. $this->debug($data, $result);
  600. $data =<<<EOF
  601. <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  602. <packet version="{$this->proto}">
  603. <domain>
  604. <set>
  605. <filter>
  606. <id>{$this->plugin_data['domain_id']}</id>
  607. </filter>
  608. <values>
  609. <gen_setup>
  610. <status>0</status>
  611. <name>{$this->service['domain_name']}.{$this->service['domain_tld']}</name>
  612. </gen_setup>
  613. </values>
  614. </set>
  615. </domain>
  616. </packet>
  617. EOF;
  618. # Connect & get response:
  619. $result = $this->connect(
  620. $this->server_cfg['host'],
  621. $this->server_cfg['port'],
  622. $this->server_cfg['user'],
  623. $this->server_cfg['pass'],
  624. $data
  625. );
  626. # Debug:
  627. $this->debug($data, $result);
  628. if(!empty($result))
  629. return true;
  630. else
  631. return false;
  632. }
  633. # delete service
  634. function p_delete()
  635. {
  636. # recycle the IP if ip_based:
  637. if ($this->plugin_data['ip_based'] == '1') {
  638. include_once(PATH_MODULES.'host_server/host_server.inc.php');
  639. $host = new host_server;
  640. $this->ip = $host->unuseipaddress($this->server, $this->service['host_ip']);
  641. }
  642. $data =<<<EOF
  643. <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  644. <packet version="{$this->proto}">
  645. <client>
  646. <del>
  647. <filter>
  648. <id>{$this->plugin_data['account_id']}</id>
  649. </filter>
  650. </del>
  651. </client>
  652. </packet>
  653. EOF;
  654. # Connect & get response:
  655. $result = $this->connect(
  656. $this->server_cfg['host'],
  657. $this->server_cfg['port'],
  658. $this->server_cfg['user'],
  659. $this->server_cfg['pass'],
  660. $data
  661. );
  662. # Debug:
  663. $this->debug($data, $result);
  664. if(!empty($result))
  665. return true;
  666. else
  667. return false;
  668. }
  669. # construct echo all updates
  670. function p_one($id)
  671. {
  672. global $C_debug;
  673. # Get the service details
  674. $db = &DB();
  675. $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'service WHERE
  676. id = ' . $db->qstr( $id ) . ' AND
  677. site_id = ' . $db->qstr(DEFAULT_SITE);
  678. $rs = $db->Execute($sql);
  679. if($rs->RecordCount() == 0) {
  680. return false;
  681. }
  682. $this->service = $rs->fields;
  683. $this->service_id = $rs->fields['id'];
  684. @$this->plugin_data = unserialize($this->service['host_provision_plugin_data']);
  685. # Get the account details
  686. $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'account WHERE
  687. id = ' . $db->qstr( $this->service['account_id'] ) . ' AND
  688. site_id = ' . $db->qstr(DEFAULT_SITE);
  689. $acct = $db->Execute($sql);
  690. $this->account = $acct->fields;
  691. # Get the server details
  692. $db = &DB();
  693. $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'host_server WHERE
  694. id = ' . $db->qstr( $this->service['host_server_id'] ) . ' AND
  695. site_id = ' . $db->qstr(DEFAULT_SITE);
  696. $rs = $db->Execute($sql);
  697. if (@$rs->RecordCount() == 0) {
  698. return false;
  699. } else {
  700. $this->server = $rs->fields;
  701. @$this->server_cfg = unserialize($rs->fields['provision_plugin_data']);
  702. }
  703. # determine the correct action
  704. switch ($this->service['queue'])
  705. {
  706. # new
  707. case 'new':
  708. $result = $this->p_new();
  709. break;
  710. # active
  711. case 'active':
  712. $result = $this->p_active();
  713. break;
  714. # inactive
  715. case 'inactive':
  716. $result = $this->p_inactive();
  717. break;
  718. # edit
  719. case 'edit':
  720. $result = $this->p_edit();
  721. if ($this->service['active'] == 1 )
  722. $result = $this->p_active();
  723. else
  724. $result = $this->p_inactive();
  725. break;
  726. # delete
  727. case 'delete':
  728. $result = $this->p_delete();
  729. break;
  730. }
  731. # update service record
  732. if(@$result)
  733. {
  734. # update
  735. $db = &DB();
  736. $sql = 'UPDATE ' . AGILE_DB_PREFIX . 'service SET
  737. queue = ' . $db->qstr( 'none' ) . ',
  738. date_last = ' . $db->qstr( time() ) . '
  739. WHERE
  740. id = ' . $db->qstr( $this->service_id ) . ' AND
  741. site_id = ' . $db->qstr(DEFAULT_SITE);
  742. $upd = $db->Execute($sql);
  743. } else {
  744. # error log
  745. $C_debug->error($this->name.'.php', $this->service['queue'], $this->service['queue'] . ' For service id '. $this->service_id . ' Failed!');
  746. }
  747. }
  748. /*
  749. * Get the id returned
  750. */
  751. function getid($result)
  752. {
  753. preg_match ("/(<id>)+([0-9]){1,99}/i", $result, $arr);
  754. if(is_array($arr) && count($arr) > 0) {
  755. $id = ereg_replace("<id>","", $arr[0]);
  756. if(!is_numeric($id))
  757. return false;
  758. else
  759. return $id;
  760. } else {
  761. return false;
  762. }
  763. return false;
  764. }
  765. /*
  766. * Debug
  767. */
  768. function debug($data,$result=false)
  769. {
  770. if($this->server['debug']) {
  771. echo '<B><BR>REQUEST:</B><BR>';
  772. echo "<pre>" . htmlspecialchars($data) . "</pre>";
  773. echo '<B>RESPONSE:</B><BR>';
  774. echo "<pre>" . htmlspecialchars($result) . "</pre>";
  775. }
  776. }
  777. /*
  778. * Curl connect functions
  779. */
  780. function connect($HOST, $PORT, $LOGIN, $PASSWD, $DATA)
  781. {
  782. $url = "https://" . $HOST . ":" . $PORT . "/" . $this->psapath;
  783. $headers = array(
  784. "HTTP_AUTH_LOGIN: " . $LOGIN,
  785. "HTTP_AUTH_PASSWD: " . $PASSWD,
  786. "HTTP_PRETTY_PRINT: TRUE",
  787. "Content-Type: text/xml",
  788. );
  789. $ch = curl_init();
  790. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  791. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  792. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  793. curl_setopt($ch, CURLOPT_URL, $url);
  794. curl_setopt($ch, CURLOPT_POSTFIELDS, $DATA);
  795. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  796. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  797. $result = curl_exec($ch);
  798. $this->result = $result;
  799. curl_close($ch);
  800. return $result;
  801. }
  802. }
  803. ?>