forked from cydrobolt/polr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib-auth.php
172 lines (147 loc) · 5.85 KB
/
lib-auth.php
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
168
169
170
171
172
<?php
/*
# Copyright (C) 2013-2015 Chaoyi Zha
# Polr is an open-source project licensed under the GPL.
# The above copyright notice and the following license are applicable to
# the entire project, unless explicitly defined otherwise.
# http://github.com/cydrobolt/polr
# 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.
# See http://www.gnu.org/copyleft/gpl.html for the full text of the
# license.
#
*/
require_once('lib-core.php');
require_once('lib-password.php');
class polrauth {
public $authcreds = array();
public function islogged () {
if (@$_SESSION['li'] !== sha1('li')) {
return false;
} else {
$data['username'] = $_SESSION['username'];
$data['role'] = $_SESSION['role'];
return $data;
}
}
public function isadminli() {
if ($_SESSION['li'] !== sha1('li')) {
return false;
} else {
if ($_SESSION['role'] == 'adm') {
return true;
} else {
return false;
}
}
}
public function isadmin ($user) {
if ($this->getrole($user) == 'adm') {
return true;
} else {
return false;
}
}
public function headblock () {
if (is_array($this->islogged())) {
echo "<!--";
}
}
public function headendblock ($ar = false) {
if (is_array($this->islogged())) {
$authinfo = $this->islogged();
echo "-->";
$text = '<div class=\'nav pull-right navbar-nav\' style=\'color: white\'>
<li class=\'dropdown\'>
<a class="dropdown-toggle" href="#" data-toggle="dropdown" style=\'padding-right: 10px\'>' . $authinfo['username'] . ' <strong class="caret"></strong></a>
<ul class="dropdown-menu pull-right" role="menu" aria-labelledby="dropdownMenu">
<li><a tabindex="-1" href="admin/index.php">Dashboard</a></li>
<li><a tabindex="-1" href="admin/index.php#settings">Settings</a></li>
<li><a tabindex="-1" href="logout.php">Logout</a></li>
</ul>
</li>
</div>';
if ($ar == true) {
# if called from UCP
$text = '<div class=\'nav pull-right navbar-nav\' style=\'color: white\'>
<li class=\'dropdown\'>
<a class="dropdown-toggle" href="#" data-toggle="dropdown" style=\'padding-right: 10px\'>' . $authinfo['username'] . ' <strong class="caret"></strong></a>
<ul class="dropdown-menu pull-right" role="menu" aria-labelledby="dropdownMenu">
<li><a tabindex="-1" href="index.php">Dashboard</a></li>
<li><a tabindex="-1" href="index.php#settings">Settings</a></li>
<li><a tabindex="-1" href="../logout.php">Logout</a></li>
</ul>
</li>
</div>';
}
echo $text;
}
}
public function processlogin ($username, $password) {
global $mysqli;
$a = "SELECT `password`,`valid` FROM `auth` WHERE `username`=?";
$b = $mysqli->prepare($a);
$b->bind_param('s', $username);
$b->execute();
$d = $b->get_result();
echo $b->error;
$c = mysqli_fetch_assoc($d);
$hpw = $c['password'];
$uv = $c['valid'];
if ((!$hpw) || (!$uv)) {
return false;
}
$pwf = password_verify($password, $hpw);
if ($pwf && ($uv = 1)) {
return true;
} else {
return false;
}
}
public function getrole ($username) {
global $mysqli;
$a = "SELECT role FROM auth WHERE username='{$username}'";
$b = $mysqli->query($a) or showerror();
$c = mysqli_fetch_assoc($b);
return $c['role'];
}
public function getinfomu ($username) {
global $mysqli;
$username = $mysqli->real_escape_string($username);
$a = "SELECT `role`,`username`,`ip`,`theme`,`rkey` FROM `auth` WHERE username='{$username}';";
$b = $mysqli->query($a) or showerror();
$numrows = $b->num_rows;
if (!$numrows) {
return false;
}
$c = mysqli_fetch_assoc($b);
return $c;
}
public function getinfome ($email) {
global $mysqli;
$email = $mysqli->real_escape_string($email);
//$a = "SELECT `role`,`username`,`ip,`theme`,`rkey` FROM `auth` WHERE email='{$email}';";
$a = "SELECT `role`,`username`,`ip`,`theme`,`rkey` FROM `auth` WHERE email='{$email}';";
$b = $mysqli->query($a) or showerror();
$numrows = $b->num_rows;
if (!$numrows) {
return false;
}
$c = mysqli_fetch_assoc($b);
return $c;
}
public function remember_me () {
// Extend the login session cookie to last 30 days
$params = session_get_cookie_params();
setcookie(session_name(), $_COOKIE[session_name()], time() + 60 * 60 * 24 * 30, $params["path"], $params["domain"], $params["secure"], $params["httponly"]);
}
public function crkey ($username) {
global $mysqli;
$nrkey = sha1($username . (string) (rand(100, 4434555)) . date('yDm'));
$usernamesan = $mysqli->real_escape_string($username);
$qr = "UPDATE auth SET rkey='{$nrkey}' WHERE username='$usernamesan';";
$e = $mysqli->query($qr) or showerror();
}
}