ISPConfig module for simplify the creation of websites and DNS zones in a only step
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

619 Zeilen
21 KiB

  1. <?php
  2. /*
  3. Copyright (c) 2016, Kristián Feldsam, FELDSAM s.r.o. <info@feldsam.cz>
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without modification,
  6. are permitted provided that the following conditions are met:
  7. * Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright notice,
  10. this list of conditions and the following disclaimer in the documentation
  11. and/or other materials provided with the distribution.
  12. * Neither the name of ISPConfig nor the names of its contributors
  13. may be used to endorse or promote products derived from this software without
  14. specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  19. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  20. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  24. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. /******************************************
  27. * Begin Form configuration
  28. ******************************************/
  29. $tform_def_file = "form/ftp_bd_service.tform.php";
  30. /******************************************
  31. * End Form configuration
  32. ******************************************/
  33. require_once '../../lib/config.inc.php';
  34. require_once '../../lib/app.inc.php';
  35. //* Check permissions for module
  36. $app->auth->check_module_permissions('webdns');
  37. // Loading classes
  38. $app->uses('tpl,tform,remoting');
  39. $app->load('tform_actions');
  40. class page_action extends tform_actions {
  41. function onShowEnd() {
  42. global $app, $conf;
  43. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  44. // select first template as default
  45. if($fields['dns_template_id'] == 0)
  46. {
  47. $first_template = $app->db->queryOneRecord("SELECT template_id FROM dns_template WHERE visible = 'Y' ORDER BY name ASC");
  48. $fields['dns_template_id'] = $first_template['template_id'];
  49. }
  50. $template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = ?", $fields['dns_template_id']);
  51. $fields = explode(',', $template_record['fields']);
  52. if(is_array($fields)) {
  53. foreach($fields as $field) {
  54. $app->tpl->setVar($field."_VISIBLE", 1);
  55. $field = strtolower($field);
  56. $app->tpl->setVar($field, $_POST['dns_'.$field]);
  57. }
  58. }
  59. parent::onShowEnd();
  60. }
  61. function onSubmit() {
  62. global $app, $conf;
  63. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  64. // check for domain unique name
  65. if($app->db->queryOneRecord('SELECT domain_id FROM domain WHERE domain = "'.$fields['domain'].'"')) {
  66. $app->tform->errorMessage = $app->tform->wordbook['domain_error_unique'];
  67. }
  68. if($app->tform->errorMessage)
  69. {
  70. $this->onError();
  71. return;
  72. }
  73. if($_POST['create'] != 1)
  74. {
  75. $app->tform->errorMessage = 'DUMMY';
  76. $app->tpl->setVar($this->dataRecord);
  77. $this->onShow();
  78. return;
  79. }
  80. // Domain OK, continue
  81. $remote = new remote_actions;
  82. // load template
  83. $template = $app->db->queryOneRecord("SELECT * FROM wizard_template WHERE template_id = ? LIMIT 0,1", $fields['template_id']);
  84. // client prefix and group id
  85. $res = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($fields['client_id']));
  86. $client_group_id = $res['groupid'];
  87. $client_prefix = 'c'.$fields['client_id'];
  88. // add domain
  89. $domain_id = $remote->insert_query('../client/form/domain.tform.php', $fields['client_id'], array('domain' => $fields['domain']));
  90. // DNS Zone
  91. if($fields['dns'])
  92. {
  93. if(isset($_POST['dns_ns1']) && $_POST['dns_ns1'] != ''){
  94. $_POST['dns_ns1'] = $app->functions->idn_encode($_POST['dns_ns1']);
  95. $_POST['dns_ns1'] = strtolower($_POST['dns_ns1']);
  96. }
  97. if(isset($_POST['dns_ns2']) && $_POST['dns_ns2'] != ''){
  98. $_POST['dns_ns2'] = $app->functions->idn_encode($_POST['dns_ns2']);
  99. $_POST['dns_ns2'] = strtolower($_POST['dns_ns2']);
  100. }
  101. if(isset($_POST['dns_email']) && $_POST['dns_email'] != ''){
  102. $_POST['dns_email'] = $app->functions->idn_encode($_POST['dns_email']);
  103. $_POST['dns_email'] = strtolower($_POST['dns_email']);
  104. }
  105. $dns_error = '';
  106. if(isset($_POST['dns_ip']) && $_POST['dns_ip'] == '') $dns_error .= $app->lng('error_ip_empty').'<br />';
  107. if(isset($_POST['dns_ipv6']) && $_POST['dns_ipv6'] == '') $dns_error .= $app->lng('error_ipv6_empty').'<br />';
  108. if(isset($_POST['dns_ns1']) && $_POST['dns_ns1'] == '') $dns_error .= $app->lng('error_ns1_empty').'<br />';
  109. elseif(isset($_POST['ns1']) && !preg_match('/^[\w\.\-]{2,64}\.[a-zA-Z0-9]{2,30}$/', $_POST['ns1'])) $dns_error .= $app->lng('error_ns1_regex').'<br />';
  110. if(isset($_POST['dns_ns2']) && $_POST['dns_ns2'] == '') $dns_error .= $app->lng('error_ns2_empty').'<br />';
  111. elseif(isset($_POST['ns2']) && !preg_match('/^[\w\.\-]{2,64}\.[a-zA-Z0-9]{2,30}$/', $_POST['ns2'])) $dns_error .= $app->lng('error_ns2_regex').'<br />';
  112. if(isset($_POST['dns_email']) && $_POST['dns_email'] == '') $dns_error .= $app->lng('error_email_empty').'<br />';
  113. elseif(isset($_POST['dns_email']) && filter_var($_POST['dns_email'], FILTER_VALIDATE_EMAIL) === false) $dns_error .= $app->lng('error_email_regex').'<br />';
  114. // check for dns errors
  115. if($dns_error)
  116. {
  117. $app->tform->errorMessage = $dns_error;
  118. $this->onError();
  119. return;
  120. }
  121. $tform_def_file = "../dns/form/dns_soa.tform.php";
  122. $app->tform->loadFormDef($tform_def_file);
  123. // replace template placeholders
  124. $template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = ?", $fields['dns_template_id']);
  125. $tpl_content = $template_record['template'];
  126. $tpl_content = str_replace('{DOMAIN}', $fields['domain'], $tpl_content);
  127. if($_POST['dns_ip'] != '') $tpl_content = str_replace('{IP}', $_POST['dns_ip'], $tpl_content);
  128. if($_POST['dns_ipv6'] != '') $tpl_content = str_replace('{IPV6}',$_POST['dns_ipv6'],$tpl_content);
  129. if($_POST['dns_ns1'] != '') $tpl_content = str_replace('{NS1}', $_POST['dns_ns1'], $tpl_content);
  130. if($_POST['dns_ns2'] != '') $tpl_content = str_replace('{NS2}', $_POST['dns_ns2'], $tpl_content);
  131. if($_POST['dns_email'] != '') $tpl_content = str_replace('{EMAIL}', $_POST['dns_email'], $tpl_content);
  132. $enable_dnssec = (($_POST['dns_dnssec'] == 'Y') ? 'Y' : 'N');
  133. // Parse the template
  134. $tpl_rows = explode("\n", $tpl_content);
  135. $section = '';
  136. $vars = array();
  137. $vars['xfer']='';
  138. $dns_rr = array();
  139. foreach($tpl_rows as $row) {
  140. $row = trim($row);
  141. if(substr($row, 0, 1) == '[') {
  142. if($row == '[ZONE]') {
  143. $section = 'zone';
  144. } elseif($row == '[DNS_RECORDS]') {
  145. $section = 'dns_records';
  146. } else {
  147. die('Unknown section type');
  148. }
  149. } else {
  150. if($row != '') {
  151. // Handle zone section
  152. if($section == 'zone') {
  153. $parts = explode('=', $row);
  154. $key = trim($parts[0]);
  155. $val = trim($parts[1]);
  156. if($key != '') $vars[$key] = $val;
  157. }
  158. // Handle DNS Record rows
  159. if($section == 'dns_records') {
  160. $parts = explode('|', $row);
  161. $dns_rr[] = array(
  162. 'name' => $parts[1],
  163. 'type' => $parts[0],
  164. 'data' => $parts[2],
  165. 'aux' => $parts[3],
  166. 'ttl' => $parts[4]
  167. );
  168. }
  169. }
  170. }
  171. } // end foreach
  172. $dns_error = '';
  173. if($vars['origin'] == '') $dns_error .= $app->lng('error_origin_empty').'<br />';
  174. if($vars['ns'] == '') $dns_error .= $app->lng('error_ns_empty').'<br />';
  175. if($vars['mbox'] == '') $dns_error .= $app->lng('error_mbox_empty').'<br />';
  176. if($vars['refresh'] == '') $dns_error .= $app->lng('error_refresh_empty').'<br />';
  177. if($vars['retry'] == '') $dns_error .= $app->lng('error_retry_empty').'<br />';
  178. if($vars['expire'] == '') $dns_error .= $app->lng('error_expire_empty').'<br />';
  179. if($vars['minimum'] == '') $dns_error .= $app->lng('error_minimum_empty').'<br />';
  180. if($vars['ttl'] == '') $dns_error .= $app->lng('error_ttl_empty').'<br />';
  181. // check for dns errors
  182. if($dns_error)
  183. {
  184. $app->tform->errorMessage = $dns_error;
  185. $this->onError();
  186. return;
  187. }
  188. // Insert the soa record
  189. $sys_userid = $_SESSION['s']['user']['userid'];
  190. $origin = $vars['origin'];
  191. $ns = $vars['ns'];
  192. $mbox = str_replace('@', '.', $vars['mbox']);
  193. $refresh = $vars['refresh'];
  194. $retry = $vars['retry'];
  195. $expire = $vars['expire'];
  196. $minimum = $vars['minimum'];
  197. $ttl = $vars['ttl'];
  198. $xfer = $vars['xfer'];
  199. $also_notify = $vars['also_notify'];
  200. $update_acl = $vars['update_acl'];
  201. $serial = $app->validate_dns->increase_serial(0);
  202. $insert_data = array(
  203. "sys_userid" => $sys_userid,
  204. "sys_groupid" => $client_group_id,
  205. "sys_perm_user" => 'riud',
  206. "sys_perm_group" => 'riud',
  207. "sys_perm_other" => '',
  208. "server_id" => $template['dns_server_id'],
  209. "origin" => $origin,
  210. "ns" => $ns,
  211. "mbox" => $mbox,
  212. "serial" => $serial,
  213. "refresh" => $refresh,
  214. "retry" => $retry,
  215. "expire" => $expire,
  216. "minimum" => $minimum,
  217. "ttl" => $ttl,
  218. "active" => 'Y',
  219. "xfer" => $xfer,
  220. "also_notify" => $also_notify,
  221. "update_acl" => $update_acl,
  222. "dnssec_wanted" => $enable_dnssec
  223. );
  224. $dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');
  225. // Insert the dns_rr records
  226. if(is_array($dns_rr) && $dns_soa_id > 0) {
  227. foreach($dns_rr as $rr) {
  228. $insert_data = array(
  229. "sys_userid" => $sys_userid,
  230. "sys_groupid" => $client_group_id,
  231. "sys_perm_user" => 'riud',
  232. "sys_perm_group" => 'riud',
  233. "sys_perm_other" => '',
  234. "server_id" => $template['dns_server_id'],
  235. "zone" => $dns_soa_id,
  236. "name" => $rr['name'],
  237. "type" => $rr['type'],
  238. "data" => $rr['data'],
  239. "aux" => $rr['aux'],
  240. "ttl" => $rr['ttl'],
  241. "active" => 'Y'
  242. );
  243. $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
  244. }
  245. if($fields['dkim'])
  246. {
  247. $insert_data = array(
  248. "sys_userid" => $sys_userid,
  249. "sys_groupid" => $client_group_id,
  250. "sys_perm_user" => 'riud',
  251. "sys_perm_group" => 'riud',
  252. "sys_perm_other" => '',
  253. "server_id" => $template['dns_server_id'],
  254. "zone" => $dns_soa_id,
  255. "name" => $fields['dkim_selector'].'._domainkey.'.$fields['domain'].'.',
  256. "type" => 'TXT',
  257. "data" => 'v=DKIM1; t=s; p='.str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\r","\n"), '', $_POST['dkim_public']),
  258. "aux" => 0,
  259. "ttl" => 86400,
  260. "active" => 'Y'
  261. );
  262. $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
  263. }
  264. }
  265. $tform_def_file = "form/ftp_bd_service.tform.php";
  266. $app->tform->loadFormDef($tform_def_file);
  267. }
  268. if($fields['mail'])
  269. {
  270. // add mail domain
  271. $params = array(
  272. 'server_id' => $template['mail_server_id'],
  273. 'domain' => $fields['domain'],
  274. 'dkim' => $fields['dkim'],
  275. 'dkim_private' => $_POST['dkim_private'],
  276. 'dkim_public' => $_POST['dkim_public'],
  277. 'dkim_selector' => $fields['dkim_selector'],
  278. 'active' => 'y'
  279. );
  280. $mail_domain_id = $remote->insert_query('../mail/form/mail_domain.tform.php', $fields['client_id'], $params);
  281. if($template['policy'])
  282. {
  283. $params = array(
  284. 'server_id' => $template['mail_server_id'],
  285. 'policy_id' => $template['policy'],
  286. 'priority' => 5,
  287. 'email' => '@'.$fields['domain'],
  288. 'fullname' => '@'.$fields['domain'],
  289. 'local' => 'Y',
  290. );
  291. $remote->insert_query('../mail/form/spamfilter_users.tform.php', $fields['client_id'], $params);
  292. }
  293. if($fields['mailboxes'])
  294. {
  295. $mailboxes = explode(',', $fields['mailboxes']);
  296. $mailbox_passwords = array();
  297. foreach($mailboxes as $alias)
  298. {
  299. $alias = strtolower($app->functions->idn_encode($alias));
  300. $mailbox = $alias.'@'.$fields['domain'];
  301. // validate, on error skip
  302. if( ! preg_match('/^[_a-z0-9][\w\.\-_\+@]{1,63}$/', $mailbox)) continue;
  303. $mailbox_passwords[$mailbox] = substr(sha1(rand()), 0, 10);
  304. $params = array(
  305. 'server_id' => $template['mail_server_id'],
  306. 'uid' => -1,
  307. 'gid' => -1,
  308. 'email' => $mailbox,
  309. 'login' => $mailbox,
  310. 'password' => $mailbox_passwords[$mailbox],
  311. 'quota' => $template['mailbox_quota']*1024*1024,
  312. 'postfix' => 'y',
  313. 'disableimap' => ($template['enableimap'] == 'y' ? 'n' : 'y'),
  314. 'disablepop3' => ($template['enablepop3'] == 'y' ? 'n' : 'y'),
  315. 'disablesmtp' => ($template['enablesmtp'] == 'y' ? 'n' : 'y'),
  316. 'maildir' => '/var/vmail/'.$fields['domain'].'/'.$alias,
  317. 'homedir' => '/var/vmail',
  318. );
  319. $remote->insert_query('../mail/form/mail_user.tform.php', $fields['client_id'], $params);
  320. }
  321. }
  322. }
  323. // add site
  324. $params = array(
  325. 'type' => 'vhost',
  326. 'domain' => $fields['domain'],
  327. 'server_id' => $template['web_server_id'],
  328. 'ip_address' => $template['ip_address'],
  329. 'ipv6_address' => $template['ipv6_address'],
  330. 'traffic_quota' => $template['traffic_quota'],
  331. 'hd_quota' => $template['hd_quota'],
  332. 'cgi' => $template['cgi'],
  333. 'ssi' => $template['ssi'],
  334. 'suexec' => $template['suexec'],
  335. 'ruby' => $template['ruby'],
  336. 'python' => $template['python'],
  337. 'perl' => $template['perl'],
  338. 'errordocs' => $template['errordocs'],
  339. 'subdomain' => $template['subdomain'],
  340. 'php' => $template['php'],
  341. 'fastcgi_php_version' => $template['fastcgi_php_version'],
  342. 'seo_redirect' => $template['seo_redirect'],
  343. 'rewrite_to_https' => $template['rewrite_to_https'],
  344. 'allow_override' => $template['allow_override'],
  345. 'http_port' => $template['http_port'],
  346. 'https_port' => $template['https_port'],
  347. 'apache_directives' => $template['apache_directives'],
  348. 'nginx_directives' => $template['nginx_directives'],
  349. 'php_fpm_use_socket' => $template['php_fpm_use_socket'],
  350. 'pm' => $template['pm'],
  351. 'pm_max_children' => $template['pm_max_children'],
  352. 'pm_start_servers' => $template['pm_start_servers'],
  353. 'pm_min_spare_servers' => $template['pm_min_spare_servers'],
  354. 'pm_max_spare_servers' => $template['pm_max_spare_servers'],
  355. 'pm_process_idle_timeout' => $template['pm_process_idle_timeout'],
  356. 'pm_max_requests' => $template['pm_max_requests'],
  357. 'custom_php_ini' => $template['custom_php_ini'],
  358. 'active' => 'y',
  359. 'document_root' => '-',
  360. 'system_user' => '-',
  361. 'system_group' => '-',
  362. 'client_group_id' => $client_group_id,
  363. );
  364. $site_id = $remote->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_id'], $params, 'sites:web_vhost_domain:on_after_insert');
  365. // get site data
  366. $app->uses('remoting_lib');
  367. $app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php');
  368. $site_data = $app->remoting_lib->getDataRecord($site_id);
  369. // generate username
  370. $generated_username = $client_prefix.substr(sha1(rand()), 0, 8);
  371. if($fields['db'])
  372. {
  373. // add database user
  374. $db_user_params = array(
  375. 'server_id' => $template['database_server_id'],
  376. 'database_user' => $generated_username,
  377. 'database_password' => substr(sha1(rand()), 0, 10)
  378. );
  379. $db_user_id = $remote->insert_query('../sites/form/database_user.tform.php', $fields['client_id'], $db_user_params, 'sites:web_database_user:on_after_insert');
  380. // add database
  381. $params = array(
  382. 'server_id' => $template['database_server_id'],
  383. 'parent_domain_id' => $site_id,
  384. 'type' => $fields['db_type'],
  385. 'database_quota' => $template['database_quota'],
  386. 'database_name' => $db_user_params['database_user'],
  387. 'database_user_id' => $db_user_id,
  388. 'database_charset' => $template['database_charset'],
  389. 'remote_access' => $template['database_remote_access'],
  390. 'remote_ips' => $template['database_remote_ips'],
  391. 'active' => 'y'
  392. );
  393. $remote->sites_database_add($fields['client_id'], $params);
  394. }
  395. if($fields['ftp']) {
  396. // add ftp user
  397. $ftp_params = array(
  398. 'server_id' => $template['web_server_id'],
  399. 'parent_domain_id' => $site_id,
  400. 'username' => $generated_username,
  401. 'password' => substr(sha1(rand()), 0, 10),
  402. 'quota_size' => $template['hd_quota'],
  403. 'dir' => $site_data['document_root'],
  404. 'uid' => $site_data['system_user'],
  405. 'gid' => $site_data['system_group'],
  406. 'sys_groupid' => $site_data['sys_groupid'],
  407. 'quota_files' => $template['quota_files'],
  408. 'ul_ratio' => $template['ul_ratio'],
  409. 'dl_ratio' => $template['dl_ratio'],
  410. 'ul_bandwidth' => $template['ul_bandwidth'],
  411. 'dl_bandwidth' => $template['dl_bandwidth'],
  412. 'active' => 'y',
  413. );
  414. $remote->insert_query('../sites/form/ftp_user.tform.php', $fields['client_id'], $ftp_params);
  415. }
  416. if($fields['ssh']) {
  417. // add ssh user
  418. $ssh_params = array(
  419. 'server_id' => $template['web_server_id'],
  420. 'parent_domain_id' => $site_id,
  421. 'quota_size' => $template['hd_quota'],
  422. 'dir' => $site_data['document_root'],
  423. 'puser' => $site_data['system_user'],
  424. 'pgroup' => $site_data['system_group'],
  425. 'sys_groupid' => $site_data['sys_groupid'],
  426. 'chroot' => $template['shell_chroot'],
  427. 'shell' => $template['shell'],
  428. 'active' => 'y',
  429. 'username' => $generated_username,
  430. );
  431. // username, password
  432. if(isset($ftp_params)) {
  433. $ssh_params['password'] = $ftp_params['password'];
  434. } else {
  435. $ssh_params['password'] = substr(sha1(rand()), 0, 10);
  436. }
  437. $remote->insert_query('../sites/form/shell_user.tform.php', $fields['client_id'], $ssh_params);
  438. }
  439. // results
  440. echo '
  441. <div class="page-header">
  442. <h1>New service</h1>
  443. </div>
  444. <div class="table-wrapper marginTop15">
  445. <table class="table">
  446. <thead class="dark">
  447. <tr>
  448. <th colspan="2">'.$fields['domain'].'</th>
  449. </tr>
  450. </thead>
  451. <tbody>';
  452. if(isset($db_user_params)) {
  453. echo
  454. '<tr class="info">
  455. <th>DB name/user</th>
  456. <th>DB password</th>
  457. </tr>
  458. <tr>
  459. <td>'.$db_user_params['database_user'].'</td>
  460. <td>'.$db_user_params['database_password'].'</td>
  461. </tr>';
  462. }
  463. if(isset($ftp_params)) {
  464. echo'
  465. <tr class="info">
  466. <th>FTP user</th>
  467. <th>FTP password</th>
  468. </tr>
  469. <tr>
  470. <td>'.$ftp_params['username'].'</td>
  471. <td>'.$ftp_params['password'].'</td>
  472. </tr>';
  473. }
  474. if(isset($ssh_params)) {
  475. echo'
  476. <tr class="info">
  477. <th>SSH user</th>
  478. <th>SSH password</th>
  479. </tr>
  480. <tr>
  481. <td>'.$ssh_params['username'].'</td>
  482. <td>'.$ssh_params['password'].'</td>
  483. </tr>';
  484. }
  485. if(isset($mailbox_passwords) and (bool)count($mailbox_passwords))
  486. {
  487. echo '
  488. <tr class="info">
  489. <th>Mailbox</th>
  490. <th>Password</th>
  491. </tr>';
  492. foreach($mailbox_passwords as $mail => $pass)
  493. {
  494. echo'
  495. <tr>
  496. <td>'.$mail.'</td>
  497. <td>'.$pass.'</td>
  498. </tr>';
  499. }
  500. }
  501. echo'
  502. </tbody>
  503. </table>
  504. </div>
  505. ';
  506. }
  507. private function clean_private_key($key)
  508. {
  509. return str_replace('\r\n', '', $key);
  510. }
  511. }
  512. class remote_actions extends remoting {
  513. public function insert_query($formdef_file, $client_id, $params, $event_identifier = '') {
  514. return $this->insertQuery($formdef_file, $client_id, $params, $event_identifier);
  515. }
  516. public function sites_database_add($client_id, $params)
  517. {
  518. global $app;
  519. $sql = $this->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params);
  520. if($sql !== false) {
  521. $app->uses('sites_database_plugin');
  522. $this->id = 0;
  523. $this->dataRecord = $params;
  524. $app->sites_database_plugin->processDatabaseInsert($this);
  525. $retval = $this->insertQueryExecute($sql, $params);
  526. // set correct values for backup_interval and backup_copies
  527. if(isset($params['backup_interval']) || isset($params['backup_copies'])){
  528. $sql_set = array();
  529. if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
  530. if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
  531. //$app->db->query("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval);
  532. $this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval, $retval, $params);
  533. }
  534. return $retval;
  535. }
  536. return false;
  537. }
  538. }
  539. $page = new page_action;
  540. $page->onLoad();