📄 spalarm.h
字号:
/************************************************************************
* 文件名: spalarm.h
* 文件描述: 带宽管理器告警程序
* 创建人 : 王晓筠
* 创建时间: 2007年10月10日
* 版本号: 1.0
* 修改记录:
* 修改说明:
************************************************************************/
#include <stdio.h> /*标准输入输出定义*/
#include <stdlib.h> /*标准函数库定义*/
#include <unistd.h> /*Unix标准函数定义*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> /*文件控制定义*/
#include <termios.h> /*PPSIX终端控制定义*/
#include <errno.h> /*错误号定义*/
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <mysql.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <pthread.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include "cc_configfile_operate.h"
#include "cc_mailcontrol.h"
#ifndef _LCD_ALARM_
#define _LCD_ALARM_
#define DB_HOST_NAME "localhost"
#define DB_USER_NAME "coway"
#define DB_USER_PWD "dg-coway"
#define DB_DBAS_NAME "SPDB"
#define __Message_Id_101 0x00 // connect 错误
#define __Message_Id_102 0x00 // write select 错误
#define __Message_Id_103 0x00 // write 错误
#define __Message_Id_104 0x00 // read select 错误
#define __Message_Id_105 0x00 // read 错误
#define __Message_Id_107 0x00 // 返回的数据格式错误
#define __Message_Id_109 0x00 // 返回Server传给XML的数据
#define MSG_Server_Timeout 10
#define Max_Rec_Size 256*5
#define Max_Rec_Block_Size 100
#define Max_Rec_DataBegin_Index 6
#define FILEPATH "/sbin/mail_config.ini" //邮件头配置信息文件
#define DNS_CONFIGFILE_PATH "/etc/resolv.conf" //DNS服务器配置文件
//#define _TEST_DEBUG_
struct SP_Flow_Control_table {
char firewallid[12];
char ip[16];
char mask[16];
char direction[2];
char flow[10];
char time_b[20];
char time_e[20];
char state[12];
char id[12];
char stattype[12];
};
struct SP_Flow_Interdiction_table
{
char ip[16];
char mask[16];
char direction[2];
char time_b[20];
char time_e[20];
char id[12];
};
struct SP_Flow_Interdiction_table sp_interdiction_table[255];
struct SP_Flow_Control_table sp_control_table[255];
int interdiction_tablecount;
int tablecount;
int setting_flow;
unsigned long long now_flow;
unsigned long long standardin;
unsigned long long standardout;
unsigned long long standardtotal;
unsigned long long inboundflow;
unsigned long long outboundflow;
unsigned long long totalboundflow;
int alarmin,alarmout,alarmtotal;
//int timein,timeout,timetotal;
int is_alarmin, is_alarmout, is_alarmtotal;
void checktotalflow(void);
void checkipflow(void);
int ReadConfig( char *filename, char *scetion, char *item, char *value, char *Default ) ;
int GetControlProject(void) ;
int InquiriesFlow(void);
unsigned long Get_inet_addr(char *ip);
int Get_inet_mask(char *mask);
void tests (char *test) ;
inline void get_ctime(char *ctime) ;
int NoticeToFirewall(char *ip,char *mask,char *direct);
int ModifyDB(int type, char *id,char *firewallid);
int Setrun(void);
unsigned long long GetFlux(int eth);
int GetAlarmData(void);
int SetDBTable(int type,char *ip,char *mask,int direction, int flow_setting, unsigned long long flow_now);
int ClientToServer(char *sendbuf,int sendbuf_len,int server_port,int server_index,int timeout);
int General_CreatSocket_SendData(int *sockfd,char *sendbuf,int sendlen,int server_port,int server_index,int timeout);
int General_Only_GetData(int *sockfd,char *prcvbuf,int timeout);
int General_Only_SendData(int *sockfd,char *sendbuf,int sendlen,int timeout);
int General_CreatSocket(int *sockfd,int server_port,int server_index);
int General_CreatSocket_SendData_GetData(char *sendbuf,int sendlen,char *prcvbuf,int server_port,int server_index,int timeout);
char * getServer_Ip(int server_index);
char now[20];
//判断闰年的函数
int IsLeap(int year);
//每个月有多少天
int DayOfMonth(int year,int month);
//判断流量是否超出
int IsOverStep(int i);
//增加生效标记
int AddFlag(int i);
//判断时间范围是否交叉
int istimeacross(int i, int j);
//删除防火墙策略
int DeleteToFirewall(int i);
//判断给定日期是星期几
int week_no (int y , int m , int d );
//用int初始化struct tm
void int_to_tm(struct tm * t, int y, int m, int d, int h, int min, int s, int wd);
//用char初始化struct tm
void char_to_tm(struct tm * t,char *t_char);
//将struct tm 用字符串形式表示
void tm_to_char(char *t_char, struct tm *t);
//比较(字符串)时间先后
int comparetime(char *time1, char *time2);
void add_day(struct tm *t, int n);
void less_day(struct tm *t, int n);
void less_now_day(struct tm *t, int n);
void get_weekarea_head(char *time_b, char *week_b, char *week_e);
void get_montharea_head(char *time_b, char *mon_b, char *mon_e);
void get_yeararea_head(char *time_b, char *year_b, char *year_e);
void get_weekarea_tail(char *time_e, char *week_b, char *week_e);
void get_montharea_tail(char *time_e, char *mon_b, char *mon_e);
void get_yeararea_tail(char *time_b, char *year_b, char *year_e);
void get_weekarea_now(char *time_now, char *week_b, char *week_e);
void get_montharea_now(char *time_now, char *mon_b, char *mon_e);
void get_yeararea_now(char *time_b, char *year_b, char *year_e);
void get_timeby_week(int i, char *begin, char *end);
void get_timeby_month(int i, char *begin, char *end);
void get_timeby_year(int i, char *begin, char *end);
void get_time_begin_end(int type, int i, char *begin, char *end);
void mytests(char *test);
void int_tests(char *name, int i);
int DeleteFluxControl(char *id);
int MailMsg(char *ip,char *mask,int direction, char *alarmtime, char *alarmmsg);
int is_usemail(void);
void build_msg(char *ip,char *mask,int direction, char *alarmtime, char *alarmmsg, char* content);
int findotherinfo(cc_mailhead *my_mail_info);
void IpAndMask(char *ip, char *mask, char *des);
int GetMask(int x);
int ChangeChar2Int(char x);
int CheckNetMask(char mask[16]);
/*****************************************************/
//将ANSI转化为Base64
//para1: char *s ANSI内容
//para2: char *d 转化后的Base64内容
//para3: int s1 ANSI内容长度
//return code: 返回转化后的字节数
/*****************************************************/
int base64(char *s,char *d,int sl);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -