<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* Original Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)   */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2004 by Philippe Brunier   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
function Admin_alert($motif) {
    global $admin;
    setcookie("admin","",0);
    unset($admin);

    Ecr_Log("security", "auth.inc.php/Admin_alert : ".$motif, "");
    if (file_exists("meta/meta.php"))
       include("meta/meta.php");
    echo "</head>\n<body bgcolor=\"#FFFFFF\" text=\"#000000\">\n<br /><br /><br />";
    echo "<p align=\"center\" style=\"font-size: 14px; font-family: Tahoma, Arial; color: Red;\"><b>.: ".translate("Your IP is recorded")." :.</b></p>\n";
    echo "</body>\n";
    echo "</html>\n";
    die();
}

if ((isset($aid)) and (isset($pwd)) and ($op == "login")) {
    if ($aid!="" and $pwd!="") {
        $result=mysql_query("select pwd from authors where aid='$aid'");
        if (!$result) {
           Admin_Alert("DB not ready #1 : $aid | ");
        } else {
           list($pass)=mysql_fetch_row($result);
           if ($system_md5) {
              $passwd=crypt($pwd,$pass);
           } else {
              $passwd=$pwd;
           }

           if ((strcmp($passwd,$pass)==0) and ($pass != "")) {
              $admin = base64_encode("$aid:".md5($passwd));
              if ($admin_cook_duration<=0) {$admin_cook_duration=1;}
              $timeX=time()+(3600*$admin_cook_duration);
              setcookie("admin","$admin",$timeX);
           } else {
              Admin_Alert("Passwd not in DB#1 : $aid | ");
           }
        }
    }
}

#autodoc $admintest - $super_admintest : permet de savoir si un admin est connect&ecute; ($admintest=true) et s'il est SuperAdmin ($super_admintest=true)
$admintest = false;
$super_admintest = false;

if ($admin!="") {
  $Xadmin = base64_decode($admin);
  $Xadmin = explode(":", $Xadmin);
  $aid = urlencode($Xadmin[0]);
  $AIpwd = $Xadmin[1];
  if ($aid=="" or $AIpwd=="") {
     Admin_Alert("Null Aid or Passwd");
  }
  $result=mysql_query("select pwd, radminsuper from authors where aid='$aid'");
  if (!$result) {
     Admin_Alert("DB not ready #2 : $aid / $AIpwd | ");
  } else {
    list($AIpass, $Xsuper_admintest)=mysql_fetch_row($result);
    if (md5($AIpass) == $AIpwd and $AIpass != "") {
       $admintest = true;
       $super_admintest = $Xsuper_admintest;
    } else {
       Admin_Alert("Password in Cookies not Good #1 : $aid / $AIpwd | ");
    }
  }
  unset ($AIpass);
  unset ($AIpwd);
  unset ($Xadmin);
  unset ($Xsuper_admintest);
}
?>