From 2a8c13d774f3d8ea97bdf85c842033797ab86cd0 Mon Sep 17 00:00:00 2001 From: SJ Date: Fri, 9 Aug 2013 10:13:54 +0200 Subject: [PATCH] added indexer stat to health page --- src/hash.c | 149 ++++++++++++++++++ src/hash.h | 20 +++ util/indexer.delta.sh | 3 + util/indexer.main.sh | 3 + webui/config.php | 1 + webui/controller/health/worker.php | 4 + webui/language/de/messages.php | 1 + webui/language/en/messages.php | 1 + webui/language/hu/messages.iso-8859-2.php | 1 + webui/language/hu/messages.php | 1 + webui/language/pt/messages.php | 1 + webui/model/health/health.php | 17 ++ webui/model/saas/customer.php | 2 +- webui/model/user/auth.php | 2 +- .../theme/default/templates/health/worker.tpl | 10 ++ .../theme/mobile/templates/health/worker.tpl | 7 + 16 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 src/hash.c create mode 100644 src/hash.h diff --git a/src/hash.c b/src/hash.c new file mode 100644 index 00000000..4b9f2ae3 --- /dev/null +++ b/src/hash.c @@ -0,0 +1,149 @@ +/* + * hash.c, SJ + */ + +#include +#include +#include +#include +#include + + +void inithash(struct node *xhash[]){ + int i; + + for(i=0;ir; + if(p){ + if(p->str){ + free(p->str); + } + free(p); + } + } + xhash[i] = NULL; + } +} + + +struct node *makenewnode(struct node *xhash[], char *s){ + struct node *h; + int len; + + if(s == NULL) return NULL; + + len = strlen(s); + + if((h = malloc(sizeof(struct node))) == NULL) return NULL; + + memset(h, 0, sizeof(struct node)); + + h->str = malloc(len+2); + + if(h->str == NULL){ + free(h); + return NULL; + } + + memset(h->str, 0, len+2); + + snprintf(h->str, len+1, "%s", s); + + h->key = DJBHash(s, len); + h->r = NULL; + + return h; +} + + +int addnode(struct node *xhash[], char *s){ + struct node *p=NULL, *q; + unsigned int key = 0; + int len; + + if(s == NULL) return 0; + + len = strlen(s); + + key = DJBHash(s, len); + + if(xhash[hash(key)] == NULL){ + xhash[hash(key)] = makenewnode(xhash, s); + } + else { + q = xhash[hash(key)]; + while(q != NULL){ + p = q; + if(p->key == key){ + return 0; + } + else { + q = q->r; + } + } + p->r = makenewnode(xhash, s); + } + + return 1; +} + + +struct node *findnode(struct node *xhash[], char *s){ + struct node *q; + unsigned int key; + int len; + + if(s == NULL) return NULL; + + len = strlen(s); + + key = DJBHash(s, len); + + q = xhash[hash(key)]; + + if(q == NULL) return NULL; + + while(q != NULL){ + + if(strcmp(q->str, s) == 0){ + return q; + } + else { + q = q->r; + } + } + + return NULL; +} + + +inline int hash(unsigned int key){ + return key % MAXHASH; +} + + +unsigned int DJBHash(char* str, unsigned int len){ + unsigned int hash = 5381; + unsigned int i = 0; + + for(i=0; i < len; str++, i++){ + hash = ((hash << 5) + hash) + (*str); + } + + return hash; +} + diff --git a/src/hash.h b/src/hash.h new file mode 100644 index 00000000..da57d1f8 --- /dev/null +++ b/src/hash.h @@ -0,0 +1,20 @@ +/* + * hash.h, SJ + */ + +#ifndef _HASH_H + #define _HASH_H + +#include "cfg.h" +#include "defs.h" + + +void inithash(struct node *xhash[]); +void clearhash(struct node *xhash[]); +struct node *makenewnode(struct node *xhash[], char *s); +int addnode(struct node *xhash[], char *s); +struct node *findnode(struct node *xhash[], char *s); +inline int hash(unsigned int key); +unsigned int DJBHash(char* str, unsigned int len); + +#endif /* _HASH_H */ diff --git a/util/indexer.delta.sh b/util/indexer.delta.sh index ab2e2f58..c503dde0 100755 --- a/util/indexer.delta.sh +++ b/util/indexer.delta.sh @@ -5,6 +5,7 @@ MAINTMPFILE=/var/run/piler/main.indexer.tmp DELTATMPFILE=/var/run/piler/delta.indexer.tmp INDEXER=indexer PRIORITY=mail.error +TOUCHFILE=/var/piler/stat/indexer if [ -f $MAINTMPFILE ]; then echo "INDEXER ERROR: indexer merging to main index is already running. It started at "`cat $MAINTMPFILE` | logger -p $PRIORITY ; exit 1; fi @@ -12,6 +13,8 @@ if [ -f $DELTATMPFILE ]; then echo "INDEXER ERROR: delta indexing and merging is date > $DELTATMPFILE +touch $TOUCHFILE + function finish { rm -f $DELTATMPFILE } diff --git a/util/indexer.main.sh b/util/indexer.main.sh index 4bc0698e..d282171c 100755 --- a/util/indexer.main.sh +++ b/util/indexer.main.sh @@ -4,11 +4,14 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin MAINTMPFILE=/var/run/piler/main.indexer.tmp INDEXER=indexer PRIORITY=mail.error +TOUCHFILE=/var/piler/stat/indexer if [ -f $MAINTMPFILE ]; then echo "INDEXER ERROR: indexer merging to main index is already running. It started at "`cat $MAINTMPFILE` | logger -p $PRIORITY ; exit 1; fi date > $MAINTMPFILE +touch $TOUCHFILE + function finish { rm -f $MAINTMPFILE } diff --git a/webui/config.php b/webui/config.php index c1f9e729..ca3de2be 100644 --- a/webui/config.php +++ b/webui/config.php @@ -39,6 +39,7 @@ $config['PROVIDED_BY'] = 'www.mailpiler.org'; $config['SITE_KEYWORDS'] = 'piler email archiver'; $config['SITE_DESCRIPTION'] = 'piler email archiver'; +$config['INDEXER_BEACON'] = '/var/piler/stat/indexer'; // authentication against an ldap directory (disabled by default) diff --git a/webui/controller/health/worker.php b/webui/controller/health/worker.php index 56c3dcb6..83527bbf 100644 --- a/webui/controller/health/worker.php +++ b/webui/controller/health/worker.php @@ -146,6 +146,10 @@ class ControllerHealthWorker extends Controller { $this->data['usagetrend'] = 0; } + + $this->data['indexer_stat'] = $this->model_health_health->indexer_stat(); + + $this->render(); } diff --git a/webui/language/de/messages.php b/webui/language/de/messages.php index 8f171a57..9fdf3a4d 100644 --- a/webui/language/de/messages.php +++ b/webui/language/de/messages.php @@ -151,6 +151,7 @@ $_['text_import'] = "Import"; $_['text_import_users'] = "Benutzer importieren"; $_['text_import_users_from_LDAP'] = "Benutzer aus LDAP importieren"; $_['text_inbound'] = "eingehend"; +$_['text_indexer_job'] = "Indexer job"; $_['text_install_sudo_apply'] = "Add the following to /etc/sudoers: 'www-data ALL=NOPASSWD: /etc/init.d/rc.piler reload'"; $_['text_internal'] = "intern"; $_['text_invalid_data'] = "UngĂĽltige Daten"; diff --git a/webui/language/en/messages.php b/webui/language/en/messages.php index 31e04b2d..e148c054 100644 --- a/webui/language/en/messages.php +++ b/webui/language/en/messages.php @@ -151,6 +151,7 @@ $_['text_import'] = "Import"; $_['text_import_users'] = "Import users"; $_['text_import_users_from_LDAP'] = "Import users from LDAP"; $_['text_inbound'] = "inbound"; +$_['text_indexer_job'] = "Indexer job"; $_['text_install_sudo_apply'] = "Add the following to /etc/sudoers: 'www-data ALL=NOPASSWD: /etc/init.d/rc.piler reload'"; $_['text_internal'] = "internal"; $_['text_invalid_data'] = "Invalid data"; diff --git a/webui/language/hu/messages.iso-8859-2.php b/webui/language/hu/messages.iso-8859-2.php index cf999a24..bef73081 100644 --- a/webui/language/hu/messages.iso-8859-2.php +++ b/webui/language/hu/messages.iso-8859-2.php @@ -151,6 +151,7 @@ $_['text_import'] = "Import"; $_['text_import_users'] = "Felhasználók importálása"; $_['text_import_users_from_LDAP'] = "Felhasználók importálása LDAP-ból"; $_['text_inbound'] = "bejövő"; +$_['text_indexer_job'] = "Indexer futás"; $_['text_install_sudo_apply'] = "Adja az alábbi sort a /etc/sudoers file-hoz: 'www-data ALL=NOPASSWD: /etc/init.d/rc.piler reload'"; $_['text_internal'] = "belső"; $_['text_invalid_data'] = "Érvénytelen adat(ok)"; diff --git a/webui/language/hu/messages.php b/webui/language/hu/messages.php index 1c244e13..0630ff2c 100644 --- a/webui/language/hu/messages.php +++ b/webui/language/hu/messages.php @@ -151,6 +151,7 @@ $_['text_import'] = "Import"; $_['text_import_users'] = "FelhasználĂłk importálása"; $_['text_import_users_from_LDAP'] = "FelhasználĂłk importálása LDAP-bĂłl"; $_['text_inbound'] = "bejövĹ‘"; +$_['text_indexer_job'] = "Indexer futás"; $_['text_install_sudo_apply'] = "Adja az alábbi sort a /etc/sudoers file-hoz: 'www-data ALL=NOPASSWD: /etc/init.d/rc.piler reload'"; $_['text_internal'] = "belsĹ‘"; $_['text_invalid_data'] = "ÉrvĂ©nytelen adat(ok)"; diff --git a/webui/language/pt/messages.php b/webui/language/pt/messages.php index 6c355120..edec66f1 100644 --- a/webui/language/pt/messages.php +++ b/webui/language/pt/messages.php @@ -147,6 +147,7 @@ $_['text_import'] = "Importar"; $_['text_import_users'] = "Importar usuários"; $_['text_import_users_from_LDAP'] = "Importar usuários de LDAP"; $_['text_inbound'] = "interno"; +$_['text_indexer_job'] = "Indexer job"; $_['text_install_sudo_apply'] = "Add the following to /etc/sudoers: 'www-data ALL=NOPASSWD: /etc/init.d/rc.piler reload'"; $_['text_internal'] = "interno"; $_['text_invalid_data'] = "Dados inválidos"; diff --git a/webui/model/health/health.php b/webui/model/health/health.php index ff124422..c07b3caf 100644 --- a/webui/model/health/health.php +++ b/webui/model/health/health.php @@ -198,6 +198,23 @@ class ModelHealthHealth extends Model { return $dirSize; } + + public function indexer_stat() { + $data = array('', ''); + + if(file_exists(INDEXER_BEACON)) { + + $st = stat(INDEXER_BEACON); + $t1 = date(DATE_TEMPLATE . " H:i", $st['mtime']); + $t2 = date(DATE_TEMPLATE . " H:i", $st['mtime']+30*60); + + $data = array($t1, $t2); + } + + return $data; + } + + } diff --git a/webui/model/saas/customer.php b/webui/model/saas/customer.php index 5c4a9cc4..005afd38 100644 --- a/webui/model/saas/customer.php +++ b/webui/model/saas/customer.php @@ -118,7 +118,7 @@ class ModelSaasCustomer extends Model $query = $this->db->query("INSERT INTO " . TABLE_ONLINE . " (username, ts, last_activity, ipaddr) VALUES(?,?,?,?)", array($username, NOW, NOW, $_SERVER['REMOTE_ADDR'])); if($this->db->countAffected() == 0) { - $query = $this->db->query("UPDATE " . TABLE_ONLINE . " SET ts=?, last_activity=? WHERE username=? AND ipaddr=?", array(NOW, $username, $_SERVER['REMOTE_ADDR'])); + $query = $this->db->query("UPDATE " . TABLE_ONLINE . " SET ts=?, last_activity=? WHERE username=? AND ipaddr=?", array(NOW, NOW, $username, $_SERVER['REMOTE_ADDR'])); } return 1; diff --git a/webui/model/user/auth.php b/webui/model/user/auth.php index 58408541..ab183786 100644 --- a/webui/model/user/auth.php +++ b/webui/model/user/auth.php @@ -130,7 +130,7 @@ class ModelUserAuth extends Model { if($ldap_auditor_member_dn == '') { return 0; } foreach($e as $a) { - foreach (array("memberof") as $memberattr) { + foreach (array("memberof", "dn") as $memberattr) { if(isset($a[$memberattr])) { if(isset($a[$memberattr]['count'])) { diff --git a/webui/view/theme/default/templates/health/worker.tpl b/webui/view/theme/default/templates/health/worker.tpl index 13ab96a2..87ab70e6 100644 --- a/webui/view/theme/default/templates/health/worker.tpl +++ b/webui/view/theme/default/templates/health/worker.tpl @@ -67,6 +67,16 @@ . . + + + + + : , : + + + + + diff --git a/webui/view/theme/mobile/templates/health/worker.tpl b/webui/view/theme/mobile/templates/health/worker.tpl index 833a76c1..4832920d 100644 --- a/webui/view/theme/mobile/templates/health/worker.tpl +++ b/webui/view/theme/mobile/templates/health/worker.tpl @@ -126,6 +126,13 @@ + +
+
+
: , :
+
+ +