cvs: docweb /include cvs-auth.inc lib_auth.inc.php lib_general.inc.php /www login.php
[email protected] ("Nuno Lopes")
| Newsgroups | php.doc.web |
|---|---|
| Message-ID | <cvsnlopess1122573912@cvsserver> |
nlopess Thu Jul 28 14:05:12 2005 EDT
Modified files:
/docweb/include cvs-auth.inc lib_auth.inc.php lib_general.inc.php
/docweb/www login.php
Log:
clean up auth stuff. add a is_admin() function.
http://cvs.php.net/diff.php/docweb/include/cvs-auth.inc?r1=1.5&r2=1.6&ty=u
Index: docweb/include/cvs-auth.inc
diff -u docweb/include/cvs-auth.inc:1.5 docweb/include/cvs-auth.inc:1.6
--- docweb/include/cvs-auth.inc:1.5 Tue Apr 5 20:32:36 2005
+++ docweb/include/cvs-auth.inc Thu Jul 28 14:05:10 2005
@@ -18,7 +18,7 @@
* | Jacques Marneweck <[email protected]> |
* +----------------------------------------------------------------------+
*
- * $Id: cvs-auth.inc,v 1.5 2005/04/06 00:32:36 philip Exp $
+ * $Id: cvs-auth.inc,v 1.6 2005/07/28 18:05:10 nlopess Exp $
*/
require_once(dirname(__FILE__) . '/../build-ops.php');
@@ -64,7 +64,7 @@
$response = fgets($cvs);
fclose($cvs);
- return (0 == strncmp($response, 'I LOVE YOU', 10));
+ return !strncmp($response, 'I LOVE YOU', 10);
}
/**
@@ -108,7 +108,7 @@
}
if (auth_vs_local($idx, $user, $pass)) {
- return $user;
+ return true;
}
if (auth_vs_cvs($user, $pass)) {
@@ -116,7 +116,7 @@
sqlite_query($idx, "REPLACE INTO auth VALUES ('" . sqlite_escape_string($user) . "', '" . sha1($pass) . "', '" . time() . "')");
sqlite_close($idx);
- return $user;
+ return true;
}
return false;
http://cvs.php.net/diff.php/docweb/include/lib_auth.inc.php?r1=1.3&r2=1.4&ty=u
Index: docweb/include/lib_auth.inc.php
diff -u docweb/include/lib_auth.inc.php:1.3 docweb/include/lib_auth.inc.php:1.4
--- docweb/include/lib_auth.inc.php:1.3 Sun Feb 13 04:21:22 2005
+++ docweb/include/lib_auth.inc.php Thu Jul 28 14:05:10 2005
@@ -16,39 +16,76 @@
* | Authors: Jacques Marneweck <[email protected]> |
* +----------------------------------------------------------------------+
*
- * $Id: lib_auth.inc.php,v 1.3 2005/02/13 09:21:22 jacques Exp $
+ * $Id: lib_auth.inc.php,v 1.4 2005/07/28 18:05:10 nlopess Exp $
*/
require_once 'cvs-auth.inc';
+//list of docweb admins that have 'special' rights
+$admins = array(
+ 'didou',
+ 'goba',
+ 'jacques',
+ 'nlopess',
+ 'philip',
+ 'sean',
+);
+
$user = $pw = false;
+
/**
- * Credential checking of the $_COOKIE['MAGIC_COOKIE']
+ * read the magic cookie and return array(user, pass)
*/
-if (isset($_COOKIE['MAGIC_COOKIE'])) {
- list($user, $pw) = explode(":", base64_decode($_COOKIE['MAGIC_COOKIE']));
+function read_magic_cookie()
+{
+ return explode(':', base64_decode($_COOKIE['MAGIC_COOKIE']));
+}
- if (!$user || !$pw || !verify_password($user,stripslashes($pw))) {
- Header ("Location: http://doc.php.net/login.php");
- exit;
- }
-} elseif (isset($_POST['username']) && isset($_POST['passwd'])) {
- if (!$_POST['username'] || !$_POST['passwd'] || !verify_password($_POST['username'], stripslashes($_POST['passwd']))) {
- Header ("Location: http://doc.php.net/login.php");
+
+/**
+ * Credential checking of the $_COOKIE['MAGIC_COOKIE']
+ */
+function auth()
+{
+ if (isset($_COOKIE['MAGIC_COOKIE'])) {
+ list($user, $pw) = read_magic_cookie();
+
+ if (!verify_password($user, $pw)) {
+ header ('Location: http://doc.php.net/login.php');
+ exit;
+ }
+ } elseif (isset($_POST['username']) && isset($_POST['passwd'])) {
+ if (!verify_password($_POST['username'], $_POST['passwd'])) {
+ header ('Location: http://doc.php.net/login.php');
+ exit;
+ }
+
+ setcookie(
+ 'MAGIC_COOKIE',
+ base64_encode("{$_POST['username']}:{$_POST['passwd']}"),
+ time()+3600*24*12,
+ '/',
+ '.php.net'
+ );
+ } else {
+ header ('Location: http://doc.php.net/login.php');
exit;
}
+}
+
+
+/**
+ * Checks if a user has admin rights
+ */
+function is_admin()
+{
+ if (!isset($_COOKIE['MAGIC_COOKIE']))
+ return false;
+
+ list($user) = read_magic_cookie();
- setcookie(
- "MAGIC_COOKIE",
- base64_encode("{$_POST['username']}:{$_POST['passwd']}"),
- time()+3600*24*12,
- '/',
- '.php.net'
- );
-} else {
- Header ("Location: http://doc.php.net/login.php");
- exit;
+ return in_array($user, $GLOBALS['admins']);
}
/* vim: set noet ts=4 sw=4 ft=php: : */
http://cvs.php.net/diff.php/docweb/include/lib_general.inc.php?r1=1.44&r2=1.45&ty=u
Index: docweb/include/lib_general.inc.php
diff -u docweb/include/lib_general.inc.php:1.44 docweb/include/lib_general.inc.php:1.45
--- docweb/include/lib_general.inc.php:1.44 Fri Jun 10 18:06:37 2005
+++ docweb/include/lib_general.inc.php Thu Jul 28 14:05:10 2005
@@ -18,9 +18,11 @@
| Gabor Hojtsy <[email protected]> |
| Sean Coates <[email protected]> |
+----------------------------------------------------------------------+
-$Id: lib_general.inc.php,v 1.44 2005/06/10 22:06:37 mazzanet Exp $
+$Id: lib_general.inc.php,v 1.45 2005/07/28 18:05:10 nlopess Exp $
*/
+require_once dirname(__FILE__) . '/lib_auth.inc.php';
+
function is_translation($project, $language)
{
return is_dir(CVS_DIR . $GLOBALS['PROJECTS'][$project] . '/' . $language);
@@ -210,6 +212,9 @@
}
}
+ if (is_admin())
+ $links['admin'] = BASE_URL . '/admin.php';
+
return DocWeb_Template::get(
'shared/nav_links.tpl.php',
array('links' => $links, 'Language' => &$GLOBALS['Language'])
http://cvs.php.net/diff.php/docweb/www/login.php?r1=1.2&r2=1.3&ty=u
Index: docweb/www/login.php
diff -u docweb/www/login.php:1.2 docweb/www/login.php:1.3
--- docweb/www/login.php:1.2 Sun Feb 13 12:33:29 2005
+++ docweb/www/login.php Thu Jul 28 14:05:11 2005
@@ -1,12 +1,14 @@
<?php
-/* $Id: login.php,v 1.2 2005/02/13 17:33:29 sean Exp $ */
+/* $Id: login.php,v 1.3 2005/07/28 18:05:11 nlopess Exp $ */
include '../include/init.inc.php';
-if (isset($_POST) && !empty($_POST)) {
+if (isset($_COOKIE['MAGIC_COOKIE']) || !empty($_POST)) {
require_once '../include/lib_auth.inc.php';
+ auth();
- echo "You are logged in.";
+ echo 'You are logged in';
+ echo is_admin() ? ' <strong>with admin rights</strong>.' : '.';
} else {
echo site_header('docweb.common.header.login');
echo DocWeb_Template::get('login.tpl.php');