From 5330813408668f70db9dcffc9ee6037a58da223e Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Tue, 21 Jun 2016 15:11:47 +0200 Subject: warn if writing into replication slave --- it_dbi.class | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/it_dbi.class b/it_dbi.class index d65d1a2..f6614d8 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -454,11 +454,16 @@ function query($query, $p = array()) $p += $this->_p; $start = gettimeofday(true); - if ($p['server_update'] && !preg_match('/^(EXPLAIN|SELECT|SHOW) /i', $query)) + if (!it::match('^(EXPLAIN|SELECT|SHOW)', $query)) { - debug("switching to update server \"{$p['server_update']}\"", 5); - $this->_p['server'] = $p['server'] = $p['server_update']; - unset($this->_p['server_update'], $p['server_update'], $this->_link); + if ($p['server_update']) + { + debug("switching to update server \"{$p['server_update']}\"", 5); + $this->_p['server'] = $p['server'] = $p['server_update']; + unset($this->_p['server_update'], $p['server_update'], $this->_link); + } + else if ($p['server'] == "localhost" && ($t = @file($GLOBALS['ULTRAHOME'] . "/doc/machines.txt")) && preg_grep("/^" . gethostname() . "/", array_slice($t, 2))) + it::error("local write access on a replication slave machine?"); } $this->_connect($p); # must be called after update server switching code -- cgit v1.2.3