#include #include #include "syslogconf.h" #include "syslogconf.m" #include #include #include #include HELP_FILE help_syslog ("syslogconf","syslog"); static HELP_FILE help_onelog ("syslogconf","onelog"); static const char subsys_syslog[]="syslog"; static CONFIG_FILE f_syslog ("/etc/syslog.conf",help_syslog ,CONFIGF_MANAGED ,subsys_syslog); static LINUXCONF_SUBSYS subb (subsys_syslog ,P_MSG_U(M_SYSLOG,"System logger")); PUBLIC SYSLOG_FILE::SYSLOG_FILE (VIEWITEM *_item) { item = _item; const char *pt = selections.copyword (item->line.get()); pt = str_skip (pt); issync = 1; if (*pt == '-'){ pt++; issync = 0; } path.setfrom (pt); } PUBLIC SYSLOG_FILE::SYSLOG_FILE () { item = NULL; issync = 1; } /* Return true if this syslog configuration defines a file */ PUBLIC bool SYSLOG_FILE::is_file () const { const char *pt = path.get(); return pt[0] == '/' && strncmp(pt,"/dev/",5)!=0; } PUBLIC int SYSLOG_FILE::edit () { DIALOG dia; dia.newf_str (MSG_U(F_DESTINATION,"Syslog file or destination"),path); dia.newf_str (MSG_U(F_SELECTIONS,"Selections"),selections); dia.newf_chk ("",issync,MSG_U(I_ISSYNC,"Sync file after each message")); int nof = 0; int ret = -1; while (1){ MENU_STATUS code = dia.edit (MSG_U(T_ONELOG,"One syslog destination") ,MSG_U(I_ONELOG ,"You generally define a log file\n" "or destination (other host, device, users\n") ,help_onelog ,nof ,MENUBUT_CANCEL|MENUBUT_ACCEPT|MENUBUT_DEL); if (code == MENU_ESCAPE || code == MENU_CANCEL){ break; }else if (code == MENU_DEL){ if (xconf_delok()){ ret = 1; break; } }else{ ret = 0; break; } } return ret; } PUBLIC void SYSLOG_FILE::format (VIEWITEMS &items) { if (item == NULL){ item = new VIEWITEM (""); items.add (item); } item->line.setfromf ("%s\t%s%s",selections.get(),(issync ? "" : "-") ,path.get()); } static int config_cmp_by_path (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { SYSLOG_FILE *f1 = (SYSLOG_FILE*)o1; SYSLOG_FILE *f2 = (SYSLOG_FILE*)o2; return f1->path.cmp(f2->path); } PUBLIC SYSLOG_FILE *SYSLOGCONF::getitem(int no) const { return (SYSLOG_FILE*)ARRAY::getitem(no); } PUBLIC SYSLOGCONF::SYSLOGCONF() { items.read (f_syslog); for (int i=0; iformat(items); } return items.write (f_syslog,NULL); } PUBLIC void SYSLOGCONF::setmenubar() { if (getnb() > 0){ sort (); diagui_sendcmd (P_Submenu,"\"%s\"\n",MSG_U(M_LOGS,"System logs")); int no = 0; for (int i=0; iis_file()){ diagui_sendcmd (P_Menuentry,"%d %s\n",no+100,f->path.get()); no++; } } diagui_sendcmd (P_End,"\n"); } } static void config_fct (void *p) { char *file = (char *)p; syslog_viewone (file,NULL); free (file); } PUBLIC void SYSLOGCONF::execmenu (int no) { sort (); int code = 100; for (int i=0; iis_file()){ if (code == no){ uithread (config_fct,strdup(f->path.get())); break; }else{ code++; } } } } PUBLIC void SYSLOGCONF::sort() { ARRAY::sort (config_cmp_by_path); } PUBLIC int SYSLOGCONF::edit() { SYSLOGCONF *conf; glocal.conf = this; (MSG_U(T_SYSLOGCONF,"Syslog files") ,MSG_U(I_SYSLOGCONF,"This is the list of log files\n" "and log destinations") ,help_syslog); newf_head (MSG_U(H_LOGFILE,"Log destination\tMessages selection")); addwhat (MSG_U(I_ADDENTRY,"Select [Add] to add a new syslog destination")); SYSLOGCONF *files = glocal.conf; files->sort (); for (int i=0; igetnb(); i++){ SYSLOG_FILE *f = files->getitem(i); new_menuitem (f->path.get(),f->selections.get()); } SYSLOG_FILE *f = new SYSLOG_FILE; int ok = f->edit(); if (ok!=0){ delete f; }else if (ok == 0){ glocal.conf->add (f); glocal.conf->write(); } SYSLOG_FILE *f = glocal.conf->getitem(no); int ok = f->edit(); if (ok==1){ glocal.conf->items.remove_del (f->item); glocal.conf->remove_del(f); glocal.conf->write(); }else if (ok == 0){ glocal.conf->write(); } return 0; }