1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
<?php
/***************************************************************************
* auth.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id$
*
*
***************************************************************************/
/***************************************************************************
*
* 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, or
* (at your option) any later version.
*
*
***************************************************************************/
/* Notes:
* auth() is going to become a very complex function and can take in a LARGE number of arguments.
* The currently included argements should be enough to handle any situation, however, if you need access to another
* the best option would be to create a global variable and access it that way if you can.
*
* auth() returns:
* TRUE if the user authorized
* FALSE if the user is not
*/
function auth($type, $db, $id = "", $user_ip = "")
{
global $userdata;
switch($type)
{
case 'ip ban':
$sql = "DELETE FROM ".BANLIST_TABLE."
WHERE (ban_end < ". mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")).")
AND (ban_end > 0)";
$db->sql_query($sql);
$sql = "SELECT ban_ip FROM ".BANLIST_TABLE;
if($result = $db->sql_query($sql))
{
if($totalrows = $db->sql_numrows($result))
{
$iprow = $db->sql_fetchrowset($result);
for($x = 0; $x < $totalrows; $x++)
{
$ip = $iprow[$x]["ban_ip"];
if($ip[strlen($ip) - 1] == ".")
{
$db_ip = explode(".", $ip);
$this_ip = explode(".", $user_ip);
for($x = 0; $x < count($db_ip) - 1; $x++)
{
$my_ip .= $this_ip[$x] . ".";
}
if($my_ip == $ip)
{
return(FALSE);
}
}
else
{
if($ipuser == $ip)
{
return(FALSE);
}
}
}
return(TRUE);
}
else
{
return(TRUE);
}
}
return(TRUE);
break;
case 'username ban':
$sql = "DELETE FROM ".BANLIST_TABLE."
WHERE (ban_end < ". mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")).")
AND (ban_end > 0)";
$db->sql_query($sql);
$sql = "SELECT ban_userid FROM ".BANLIST_TABLE." WHERE ban_userid = '$user_id'";
if($result = $db->sql_query($sql))
{
if($db->sql_numrows($result))
{
return(FALSE);
}
else
{
return(TRUE);
}
}
else
{
return(TRUE);
}
break;
case 'login':
global $password;
if($userdata["user_password"] != md5($password))
{
return(FALSE);
}
else if($userdata["user_active"] == 0)
{
return(FALSE);
}
else
{
return(TRUE);
}
}
}
/*
* The following functions are used for getting user information. They are not related directly to auth()
*/
function get_userdata_from_id($userid, $db)
{
$sql = "SELECT * FROM ".USERS_TABLE." WHERE user_id = $userid";
if(!$result = $db->sql_query($sql))
{
$userdata = array("error" => "1");
return ($userdata);
}
if($db->sql_numrows($result))
{
$myrow = $db->sql_fetchrowset($result);
return($myrow[0]);
}
else
{
$userdata = array("error" => "1");
return ($userdata);
}
}
function get_userdata($username, $db) {
$sql = "SELECT * FROM ".USERS_TABLE." WHERE username = '$username' AND user_level != ".DELETED;
if(!$result = $db->sql_query($sql))
{
$userdata = array("error" => "1");
}
if($db->sql_numrows($result))
{
$myrow = $db->sql_fetchrowset($result);
return($myrow[0]);
}
else
{
$userdata = array("error" => "1");
return ($userdata);
}
}
?>
|