00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 include_once 'global.php';
00026
00031 function valid_user()
00032 {
00033 $username = $_SERVER["PHP_AUTH_USER"];
00034 $password = $_SERVER["PHP_AUTH_PW"];
00035
00036 if ($username=='superuser')
00037 {
00038 $crypted_passwd = shell_exec('cat .su/passwd');
00039 $crypted_passwd = trim($crypted_passwd);
00040 }
00041 else
00042 {
00043
00044 $get_user = "templates/scripts/users/get_user.sh";
00045 $record = shell_exec("$get_user $username");
00046 $fields = explode(':', $record);
00047 if ($fields[0]!=$username) return false;
00048 $crypted_passwd = $fields[1];
00049 $email = $fields[3];
00050 }
00051
00052 $valid = ($crypted_passwd == crypt($password, $crypted_passwd));
00053 if (!$valid) return false;
00054
00055 if ($username=='superuser')
00056 {
00057 define('SU', 'true');
00058 define('USER', 'su');
00059 define('EMAIL', ADMIN_EMAIL);
00060 }
00061 else
00062 {
00063 define('SU', 'false');
00064 define('USER', $username);
00065 define('EMAIL', $email);
00066 }
00067
00068 return true;
00069 }
00070
00071 function authenticate()
00072 {
00073 header("WWW-Authenticate: Basic realm=\"DocBook Editor\"");
00074 header("HTTP/1.0 401 Unauthorized");
00075 $host = $_SERVER['HTTP_HOST'];
00076 $file = $_SERVER['SCRIPT_NAME'];
00077 $url = 'http:
00078 print "
00079 <html>
00080 <head>
00081 <title>Unauthorized</title>
00082 <meta http-equiv='refresh' content='2;url=$url'>
00083 </head>
00084 <body>
00085 <h1>Sorry, you cannot access this page.</h1>
00086 </body>
00087 ";
00088
00089 exit;
00090 }
00091
00092
00093 if (!isset($_SERVER['PHP_AUTH_USER'])) authenticate();
00094 else if (!valid_user()) authenticate();
00095 ?>