cleaned a few things up in messages.c ... geez this is such old code
[citadel.git] / citadel / modules / mrtg / serv_mrtg.c
index dab0ab7b809ad90f33eaba51e503b37d08d85af6..0402461db3ef08998cbc5b2b0ababa947e15ae73 100644 (file)
@@ -1,12 +1,19 @@
 /*
- * $Id$
- *
  * This module supplies statistics about the activity levels of your Citadel
  * system.  We didn't bother writing a reporting module, because there is
  * already an excellent tool called MRTG (Multi Router Traffic Grapher) which
  * is available at http://www.mrtg.org that can fetch data using external
  * scripts.  This module supplies data in the format expected by MRTG.
  *
+ * Copyright (c) 1987-2015 by the citadel.org team
+ *
+ * This program is open source software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3.
+ *
+ * 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.
  */
 
 #include "sysdep.h"
@@ -40,9 +47,7 @@
 #include "support.h"
 #include "config.h"
 #include "control.h"
-#include "room_ops.h"
 #include "user_ops.h"
-#include "policy.h"
 #include "database.h"
 #include "msgbase.h"
 
@@ -67,7 +72,7 @@ void mrtg_output(long value1, long value2) {
        cprintf("%ld\n", value2);
        cprintf("%d days, %d hours, %d minutes\n",
                uptime_days, uptime_hours, uptime_minutes);
-       cprintf("%s\n", config.c_humannode);
+       cprintf("%s\n", CtdlGetConfigStr("c_humannode"));
        cprintf("000\n");
 }
 
@@ -83,6 +88,7 @@ void mrtg_users(void) {
        
        struct CitContext *cptr;
 
+       begin_critical_section(S_SESSION_TABLE);
         for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
 
                if (cptr->internal_pgm == 0) {
@@ -94,7 +100,8 @@ void mrtg_users(void) {
                }
 
        }
-
+       end_critical_section(S_SESSION_TABLE);
+       
        mrtg_output(connected_users, active_users);
 }
 
@@ -103,7 +110,38 @@ void mrtg_users(void) {
  * Volume of messages submitted
  */
 void mrtg_messages(void) {
-       mrtg_output(CitControl.MMhighest, 0L);
+       mrtg_output(CtdlGetConfigLong("MMhighest"), 0);
+}
+
+
+struct num_accounts {
+       long total;
+       long active;
+};
+
+/*
+ * Helper function for mrtg_accounts()
+ */
+void tally_account(struct ctdluser *EachUser, void *userdata)
+{
+       struct num_accounts *n = (struct num_accounts *) userdata;
+
+       ++n->total;
+       if ( (time(NULL) - EachUser->lastcall) <= 2592000 ) ++n->active;
+}
+
+
+/*
+ * Number of accounts and active accounts
+ */
+void mrtg_accounts(void) {
+       struct num_accounts n = {
+               0,
+               0
+       };
+
+       ForEachUser(tally_account, (void *)&n );
+       mrtg_output(n.total, n.active);
 }
 
 
@@ -121,17 +159,22 @@ void cmd_mrtg(char *argbuf) {
        else if (!strcasecmp(which, "messages")) {
                mrtg_messages();
        }
+       else if (!strcasecmp(which, "accounts")) {
+               mrtg_accounts();
+       }
        else {
-               cprintf("%d Unrecognized keyword '%s'\n",
-                       ERROR + ILLEGAL_VALUE, which);
+               cprintf("%d Unrecognized keyword '%s'\n", ERROR + ILLEGAL_VALUE, which);
        }
 }
 
 
 CTDL_MODULE_INIT(mrtg)
 {
-        CtdlRegisterProtoHook(cmd_mrtg, "MRTG", "Supply stats to MRTG");
-
-       /* return our Subversion id for the Log */
-        return "$Id$";
+       if (!threading)
+       {
+               CtdlRegisterProtoHook(cmd_mrtg, "MRTG", "Supply stats to MRTG");
+       }
+       
+       /* return our module name for the log */
+        return "mrtg";
 }