Project

General

Profile

eXtplorer 2.1.3 Security Release » users.php

Sören Eberhardt-Biermann, 12/25/2012 08:21 AM

 
1
<?php
2
// ensure this file is being included by a parent file
3
if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' );
4
/**
5
 * @version $Id: users.php 226 2012-12-25 06:51:02Z soeren $
6
 * @package eXtplorer
7
 * @copyright soeren 2007-2009
8
 * @author The eXtplorer project (http://extplorer.net)
9
 * @author The	The QuiX project (http://quixplorer.sourceforge.net)
10
 * 
11
 * @license
12
 * The contents of this file are subject to the Mozilla Public License
13
 * Version 1.1 (the "License"); you may not use this file except in
14
 * compliance with the License. You may obtain a copy of the License at
15
 * http://www.mozilla.org/MPL/
16
 * 
17
 * Software distributed under the License is distributed on an "AS IS"
18
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
19
 * License for the specific language governing rights and limitations
20
 * under the License.
21
 * 
22
 * Alternatively, the contents of this file may be used under the terms
23
 * of the GNU General Public License Version 2 or later (the "GPL"), in
24
 * which case the provisions of the GPL are applicable instead of
25
 * those above. If you wish to allow use of your version of this file only
26
 * under the terms of the GPL and not to allow others to use
27
 * your version of this file under the MPL, indicate your decision by
28
 * deleting  the provisions above and replace  them with the notice and
29
 * other provisions required by the GPL.  If you do not delete
30
 * the provisions above, a recipient may use your version of this file
31
 * under either the MPL or the GPL."
32
 * 
33
 * Administrative Functions regarding users
34
 */
35
function ext_load_users() {
36
	require _EXT_PATH."/config/.htusers.php";
37
}
38
//------------------------------------------------------------------------------
39
function ext_save_users() {
40
	$cnt=count($GLOBALS["users"]);
41
	if($cnt>0) sort($GLOBALS["users"]);
42

    
43
	// Make PHP-File
44
	$content='<?php 
45
	// ensure this file is being included by a parent file
46
	if( !defined( \'_JEXEC\' ) && !defined( \'_VALID_MOS\' ) ) die( \'Restricted access\' );
47
	$GLOBALS["users"]=array(';
48
	for($i=0;$i<$cnt;++$i) {
49
		// if($GLOBALS["users"][6]&4==4) $GLOBALS["users"][6]=7;	// If admin, all permissions
50
		$content.="\r\n\tarray('".$GLOBALS["users"][$i][0]."','".
51
			$GLOBALS["users"][$i][1]."','".$GLOBALS["users"][$i][2]."','".$GLOBALS["users"][$i][3]."','".
52
			$GLOBALS["users"][$i][4]."','".$GLOBALS["users"][$i][5]."','".$GLOBALS["users"][$i][6]."',".
53
			$GLOBALS["users"][$i][7].'),';
54
	}
55
	$content.="\r\n); \r\n?>";
56

    
57
	// Write to File
58
	if( !is_writable(_EXT_PATH."/config/.htusers.php") && !chmod( _EXT_PATH."/config/.htusers.php", 0644 ) ) {
59
		return false;
60
	}
61
	file_put_contents( _EXT_PATH."/config/.htusers.php", $content);
62

    
63
	return true;
64
}
65
//------------------------------------------------------------------------------
66
function &ext_find_user($user,$pass) {
67
	$return = null;
68
	$cnt=count($GLOBALS["users"]);
69
	for($i=0;$i<$cnt;++$i) {
70
		if($user==$GLOBALS["users"][$i][0]) {
71
			if($pass===NULL || ($pass==$GLOBALS["users"][$i][1] && $GLOBALS["users"][$i][7])) {
72
				return $GLOBALS["users"][$i];
73
			}
74
		}
75
	}
76

    
77
	return $return;
78
}
79

    
80
//------------------------------------------------------------------------------
81
function ext_update_user($user,$new_data) {
82
	$data=&ext_find_user($user,NULL);
83
	if($data==NULL) return false;
84

    
85
	$data=$new_data;
86
	return ext_save_users();
87
}
88
//------------------------------------------------------------------------------
89
function ext_add_user($data) {
90
	if(ext_find_user($data[0],NULL)) return false;
91

    
92
	$GLOBALS["users"][]=$data;
93
	return ext_save_users();
94
}
95
//------------------------------------------------------------------------------
96
function ext_remove_user($user) {
97
	$data=&ext_find_user($user,NULL);
98
	if($data==NULL) return false;
99

    
100
	// Remove
101
	$data=NULL;
102

    
103
	// Copy Valid Users
104
	$cnt=count($GLOBALS["users"]);
105
	for($i=0;$i<$cnt;++$i) {
106
		if($GLOBALS["users"][$i]!=NULL) $ext_save_users[]=$GLOBALS["users"][$i];
107
	}
108
	$GLOBALS["users"]=$ext_save_users;
109
	return ext_save_users();
110
}
111
//------------------------------------------------------------------------------
112
/*
113
function num_users($active=true) {
114
	$cnt=count($GLOBALS["users"]);
115
	if(!$active) return $cnt;
116

    
117
	for($i=0, $j=0;$i<$cnt;++$i) {
118
		if($GLOBALS["users"][$i][7]) ++$j;
119
	}
120
	return $j;
121
}
122
*/
123
//------------------------------------------------------------------------------
124

    
125
?>
    (1-1/1)