From b3e84a339e7a4c777209b0bbceaca40bb71a2594 Mon Sep 17 00:00:00 2001 From: pk910 Date: Thu, 26 Jul 2012 03:21:06 +0200 Subject: [PATCH] added NeonHelp history command --- Makefile.am | 1 + src/modules/NeonHelp.mod/NeonHelpHistory.php | 61 ++++++++ src/modules/NeonHelp.mod/bot_NeonHelp.c | 4 + src/modules/NeonHelp.mod/cmd_neonhelp.c | 1 + src/modules/NeonHelp.mod/cmd_neonhelp.h | 1 + .../NeonHelp.mod/cmd_neonhelp_history.c | 136 ++++++++++++++++++ src/tools.c | 3 +- src/tools.h | 7 +- 8 files changed, 210 insertions(+), 4 deletions(-) create mode 100644 src/modules/NeonHelp.mod/NeonHelpHistory.php create mode 100644 src/modules/NeonHelp.mod/cmd_neonhelp_history.c diff --git a/Makefile.am b/Makefile.am index 82b3e8e..f1cf173 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000..1c05d08 --- /dev/null +++ b/src/modules/NeonHelp.mod/NeonHelpHistory.php @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
Nick:
Hostmask: (auth: )
Time
State + +
", $row[5]); ?>
", $row[6]); ?>
\ No newline at end of file diff --git a/src/modules/NeonHelp.mod/bot_NeonHelp.c b/src/modules/NeonHelp.mod/bot_NeonHelp.c index ac36300..12c3576 100644 --- a/src/modules/NeonHelp.mod/bot_NeonHelp.c +++ b/src/modules/NeonHelp.mod/bot_NeonHelp.c @@ -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"}, diff --git a/src/modules/NeonHelp.mod/cmd_neonhelp.c b/src/modules/NeonHelp.mod/cmd_neonhelp.c index 35dbd38..97c5b6a 100644 --- a/src/modules/NeonHelp.mod/cmd_neonhelp.c +++ b/src/modules/NeonHelp.mod/cmd_neonhelp.c @@ -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 diff --git a/src/modules/NeonHelp.mod/cmd_neonhelp.h b/src/modules/NeonHelp.mod/cmd_neonhelp.h index 960b627..b9f28e5 100644 --- a/src/modules/NeonHelp.mod/cmd_neonhelp.h +++ b/src/modules/NeonHelp.mod/cmd_neonhelp.h @@ -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 index 0000000..2378d5a --- /dev/null +++ b/src/modules/NeonHelp.mod/cmd_neonhelp_history.c @@ -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 . + */ + +#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); +} diff --git a/src/tools.c b/src/tools.c index 6ecb7da..985362d 100644 --- a/src/tools.c +++ b/src/tools.c @@ -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++) { diff --git a/src/tools.h b/src/tools.h index e6e7f13..28672bb 100644 --- a/src/tools.h +++ b/src/tools.h @@ -19,9 +19,10 @@ #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; -- 2.20.1