#include "uptime.h"
#include "lib/eggdrop/module.h"
#include "modules/server/server.h"
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
Go to the source code of this file.
Data Structures | |
struct | PackUp |
Defines | |
#define | MODULE_NAME "uptime" |
#define | MAKING_UPTIME |
#define | start uptime_LTX_start |
Functions | |
static void | uptime_report (int idx, int details) |
unsigned long | get_ip () |
int | init_uptime (void) |
int | send_uptime (void) |
void | check_hourly () |
static int | uptime_set_send (struct userrec *u, int idx, char *par) |
static char * | uptime_close () |
EXPORT_SCOPE char * | start () |
char * | start (eggdrop_t *eggdrop) |
Variables | |
static const char | rcsid [] = "$Id: uptime.c,v 1.14 2003-12-11 00:49:11 wcc Exp $" |
PackUp | upPack |
static Function * | server_funcs = NULL |
static eggdrop_t * | egg = NULL |
char * | uptime_host = NULL |
int | uptimeport = 9969 |
int | hours = 0 |
int | uptimesock |
int | uptimecount |
unsigned long | uptimeip |
unsigned long | uptimecookie |
time_t | uptimelast |
char | uptime_version [50] = "" |
static cmd_t | mydcc [] |
static tcl_strings | mystrings [] |
static tcl_ints | myints [] |
static Function | uptime_table [] |
void check_hourly | ( | ) |
Definition at line 181 of file uptime.c.
References hours, and send_uptime().
Referenced by start(), and uptime_close().
00181 { 00182 hours++; 00183 if (hours==6) { 00184 send_uptime(); 00185 hours=0; 00186 } 00187 }
unsigned long get_ip | ( | ) |
Definition at line 92 of file uptime.c.
References NULL, and uptime_host.
Referenced by send_uptime().
00093 { 00094 struct hostent *hp; 00095 IP ip; 00096 struct in_addr *in; 00097 00098 /* could be pre-defined */ 00099 if (uptime_host[0]) { 00100 if ((uptime_host[strlen(uptime_host) - 1] >= '0') && (uptime_host[strlen(uptime_host) - 1] <= '9')) 00101 return (IP) inet_addr(uptime_host); 00102 } 00103 hp = gethostbyname(uptime_host); 00104 if (hp == NULL) 00105 return -1; 00106 in = (struct in_addr *) (hp->h_addr_list[0]); 00107 ip = (IP) (in->s_addr); 00108 return ip; 00109 }
int init_uptime | ( | void | ) |
Definition at line 111 of file uptime.c.
References PackUp::cookie, LOG_DEBUG, online_since, PackUp::pid, putlog(), PackUp::regnr, PackUp::type, PackUp::uptime, UPTIME_EGGDROP, uptime_version, uptimecookie, uptimecount, uptimeip, uptimelast, and uptimesock.
Referenced by start().
00112 { 00113 struct sockaddr_in sai; 00114 char temp[50]=""; 00115 upPack.regnr = 0; 00116 upPack.pid = htonl(getpid()); 00117 upPack.type = htonl(UPTIME_EGGDROP); 00118 upPack.cookie = 0; 00119 upPack.uptime = htonl(online_since); 00120 uptimecookie = rand(); 00121 uptimecount = 0; 00122 uptimelast = 0; 00123 uptimeip = -1; 00124 00125 00126 strcpy(temp,ver); 00127 splitc(uptime_version,temp,' '); 00128 strcpy(uptime_version,temp); 00129 00130 if ((uptimesock = socket(AF_INET,SOCK_DGRAM,0)) < 0) { 00131 putlog(LOG_DEBUG, "*", "init_uptime socket returned <0 %d",uptimesock); 00132 return((uptimesock = -1)); 00133 } 00134 memset(&sai,0,sizeof(sai)); 00135 sai.sin_addr.s_addr = INADDR_ANY; 00136 sai.sin_family = AF_INET; 00137 if (bind(uptimesock,(struct sockaddr*)&sai,sizeof(sai)) < 0) { 00138 close(uptimesock); 00139 return((uptimesock = -1)); 00140 } 00141 fcntl(uptimesock,F_SETFL,O_NONBLOCK | fcntl(uptimesock,F_GETFL)); 00142 return(0); 00143 }
int send_uptime | ( | void | ) |
Definition at line 146 of file uptime.c.
References PackUp::cookie, get_ip(), PackUp::now2, NULL, online_since, PackUp::ontime, PackUp::sysup, PackUp::uptime, uptime_version, uptimecookie, uptimecount, uptimeip, uptimeport, and uptimesock.
Referenced by check_hourly(), and uptime_set_send().
00147 { 00148 struct sockaddr_in sai; 00149 struct stat st; 00150 PackUp *mem; 00151 int len; 00152 00153 uptimecookie = (uptimecookie + 1) * 18457; 00154 upPack.cookie = htonl(uptimecookie); 00155 upPack.now2 = htonl(time(NULL)); 00156 if (stat("/proc",&st) < 0) 00157 upPack.sysup = 0; 00158 else 00159 upPack.sysup = htonl(st.st_ctime); 00160 upPack.uptime = htonl(online_since); 00161 upPack.ontime = htonl(server_online); 00162 uptimecount++; 00163 if (((uptimecount & 0x7) == 0) || (uptimeip == -1)) { 00164 uptimeip = get_ip(); 00165 if (uptimeip == -1) 00166 return -2; 00167 } 00168 len = sizeof(upPack) + strlen(myname) + strlen(dcc[servidx].host) + strlen(uptime_version); 00169 mem = (PackUp*)malloc(len); 00170 memcpy(mem,&upPack,sizeof(upPack)); 00171 sprintf(mem->string,"%s %s %s",myname,dcc[servidx].host,uptime_version); 00172 memset(&sai,0,sizeof(sai)); 00173 sai.sin_family = AF_INET; 00174 sai.sin_addr.s_addr = uptimeip; 00175 sai.sin_port = htons(uptimeport); 00176 len = sendto(uptimesock,(void*)mem,len,0,(struct sockaddr*)&sai,sizeof(sai)); 00177 free(mem); 00178 return len; 00179 }
char* start | ( | eggdrop_t * | eggdrop | ) |
Definition at line 234 of file uptime.c.
References _, check_hourly(), egg, init_uptime(), MODULE_NAME, mydcc, myints, mystrings, NULL, server_funcs, UPTIME_HOST, uptime_host, and uptime_table.
00235 { 00236 egg = eggdrop; 00237 00238 if (!module_depend(MODULE_NAME, "eggdrop", 107, 0)) { 00239 module_undepend(MODULE_NAME); 00240 return _("This module requires eggdrop1.7.0 or later"); 00241 } 00242 if (!(server_funcs = module_depend(MODULE_NAME, "server", 1, 0))) 00243 return _("You need the server module to use the uptime module."); 00244 module_register(MODULE_NAME, uptime_table, 1, 1); 00245 add_tcl_strings(mystrings); 00246 add_tcl_ints(myints); 00247 add_builtins("dcc", mydcc); 00248 add_hook(HOOK_HOURLY, (Function) check_hourly); 00249 uptime_host = strdup(UPTIME_HOST); 00250 init_uptime(); 00251 return NULL; 00252 }
EXPORT_SCOPE char* start | ( | ) |
static char* uptime_close | ( | ) | [static] |
Definition at line 212 of file uptime.c.
References check_hourly(), MODULE_NAME, mydcc, myints, mystrings, NULL, uptime_host, and uptimesock.
00213 { 00214 rem_tcl_strings(mystrings); 00215 rem_tcl_ints(myints); 00216 rem_builtins("dcc", mydcc); 00217 free(uptime_host); 00218 close(uptimesock); 00219 del_hook(HOOK_HOURLY, (Function) check_hourly); 00220 module_undepend(MODULE_NAME); 00221 return NULL; 00222 }
static void uptime_report | ( | int | idx, | |
int | details | |||
) | [static] |
static int uptime_set_send | ( | struct userrec * | u, | |
int | idx, | |||
char * | par | |||
) | [static] |
Definition at line 189 of file uptime.c.
References online_since, send_uptime(), and uptime_version.
00190 { 00191 dprintf(idx,"Nick %s Ontime %lu Version %s Result %d\n", myname, online_since, 00192 uptime_version, send_uptime()); 00193 return 1; 00194 }
int hours = 0 |
cmd_t mydcc[] [static] |
Initial value:
{ {"usetsend", "", uptime_set_send, NULL}, {0, 0, 0, 0} }
tcl_strings mystrings[] [static] |
const char rcsid[] = "$Id: uptime.c,v 1.14 2003-12-11 00:49:11 wcc Exp $" [static] |
Function* server_funcs = NULL [static] |
char* uptime_host = NULL |
Function uptime_table[] [static] |
Initial value:
{ (Function) start, (Function) uptime_close, (Function) 0, (Function) uptime_report, }
Definition at line 226 of file uptime.c.
Referenced by start().
char uptime_version[50] = "" |
Definition at line 85 of file uptime.c.
Referenced by init_uptime(), send_uptime(), and uptime_set_send().
unsigned long uptimecookie |
int uptimecount |
unsigned long uptimeip |
time_t uptimelast |
int uptimeport = 9969 |
int uptimesock |
Definition at line 80 of file uptime.c.
Referenced by init_uptime(), send_uptime(), and uptime_close().