From b8c96d85331a0c8e4878b3b6479166cff3adc885 Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 16 May 2024 10:21:40 +0200 Subject: [PATCH] Version 1.0 --- octave.c | 347 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 196 insertions(+), 151 deletions(-) diff --git a/octave.c b/octave.c index 624e7e6..52ab5ba 100644 --- a/octave.c +++ b/octave.c @@ -406,20 +406,55 @@ int markElt(int i, int v) return 1; } -void listElt(void) +void listElt(char c) { -int i; - for (i=0; i0) { printf("%d : %s (%d)\n",Tno[i], Turl[i], Trv[i]); + n++; + } + break; + default: + for (i=0; i/dev/null 2>&1",comm); - return system(b); + return comsh(b); } /* ### fct de MAJ iptables */ @@ -575,7 +610,7 @@ FILE * fw; static int NBin=0, NBout=0; void prInOut(void) { - printf("%d echanges DNS : %d requetes, %d reponses.\n",NBout+NBin,NBout,NBin); + printf(" %d messages DNS: %d requetes, %d reponses.\n",NBout+NBin,NBout,NBin); } int printQ(char * q) @@ -615,150 +650,159 @@ pid_t pid; fauth = (char*)p; pid = getpid(); read_history(FHISTO); - if (REPR) system("reset"); + if (REPR) comsh("reset"); while (REQ) { - if (kill(pid,SIGUSR1) < 0) { /* verif processus acquisition */ - ENDT=1; - write(p1[1],"\n",1); - } - free(cmd); - cmd = readline("O-> "); - if ((n2 = strlen(cmd)) > 0) { - write(p1[1],"\n",1); - add_history(cmd); - switch (*cmd) { - case '+' : - if (*(cmd+1) != '\0') { - if (litligne(cmd+1)) { /* ajout au fichier fauth */ - if (debloqueIP(cmd+1,NULL)) printf("Element non valable !\n"); - else { - if (printQ("ajouter au fichier parametres")) - ajoutParam(fauth,cmd+1); - listeAllow(); - } - } else printf("Erreur ajout param. !\n"); - } else listeAllow(); - break; - case '-' : - if (*(cmd+1) != '\0') { - if (litligne(cmd)) { /* ajout au fichier fauth */ - if (rebloqueIP(cmd+1)) printf("Element non valable !\n"); - else { - if (printQ("ajouter au fichier parametres")) - ajoutParam(fauth,cmd); - listeDeny(); - } - } else printf("Erreur ajout param. !\n"); - } else listeDeny(); - break; - case 'l' : - listElt(); - printf("%sReste %d elts (Max. %d)!\n",ctime(&tim1),iT,MaxElt); - prInOut(); - break; - case 't' : - if (*(cmd+1) != '\0') { - if ((cmd[1] == '+') || (cmd[1] == '-')) { - if ((cmd[1] == '+') && (Trace < TMAX)) Trace++; - else { - if ((cmd[1] == '-') && (Trace > TMIN)) Trace--; - else printf("Erreur: niveau dans [%d, %d].\n",TMIN,TMAX); - } - } else printf("Erreur: Utiliser t+ ou t- !\n"); + if (kill(pid,SIGUSR1) < 0) { /* verif processus acquisition */ + ENDT=1; + write(p1[1],"\n",1); + } + free(cmd); + cmd = readline("O-> "); + if ((n2 = strlen(cmd)) > 0) { + write(p1[1],"\n",1); + add_history(cmd); + switch (*cmd) { + case '+' : + if (*(cmd+1) != '\0') { + if (litligne(cmd+1)) { /* ajout au fichier fauth */ + if (debloqueIP(cmd+1,NULL)) printf("Element non valable !\n"); + else { + if (printQ("ajouter au fichier parametres")) + ajoutParam(fauth,cmd+1); + listeAllow(); } - printf("Trace niveau %d\n",Trace); - break; - case 'a' : - if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); - sprintf(com,"grep '%s\\[%d\\]%s' %s%s%s",NPROG,pid,".* ok",CHLOG,CUT6,SUNIC); - system(com); - break; - case 'i' : - if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); - sprintf(com,"grep '%s\\[%d\\]%s' %s%s%s",NPROG,pid,".* DENY",CHLOG,CUT6,SUNIC); - system(com); - break; - case 'e' : - if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); - sprintf(com,"grep '%s\\[%d\\]%s' %s%s%s",NPROG,pid,".* ACCEPT",CHLOG,CUT6,SUNIC); - system(com); - break; - case 'E' : - if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); - sprintf(com,"grep '%s\\[%d\\]%s' %s",NPROG,pid,".*ERR: ",CHLOG); - system(com); - break; - case 'L' : - if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); - sprintf(com,"grep '%s\\[%d\\]' %s%s",NPROG,pid,CHLOGREP,"-v 'Re[pq]. '"); - system(com); - break; - case 'T' : - if (*(cmd+1) != '\0') - sprintf(com,"grep '%s\\[%d\\].*%s' %s%s",NPROG,pid,cmd+1,CHLOGREP," 'Re[pq]. '"); - else - sprintf(com,"grep '%s\\[%d\\]' %s%s",NPROG,pid,CHLOGREP," 'Re[pq]. '"); - system(com); - prInOut(); - break; - case '>' : - if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); - sprintf(com,"grep '%s\\[%d\\]' %s%s%s%s",NPROG,pid,CHLOGREP," 'Req. '",CUT7S,SUNIC); - system(com); - prInOut(); - break; - case '<' : - if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); - sprintf(com,"grep '%s\\[%d\\]' %s%s%s%s",NPROG,pid,CHLOGREP," 'Rep. '",CUT7S,SUNIC); - system(com); - prInOut(); - break; - case 'r' : - if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); - sprintf(com,"%s -L|grep %s%s%s",IPT,DREJ,AWK5,SUNIC); - pr_encours(); - system(com); - break; - case 'R' : - if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); - sprintf(com,"%s -L|grep %s%s%s",IP6T,DREJ,AWK4,SUNIC); - pr_encours(); - system(com); - break; - case 'S' : - if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); - RUN = 0; - REQ = 0; - write(p1[1],"\n",1); - break; - case 'V' : - if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); - printf("Version %s\n",Version); - prInOut(); - break; - case ' ' : - if (*(cmd+1) != '\0') system(cmd+1); - break; - default : - printf("+url\t: Allow (autoriser une Url)\n"); - printf("-url\t: Deny (interdire une Url)\n"); - printf("a\t: Autorisations suivant analyse\n"); - printf("i\t: Interdictions suivant analyse\n"); - printf("e\t: Exceptions suivant analyse\n"); - printf("E\t: Liste des erreurs\n"); - printf("l\t: Liste des elements dynamiques\n"); - printf("L\t: Logs du systeme\n"); - printf("r\t: Rejets actifs IPv4 (dure plusieurs sec.)\n"); - printf("R\t: Rejets actifs IPv6 (dure plusieurs sec.)\n"); - printf("S\t: Stopper\n"); - printf("t+|-\t: Niveau de trace : 0 (off) => 3\n"); - printf("T[mot]\t: Traces des demandes/reponses contenant mot\n"); - printf(">\t: Traces des demandes triees\n"); - printf("<\t: Traces des reponses triees\n"); - printf("V\t: Version\n"); - break; - } - } + } else printf("Erreur ajout param. !\n"); + } else listeAllow(); + break; + case '-' : + if (*(cmd+1) != '\0') { + if (litligne(cmd)) { /* ajout au fichier fauth */ + if (rebloqueIP(cmd+1)) printf("Element non valable !\n"); + else { + if (printQ("ajouter au fichier parametres")) + ajoutParam(fauth,cmd); + listeDeny(); + } + } else printf("Erreur ajout param. !\n"); + } else listeDeny(); + break; + case 'l' : + listElt(cmd[1]); + printf(" %s Utilise %d elts/%d : %.2f%% (Max. %d)!\n",ctime(&tim1),iT, + NBT, (float)(iT*100)/(float)NBT, MaxElt); + prInOut(); + break; + case 't' : + if (*(cmd+1) != '\0') { + if ((cmd[1] == '+') || (cmd[1] == '-')) { + if ((cmd[1] == '+') && (Trace < TMAX)) Trace++; + else { + if ((cmd[1] == '-') && (Trace > TMIN)) Trace--; + else printf("Erreur: niveau dans [%d, %d].\n",TMIN,TMAX); + } + } else printf("Erreur: Utiliser t+ ou t- !\n"); + } + printf(" Trace niveau %d\n",Trace); + break; + case 'a' : + if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); + sprintf(com,"grep '%s\\[%d\\]%s' %s%s%s",NPROG,pid,".* ok", + CHLOG,CUT6,SUNIC); + comsh(com); + break; + case 'i' : + if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); + sprintf(com,"grep '%s\\[%d\\]%s' %s%s%s",NPROG,pid,".* DENY", + CHLOG,CUT6,SUNIC); + comsh(com); + break; + case 'e' : + if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); + sprintf(com,"grep '%s\\[%d\\]%s' %s%s%s",NPROG,pid,".* ACCEPT", + CHLOG,CUT6,SUNIC); + comsh(com); + break; + case 'E' : + if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); + sprintf(com,"grep '%s\\[%d\\]%s' %s",NPROG,pid,".*ERR: ",CHLOG); + comsh(com); + break; + case 'L' : + if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); + sprintf(com,"grep '%s\\[%d\\]' %s%s",NPROG,pid, + CHLOGREP,"-v 'Re[pq]. '"); + comsh(com); + break; + case 'T' : + if (*(cmd+1) != '\0') + sprintf(com,"grep '%s\\[%d\\].*%s' %s%s",NPROG,pid,cmd+1, + CHLOGREP," 'Re[pq]. '"); + else + sprintf(com,"grep '%s\\[%d\\]' %s%s",NPROG,pid, + CHLOGREP," 'Re[pq]. '"); + comsh(com); + prInOut(); + break; + case '>' : + if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); + sprintf(com,"grep '%s\\[%d\\]' %s%s%s%s",NPROG,pid, + CHLOGREP," 'Req. '",CUT7S,SUNIC); + comsh(com); + prInOut(); + break; + case '<' : + if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); + sprintf(com,"grep '%s\\[%d\\]' %s%s%s%s",NPROG,pid, + CHLOGREP," 'Rep. '",CUT7S,SUNIC); + comsh(com); + prInOut(); + break; + case 'r' : + if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); + sprintf(com,"%s -L|grep %s%s%s",IPT,DREJ,AWK5,SUNIC); + pr_encours(); + comsh(com); + break; + case 'R' : + if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); + sprintf(com,"%s -L|grep %s%s%s",IP6T,DREJ,AWK4,SUNIC); + pr_encours(); + comsh(com); + break; + case 'S' : + if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); + RUN = 0; + REQ = 0; + write(p1[1],"\n",1); + break; + case 'V' : + if (*(cmd+1) != '\0') printf("ignore %s\n",cmd+1); + printf("Version %s\n",Version); + prInOut(); + break; + case ' ' : + if (*(cmd+1) != '\0') comsh(cmd+1); + break; + default : + printf("+url\t: Allow (autoriser une Url)\n"); + printf("-url\t: Deny (interdire une Url)\n"); + printf("a\t: Autorisations suivant analyse\n"); + printf("i\t: Interdictions suivant analyse\n"); + printf("e\t: Exceptions suivant analyse\n"); + printf("E\t: Liste des erreurs\n"); + printf("l[+|-]\t: Liste des elements dynamiques\n"); + printf("L\t: Logs du systeme\n"); + printf("r\t: Rejets actifs IPv4 (dure plusieurs sec.)\n"); + printf("R\t: Rejets actifs IPv6 (dure plusieurs sec.)\n"); + printf("S\t: Stopper\n"); + printf("t+|-\t: Niveau de trace : 0 (off) => 3\n"); + printf("T[mot]\t: Traces des demandes/reponses contenant mot\n"); + printf(">\t: Traces des demandes triees\n"); + printf("<\t: Traces des reponses triees\n"); + printf("V\t: Version\n"); + break; + } + } } write_history(FHISTO); free(cmd); @@ -1018,8 +1062,9 @@ int Inter=0, LogC=0, i, ie, np=0, opt; REQ = 0; break; case 'L' : - printf("Reste %d elts !\n",iT); - listElt(); + listElt(cmd[1]); + printf(" %s Utilise %d elts/%d : %.2f%% (Max. %d)!\n", + ctime(&tim1),iT,NBT,(float)(iT*100)/(float)NBT,MaxElt); break; case 'S' : RUN = 0; @@ -1042,7 +1087,7 @@ int Inter=0, LogC=0, i, ie, np=0, opt; close(p1[1]); closelog(); if (ENDT) { /* relance auto */ - system("reset"); + comsh("reset"); if (T1) printf("Relance auto %s dans %d sec. ...\n",strPID, DELAYR); sleep(DELAYR); /* attend N s */ NP = (char**)malloc((sizeof(Pars))*(N+3));