⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 radlist.c

📁 This program is a RADIUS RFC-compliant daemon, which is derived from original Livingston Enterprise
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 1999-2002 Francesco P. Lovergine.  * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms stated in the LICENSE file which should be * enclosed with sources. */static char rcsid[] = "$Id: radlist.c,v 1.8.2.1 2004/08/02 18:40:07 flovergine Exp $";    #define __MAIN__#include "yard.h"#include "global.h"static char *username = NULL;static int month = 0;static int portinfo = 0;static int brief = 0;static int dostat = 0;static int traditional = 0;static int noheader = 0;static char hdrstr[] = "  Username   Sess Logs    OnLine       Input/Output/Total      AvgIO    AvgTM\n"                        "------------ ---- ----  ---------- ------------------------- -------- --------\n";/*	Next functions are used to report time, traffic and other 	accounting data*/UINT4 get_daily_online( user_entry *ue,int month,int day ){  return ue->day[month][day].on_line;}UINT4 get_monthly_online( user_entry *ue,int month,int day ){  int i;  UINT4 sum=0;  for ( i=0; i<=day; i++ ) sum += ue->day[month][i].on_line;  return sum;}UINT4 get_yearly_online( user_entry *ue,int month,int day ){  int i, j;  UINT4 sum=0;  for ( i=0; i<=month; i++ )    for ( j=0; j<=day; j++ ) sum += ue->day[i][j].on_line;  return sum;}UINT4 get_daily_itraffic( user_entry *ue,int month,int day ){  return ue->day[month][day].input_octets;}UINT4 get_monthly_itraffic( user_entry *ue,int month,int day ){  int i;  UINT4 sum=0;  for ( i=0; i<=day; i++ ) sum += ue->day[month][i].input_octets;  return sum;}UINT4 get_yearly_itraffic( user_entry *ue,int month,int day ){  int i, j;  UINT4 sum=0;  for ( i=0; i<=month; i++ )    for ( j=0; j<=day; j++ ) sum += ue->day[i][j].input_octets;  return sum;}UINT4 get_daily_otraffic( user_entry *ue,int month,int day ){  return ue->day[month][day].output_octets;}UINT4 get_monthly_otraffic( user_entry *ue,int month,int day ){  int i;  UINT4 sum=0;  for ( i=0; i<=day; i++ ) sum += ue->day[month][i].output_octets;  return sum;}UINT4 get_yearly_otraffic( user_entry *ue,int month,int day ){  int i, j;  UINT4 sum=0;  for ( i=0; i<=month; i++ )    for ( j=0; j<=day; j++ ) sum += ue->day[i][j].output_octets;  return sum;}UINT4 get_daily_nr_logins( user_entry *ue,int month,int day ){  return ue->day[month][day].nr_logins;}UINT4 get_monthly_nr_logins( user_entry *ue,int month,int day ){  int i;  UINT4 sum=0;  for ( i=0; i<=day; i++ ) sum += ue->day[month][i].nr_logins;  return sum;}UINT4 get_yearly_nr_logins( user_entry *ue,int month,int day ){  int i, j;  UINT4 sum=0;  for ( i=0; i<=month; i++ )    for ( j=0; j<=day; j++ ) sum += ue->day[i][j].nr_logins;  return sum;}/*	This structure is a lookup table to get accounting data 	in short*/#define DAILY_STAT   0#define MONTHLY_STAT 1#define YEARLY_STAT  2#define ON_LINE   0#define ITRAFFIC  1#define OTRAFFIC  2#define NR_LOGINS 3typedef UINT4 (*fptr)(user_entry*,int,int);fptr get_stat[4][3] = {  { get_daily_online, get_monthly_online, get_yearly_online },{ get_daily_itraffic, get_monthly_itraffic, get_yearly_itraffic },{ get_daily_otraffic, get_monthly_otraffic, get_yearly_otraffic },{ get_daily_nr_logins, get_monthly_nr_logins, get_yearly_nr_logins }};static void radlist_usage(void){    printf("\nUsage: %s <option>\nValid options are:\n", progname);    printf("\t-s\t\tlist stats\n");    printf("\t-b\t\tbrief output format\n");    printf("\t-t\t\ttraditional output format\n");    printf("\t-n\t\tno header for traditional output\n");    printf("\t-x\t\tprint port information\n");    printf("\t-F <format>\t\tcustom output format\n");    printf("\t-h\t\tthis help screen\n");    printf("\t-m <month>\treport statistics for month <month>\n");    printf("\t-d <day>\treport statistics for day <day>\n");    printf("\t-y <year>\treport statistics for year <year>\n");    printf("\t-u <username>\tget username database entry\n");    printf("\t-Y\t\treport statistics per year\n");    printf("\t-M\t\treport statistics per month\n");    printf("\t-D\t\treport statistics per day\n\n");    exit(-1);}static const char * proto_type_str(int proto){    switch (proto) {        case P_TELNET:            return "TELNET";        case P_RLOGIN:            return "RLOGIN";        case P_TCP_CLEAR:            return "NETDATA";        case P_PORTMASTER:            return "PM";        case P_PPP:            return "PPP";        case P_SLIP:            return "SLIP";        case P_CSLIP:            return "CSLIP";        default:            return "UNK";    }    /* not reached */    return "UNK";}static void print_error(char * fmt,va_list args) {  vfprintf( stderr,fmt,args );   return;}static void error(char *fmt,...){  va_list arg;  va_start(arg,fmt);  fprintf( stderr,"%s: ",progname );  print_error(fmt,arg);  va_end(fmt);}static int parse_width(char **format){  int width=0;  char *endstr;  if ( isdigit(**format) || **format=='+' || **format=='-' )    {    width=(int)strtol(*format,&endstr,10);    *format=endstr;    }  return width;}static void parse_format(char *format, char *entry, user_entry *tmp, int datasize, int mday,int month,int stat){    UINT4 on_line;    UINT4 itraffic,otraffic;    UINT4 nr_logins;    UINT4 timepersess;    char  fstr[100];    char *ptr;    int   width;    on_line         = get_stat[ON_LINE][stat](tmp,month,mday);    nr_logins       = get_stat[NR_LOGINS][stat](tmp,month,mday);     itraffic        = get_stat[ITRAFFIC][stat](tmp,month,mday);     otraffic        = get_stat[OTRAFFIC][stat](tmp,month,mday);     while (*format) {      switch (*format) {        case '%':	  format++;	  width=parse_width(&format);	  if (width) snprintf(fstr,sizeof(fstr),"%%%d",width);	  else strcpy(fstr,"%");	  switch(*format) {	    case 'l':	      strcat(fstr,"s"); printf(fstr,entry);	      break;	    case 's':	      strcat(fstr,"d"); printf(fstr,tmp->logins);	      break;	    case 'n':	      strcat(fstr,"d"); printf(fstr,nr_logins);	      break;	    case 't':	      strcat(fstr,"d"); printf(fstr,on_line);	      break;	    case 'T':	      ptr=fstr+50;	      snprintf(ptr,sizeof(fstr)/2,"%d:%d:%d",	               on_line/3600, (on_line%3600)/60,(on_line%3600)%60);	      strcat(fstr,"s"); printf(fstr,ptr);	      break;	    case 'i':	      strcat(fstr,"ld"); printf(fstr,itraffic);	      break;	    case 'I':	      strcat(fstr,"ldKB"); printf(fstr,itraffic/1024);	      break;	    case 'o':	      strcat(fstr,"ld"); printf(fstr,otraffic);	      break;	    case 'O':	      strcat(fstr,"ldKB"); printf(fstr,otraffic/1024);	      break;	    case 'm':	      strcat(fstr,"ld"); printf(fstr,itraffic+otraffic);	      break;	    case 'M':	      strcat(fstr,"ldKB"); printf(fstr,(itraffic+otraffic)/1024);	      break;	    case 'g':	      strcat(fstr,"ld"); printf(fstr,(itraffic+otraffic)/(nr_logins+1));	      break;	    case 'G':	      strcat(fstr,"ldKB"); 	      printf(fstr,(itraffic+otraffic)/(nr_logins?nr_logins:1)/1024);	      break;	    case 'k':	      strcat(fstr,"d"); printf(fstr,on_line/(nr_logins?nr_logins:1));	      break;	    case 'K':	      ptr=fstr+50;	      timepersess = on_line/(nr_logins?nr_logins:1); 	      snprintf(ptr,sizeof(fptr)/2,"%d:%d:%d",	      	       timepersess/3600, (timepersess%3600)/60,		       (timepersess%3600)%60);	      strcat(fstr,"s"); printf(fstr,ptr);	      break;	    case '%':              putchar('%');	    default:	      break;	  }	  break;	case '\\':          format++;          switch(*format)            {            case 'n':              printf("\n");              break;            case 't':              printf("\t");              break;            case 'r':              printf("\r");              break;            case '\\':              printf("\\");            default:              break;            }	    break;	default:	  putchar(*format);	  break;      }    format++;    }}static void parse_pformat(char *format, char *entry, user_entry *tmp, int datasize, int mday,int month,int stat, port_entry *tpe, int number){    static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",		              "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };    int i,width;    char str_time[512];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -