IspcfgClient.php

A PHP wrapper to assist in interactions with the ISPConfig 3 web service offering. Also a list of patches to add features necessary for tasks I was attempting to complete. Each addition has been submitted to ISPConfig 3 for inclusion.

  1. <?php
  2. /**
  3.  * @author Ben Lake <me@benlake.org>
  4.  * @license GNU Lesser Public License v3 (http://opensource.org/licenses/lgpl-3.0.html)
  5.  * @copyright Copyright (c) 2011, Ben Lake
  6.  * @link http://benlake.org/projects/show/ispconfigclient
  7.  *
  8.  * This file is part of the ISPConfig PHP Client.
  9.  *
  10.  * ISPConfig PHP Client is free software: you can redistribute it and/or modify
  11.  * it under the terms of the GNU Lesser General Public License as published by
  12.  * the Free Software Foundation, either version 3 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * ISPConfig PHP Client is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18.  * GNU Lesser General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU Lesser General Public License
  21.  * along with ISPConfig PHP Client. If not, see <http://www.gnu.org/licenses/>.
  22.  *
  23.  *
  24.  * This software is is NO WAY affiliated with ISPConfig. The license of this client does
  25.  * not extend to ISPConfig itself!
  26.  * ISPConfig is Copyright (c) 2007, Till Brehm, projektfarm Gmbh, All rights reserved.
  27.  * You can find the source at http://www.ispconfig.org/ispconfig-3/
  28.  */
  29.  
  30. /**
  31.  * Remote API client for ISPConfig3 to support logical operations of Lollipop.
  32.  * Instantiate one object per server you wish to make adjustments to. Do not connect to server1
  33.  * to modify server2 (at least for now as there is no way to specify your server id explicitly).
  34.  * MUST be able to connect over SSL!
  35.  *
  36.  * @package ispconfig3
  37.  * @version 0.1
  38.  */
  39. class IspcfgClient
  40. {
  41. protected $host;
  42. protected $server_id;
  43. protected $soap;
  44. protected $client_username;
  45. protected $client_id;
  46. protected $session_id;
  47.  
  48. /**
  49.   * @param string the hostname of the ISPConfig3 server
  50.   * @param string the client username this client will manipulate
  51.   * @param int [8080] the port number
  52.   * @param string [remote/index.php] the path of the web services endpoint
  53.   */
  54. function __construct($host, $client_username, $port = '8080', $path = 'remote/index.php')
  55. {
  56. $opts = array(
  57. 'location' => 'https://'.$host.':'.$port.'/'.$path,
  58. 'uri' => 'http://'.$host.'/remote/',
  59. 'exceptions' => true,
  60. // 'trace' => true,
  61. );
  62.  
  63. // create soap client in non-wsdl mode
  64. $this->soap = new SoapClient(null, $opts);
  65.  
  66. $this->client_username = $client_username;
  67. $this->host = $host;
  68. }
  69.  
  70. /**
  71.   * Login to the remote interface (also fetches the server id and client id needed
  72.   * by all other commands)
  73.   * @param string the username to connect as
  74.   * @param string the password of said user
  75.   * @throws IspcfgCannotConnectException
  76.   * @throws IspcfgAuthFailed
  77.   * @throws IspcfgInvalidClient
  78.   */
  79. public function login($user, $pass)
  80. {
  81. try {
  82. $this->session_id = $this->soap->login($user, $pass);
  83. } catch (SoapFault $e) {
  84. if (strpos($e->getMessage(), 'login failed') !== false)
  85. throw new IspcfgAuthFailed($e->getMessage(), 403);
  86. else
  87. throw new IspcfgCannotConnectException($e->getMessage(), 0);
  88. }
  89.  
  90. // grab the client id necessary for any other command
  91. $this->client_id = $this->fetchClientId($this->client_username);
  92. $this->server_id = $this->fetchServerId($this->host);
  93. }
  94.  
  95. /**
  96.   * Adds a subdomain to one of the clients domains. Does the following:
  97.   * 1. Adds a A record for <name>.tld
  98.   * 2. Adds an MX record for <name>.tld to mail.tld
  99.   * TODO maybe some basic validation on the TLD and IP?
  100.   * @param string the top level domain name (eg. blah.com)
  101.   * @param string the name of the subdomain (eg. mail)
  102.   * @param string the IP address for this subdomain to resolve to
  103.   * @return boolean
  104.   * @throws IspcfgException
  105.   * @throws IspcfgNoSessionException
  106.   */
  107. public function addSubdomain($tld, $name, $ip)
  108. {
  109. $this->checkSession();
  110.  
  111. $zone_id = $this->fetchZoneId($tld);
  112.  
  113. // add the A record
  114. $params = array(
  115. 'server_id' => $this->server_id,
  116. 'zone' => $zone_id,
  117. 'type' => 'A',
  118. 'name' => $name,
  119. 'data' => $ip,
  120. 'ttl' => '86400',
  121. 'active' => 'y',
  122. );
  123. try {
  124. $this->soap->dns_a_add($this->session_id, $this->client_id, $params);
  125. } catch (SoapFault $e) {
  126. throw new IspcfgException($e->getMessage());
  127. }
  128.  
  129. // add the MX record
  130. $params = array(
  131. 'server_id' => $this->server_id,
  132. 'zone' => $zone_id,
  133. 'type' => 'MX',
  134. 'name' => $name.'.'.$tld.'.',
  135. 'data' => 'mail.'.$tld.'.',
  136. 'ttl' => '86400',
  137. 'aux' => '10',
  138. 'active' => 'y',
  139. );
  140. try {
  141. $this->soap->dns_mx_add($this->session_id, $this->client_id, $params);
  142. } catch (SoapFault $e) {
  143. throw new IspcfgException($e->getMessage());
  144. }
  145.  
  146. return true;
  147. }
  148.  
  149. /**
  150.   * Setup mail for a domain and setup default SPAM policy.
  151.   * @param string the domain to add
  152.   * @return boolean
  153.   * @throws IspcfgException
  154.   * @throws IspcfgNoSessionException
  155.   */
  156. public function addMailDomain($domain)
  157. {
  158. $this->checkSession();
  159.  
  160. // Add domain to mailserver
  161. $params = array(
  162. 'server_id' => $this->server_id,
  163. 'domain' => $domain,
  164. 'active' => 'y',
  165. );
  166. try {
  167. $this->soap->mail_domain_add($this->session_id, $this->client_id, $params);
  168. } catch (SoapFault $e) {
  169. throw new IspcfgException($e->getMessage());
  170. }
  171.  
  172. // Add spam policy for domain
  173. $params = array(
  174. 'server_id' => $this->server_id,
  175. 'priority' => 5,
  176. 'policy_id' => 5, // Normal
  177. 'email' => '@'.$domain,
  178. 'fullname' => '@'.$domain,
  179. 'local' => 'Y',
  180. );
  181. try {
  182. $this->soap->mail_spamfilter_user_add($this->session_id, $this->client_id, $params);
  183. } catch (SoapFault $e) {
  184. throw new IspcfgException($e->getMessage());
  185. }
  186.  
  187. return true;
  188. }
  189.  
  190. /**
  191.   * Add a new mail account to domain with SPAM policy
  192.   * @param string the domain the email account is being added to
  193.   * @param string the name (that which precedes @) of the mail account
  194.   * @param string the password for the mail account
  195.   * @param integer [50] number in MB of mail quota
  196.   * @param string [normal] the spam policy to set for the mail account
  197.   * @return boolean
  198.   * @throws IspcfgException
  199.   * @throws IspcfgNoSessionException
  200.   */
  201. public function addMailAccount($domain, $mailbox, $passwd, $quota = 50, $spam = 'normal')
  202. {
  203. $this->checkSession();
  204.  
  205. switch ($spam) {
  206. default:
  207. $spam = 5;
  208. break;
  209. }
  210.  
  211. // Add mail user
  212. $params = array(
  213. 'server_id' => $this->server_id,
  214. 'email' => $mailbox.'@'.$domain,
  215. 'name' => $mailbox,
  216. 'password' => $passwd,
  217. 'quota' => intval($quota) * pow(1024, 2), // bytes converted to MB
  218. 'postfix' => 'y', // enable receiving
  219. 'homedir' => '/var/vmail',
  220. 'maildir' => '/var/vmail/'.$domain.'/'.$mailbox,
  221. 'uid' => 5000,
  222. 'gid' => 5000,
  223. );
  224. try {
  225. $this->soap->mail_user_add($this->session_id, $this->client_id, $params);
  226. } catch (SoapFault $e) {
  227. throw new IspcfgException($e->getMessage());
  228. }
  229.  
  230. // Add mail user's spam policy
  231. $params = array(
  232. 'server_id' => $this->server_id,
  233. 'priority' => 10,
  234. 'policy_id' => $spam, // Normal
  235. 'email' => $mailbox.'@'.$domain,
  236. 'fullname' => $mailbox,
  237. 'local' => 'Y',
  238. );
  239. try {
  240. $this->soap->mail_spamfilter_user_add($this->session_id, $this->client_id, $params);
  241. } catch (SoapFault $e) {
  242. throw new IspcfgException($e->getMessage());
  243. }
  244.  
  245. return true;
  246. }
  247.  
  248. /**
  249.   * Remove a top-level domain and associated records from DNS.
  250.   * @param string the fully qualified domain name (or subdomain)
  251.   * @return boolean true on success
  252.   * @throws IspcfgInvalidDomainException if the domain does not exist
  253.   * @throws IspcfgException
  254.   * @throws IspcfgNoSessionException
  255.   */
  256. public function removeDomain($tld, $name)
  257. {
  258. $this->checkSession();
  259.  
  260. try {
  261. $r = $this->soap->dns_delete_all($this->session_id, $domain);
  262.  
  263. if (empty($r))
  264. throw new IspcfgInvalidDomainException('Domain '.$domain.' was not found');
  265.  
  266. } catch (SoapFault $e) {
  267. throw new IspcfgException($e->getMessage());
  268. }
  269.  
  270. return true;
  271. }
  272.  
  273. /**
  274.   * Remove a subdomain and associated records from DNS.
  275.   * Removes a subdomain to from a top level domain and any A, CNAME, MX records that are related.
  276.   * TODO maybe some basic validation on the TLD and IP?
  277.   * @param string the top level domain name (eg. blah.com)
  278.   * @param string the name of the subdomain (eg. mail)
  279.   * @throws IspcfgInvalidDomainException if the domain does not exist
  280.   * @throws IspcfgException
  281.   * @throws IspcfgNoSessionException
  282.   */
  283. public function removeSubdomain($tld, $name)
  284. {
  285. $this->checkSession();
  286.  
  287. try {
  288. return $this->soap->dns_delete_subdomain($this->session_id, $tld, $name);
  289. } catch (SoapFault $e) {
  290. throw new IspcfgException($e->getMessage());
  291. }
  292. }
  293.  
  294. /**
  295.   * Remove a mail domain, all associated users, and any spam settings for the domain or users.
  296.   * @param string the fully qualified domain name (or subdomain)
  297.   * @return boolean true on success
  298.   * @throws IspcfgInvalidDomainException if the domain does not exist
  299.   * @throws IspcfgException
  300.   * @throws IspcfgNoSessionException
  301.   */
  302. public function removeMailDomain($domain)
  303. {
  304. $this->checkSession();
  305.  
  306. try {
  307. $r = $this->soap->mail_domain_get_by_domain($this->session_id, $domain);
  308.  
  309. if (empty($r))
  310. throw new IspcfgInvalidDomainException('Domain '.$domain.' was not found');
  311.  
  312. $domain_id = $r[0]['domain_id'];
  313.  
  314. $this->removeMailAccounts($domain);
  315.  
  316. $this->soap->mail_spamfilter_user_delete_by_email($this->session_id, '@'.$domain);
  317. $this->soap->mail_domain_delete($this->session_id, $domain_id);
  318. } catch (SoapFault $e) {
  319. throw new IspcfgException($e->getMessage());
  320. }
  321.  
  322. return true;
  323. }
  324.  
  325. /**
  326.   * Remove all mail accounts for a mail domain.
  327.   * @param string the fully qualified domain name (or subdomain)
  328.   * @param array optional list of mail accounts to delete, all are delete if not specified (<user>@domain.com)
  329.   * @return boolean false if no users were found, true if any were found and successfully removed
  330.   * @throws IspcfgException
  331.   * @throws IspcfgNoSessionException
  332.   */
  333. public function removeMailAccounts($domain, $only = array())
  334. {
  335. $this->checkSession();
  336.  
  337. // affix the domain to each specified user to make comparison tolerable
  338. if (!empty($only))
  339. {
  340. foreach ($only as $k => $u)
  341. $only[$k] = $u.'@'.$domain;
  342. }
  343.  
  344. try {
  345. // TODO should probably add a paramter or method to only bring back specified users
  346. $users = $this->soap->mail_domain_get_users($this->session_id, $domain);
  347.  
  348. if (empty($users))
  349. return false;
  350.  
  351. foreach ($users as $r)
  352. {
  353. if (!empty($only) && array_search($r['email'], $only, true) === false)
  354. continue;
  355.  
  356. $this->soap->mail_spamfilter_user_delete_by_email($this->session_id, $r['email']);
  357. $this->soap->mail_user_delete($this->session_id, $r['mailuser_id']);
  358. }
  359. } catch (SoapFault $e) {
  360. throw new IspcfgException($e->getMessage());
  361. }
  362.  
  363. return true;
  364. }
  365.  
  366. /**
  367.   * Logout of the remote interface
  368.   */
  369. public function logout()
  370. {
  371. $this->checkSession();
  372.  
  373. try {
  374. $this->soap->logout($this->session_id);
  375. $this->session_id = null;
  376. } catch (SoapFault $e) {
  377. throw new IspcfgException($e->getMessage(), 500);
  378. }
  379. }
  380.  
  381. /**
  382.   * Logout if the object is destroyed and logout was not called.
  383.   */
  384. public function __destruct()
  385. {
  386. if (!is_null($this->session_id))
  387. $this->logout();
  388. }
  389.  
  390. // ============
  391. // = internal =
  392. // ============
  393.  
  394. /**
  395.   * Retrieve the server id from the specified IP address.
  396.   * @param string the server's hostname or IP address
  397.   * @return string
  398.   * @throws IspcfgException
  399.   * @throws IspcfgUnknownServerException
  400.   */
  401. protected function fetchServerId($host)
  402. {
  403. // TODO make IPv6 aware
  404. if (preg_match('/^\d+/', $host) != 1)
  405. $ip = gethostbyname($host);
  406. else
  407. $ip = $host;
  408.  
  409. if (empty($ip))
  410. throw new IspcfgException('Unable to determine IP for host '.$host);
  411.  
  412. try {
  413. $server_id = $this->soap->server_get_serverid_by_ip($this->session_id, $ip);
  414.  
  415. if (is_array($server_id))
  416. $server_id = array_pop($server_id);
  417.  
  418. if ($server_id === false || !isset($server_id['server_id']))
  419. throw new IspcfgUnknownServerException('No server found with IP '.$ip);
  420.  
  421. $server_id = $server_id['server_id'];
  422.  
  423. } catch (SoapFault $e) {
  424. throw new IspcfgException($e->getMessage(), 500);
  425. }
  426. return $server_id;
  427. }
  428.  
  429. /**
  430.   * Retrieve the client id from the provided username. This value is necessary for nearly
  431.   * every other commands.
  432.   * @param string the client username
  433.   * @return integer
  434.   * @throws IspcfgInvalidClientException if the client is not found
  435.   */
  436. protected function fetchClientId($username)
  437. {
  438. try {
  439. $client_id = $this->soap->client_get_by_username(
  440. $this->session_id,
  441. $username
  442. );
  443.  
  444. if ($client_id === false || !isset($client_id['client_id']))
  445. throw new IspcfgInvalidClientException('Client username not found');
  446.  
  447. $client_id = $client_id['client_id'];
  448.  
  449. } catch (SoapFault $e) {
  450. throw new IspcfgException($e->getMessage(), 500);
  451. }
  452. return $client_id;
  453. }
  454.  
  455. /**
  456.   * Retrieve the zone id for a domain which is an internal identifier needed when
  457.   * calling dns related commands.
  458.   * TODO cache zone id lookups performed while this object is alive
  459.   * @param string the domain name to fetch the zone id for
  460.   * @return integer
  461.   * @throws IspcfgInvalidDomainException
  462.   * @throws IspcfgException
  463.   */
  464. protected function fetchZoneId($root_tld)
  465. {
  466. // the value returned will have a trailing dot so add for comparison
  467. $root_tld .= '.';
  468.  
  469. try {
  470. $zones = $this->soap->dns_zone_get_by_user(
  471. $this->session_id,
  472. $this->client_id,
  473. $this->server_id
  474. );
  475. if (is_array($zones))
  476. {
  477. foreach ($zones as $z)
  478. {
  479. if ($z['origin'] == $root_tld)
  480. {
  481. $zone_id = $z['id'];
  482. break;
  483. }
  484. }
  485. }
  486. else
  487. {
  488. throw new IspcfgInvalidDomainException('The domain '.$root_tld.' is not valid for this client');
  489. }
  490. } catch (SoapFault $e) {
  491. throw new IspcfgException($e->getMessage(), 500);
  492. }
  493. return $zone_id;
  494. }
  495.  
  496. /**
  497.   * Verify we've logged into the remote interface successfully.
  498.   * @throws IspcfgNoSessionException
  499.   */
  500. protected function checkSession()
  501. {
  502. if (is_null($this->session_id))
  503. throw new IspcfgNoSessionException('Please login first!');
  504. }
  505.  
  506. } // END Ispcfg3Client
  507.  
  508. // ==============
  509. // = Exceptions =
  510. // ==============
  511. class IspcfgException extends Exception {}
  512. class IspcfgUnknownServerException extends Exception {}
  513. /**
  514.  * Thrown when calling a command without first calling login.
  515.  */
  516. class IspcfgNoSessionException extends Exception {}
  517. class IspcfgInvalidClientException extends Exception {}
  518. class IspcfgInvalidDomainException extends Exception {}
  519. class IspcfgCannotConnectException extends Exception {}
  520. class IspcfgAuthFailed extends Exception {}
  521.  

