]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Detecting if logname is and php adin
authorJean-Marc Pigeon <jmp@safe.c>
Thu, 4 Sep 2025 18:47:36 +0000 (14:47 -0400)
committerJean-Marc Pigeon <jmp@safe.c>
Thu, 4 Sep 2025 18:47:36 +0000 (14:47 -0400)
lib/unimar.c
sql/datatest.sql
www/gessql.php
www/home.php [deleted file]
www/index.php
www/login.php
www/mailleur.php
www/scrfun.php
www/subrou.php

index f296c21dee995a426e7ee29fe9eb2bdf899c0dfe..e8173298a61076955a62f754fd67202f8d758f47 100644 (file)
@@ -291,7 +291,7 @@ locked=false;
   phase=0;
   proceed=true;
   while (proceed==true) {
-    (void) rou_alert(0,"%s JMPDBG phase='%d'",OPEP,phase);
+    //(void) rou_alert(0,"%s JMPDBG phase='%d'",OPEP,phase);
     switch (phase) {
       case 0    :       //Starting lock
         if (mar_request(marptr,"BEGIN")<0) {
index ba678eb6672140a2331fdbaa619303d86eb5e02d..efeb35ad07b2654752af01a41c3dbd7c0f31ae98 100644 (file)
@@ -8,7 +8,10 @@ DELETE FROM emails;
 //present password is crypted as a hash and in password too
 //adding a list of local email
 
+//==============================================================
 //set for local test
+INSERT INTO emails (email,password)                            \
+        values ('root@example.com','4cabri');
 INSERT INTO emails (email,password)                            \
         values ('postmaster@example.com','postmaster');
 INSERT INTO emails (email,password)                            \
@@ -30,6 +33,7 @@ INSERT INTO emails (email,password)                           \
 INSERT INTO emails (email,password)                            \
          values ('user2@mardb.example.com','user2');
 
+//==============================================================
 //List of remote IP status
 INSERT INTO remotes (remoteip,credit,lastscan)                 \
          values ('127.127.0.25',10,now());
@@ -51,6 +55,7 @@ INSERT INTO remotes (remoteip)                                        \
 INSERT INTO remotes (remoteip)                                 \
          values ('193.111.208.122');
 
+//==============================================================
 //selected IP from from 'clean' server
 INSERT INTO remotes (remoteip)                                 \
          values ('192.219.254.189');
@@ -60,3 +65,9 @@ INSERT INTO remotes (remoteip)                                        \
 //selected IP with low credit
 INSERT INTO remotes (remoteip,credit)                          \
          values ('127.127.127.127',-50);
+
+//==============================================================
+//defining admin user
+INSERT INTO admins (email)                             \
+         values ('root@example.com');
+//==============================================================
index 107498b2f1e8fb06564915fabafc2c2bcf128480..aed6b8c0f85a50265702f10ebe4238666331a769 100644 (file)
@@ -71,8 +71,11 @@ return $isgood;
 function sql_getlogname($dbsql)
 
 {
+global $isadmin;
+
 $OPEP="gessql.php:sql_getlogname";
 
+$isadmin=0;
 $logname=NULL;
 $expire=NULL;
 $cookie=$_COOKIE[getenv("APPNAME")];
@@ -109,6 +112,12 @@ while ($proceed==true) {
         $phase=999;
         }
       break;
+    case 4      :       //checking if logname is an admin
+      $stmt=$dbsql->Select("Select * from admins where email='$logname'");
+      $id=$stmt->fetch(PDO::FETCH_ASSOC)['email'];
+      if ($id!=NULL)
+        $isadmin=true;
+      break;
     default     :       //SAFE Guard
       $proceed=false;
       break;
diff --git a/www/home.php b/www/home.php
deleted file mode 100644 (file)
index dff3648..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-// vim: smarttab tabstop=8 shiftwidth=2 expandtab
-include_once "subrou.php";
-include_once "unienv.php";
-include_once "scrfun.php";
-include_once "gessql.php";
-
-//section to generate the main screen body
-//
-function body()
-
-{
-//including screen function
-//
-
-$footer=footer("home");
-$login=login();
-
-$STR  = <<<EOT
-<!DOCTYPE html>
-<HTML>    
-<HEAD>
-<TITLE>Starting</TITLE>
-<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
-</HEAD>
-<BODY="white">
-
-<CENTER><STRONG><FONT SIZE=+2 color=red>
-Mailleur
-</FONT></STRONG></CENTER>
-$login
-$footer
-</BODY>
-</HTML>
-EOT;
-
-return $STR;
-}
-
-if ($_SERVER["REQUEST_METHOD"] == "POST") {
-  $pass=$_POST["passwd"];
-  $logname=$_POST["email"];
-  $dbsql=sql_connect();
-  $isok=sql_checkpassword($dbsql,$logname,$pass);
-  sql_close($dbsql);
-  switch ($isok) {
-    case false  :       //trouble report
-      echo "<script>";
-      echo "alert('wrong username or password. Please try again.');";
-      echo "</script>";
-      break;
-    default     :
-      header('Location: mailleur.php');
-      break;
-    }
-  }
-
-//display main screen
-echo body();
-?>
-
-
-
index af1907f2cbadd2e7e44e485077df90918d058bdf..ce0cbc5876203d31d2c17507617d780e3796f0bf 120000 (symlink)
@@ -1 +1 @@
-home.php
\ No newline at end of file
+login.php
\ No newline at end of file
index a81d71d935c50c85d1f2263d5486a85cbf59187d..9b4c4e0ec5396701dd4b06fd6bf3d2799f427be8 100644 (file)
@@ -1,18 +1,68 @@
 <?php
-// In a real application, connect to a database and verify credentials securely.
-// This is a simplified example for demonstration.
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+//==============================================================
+//
+//     login screen management
+//
+//==============================================================
+include_once "subrou.php";
+include_once "unienv.php";
+include_once "scrfun.php";
+include_once "gessql.php";
+
+//section to generate the main screen body
+//
+function body()
+
+{
+//including screen function
+//
+
+$footer=footer("login");
+$login=login();
+
+$STR  = <<<EOT
+<!DOCTYPE html>
+<HTML>    
+<HEAD>
+<TITLE>Starting</TITLE>
+<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
+</HEAD>
+<BODY="white">
+
+<CENTER><STRONG><FONT SIZE=+2 color=red>
+Mailleur
+</FONT></STRONG></CENTER>
+$login
+$footer
+</BODY>
+</HTML>
+EOT;
+
+return $STR;
+}
 
 if ($_SERVER["REQUEST_METHOD"] == "POST") {
-    $username = $_POST['username'];
-    $password = $_POST['password'];
-
-    // Example: Check if username is 'test' and password is 'wrongpass'
-    if ($username === 'test' && $password === 'correctpass') {
-        // Successful login, redirect or set session
-        echo "<script> alert('Login successful!'); window.location.href = 'dashboard.php';</script>";
-    } else {
-        // Incorrect password, display a JavaScript alert as a popup
-        echo "<script>alert('Invalid username or password. Please try again.');</script>";
+  $pass=$_POST["passwd"];
+  $logname=$_POST["email"];
+  $dbsql=sql_connect();
+  $isok=sql_checkpassword($dbsql,$logname,$pass);
+  sql_close($dbsql);
+  switch ($isok) {
+    case false  :       //trouble report
+      echo "<script>";
+      echo "alert('wrong username or password. Please try again.');";
+      echo "</script>";
+      break;
+    default     :
+      header('Location: mailleur.php');
+      break;
     }
-}
+  }
+
+//display main screen
+echo body();
 ?>
+
+
+
index 23ed23406c944585faf31b7edc3cdc7b729da517..237da88aa8710c369f255e7fd544270a3908f8f5 100644 (file)
@@ -14,6 +14,9 @@ include_once "gessql.php";
 function body($logname)
 
 {
+global $isadmin;
+
+rou_alert(0,"JMPDBG admin=$admin");
 $footer=footer(getenv("APPNAME"));
 $cook=$_COOKIE[getenv("APPNAME")];
 
@@ -30,6 +33,8 @@ Within mailleur
 <BR>
 LOGNAME=$logname
 <BR>
+ADMIN=$isadmin
+<BR>
 The cookies=$cook
 <BR>
 </FONT></STRONG></CENTER>
@@ -53,7 +58,7 @@ if ($logname!=NULL) {
   echo body($logname);
   }
 else {
-  header('Location: home.php');
+  header('Location: login.php');
   }
 ?>
 
index 42d3df1d941bd736798546ddf26d127362d36bcf..09b9dd1ea1b4771e0c8db2535811ab7d9604d2c0 100644 (file)
@@ -80,7 +80,7 @@ else {
           <tr>
             <td bgcolor="#FFFFFF" align="right">
            <form method="post"
-                 action="home.php"
+                 action="login.php"
                  enctype="application/x-www-form-urlencoded"
                  name="login">
               <table align="center" border="0" cellspacing="2" cellpadding="0">
index 96cad9b6010a4f481e6136c44791bebdf1ac2e41..fe625584547c081e942bd98758134cb0393b8249 100644 (file)
@@ -4,10 +4,9 @@
 //     To manage very low level function
 //
 //==============================================================
-global $debug;
-
-
-$debug=0;
+//gobal variables.
+$debug=0;              //default debug level
+$isadmin=0;            //authenticated user with admin level
 
 //==============================================================
 //     Open a syslog channel
@@ -36,7 +35,7 @@ function rou_alert($dbglvl,$report)
 global $debug;
 
 if ($debug>=$dbglvl)
-  syslog(LOG_INFO,"$report");
+  syslog(LOG_INFO,"dbg=$debug, $report");
 }
 
 rou_openlog();