]> SAFE projects GIT repository - jmp/mailleur/commitdiff
updating remotes tables start to work
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 13 Jul 2025 14:24:59 +0000 (10:24 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 13 Jul 2025 14:24:59 +0000 (10:24 -0400)
app/scarmt.c
lib/gessql.c

index 0245c760b2c4eae2c23aa92a148713fbdb34032f..9dcbf24816138f6515b7ce85ca9974b270a00232 100644 (file)
@@ -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
 }
 /*
index 39f52f62440b952214aa91b6182d0a74a2c25e50..f73fd54921d80cf00be02da961f7d0a67199ec73 100644 (file)
 #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;
 /*
 \f
 */
@@ -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
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      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;