Save-As: plain/text

ispcfg-3.0.3.3/001-mail_domain_get_by_domain.patch

Patch accepted! See revision 2331

  1. --- /usr/local/ispconfig/interface/lib/classes/remoting.inc.php 2011-04-20 11:58:02.150102228 -0500
  2. +++ ispconfig3_install/interface/lib/classes/remoting.inc.php 2011-04-20 12:08:02.618061519 -0500
  3. @@ -2395,24 +2395,29 @@
  4. return false;
  5. }
  6. }
  7. -
  8. - public function mail_domain_get_by_domain($session_id, $domain) {
  9. +
  10. + /**
  11. + * Fetch the mail_domain record for the provided domain.
  12. + * @param int session_id
  13. + * @param string the fully qualified domain (or subdomain)
  14. + * @return array array of arrays corresponding to the mail_domain table's records
  15. + * @author Unknown
  16. + */
  17. + public function mail_domain_get_by_domain($session_id, $domain) {
  18. global $app;
  19. if(!$this->checkPerm($session_id, 'mail_domain_get_by_domain')) {
  20. $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
  21. return false;
  22. - }
  23. - if (!empty($domain_id)) {
  24. - $domain = $app->db->quote($domain);
  25. - $sql = "SELECT * FROM mail_domain WHERE domain = $domain";
  26. + }
  27. + if (!empty($domain)) {
  28. + $domain = $app->db->quote($domain);
  29. + $sql = "SELECT * FROM mail_domain WHERE domain = '$domain'";
  30. $result = $app->db->queryAllRecords($sql);
  31. return $result;
  32. }
  33. return false;
  34. }
  35. -
  36. -
  37. -
  38. +
  39. /**
  40. * Get a list of functions
  41. * @param int session id
  42. @@ -2534,4 +2539,4 @@
  43. }
  44. }
  45. }
  46. -?>
  47. \ No newline at end of file
  48. +?>
  49.  

Save-As: plain/text

ispcfg-3.0.3.3/002-mail_domain_get_users.patch
  1. --- /usr/local/ispconfig/interface/lib/classes/remoting.inc.php 2011-04-20 10:38:28.574075332 -0500
  2. +++ ispconfig3_install/interface/lib/classes/remoting.inc.php 2011-04-20 11:14:08.730841387 -0500
  3. @@ -2397,6 +2397,43 @@
  4. }
  5.  
  6. /**
  7. + * Retrieve all mail accounts for the specified domain or domain id.
  8. + * @param int session_id
  9. + * @param string [null] the fully qualified domain (or subdomain), null to ignore
  10. + * @param int [null] the domain id, null to ignore, takes precedence if both are provided
  11. + * @return array array of arrays representing mail_user records or an empty array if no results
  12. + * @author Ben Lake <dev@benlake.org>
  13. + */
  14. + public function mail_domain_get_users($session_id, $domain = null, $domain_id = null)
  15. + {
  16. + global $app;
  17. +
  18. + if (empty($domain) && empty($domain_id)) {
  19. + $this->server->fault('invalid_arguments', 'You must specify either a domain name or domain id, neither provided');
  20. + }
  21. +
  22. + if(!$this->checkPerm($session_id, 'mail_domain_get_users')) {
  23. + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
  24. + return false;
  25. + }
  26. +
  27. + if (!empty($domain_id)) {
  28. + $domain_id = intval($domain_id);
  29. + $sql = "SELECT * FROM mail_user WHERE email LIKE concat('%@', (SELECT domain FROM mail_domain WHERE domain_id = ".$domain_id."))";
  30. + }
  31. + elseif (!empty($domain)) {
  32. + $domain = $app->db->quote($domain);
  33. + $sql = "SELECT * FROM mail_user WHERE email LIKE '%@".$domain."'";
  34. + }
  35. +
  36. + $result = $app->db->queryAllRecords($sql);
  37. + if (!is_array($result))
  38. + $result = array();
  39. +
  40. + return $result;
  41. + }
  42. +
  43. + /**
  44. * Fetch the mail_domain record for the provided domain.
  45. * @param int session_id
  46. * @param string the fully qualified domain (or subdomain)
  47.  

Save-As: plain/text

ispcfg-3.0.3.3/003-mail_spamfilter_user_delete_by_email.patch
  1. --- /usr/local/ispconfig/interface/lib/classes/remoting.inc.php 2011-04-20 12:31:46.906037774 -0500
  2. +++ ispconfig3_install/interface/lib/classes/remoting.inc.php 2011-04-20 12:52:37.786813579 -0500
  3. @@ -652,7 +652,29 @@
  4. $affected_rows = $this->deleteQuery('../mail/form/spamfilter_users.tform.php', $primary_id);
  5. return $affected_rows;
  6. }
  7. -
  8. +
  9. + /**
  10. + * Remove a spamfilter user using the user's email address.
  11. + * @param int session_id
  12. + * @param string email address or (@tld is ok too, but this is not a wildcard or anything)
  13. + * @return int the number of removed policies
  14. + * @author Unknown
  15. + */
  16. + public function mail_spamfilter_user_delete_by_email($session_id, $email)
  17. + {
  18. + global $app;
  19. + if (!$this->checkPerm($session_id, 'mail_spamfilter_user_delete')) {
  20. + $this->server->fault('permission_denied','You do not have the permissions to access this function.');
  21. + return false;
  22. + }
  23. +
  24. + $email = $app->db->quote($email);
  25. + $sql = "DELETE FROM spamfilter_users WHERE email = '".$email."'";
  26. + $app->db->query($sql);
  27. +
  28. + return $app->db->affectedRows();
  29. + }
  30. +
  31. //* Get policy details
  32. public function mail_policy_get($session_id, $primary_id)
  33. {
  34.  

Save-As: plain/text

ispcfg-3.0.3.3/004-dns_delete_all.patch
  1. --- /usr/local/ispconfig/interface/lib/classes/remoting.inc.php 2011-04-20 14:05:35.064084960 -0500
  2. +++ ispconfig3_install/interface/lib/classes/remoting.inc.php 2011-04-20 15:06:35.519360973 -0500
  3. @@ -2575,7 +2575,55 @@
  4. return false;
  5. }
  6. }
  7. -
  8. +
  9. + /**
  10. + * Remove a DNS zone and all associated records.
  11. + * @param int session_id
  12. + * @param string [null] the fully qualified domain (or subdomain), null to ignore
  13. + * @param int [null] the domain id, null to ignore, takes precedence if both are provided
  14. + * @return boolean true upon success, false if the dns_soa record is not found
  15. + * @author Ben Lake <dev@benlake.org>
  16. + */
  17. + public function dns_delete_all($session_id, $domain = null, $domain_id = null) {
  18. + global $app;
  19. +
  20. + if (empty($domain) && empty($domain_id)) {
  21. + $this->server->fault('invalid_arguments', 'You must specify either a domain name or domain id, neither provided');
  22. + }
  23. +
  24. + if(!$this->checkPerm($session_id, 'dns_zone_delete')) {
  25. + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
  26. + return false;
  27. + }
  28. +
  29. + // affix a dot to the domain as that is how they are stored
  30. + $domain .= '.';
  31. +
  32. + // look up the domain id needed for removing dns_rr records
  33. + if (empty($domain_id)) {
  34. + $domain = $app->db->quote($domain);
  35. + $sql = "SELECT id FROM dns_soa WHERE origin = '".$domain."' LIMIT 1";
  36. + $r = $app->db->queryOneRecord($sql);
  37. + if (empty($r)) return false;
  38. + $domain_id = $r['id'];
  39. + }
  40. +
  41. + $domain_id = intval($domain_id);
  42. + if ($domain_id == 0) return false;
  43. +
  44. + // remove the SOA record
  45. + $sql = "DELETE FROM dns_soa WHERE id = ".$domain_id;
  46. + $app->db->query($sql);
  47. +
  48. + // if we had a hit, go for the dns_rr
  49. + if ($app->db->affectedRows() > 0) {
  50. + $sql = "DELETE FROM dns_rr WHERE zone = ".$domain_id;
  51. + $app->db->query($sql);
  52. + }
  53. +
  54. + return true;
  55. + }
  56. +
  57. public function mail_domain_set_status($session_id, $primary_id, $status) {
  58. global $app;
  59. if(!$this->checkPerm($session_id, 'mail_domain_set_status')) {
  60.  

Save-As: plain/text

ispcfg-3.0.3.3/005-dns_delete_subdomain.patch
  1. --- /usr/local/ispconfig/interface/lib/classes/remoting.inc.php 2011-04-20 17:08:31.374041468 -0500
  2. +++ ispconfig3_install/interface/lib/classes/remoting.inc.php 2011-04-20 17:50:54.818059432 -0500
  3. @@ -2624,6 +2624,56 @@
  4. return true;
  5. }
  6.  
  7. + /**
  8. + * Attempts to remove all records associated with the provided subdomain. That means all
  9. + * record types are affected.
  10. + *
  11. + * Example for zone google.com:
  12. + * mail A x.x.x.x
  13. + * google.com MX mail.google.com
  14. + *
  15. + * Performing dns_delete_subdomain($sess, 'google.com','mail') would remove both records
  16. + * becuase both rely on the subdomain mail.google.com. So any record that utilizes 'mail'
  17. + * or 'mail.google.com' will be removed.
  18. + *
  19. + * @param int session_id
  20. + * @param string top level domain (e.g. google.com)
  21. + * @param int the subdomain component (e.g. mail, or one.mail, etc.)
  22. + * @return boolean true upon success, false if no records were found
  23. + * @author Ben Lake <dev@benlake.org>
  24. + */
  25. + public function dns_delete_subdomain($session_id, $tld, $subname) {
  26. + global $app;
  27. +
  28. + if(!$this->checkPerm($session_id, 'dns_zone_delete')) {
  29. + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
  30. + return false;
  31. + }
  32. +
  33. + // affix a dot to the domain as that is how they are stored
  34. + $domain = $tld.'.';
  35. +
  36. + // look up the domain id needed for removing dns_rr records
  37. + $domain = $app->db->quote($domain);
  38. + $sql = "SELECT id FROM dns_soa WHERE origin = '".$domain."' LIMIT 1";
  39. + $r = $app->db->queryOneRecord($sql);
  40. + if (empty($r)) return false;
  41. + $domain_id = intval($r['id']);
  42. +
  43. + $domain = $subname.'.'.$tld.'.';
  44. +
  45. + $subname = $app->db->quote($subname);
  46. + $domain = $app->db->quote($domain);
  47. + $sql = "DELETE FROM dns_rr WHERE name = '".$subname."' OR name = '".$domain
  48. + ."' OR data = '".$subname."' OR data = '".$domain."' AND zone = ".$domain_id;
  49. + $app->db->query($sql);
  50. +
  51. + if ($app->db->affectedRows() == 0)
  52. + return false;
  53. +
  54. + return true;
  55. + }
  56. +
  57. public function mail_domain_set_status($session_id, $primary_id, $status) {
  58. global $app;
  59. if(!$this->checkPerm($session_id, 'mail_domain_set_status')) {
  60.  

Save-As: plain/text