From: Jean-Marc Pigeon (Delson) Date: Sun, 13 Jul 2025 14:24:59 +0000 (-0400) Subject: updating remotes tables start to work X-Git-Tag: tag-0.14~105 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=06f8fd196423b9035f1288a9891606e2b9e0914a;p=jmp%2Fmailleur updating remotes tables start to work --- diff --git a/app/scarmt.c b/app/scarmt.c index 0245c76..9dcbf24 100644 --- a/app/scarmt.c +++ b/app/scarmt.c @@ -37,13 +37,45 @@ static void check_credibility(SQLPTR *sqlptr,char **dnsbls,char *rmtip) { #define OPEP "scarmt.c:check_credibilty," -if (dnsbls!=(char **)0) { - while (*dnsbls!=(char *)0) { - (void) rou_alert(0,"%s JMPDBG scan <%s> against <%s>",OPEP,rmtip,*dnsbls); - dnsbls++; +SRVTYP *srv; +int phase; +_Bool proceed; + +srv=(SRVTYP *)0; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //loading rmtip record + if (sql_mngremote(sqlptr,sql_select,rmtip,&srv)==false) { + (void) rou_alert(0,"%s Unable to get remote <%s> data (database?)", + OPEP,rmtip); + phase=999; //Trouble trouble + } + break; + case 1 : //updating record according blacklisting + srv->credit=0; + srv->lastscan=time((time_t *)0); + if (dnsbls!=(char **)0) { + while (*dnsbls!=(char *)0) { + (void) rou_alert(0,"%s JMPDBG scan <%s> against <%s>",OPEP,rmtip,*dnsbls); + dnsbls++; + } + } + break; + case 2 : //updating record + if (sql_mngremote(sqlptr,sql_update,rmtip,&srv)==false) { + (void) rou_alert(0,"%s Unable to update remote <%s> data (database?)", + OPEP,rmtip); + } + break; + default : //SAFE Guard + proceed=false; + break; } + phase++; } - +srv=sql_freesrv(srv); #undef OPEP } /* diff --git a/lib/gessql.c b/lib/gessql.c index 39f52f6..f73fd54 100644 --- a/lib/gessql.c +++ b/lib/gessql.c @@ -18,6 +18,18 @@ #define ACTTBL "actions" //action tables #define SESTBL "sessions" //session tables +//field available in table "remotes" +static const FLDTYP usrfield[]={ + {1,"remoteip"}, + {2,"lastscan"}, + {3,"lastupdate"}, + {4,"links"}, + {5,"credit"}, + {6,"listing"}, + {0,(char *)0} + }; + +_Bool isok; /* */ @@ -254,8 +266,8 @@ return isok; */ /********************************************************/ /* */ -/* Procedure to select a user from emails tables */ -/* and return contents; */ +/* Procedure to select a remote server from remotes*/ +/* table and return contents */ /* */ /********************************************************/ static _Bool select_remote(SQLPTR *sqlptr,char *rmtip,SRVTYP **srv) @@ -265,18 +277,6 @@ static _Bool select_remote(SQLPTR *sqlptr,char *rmtip,SRVTYP **srv) static const char *sel="SELECT * FROM "RMTTBL" WHERE remoteip=%s"; -//field available in table "emails" -static const FLDTYP usrfield[]={ - {1,"remoteip"}, - {2,"lastscan"}, - {3,"lastupdate"}, - {4,"links"}, - {5,"credit"}, - {6,"listing"}, - {0,(char *)0} - }; - -_Bool isok; SRVTYP *locsrv; SQLRES *rs; register int phase; @@ -363,6 +363,39 @@ while (proceed==true) { *srv=locsrv; return isok; +#undef OPEP +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to select a remote server from remotes*/ +/* table and update contents */ +/* */ +/********************************************************/ +static _Bool update_remote(SQLPTR *sqlptr,char *rmtip,SRVTYP *srv) + +{ +#define OPEP "fgessql.c:update_remote," + +static const char *upd="UPDATE "RMTTBL" SET lastscan='%s',credit=%d,listing=%s WHERE remoteip='%s'"; + +_Bool isok; +const char *lastscan; +char *listing; + +isok=true; +lastscan=sql_fromunixtime(sqlptr,srv->lastscan); +listing=sql_gooddata(sqlptr,srv->listing); +if (sql_request(sqlptr,upd,lastscan,srv->credit,listing,srv->rmtip)!=1) { + (void) rou_alert(0,"%s Unable to update remote_ip <%s> (Database?)", + OPEP,srv->rmtip); + isok=false; + } +listing=rou_freestr(listing); +return isok; + #undef OPEP } /* @@ -683,8 +716,12 @@ while (proceed==true) { case sql_select : isok=select_remote(sqlptr,gooddata,srv); break; + case sql_update : + isok=update_remote(sqlptr,gooddata,*srv); + break; default : (void) rou_alert(0,"%s action='%d' not yet implemented!",OPEP,action); + break; } gooddata=rou_freestr(gooddata); break;