From 8da731c174110d3f0768a8599d978d26c3817bf9 Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Tue, 2 Jan 2024 08:09:53 +0100 Subject: [PATCH] Added read-only connection support for manticore Signed-off-by: Janos SUTO --- RELEASE_NOTES | 12 ++++++++++-- etc/manticore.conf.in | 3 ++- webui/controller/message/bulkremove.php | 4 ++-- webui/controller/message/remove.php | 4 ++-- webui/index.php | 9 ++++----- webui/model/search/message.php | 12 ++++++------ 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index d310feff..fce10d21 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,8 +1,16 @@ +1.4.5: +------ + +- Added read-only connection support for manticore + If using sphinx, add the following to config-site.php: + $config['SPHINX_HOSTNAME_READONLY'] = '127.0.0.1:9306'; + + 1.4.4: ------ -Renamed "group" table to "usergroup" -Be sure to run util/db-upgrade.sql on the mysql piler database +- Renamed "group" table to "usergroup" + Be sure to run util/db-upgrade.sql on the mysql piler database 1.4.3: diff --git a/etc/manticore.conf.in b/etc/manticore.conf.in index 9c110544..99d16af4 100755 --- a/etc/manticore.conf.in +++ b/etc/manticore.conf.in @@ -248,7 +248,8 @@ index note1 searchd { listen = 127.0.0.1:9312 - listen = 127.0.0.1:9306:mysql41 + listen = 127.0.0.1:9306 + listen = 127.0.0.1:9307:mysql_readonly log = /var/piler/manticore/manticore.log binlog_max_log_size = 256M binlog_path = /var/piler/manticore diff --git a/webui/controller/message/bulkremove.php b/webui/controller/message/bulkremove.php index ba3d56aa..6874fd5b 100644 --- a/webui/controller/message/bulkremove.php +++ b/webui/controller/message/bulkremove.php @@ -49,8 +49,8 @@ class ControllerMessageBulkremove extends Controller { AUDIT(ACTION_REMOVE_MESSAGE, '', '', $id, ''); $db->query("UPDATE " . TABLE_META . " SET retained=? WHERE id=?", [NOW, $id]); if(RT) { - $sphx = Registry::get('sphx'); - $sphx->query("DELETE FROM " . SPHINX_MAIN_INDEX . " WHERE id=" . (int)$this->data['id']); + $sphxrw = Registry::get('sphxrw'); + $sphxrw->query("DELETE FROM " . SPHINX_MAIN_INDEX . " WHERE id=" . (int)$this->data['id']); } syslog(LOG_INFO, $this->data['username'] . " removed message: $id"); diff --git a/webui/controller/message/remove.php b/webui/controller/message/remove.php index fb26a1be..957e0233 100644 --- a/webui/controller/message/remove.php +++ b/webui/controller/message/remove.php @@ -41,8 +41,8 @@ class ControllerMessageRemove extends Controller { $db->query("UPDATE " . TABLE_META . " SET retained=? WHERE id=?", [NOW, $id]); $db->query("UPDATE " . TABLE_DELETED . " SET deleted=1 WHERE id=?", [$id]); if(RT) { - $sphx = Registry::get('sphx'); - $sphx->query("DELETE FROM " . SPHINX_MAIN_INDEX . " WHERE id=", (int)$this->data['id']); + $sphxrw = Registry::get('sphxrw'); + $sphxrw->query("DELETE FROM " . SPHINX_MAIN_INDEX . " WHERE id=", (int)$this->data['id']); } syslog(LOG_INFO, $this->data['username'] . " removed message: $id"); diff --git a/webui/index.php b/webui/index.php index 0c284fc0..e6deee13 100644 --- a/webui/index.php +++ b/webui/index.php @@ -41,8 +41,10 @@ Registry::set('db', $db); Registry::set('DB_DRIVER', DB_DRIVER); -$sphx = new DB(SPHINX_DRIVER, SPHINX_HOSTNAME, "", "", SPHINX_DATABASE, ""); +$sphx = new DB(SPHINX_DRIVER, SPHINX_HOSTNAME_READONLY, "", "", SPHINX_DATABASE, ""); +$sphxrw = new DB(SPHINX_DRIVER, SPHINX_HOSTNAME, "", "", SPHINX_DATABASE, ""); Registry::set('sphx', $sphx); +Registry::set('sphxrw', $sphxrw); if(MEMCACHED_ENABLED) { @@ -94,7 +96,7 @@ else if(Registry::get('username')) { else { if(ENABLE_GOOGLE_LOGIN == 1 && isset($request->get['route']) && $request->get['route'] == 'login/google') { $action = new Router('login/google'); - } + } else if(ENABLE_SSO_LOGIN == 1) { if(isset($request->get['route']) && $request->get['route'] == 'login/login') { $action = new Router('login/login'); @@ -112,6 +114,3 @@ else { $controller = new Front(); $controller->dispatch($action, new Router('common/not_found')); - - -?> diff --git a/webui/model/search/message.php b/webui/model/search/message.php index 1bd73450..1cffd705 100644 --- a/webui/model/search/message.php +++ b/webui/model/search/message.php @@ -486,13 +486,13 @@ class ModelSearchMessage extends Model { if($tag == '') { if(RT) { - $this->sphx->query("DELETE FROM " . SPHINX_TAG_INDEX . " WHERE uid=$uid AND mid=$id"); + $this->sphxrw->query("DELETE FROM " . SPHINX_TAG_INDEX . " WHERE uid=$uid AND mid=$id"); } else { $query = $this->db->query("DELETE FROM " . TABLE_TAG . " WHERE uid=? AND id=?", array($uid, $id)); } } else { if(RT) { - $this->sphx->query("REPLACE INTO " . SPHINX_TAG_INDEX . " (mid, uid, tag) VALUES (?,?,?)",[$id,$uid,$tag]); + $this->sphxrw->query("REPLACE INTO " . SPHINX_TAG_INDEX . " (mid, uid, tag) VALUES (?,?,?)",[$id,$uid,$tag]); } else { $query = $this->db->query("UPDATE " . TABLE_TAG . " SET tag=? WHERE uid=? AND id=?", array($tag, $uid, $id)); if($this->db->countAffected() == 0) { @@ -510,7 +510,7 @@ class ModelSearchMessage extends Model { if(RT) { $ids_str = implode(",", $ids); - $this->sphx->query("DELETE FROM " . SPHINX_TAG_INDEX . " WHERE uid=$uid AND mid IN ($ids_str)"); + $this->sphxrw->query("DELETE FROM " . SPHINX_TAG_INDEX . " WHERE uid=$uid AND mid IN ($ids_str)"); } else { $query = $this->db->query("DELETE FROM " . TABLE_TAG . " WHERE uid=? AND id IN ($q)", $arr); } @@ -518,7 +518,7 @@ class ModelSearchMessage extends Model { if($tag) { foreach ($ids as $id) { if(RT) { - $this->sphx->query("INSERT INTO " . SPHINX_TAG_INDEX . " (mid, uid, tag) VALUES(?,?,?)", [$id, $uid, $tag]); + $this->sphxrw->query("INSERT INTO " . SPHINX_TAG_INDEX . " (mid, uid, tag) VALUES(?,?,?)", [$id, $uid, $tag]); } else { $query = $this->db->query("INSERT INTO " . TABLE_TAG . " (id, uid, tag) VALUES(?,?,?)", array($id, $uid, $tag)); } @@ -561,10 +561,10 @@ class ModelSearchMessage extends Model { public function add_message_rt_note($id = '', $uid = 0, $note = '') { if($id == '' || $uid <= 0) { return 0; } - $this->sphx->query("DELETE FROM " . SPHINX_NOTE_INDEX . " WHERE uid=$uid AND mid=$id"); + $this->sphxrw->query("DELETE FROM " . SPHINX_NOTE_INDEX . " WHERE uid=$uid AND mid=$id"); if($note) { - $this->sphx->query("INSERT INTO " . SPHINX_NOTE_INDEX . " (mid, uid, note) VALUES (?,?,?)",[$id,$uid,$note]); + $this->sphxrw->query("INSERT INTO " . SPHINX_NOTE_INDEX . " (mid, uid, note) VALUES (?,?,?)",[$id,$uid,$note]); } return 1;