ISPConfig module for simplify the creation of websites and DNS zones in a only step
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

514 wiersze
23 KiB

  1. <?php
  2. /*
  3. Copyright (c) 2008, Till Brehm, projektfarm Gmbh
  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/database.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('sites');
  37. // Loading classes
  38. $app->uses('tpl,tform,tform_actions');
  39. $app->load('tform_actions');
  40. class page_action extends tform_actions {
  41. function onShowNew() {
  42. global $app, $conf;
  43. // we will check only users, not admins
  44. if($_SESSION["s"]["user"]["typ"] == 'user') {
  45. if(!$app->tform->checkClientLimit('limit_database')) {
  46. $app->error($app->tform->wordbook["limit_database_txt"]);
  47. }
  48. if(!$app->tform->checkResellerLimit('limit_database')) {
  49. $app->error('Reseller: '.$app->tform->wordbook["limit_database_txt"]);
  50. }
  51. } else {
  52. $settings = $app->getconf->get_global_config('sites');
  53. $app->tform->formDef['tabs']['database']['fields']['server_id']['default'] = intval($settings['default_dbserver']);
  54. }
  55. parent::onShowNew();
  56. }
  57. function onShowEnd() {
  58. global $app, $conf, $interfaceConf;
  59. if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
  60. // Get the limits of the client
  61. $client_group_id = $_SESSION["s"]["user"]["default_group"];
  62. $client = $app->db->queryOneRecord("SELECT db_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
  63. // Set the webserver to the default server of the client
  64. $tmp = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE server_id IN ?", explode(',', $client['db_servers']));
  65. $only_one_server = count($tmp) === 1;
  66. $app->tpl->setVar('only_one_server', $only_one_server);
  67. if ($only_one_server) {
  68. $app->tpl->setVar('server_id_value', $tmp[0]['server_id']);
  69. }
  70. foreach ($tmp as $db_server) {
  71. $options_db_servers .= '<option value="'.$db_server['server_id'].'"'.($this->id > 0 && $this->dataRecord["server_id"] == $db_server['server_id'] ? ' selected="selected"' : '').'>'.$db_server['server_name'].'</option>';
  72. }
  73. $app->tpl->setVar("server_id", $options_db_servers);
  74. unset($tmp);
  75. } elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
  76. // Get the limits of the client
  77. $client_group_id = $_SESSION["s"]["user"]["default_group"];
  78. $client = $app->db->queryOneRecord("SELECT client.client_id, limit_web_domain, db_servers, contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
  79. // Set the webserver to the default server of the client
  80. $tmp = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE server_id IN ?", explode(',', $client['db_servers']));
  81. $only_one_server = count($tmp) === 1;
  82. $app->tpl->setVar('only_one_server', $only_one_server);
  83. if ($only_one_server) {
  84. $app->tpl->setVar('server_id_value', $tmp[0]['server_id']);
  85. }
  86. foreach ($tmp as $db_server) {
  87. $options_db_servers .= '<option value="'.$db_server['server_id'].'"'.($this->id > 0 && $this->dataRecord["server_id"] == $db_server['server_id'] ? ' selected="selected"' : '').'>'.$db_server['server_name'].'</option>';
  88. }
  89. $app->tpl->setVar("server_id", $options_db_servers);
  90. unset($tmp);
  91. } else {
  92. // The user is admin
  93. if($this->id > 0) {
  94. $server_id = $this->dataRecord["server_id"];
  95. } else {
  96. // Get the first server ID
  97. $tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1");
  98. $server_id = $tmp['server_id'];
  99. }
  100. }
  101. /*
  102. * If the names are restricted -> remove the restriction, so that the
  103. * data can be edited
  104. */
  105. //* Get the database name and database user prefix
  106. $app->uses('getconf,tools_sites');
  107. $global_config = $app->getconf->get_global_config('sites');
  108. $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord);
  109. if ($this->dataRecord['database_name'] != ""){
  110. /* REMOVE the restriction */
  111. $app->tpl->setVar("database_name", $app->tools_sites->removePrefix($this->dataRecord['database_name'], $this->dataRecord['database_name_prefix'], $dbname_prefix));
  112. }
  113. if($this->dataRecord['database_name'] == "") {
  114. $app->tpl->setVar("database_name_prefix", $dbname_prefix);
  115. } else {
  116. $app->tpl->setVar("database_name_prefix", $app->tools_sites->getPrefix($this->dataRecord['database_name_prefix'], $dbname_prefix, $global_config['dbname_prefix']));
  117. }
  118. if($this->id > 0) {
  119. //* we are editing a existing record
  120. $edit_disabled = @($_SESSION["s"]["user"]["typ"] == 'admin')? 0 : 1; //* admin can change the database-name
  121. $app->tpl->setVar("edit_disabled", $edit_disabled);
  122. $app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]);
  123. $app->tpl->setVar("database_charset_value", $this->dataRecord["database_charset"]);
  124. $app->tpl->setVar("limit_database_quota", $this->dataRecord["database_quota"]);
  125. } else {
  126. $app->tpl->setVar("edit_disabled", 0);
  127. }
  128. parent::onShowEnd();
  129. }
  130. function onSubmit() {
  131. global $app, $conf;
  132. $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), @$this->dataRecord["parent_domain_id"]);
  133. if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
  134. if($_SESSION["s"]["user"]["typ"] != 'admin') {
  135. // Get the limits of the client
  136. $client_group_id = $_SESSION["s"]["user"]["default_group"];
  137. $client = $app->db->queryOneRecord("SELECT db_servers, limit_database, limit_database_quota, parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.groupid = ?", $client_group_id);
  138. // When the record is updated
  139. if($this->id > 0) {
  140. // restore the server ID if the user is not admin and record is edited
  141. $tmp = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE database_id = ?", $app->functions->intval($this->id));
  142. $this->dataRecord["server_id"] = $tmp["server_id"];
  143. unset($tmp);
  144. //* Check client quota
  145. if ($client['limit_database_quota'] >= 0) {
  146. //* get the database prefix
  147. $app->uses('getconf,tools_sites');
  148. $global_config = $app->getconf->get_global_config('sites');
  149. $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord);
  150. //* get quota from other databases
  151. $tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = ? AND database_name <> ?", $client_group_id, $dbname_prefix.$this->dataRecord['database_name']);
  152. $used_quota = $app->functions->intval($tmp['db_quota']);
  153. $new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]);
  154. if(($used_quota + $new_db_quota > $client['limit_database_quota']) || ($new_db_quota < 0 && $client['limit_database_quota'] >= 0)) {
  155. $max_free_quota = floor($client['limit_database_quota'] - $used_quota);
  156. if($max_free_quota < 0) {
  157. $max_free_quota = 0;
  158. }
  159. $app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB<br>";
  160. $this->dataRecord['database_quota'] = $max_free_quota;
  161. }
  162. unset($tmp);
  163. unset($global_config);
  164. unset($dbname_prefix);
  165. }
  166. if($client['parent_client_id'] > 0) {
  167. // Get the limits of the reseller
  168. $reseller = $app->db->queryOneRecord("SELECT limit_database, limit_database_quota FROM client WHERE client_id = ?", $client['parent_client_id']);
  169. //* Check the website quota of the client
  170. if ($reseller['limit_database_quota'] >= 0) {
  171. //* get the database prefix
  172. $app->uses('getconf,tools_sites');
  173. $global_config = $app->getconf->get_global_config('sites');
  174. $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord);
  175. //* get quota from other databases
  176. $tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database, sys_group, client WHERE web_database.sys_groupid=sys_group.groupid AND sys_group.client_id=client.client_id AND ? IN (client.parent_client_id, client.client_id) AND database_name <> ?", $client['parent_client_id'], $dbname_prefix.$this->dataRecord['database_name']);
  177. $used_quota = $app->functions->intval($tmp['db_quota']);
  178. $new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]);
  179. if(($used_quota + $new_db_quota > $reseller["limit_database_quota"]) || ($new_db_quota < 0 && $reseller["limit_database_quota"] >= 0)) {
  180. $max_free_quota = floor($reseller["limit_database_quota"] - $used_quota);
  181. if($max_free_quota < 0) $max_free_quota = 0;
  182. $app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB<br>";
  183. $this->dataRecord["database_quota"] = $max_free_quota;
  184. }
  185. unset($tmp);
  186. unset($global_config);
  187. unset($dbname_prefix);
  188. }
  189. }
  190. // When the record is inserted
  191. } else {
  192. $client['db_servers_ids'] = explode(',', $client['db_servers']);
  193. // Check if chosen server is in authorized servers for this client
  194. if (!(is_array($client['db_servers_ids']) && in_array($this->dataRecord["server_id"], $client['db_servers_ids'])) && $_SESSION["s"]["user"]["typ"] != 'admin') {
  195. $app->error($app->tform->wordbook['error_not_allowed_server_id']);
  196. }
  197. // Check if the user may add another database
  198. if($client["limit_database"] >= 0) {
  199. $tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = ?", $client_group_id);
  200. if($tmp["number"] >= $client["limit_database"]) {
  201. $app->error($app->tform->wordbook["limit_database_txt"]);
  202. }
  203. }
  204. //* Check client quota
  205. if ($client['limit_database_quota'] >= 0) {
  206. $tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = ?", $client_group_id);
  207. $db_quota = $tmp['db_quota'];
  208. $new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]);
  209. if(($db_quota + $new_db_quota > $client['limit_database_quota']) || ($new_db_quota < 0 && $client['limit_database_quota'] >= 0)) {
  210. $max_free_quota = floor($client['limit_database_quota'] - $db_quota);
  211. if($max_free_quota < 0) $max_free_quota = 0;
  212. $app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB<br>";
  213. $this->dataRecord['database_quota'] = $max_free_quota;
  214. }
  215. unset($tmp);
  216. }
  217. }
  218. } else {
  219. // check if client of database parent domain is client of db user!
  220. $web_group = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ?", $this->dataRecord['parent_domain_id']);
  221. if($this->dataRecord['database_user_id']) {
  222. $group = $app->db->queryOneRecord("SELECT sys_groupid FROM web_database_user WHERE database_user_id = ?", $this->dataRecord['database_user_id']);
  223. if($group['sys_groupid'] != $web_group['sys_groupid']) {
  224. $app->error($app->tform->wordbook['database_client_differs_txt']);
  225. }
  226. }
  227. if($this->dataRecord['database_ro_user_id']) {
  228. $group = $app->db->queryOneRecord("SELECT sys_groupid FROM web_database_user WHERE database_user_id = ?", $this->dataRecord['database_ro_user_id']);
  229. if($group['sys_groupid'] != $web_group['sys_groupid']) {
  230. $app->error($app->tform->wordbook['database_client_differs_txt']);
  231. }
  232. }
  233. }
  234. parent::onSubmit();
  235. }
  236. function onBeforeUpdate() {
  237. global $app, $conf, $interfaceConf;
  238. //* Site shall not be empty
  239. if($this->dataRecord['parent_domain_id'] == 0) $app->tform->errorMessage .= $app->tform->lng("database_site_error_empty").'<br />';
  240. //* Get the database name and database user prefix
  241. $app->uses('getconf,tools_sites');
  242. $global_config = $app->getconf->get_global_config('sites');
  243. $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord);
  244. //* Prevent that the database name and charset is changed
  245. $old_record = $app->tform->getDataRecord($this->id);
  246. $dbname_prefix = $app->tools_sites->getPrefix($old_record['database_name_prefix'], $dbname_prefix);
  247. $this->dataRecord['database_name_prefix'] = $dbname_prefix;
  248. //* Only admin can change the database name
  249. if ($_SESSION["s"]["user"]["typ"] != 'admin') {
  250. if($old_record["database_name"] != $dbname_prefix . $this->dataRecord["database_name"]) {
  251. $app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'<br />';
  252. }
  253. }
  254. if($old_record["database_charset"] != $this->dataRecord["database_charset"]) {
  255. $app->tform->errorMessage .= $app->tform->wordbook["database_charset_change_txt"].'<br />';
  256. }
  257. if(!$this->dataRecord['database_user_id']) {
  258. $app->tform->errorMessage .= $app->tform->wordbook["database_user_missing_txt"].'<br />';
  259. }
  260. //* Database username and database name shall not be empty
  261. if($this->dataRecord['database_name'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_name_error_empty"].'<br />';
  262. //* Check if the server has been changed
  263. // We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
  264. if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
  265. if($old_record["server_id"] != $this->dataRecord["server_id"]) {
  266. //* Add a error message and switch back to old server
  267. $app->tform->errorMessage .= $app->lng('The Server can not be changed.');
  268. $this->dataRecord["server_id"] = $rec['server_id'];
  269. }
  270. }
  271. unset($old_record);
  272. if(strlen($dbname_prefix . $this->dataRecord['database_name']) > 64) $app->tform->errorMessage .= str_replace('{db}', $dbname_prefix . $this->dataRecord['database_name'], $app->tform->wordbook["database_name_error_len"]).'<br />';
  273. //* Check database name and user against blacklist
  274. $dbname_blacklist = array($conf['db_database'], 'mysql');
  275. if(in_array($dbname_prefix . $this->dataRecord['database_name'], $dbname_blacklist)) {
  276. $app->tform->errorMessage .= $app->lng('Database name not allowed.').'<br />';
  277. }
  278. if ($app->tform->errorMessage == ''){
  279. /* restrict the names if there is no error */
  280. /* crop user and db names if they are too long -> mysql: user: 16 chars / db: 64 chars */
  281. $this->dataRecord['database_name'] = substr($dbname_prefix . $this->dataRecord['database_name'], 0, 64);
  282. }
  283. //* Check for duplicates
  284. $tmp = $app->db->queryOneRecord("SELECT count(database_id) as dbnum FROM web_database WHERE database_name = ? AND server_id = ? AND database_id != ?", $this->dataRecord['database_name'], $this->dataRecord["server_id"], $this->id);
  285. if($tmp['dbnum'] > 0) $app->tform->errorMessage .= $app->lng('database_name_error_unique').'<br />';
  286. // get the web server ip (parent domain)
  287. $tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ?", $this->dataRecord['parent_domain_id']);
  288. if($tmp['server_id'] && $tmp['server_id'] != $this->dataRecord['server_id']) {
  289. // we need remote access rights for this server, so get it's ip address
  290. $server_config = $app->getconf->get_server_config($tmp['server_id'], 'server');
  291. if($server_config['ip_address']!='') {
  292. if($this->dataRecord['remote_access'] != 'y'){
  293. $this->dataRecord['remote_ips'] = $server_config['ip_address'];
  294. $this->dataRecord['remote_access'] = 'y';
  295. } else {
  296. if($this->dataRecord['remote_ips'] != ''){
  297. if(preg_match('/(^|,)' . preg_quote($server_config['ip_address'], '/') . '(,|$)/', $this->dataRecord['remote_ips']) == false) {
  298. $this->dataRecord['remote_ips'] .= ',' . $server_config['ip_address'];
  299. }
  300. $tmp = preg_split('/\s*,\s*/', $this->dataRecord['remote_ips']);
  301. $tmp = array_unique($tmp);
  302. $this->dataRecord['remote_ips'] = implode(',', $tmp);
  303. unset($tmp);
  304. }
  305. }
  306. }
  307. }
  308. if ($app->tform->errorMessage == '') {
  309. // force update of the used database user
  310. if($this->dataRecord['database_user_id']) {
  311. $user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ?', $this->dataRecord['database_user_id']);
  312. if($user_old_rec) {
  313. $user_new_rec = $user_old_rec;
  314. $user_new_rec['server_id'] = $this->dataRecord['server_id'];
  315. $app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_user_id'], $user_old_rec, $user_new_rec);
  316. }
  317. }
  318. if($this->dataRecord['database_ro_user_id']) {
  319. $user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ?', $this->dataRecord['database_ro_user_id']);
  320. if($user_old_rec) {
  321. $user_new_rec = $user_old_rec;
  322. $user_new_rec['server_id'] = $this->dataRecord['server_id'];
  323. $app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_ro_user_id'], $user_old_rec, $user_new_rec);
  324. }
  325. }
  326. }
  327. parent::onBeforeUpdate();
  328. }
  329. function onBeforeInsert() {
  330. global $app, $conf, $interfaceConf;
  331. //* Site shell not be empty
  332. if($this->dataRecord['parent_domain_id'] == 0) $app->tform->errorMessage .= $app->tform->lng("database_site_error_empty").'<br />';
  333. //* Database username and database name shall not be empty
  334. if($this->dataRecord['database_name'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_name_error_empty"].'<br />';
  335. //* Get the database name and database user prefix
  336. $app->uses('getconf,tools_sites');
  337. $global_config = $app->getconf->get_global_config('sites');
  338. $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord);
  339. $this->dataRecord['database_name_prefix'] = $dbname_prefix;
  340. if(strlen($dbname_prefix . $this->dataRecord['database_name']) > 64) $app->tform->errorMessage .= str_replace('{db}', $dbname_prefix . $this->dataRecord['database_name'], $app->tform->wordbook["database_name_error_len"]).'<br />';
  341. //* Check database name and user against blacklist
  342. $dbname_blacklist = array($conf['db_database'], 'mysql');
  343. if(in_array($dbname_prefix . $this->dataRecord['database_name'], $dbname_blacklist)) {
  344. $app->tform->errorMessage .= $app->lng('Database name not allowed.').'<br />';
  345. }
  346. /* restrict the names */
  347. /* crop user and db names if they are too long -> mysql: user: 16 chars / db: 64 chars */
  348. if ($app->tform->errorMessage == ''){
  349. $this->dataRecord['database_name'] = substr($dbname_prefix . $this->dataRecord['database_name'], 0, 64);
  350. }
  351. //* Check for duplicates
  352. $tmp = $app->db->queryOneRecord("SELECT count(database_id) as dbnum FROM web_database WHERE database_name = ? AND server_id = ?", $this->dataRecord['database_name'], $this->dataRecord["server_id"]);
  353. if($tmp['dbnum'] > 0) $app->tform->errorMessage .= $app->tform->lng('database_name_error_unique').'<br />';
  354. // get the web server ip (parent domain)
  355. $tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ?", $this->dataRecord['parent_domain_id']);
  356. if($tmp['server_id'] && $tmp['server_id'] != $this->dataRecord['server_id']) {
  357. // we need remote access rights for this server, so get it's ip address
  358. $server_config = $app->getconf->get_server_config($tmp['server_id'], 'server');
  359. if($server_config['ip_address']!='') {
  360. if($this->dataRecord['remote_access'] != 'y'){
  361. $this->dataRecord['remote_ips'] = $server_config['ip_address'];
  362. $this->dataRecord['remote_access'] = 'y';
  363. } else {
  364. if($this->dataRecord['remote_ips'] != ''){
  365. if(preg_match('/(^|,)' . preg_quote($server_config['ip_address'], '/') . '(,|$)/', $this->dataRecord['remote_ips']) == false) {
  366. $this->dataRecord['remote_ips'] .= ',' . $server_config['ip_address'];
  367. }
  368. $tmp = preg_split('/\s*,\s*/', $this->dataRecord['remote_ips']);
  369. $tmp = array_unique($tmp);
  370. $this->dataRecord['remote_ips'] = implode(',', $tmp);
  371. unset($tmp);
  372. }
  373. }
  374. }
  375. }
  376. if ($app->tform->errorMessage == '') {
  377. // force update of the used database user
  378. if($this->dataRecord['database_user_id']) {
  379. $user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ?', $this->dataRecord['database_user_id']);
  380. if($user_old_rec) {
  381. $user_new_rec = $user_old_rec;
  382. $user_new_rec['server_id'] = $this->dataRecord['server_id'];
  383. $app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_user_id'], $user_old_rec, $user_new_rec);
  384. }
  385. }
  386. if($this->dataRecord['database_ro_user_id']) {
  387. $user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ?', $this->dataRecord['database_ro_user_id']);
  388. if($user_old_rec) {
  389. $user_new_rec = $user_old_rec;
  390. $user_new_rec['server_id'] = $this->dataRecord['server_id'];
  391. $app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_ro_user_id'], $user_old_rec, $user_new_rec);
  392. }
  393. }
  394. }
  395. parent::onBeforeInsert();
  396. }
  397. function onInsertSave($sql) {
  398. global $app, $conf;
  399. $app->db->query($sql);
  400. if($app->db->errorMessage != '') die($app->db->errorMessage);
  401. $new_id = $app->db->insertID();
  402. return $new_id;
  403. }
  404. function onUpdateSave($sql) {
  405. global $app;
  406. if(!empty($sql) && !$app->tform->isReadonlyTab($app->tform->getCurrentTab(), $this->id)) {
  407. $app->db->query($sql);
  408. if($app->db->errorMessage != '') die($app->db->errorMessage);
  409. }
  410. }
  411. function onAfterInsert() {
  412. global $app, $conf;
  413. $app->uses('sites_database_plugin');
  414. $app->sites_database_plugin->processDatabaseInsert($this);
  415. }
  416. function onAfterUpdate() {
  417. global $app, $conf;
  418. $app->uses('sites_database_plugin');
  419. $app->sites_database_plugin->processDatabaseUpdate($this);
  420. }
  421. }
  422. $page = new page_action;
  423. $page->onLoad();
  424. ?>