00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 #ifndef __TACDB_H__
00038 #define __TACDB_H__
00039 
00040 #include "Snmp.h"       
00041 #include "global.h"
00042 
00043 namespace tacpp {
00044 
00045 
00046 const string T_DEV = "tacppd_v1_dev";      
00047 #define T_USR       "tacppd_v1_usr"        // user/passwords table
00048 #define T_ACC       "tacppd_v1_acc"        // access control
00049 #define T_AVP       "tacppd_v1_avp"        // authorization
00050 #define T_CMD       "tacppd_v1_cmd"        // command authoriz
00051 #define T_ADD       "tacppd_v1_add"        // additional user data
00052 #define T_LOG       "tacppd_v1_log"        // log inform
00053 #define T_TRF       "tacppd_v1_trf"        // intf traffic info
00054 #define T_NF        "tacppd_v1_nf"         // netflow traffic info
00055 #define T_BIL       "tacppd_v1_res"        // resource group
00056 #define T_BILRES    "tacppd_v1_resdata"    // resource group resources
00057 const string T_NFUSR = "tacppd_v1_nfuser"; 
00058 
00059 #define T_DEV_ID      "DEvice"
00060 #define T_USR_ID      "USer"
00061 #define T_ACC_ID      "ACcess"
00062 #define T_AVP_ID      "AVp"
00063 #define T_CMD_ID      "COmmand"
00064 #define T_ADD_ID      "ADd"
00065 #define T_LOG_ID      "LOg"
00066 #define T_TRF_ID      "TRFInt"
00067 #define T_BIL_ID      "BILLIng"
00068 #define T_BILRES_ID   "BILLRes"
00069 #define T_NFUSR_ID   "NFUser"
00070 
00071 #define AVP_SERVICE_LEN   15
00072 #define AVP_PROTOCOL_LEN  15
00073 #define AVP_VALUE_LEN     128
00074 
00080 class user_avp {
00083   pthread_mutex_t mutex_;
00086   void lock();
00089   void unlock();
00092   string service_;
00095   string protocol_;
00098   string avp_;
00099  public:
00102   string getService();
00105   void setService(const string);
00109   bool compareService(const string);
00112   string getProtocol();
00115   void setProtocol(const string);
00118   bool compareProtocol(const string);
00121   string getAvp();
00124   void setAvp(const string);
00127   void operator =(user_avp);
00130   bool operator ==(user_avp);
00133   bool operator !=(user_avp);
00136   user_avp();
00139   ~user_avp();
00140 };
00141 
00142 const int CMD_AVP_LEN = 50;
00143 
00149 class cmd_avp {
00152   pthread_mutex_t mutex_;
00155   void lock();
00158   void unlock();
00161   string cmdperm_;
00164   string cmddeny_;
00167   string argperm_;
00170   string argdeny_;
00171  public:
00174   string getCmdperm();
00177   void setCmdperm(const string);
00180   string getCmddeny();
00183   void setCmddeny(const string);
00186   string getArgperm();
00189   void setArgperm(const string);
00192   string getArgdeny();
00195   void setArgdeny(const string);
00198   void operator =(cmd_avp);
00201   bool operator ==(cmd_avp);
00204   cmd_avp();
00207   ~cmd_avp();
00208 };
00209 
00210 #define FROM_PHONE_LEN    64
00211 #define FROM_NAS_LEN      64
00212 #define FROM_PORT_LEN     64
00213 #define FROM_TIME_LEN     64
00214 
00220 class db_user_acc {
00223   pthread_mutex_t mutex_;
00226   void lock();
00229   void unlock();
00232   string phone_;
00235   string nas_;
00238   string port_;
00241   string time_;
00242  public:
00245   string getPhone();
00248   void setPhone(const string);
00251   string getNas();
00254   void setNas(const string);
00257   string getPort();
00260   void setPort(const string);
00263   string getTime();
00266   void setTime(const string);
00269   void operator =(db_user_acc);
00272   bool operator ==(db_user_acc);
00275   db_user_acc();
00278   ~db_user_acc();
00279 };
00280 
00286 class db_bilres {
00289   pthread_mutex_t mutex_;
00292   void lock();
00295   void unlock();
00298   string attribute_;
00301   string value_;
00302  public:
00305   string getAttribute();
00308   void setAttribute(const string);
00311   string getValue();
00314   void setValue(const string);
00317   void operator =(db_bilres);
00320   bool operator !=(db_bilres);
00323   bool operator ==(db_bilres);
00326   db_bilres();
00329   ~db_bilres();
00330 };
00331 
00332 #define DB_USERNAME_LEN     32
00333 #define DB_AUTHSRC_LEN      5
00334 #define DB_PASSWORD_LEN     50
00335 #define DB_ID_LEN           16
00336 #define MAX_AVP             100
00337 #define MAX_ACC             32
00338 #define MAX_BILRES          32
00339 
00345 class db_user {
00348   pthread_mutex_t mutex_;
00351   void lock();
00354   void unlock();
00357   string username_;
00360   string authsrc_;
00363   string password_;
00366   string enable_;
00369   time_t open_;
00372   time_t close_;
00375   string avpid_;
00378   string accid_;
00381   string addid_;
00384   string bilid_;
00387   int bilmodid_;
00390   list<user_avp> avp_;
00393   list<cmd_avp> cmd_;
00396   list<db_user_acc> acc_;
00399   list<db_bilres> bilres_;
00402   bool result_;
00405   bool connect_;
00408   string result_msg_;
00411   int maxsess_;
00412  public:
00415   db_user();
00418   ~db_user();
00421   string getUsername();
00424   void setUsername(const string);
00427   string getAuthsrc();
00430   void setAuthsrc(const string);
00433   string getPassword();
00436   void setPassword(const string);
00439   string getEnable();
00442   void setEnable(const string);
00445   time_t getOpen();
00448   void setOpen(time_t);
00451   time_t getClose();
00454   void setClose(time_t);
00457   string getAvpid();
00460   void setAvpid(const string);
00463   string getAccid();
00466   void setAccid(const string);
00469   string getAddid();
00472   void setAddid(const string);
00475   string getBilid();
00478   void setBilid(const string);
00481   int getBilmodid();
00484   void setBilmodid(int);
00487   void avp_add(user_avp);
00490   int avp_size();
00493   user_avp avp_get(int);
00496   void avp_set(int,user_avp);
00499   void cmd_add(cmd_avp);
00502   int cmd_size();
00505   cmd_avp cmd_get(int);
00508   void acc_add(db_user_acc);
00511   int acc_size();
00514   db_user_acc acc_get(int);
00517   void bilres_add(db_bilres);
00520   int bilres_size();
00523   db_bilres bilres_get(int);
00526   bool getResult();
00529   void setResult(bool);
00532   bool getConnect();
00535   void setConnect(bool);
00538   string getResultMsg();
00541   void setResultMsg(const string);
00544   int getMaxsess();
00547   void setMaxsess(int);
00550   void operator =(db_user);
00553   bool operator ==(db_user);
00556   bool operator !=(db_user);
00557 };
00558 
00559 
00560 #define DB_NAS_LEN              64
00561 #define DESCRIPTION_LEN         50
00562 #define SNMP_MODULE_LEN         100
00563 #define SNMP_COMMUNITY_LEN      30
00564 #define TACACS_KEY_LEN          50
00565 #define LOGINSTRING_LEN         32
00566 #define PWDSTRING_LEN           32
00567 #define DEV_TYPE_LEN            32
00568 
00569 
00570 
00571 
00572 
00573 
00574 
00575 
00576 
00577 
00578 
00579 
00580 
00581 
00582 
00583 
00584 
00585 
00586 
00587 
00588 
00589 
00590 
00591 
00592 
00593 
00594 
00595 
00596 
00597 
00598 
00599 
00600 
00601 
00602 
00603 
00604 
00605 
00606 
00607 
00608 
00609 
00610 
00611 
00612 
00613 
00614 
00615 
00616 
00617 
00618 
00619 
00620 
00621 
00622 
00623 
00624 
00625 
00626 
00627 
00628 
00629 
00630 
00631 
00632 
00633 
00634 
00635 
00636 
00637 
00638 
00639 
00640 
00641 
00642 
00643 
00644 
00645 
00646 
00647 
00648 
00649 
00650 
00651 
00652 
00653 
00654 
00655 
00656 
00657 
00658 
00659 
00660 
00661 
00662 
00663 
00664 
00665 
00666 
00667 
00668 
00669 #define DB_H323_ORIGIN_LEN  15
00670 #define DB_H323_TYPE_LEN    15
00671 
00677 class log_user {
00678  public:
00681   int action;
00684   ipaddr server;
00687   int task_id;
00690   time_t servtime;
00693   time_t start_time;
00696   string username;
00699   string from;
00702   string port;
00705   unsigned int elapsed;
00708   ipaddr ip;
00711   ipaddr nas;
00714   string service;
00717   string protocol;
00720   int disc_cause;
00723   int disc_cause_ext;
00726   unsigned int bytes_in;
00729   unsigned int bytes_out;
00732   unsigned int rx_speed;
00735   unsigned int tx_speed;
00736   
00739   string h323_call_origin;
00742   string h323_call_type;
00745   int h323_disconnect_cause;
00748   int h323_voice_quality;
00751   ipaddr h323_remote_address;
00754   time_t h323_connect_time;
00757   time_t h323_disconnect_time;
00760   log_user() {
00761     server = UNKNOWN_IP;
00762     nas = UNKNOWN_IP;
00763     ip = UNKNOWN_IP;
00764     action = 0;
00765     servtime   = 0;
00766     start_time = 0;
00767     elapsed = 0;
00768     disc_cause = 0;
00769     disc_cause_ext = 0;
00770     bytes_in   = 0;
00771     bytes_out  = 0;
00772     rx_speed   = 0;
00773     tx_speed   = 0;
00774     task_id    = 0;
00775     h323_connect_time = 0;
00776     h323_disconnect_time = 0;
00777     h323_disconnect_cause = 0;
00778     h323_voice_quality = 0;
00779   }
00782   ~log_user() {}
00783 };
00784 
00790 class DbList {
00793   pthread_mutex_t mutex_;
00796   void lock();
00799   void unlock();
00802   list<DbTable*> dt_;
00803  public:
00806   void add(const string,const string,const string);
00809   DbTable *get(const string);
00812   DbTable *get(int);
00815   DbList();
00818   ~DbList();
00821   int size();
00822 };
00823 
00827 
00828 class DbModule {
00831   pthread_mutex_t mutex_;
00834   void lock();
00837   void unlock();
00840   
00843   string dbname_;
00846   ipaddr location_;
00849   unsigned int dbport_;
00852   string cryptokey_;
00855   string username_;
00858   string password_;
00861   string module_;
00864   bool shutdown_;
00865  public:
00868   void setLocation(ipaddr);
00871   ipaddr getLocation();
00874   void setDbname(string);
00877   string getDbname();
00880   void setDbport(unsigned int);
00883   unsigned int getDbport();
00886   void setCryptokey(string);
00889   string getCryptokey();
00892   void setUsername(const string);
00895   string getUsername();
00898   void setPassword(const string);
00901   string getPassword();
00904   void setModule(const string);
00907   string getModule();
00910   void setShutdown(bool);
00913   bool getShutdown();
00916   void setdbid(const char*,const char*,int);
00919   string getdbid();
00922   string encrypt(char*,char*);
00925   string decrypt(char*,char*);
00928   void create_md5_hash(unsigned char*, unsigned char*);
00931   void md5_xor(unsigned char*,unsigned char*);
00932 
00933   
00934 
00937   void (*dl_init)();
00940   void (*dl_destroy)();
00943   int (*dl_open)(char*,int,char*,char*,char*,char*);
00946   bool (*dl_close)(int);
00949   bool (*dl_query)(int,DbTable*,char*);
00952   char* (*dl_function)(int,char*,char*);
00955   bool (*dl_get)(int,DbTable*,int,char*);
00958   bool (*dl_create)(int,DbTable*,char*);
00961   bool (*dl_create_idx)(int,DbTable*,char*);
00964   bool (*dl_add)(int,DbTable*,char*);
00967   bool (*dl_update)(int,DbTable*,char*);
00970   bool (*dl_del)(int,DbTable*,char*);
00973   DbModule(const char*,const char*,const char*,int,const char*,const char*,const char*);
00976   bool db_open(int*);
00979   bool db_close(int);
00982   bool db_query(int,DbTable*);
00985   string db_function(int,char*);
00988   bool db_get(int,DbTable*,int);
00991   bool db_create(int,DbTable*,char*);
00994   bool db_create_idx(int,DbTable*,char*);
00997   bool db_add(int,DbTable*);
01000   bool db_update(int,DbTable*);
01003   bool db_del(int,DbTable*);
01006   ~DbModule();
01007 };
01008 
01014 class TacDb : public DbModule {
01017   pthread_mutex_t Mutex_;
01020   void lock();
01023   void unlock();
01026   ipaddr our_ip_;
01027  public:
01030   DLoad *dl;
01033   TacDb(const char*,const char*,const char*,int,const char*,const char*,const char*);
01036   ~TacDb();
01039   db_user get(const string);
01042   int size();
01045   string direct_function_query(char*);
01048   string load();
01051   string create();
01052 
01053   
01056   string del(string,list<string>,list<string>);
01059   string show(string,list<string>,list<string>);
01062   list<string> sshow(string,list<string>,list<string>);
01065   string add(string,list<string>,list<string>);
01068   string modify(string,list<string>,list<string>,list<string>,list<string>);
01071   string add_log(log_user*);
01074   string add_trf(char*,SnmpOut*);
01077   int open_nf();
01080   void close_nf(int);
01083   string add_nf(int,Bit32,Bit32,Bit32,time_t,time_t,unsigned long,unsigned long,int);
01086   string get_table_name(int);
01089   string get_table_mask(int);
01092   string get_table_descr(int);
01095   string get_field_name(int,int);
01098   string get_field_descr(int,int);
01101   string get_field_defv(int,int);
01104   int get_field_type(int,int);
01107   int get_field_num(int);
01108 };
01109 
01110 };
01111 
01112 #endif //__TACDB_H__