added NeonHelp history command
authorpk910 <philipp@zoelle1.de>
Thu, 26 Jul 2012 01:21:06 +0000 (03:21 +0200)
committerpk910 <philipp@zoelle1.de>
Thu, 26 Jul 2012 06:23:55 +0000 (08:23 +0200)
Makefile.am
src/modules/NeonHelp.mod/NeonHelpHistory.php [new file with mode: 0644]
src/modules/NeonHelp.mod/bot_NeonHelp.c
src/modules/NeonHelp.mod/cmd_neonhelp.c
src/modules/NeonHelp.mod/cmd_neonhelp.h
src/modules/NeonHelp.mod/cmd_neonhelp_history.c [new file with mode: 0644]
src/tools.c
src/tools.h

index 82b3e8e7b1e46c0c14e5b5af2450a005ca9dceee..f1cf173289ddac5870bc48a78d03e5b505938079 100644 (file)
@@ -60,6 +60,7 @@ libNeonHelp_la_SOURCES = src/modules/NeonHelp.mod/bot_NeonHelp.c \
       src/modules/NeonHelp.mod/cmd_neonhelp_delete.c \
       src/modules/NeonHelp.mod/cmd_neonhelp_requests.c \
       src/modules/NeonHelp.mod/cmd_neonhelp_stats.c \
+      src/modules/NeonHelp.mod/cmd_neonhelp_history.c \
       src/modules/NeonHelp.mod/module.c
 libNeonHelp_la_LDFLAGS = -module -rpath /nowhere -avoid-version -no-undefined
 libNeonHelp_la_LIBADD = $(MYSQL_LIBS)
diff --git a/src/modules/NeonHelp.mod/NeonHelpHistory.php b/src/modules/NeonHelp.mod/NeonHelpHistory.php
new file mode 100644 (file)
index 0000000..1c05d08
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+$db['host'] = "localhost";
+$db['user'] = "neonserv";
+$db['pass'] = "";
+$db['base'] = "neonserv";
+
+$db['conn'] = @mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
+if($db['conn']) {
+    $mysql_connection=TRUE;
+    mysql_select_db($db['base'], $db['conn']) OR $mysql_connection=FALSE;
+}
+
+if(!$mysql_connection)
+    die("no connection to the MySQL Server.");
+
+$id = $_GET['id'];
+$key = $_GET['key'];
+if(!is_numeric($id) || strlen($key) != 32)
+    die("Access denied");
+
+$result = mysql_query("SELECT `nick`, `hand`, `host`, `time`, `status`, `text`, `log`, `supporter`, `users`.`user_user`, MD5(CONCAT(`id`, `host`, `time`, `supporter`)) FROM `helpserv_requests` LEFT JOIN `users` ON `supporter` = `user_id` WHERE `id` = '".mysql_real_escape_string($id)."';");
+if(mysql_num_rows($result) == 0)
+    die("Access denied");
+$row = mysql_fetch_row($result);
+if(strtolower($row[9]) != strtolower($key))
+    die("Access denied");
+
+?>
+<table border="1" width="600">
+    <tr>
+        <td width="150">Nick:</td>
+        <td><?php echo$row[0]; ?></td>
+    </tr>
+    <tr>
+        <td width="150">Hostmask:</td>
+        <td><?php echo$row[2]; ?> (auth: <?php echo$row[1]; ?>)</td>
+    </tr>
+    <tr>
+        <td width="150">Time</td>
+        <td><?php echo date("d.m.Y H:i:s", $row[3]); ?></td>
+    </tr>
+    <tr>
+        <td width="150">State</td>
+        <td>
+        <?php 
+        if($row[4] == 0)
+            echo"pending";
+        else if($row[4] == 1)
+            echo "active (".$row[8].")";
+        else if($row[4] == 2)
+            echo "closed (".($row[7] == 0 ? "*" : $row[8]).")";
+        ?>
+        </td>
+    </tr>
+    <tr>
+        <td colspan="2"><span style="font-size:10pt; font-family:Courier New;"><?php echo str_replace("\n", "<br>", $row[5]); ?></span></td>
+    </tr>
+    <tr>
+        <td colspan="2"><span style="font-size:10pt; font-family:Courier New;"><?php echo str_replace("\n", "<br>", $row[6]); ?></span></td>
+    </tr>
+</table>
\ No newline at end of file
index ac363007bdeb989d725bfa621a3e5ea008dce56f..12c357680e743877c8a4a35ad1812cc3ad85924d 100644 (file)
@@ -58,9 +58,13 @@ static const struct default_language_entry msgtab[] = {
     {"NH_REQUESTS_HEADER_STATUS", "State"},
     {"NH_REQUESTS_HEADER_NICK", "Nick"},
     {"NH_REQUESTS_HEADER_TIME", "Time"},
+    {"NH_REQUESTS_HEADER_STATUS", "State"},
+    {"NH_REQUESTS_HEADER_AUTH", "Auth"},
+    {"NH_REQUESTS_HEADER_MASK", "Mask"},
     {"NH_REQUESTS_HEADER_REQUEST", "Question"},
     {"NH_REQUESTS_STATE_ACTIVE", "active"},
     {"NH_REQUESTS_STATE_PENDING", "pending"},
+    {"NH_REQUESTS_STATE_CLOSED", "closed"},
     {"NH_REQUESTS_STATE_ERROR", "ERROR"},
     {"NH_STATS_HEADER_USER", "User"},
     {"NH_STATS_HEADER_LAST_24H", "last 24h"},
index 35dbd385f652b1bae59d97573e51835d829a9551..97c5b6a0a3e89a26af55aa45177b098e09c5b6b5 100644 (file)
@@ -29,6 +29,7 @@ void register_commands() {
     USER_COMMAND("delete",       neonhelp_cmd_delete,    1, NULL,                   CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     USER_COMMAND("requests",     neonhelp_cmd_requests,  0, NULL,                   CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     USER_COMMAND("stats",        neonhelp_cmd_stats,     0, NULL,                   CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
+    USER_COMMAND("history",      neonhelp_cmd_history,   1, NULL,                   CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     #undef USER_COMMAND
     
 }
\ No newline at end of file
index 960b627f6ad5162f8308c49a940d803d5df4e133..b9f28e55139cf5590f3733be96283f0793e88316 100644 (file)
@@ -33,6 +33,7 @@
 void register_commands();
 
 CMD_BIND(neonhelp_cmd_delete);
+CMD_BIND(neonhelp_cmd_history);
 CMD_BIND(neonhelp_cmd_next);
 CMD_BIND(neonhelp_cmd_requests);
 CMD_BIND(neonhelp_cmd_stats);
diff --git a/src/modules/NeonHelp.mod/cmd_neonhelp_history.c b/src/modules/NeonHelp.mod/cmd_neonhelp_history.c
new file mode 100644 (file)
index 0000000..2378d5a
--- /dev/null
@@ -0,0 +1,136 @@
+/* cmd_neonhelp_history.c - NeonServ v5.4
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#include "cmd_neonhelp.h"
+
+/*
+* argv[0]   matching string
+*/
+
+CMD_BIND(neonhelp_cmd_history) {
+    //check permissions
+    MYSQL_RES *res;
+    MYSQL_ROW row, row2;
+    int caccess = 0;
+    int userid;
+    printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
+    res = mysql_use();
+    if (!(row = mysql_fetch_row(res))) return;
+    //check if the user is a supporter (access in the support channel)
+    if((user->flags & USERFLAG_ISAUTHED)) {
+        if(user->flags & USERFLAG_HAS_USERID)
+            userid = user->user_id;
+        else {
+            printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
+            res = mysql_use();
+            if ((row2 = mysql_fetch_row(res)) != NULL) {
+                userid = atoi(row2[0]);
+                user->user_id = userid;
+                user->flags |= USERFLAG_HAS_USERID;
+            } else
+                userid = 0;
+        }
+        printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` WHERE `chanuser_uid` = '%d' AND `channel_name` = '%s'", userid, escape_string(row[0]));
+        res = mysql_use();
+        if ((row2 = mysql_fetch_row(res)) != NULL) {
+            int cflags = atoi(row2[1]);
+            if(!(cflags & DB_CHANUSER_SUSPENDED))
+                caccess = atoi(row2[0]);
+        }
+    }
+    if(!caccess) {
+        reply(textclient, user, "MODCMD_ACCESS_DENIED");
+        return;
+    }
+    struct Table *table;
+    char *match_str = escape_string(argv[0]);
+    printf_mysql_query("SELECT `id`, `nick`, `hand`, `host`, `time`, `text`, `status`, `supporter`, `users`.`user_user`, MD5(CONCAT(`id`, `host`, `time`, `supporter`)) FROM `helpserv_requests` LEFT JOIN `users` ON `supporter` = `user_id` WHERE `botid` = '%d' AND (`host` LIKE '%%%s%%' OR `hand` LIKE '%%%s%%' OR `nick` LIKE '%%%s%%') ORDER BY `time` ASC", client->clientid, match_str, match_str, match_str);
+    res = mysql_use();
+    table = table_init(6, mysql_num_rows(res)*3 + 1, 0);
+    table->col_flags[1] |= TABLE_FLAG_COL_SKIP_NULL;
+    table->col_flags[2] |= TABLE_FLAG_COL_SKIP_NULL;
+    table->col_flags[3] |= TABLE_FLAG_COL_SKIP_NULL;
+    table->col_flags[4] |= TABLE_FLAG_COL_SKIP_NULL;
+    char *content[6];
+    content[0] = get_language_string(user, "NH_REQUESTS_HEADER_ID");
+    content[1] = get_language_string(user, "NH_REQUESTS_HEADER_NICK");
+    content[2] = get_language_string(user, "NH_REQUESTS_HEADER_AUTH");
+    content[3] = get_language_string(user, "NH_REQUESTS_HEADER_MASK");
+    content[4] = get_language_string(user, "NH_REQUESTS_HEADER_TIME");
+    content[5] = get_language_string(user, "NH_REQUESTS_HEADER_STATUS");
+    table_add(table, content);
+    char timestr[MAXLEN];
+    time_t rawtime;
+    struct tm *timeinfo;
+    char statestr[MAXLEN];
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        content[0] = row[0];
+        content[1] = row[1];
+        content[2] = row[2];
+        content[3] = row[3];
+        rawtime = atoi(row[4]);
+        timeinfo = localtime(&rawtime);
+        strftime(timestr, MAXLEN, "%d.%m.%Y %H:%M:%S", timeinfo);
+        content[4] = timestr;
+        switch(atoi(row[6])) {
+        case 0:
+            content[5] = get_language_string(user, "NH_REQUESTS_STATE_PENDING");
+            break;
+        case 1:
+            sprintf(statestr, "%s (%s)", get_language_string(user, "NH_REQUESTS_STATE_ACTIVE"), row[8]);
+            content[5] = statestr;
+            break;
+        case 2:
+            sprintf(statestr, "%s (%s)", get_language_string(user, "NH_REQUESTS_STATE_CLOSED"), (strcmp(row[7], "0") ? row[8] : "*"));
+            content[5] = statestr;
+            break;
+        }
+        table_add(table, content);
+        char *p;
+        if((p = strstr(row[5], "\n")))
+            *p = '\0';
+        content[0] = " ";
+        content[1] = NULL;
+        content[2] = NULL;
+        content[3] = NULL;
+        content[4] = NULL;
+        sprintf(statestr, "\00314\002\002%s\003", row[5]);
+        content[5] = statestr;
+        table_add(table, content);
+        char setting[128];
+        sprintf(setting, "modules.%s.log_link", get_module_name(module_id));
+        if((p = get_string_field(setting))) {
+            statestr[0] = '\003';
+            statestr[1] = '1';
+            statestr[2] = '4';
+            int pos = sprintf(statestr+3, p, row[0], row[9]);
+            statestr[pos+3] = '\003';
+            statestr[pos+4] = '\0';
+            content[5] = statestr;
+            table_add(table, content);
+        }
+    }
+    //send the table
+    char **table_lines = table_end(table);
+    int i;
+    for(i = 0; i < table->entrys; i++) {
+        reply(textclient, user, table_lines[i]);
+    }
+    if(table->entrys == 1)
+        reply(textclient, user, "NS_TABLE_NONE");
+    table_free(table);
+}
index 6ecb7da80e68c752bccb65e7c378ece4ac03f982..985362d17c2edf8b88835911fdbaee9088f9dc19 100644 (file)
@@ -212,7 +212,8 @@ char **table_end(struct Table *table) {
                         }
                     }
                 }
-            }
+            } else if(table->col_flags[col] & TABLE_FLAG_COL_SKIP_NULL)
+                continue;
             i -= j;
             if(col < table->width-1) {
                 for(;i < table->maxwidth[col]; i++) {
index e6e7f13c7b2cae30377c474c3a4f8f5566aee38a..28672bbd3357f7337e77ec44ac966cb9a8a3bfe9 100644 (file)
 
 #include "main.h"
 
-#define TABLE_FLAG_USE_POINTER  0x01
-#define TABLE_FLAG_COL_BOLD     0x02
-#define TABLE_FLAG_COL_CONTENTS 0x04
+#define TABLE_FLAG_USE_POINTER   0x01
+#define TABLE_FLAG_COL_BOLD      0x02
+#define TABLE_FLAG_COL_CONTENTS  0x04
+#define TABLE_FLAG_COL_SKIP_NULL 0x08
 
 struct ClientSocket;
 struct UserNode;