/
main.php
executable file
·140 lines (121 loc) · 4.27 KB
/
main.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
<?php
/*
The file is part of the HOBA server.
HOBA server 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 3 of the License, or
(at your option) any later version.
HOBA server is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2016, Andrew McConachie, <andrew@depht.com>
*/
include_once 'globals.php';
include_once 'db.php';
include_once 'crypto.php';
include_once 'printers.php';
dbLogin();
// Test for cookies
if(isset($_COOKIE['HOBA'])){
dump("HOBA: Got HOBA cookie for " . $_COOKIE['HOBA']);
$err = true;
$dev = dbGetDeviceByCookie($_COOKIE['HOBA']);
if($dev){
//TODO: Refresh session if it's old
if($dev['pw'] && !$dev['passed']){ // Handle HOBA+YeOlde
if(isset($_POST['HOBAYeOldeLogin']) && isset($_POST['HOBAYeOldeUser']) && isset($_POST['HOBAYeOldePassword'])){
dump("HOBA: Handling HOBA+YeOlde Login Creds");
$uid = dbCheckUserPass($_POST['HOBAYeOldeUser'], $_POST['HOBAYeOldePassword'], $dev['did']);
if(! $uid === false){
dbModSession($_COOKIE['HOBA'], false, false, false, 1);
printHeader();
printMeat(false, $dev['did'], "");
printFooter();
}else{
printLoginFailure("HOBA: Bad Username / Password");
}
}else{
dump("HOBA: Initiating HOBA+YeOlde Login");
printHOBAYeOldePrompt();
}
}else{
if(isset($_POST['uName'])){
$err = dbSetUserName($dev['uid'], $_POST['uName']);
}elseif(isset($_POST['uPass'])){
$err = dbSetUserPass($dev['uid'], $_POST['uPass']);
}elseif(isset($_POST['msg'])){
$err = dbAddMsg($dev['uid'], $_POST['msg']);
}elseif(isset($_POST['bondAttempt'])){
$err = dbRequestBond($dev['did'], $_POST['bondAttemptTarget']);
}elseif(isset($_POST['bondConfirm'])){
if($_POST['bondMe'] === "false"){
$err = dbDeleteBond($_POST['bondConfirmSource'], $dev['uid']);
}elseif($_POST['bondMe'] === "true"){
$err = dbConfirmBond($_POST['bondConfirmSource'], $dev['uid']);
}
}
printHeader();
if($err !== true){
dump($err);
printMeat(false, $dev['did'], $err);
}else{
printMeat(false, $dev['did'], "");
}
printFooter();
}
}else{
dump("HOBA: No HOBA session found");
printLoginFailure();
}
}elseif(isset($_COOKIE['YEOLDE'])){
dump("HOBA: Got YEOLDE cookie for " . $_COOKIE['YEOLDE']);
$err = true;
$user = dbGetUserByCookie($_COOKIE['YEOLDE']);
if($user){
//TODO: Refresh session if it's old
if(isset($_POST['uPass'])){
$err = dbSetUserPass($user['uid'], $_POST['uPass']);
}elseif(isset($_POST['msg'])){
$err = dbAddMsg($user['uid'], $_POST['msg']);
}
printHeader();
if($err !== true){
dump($err);
printMeat($user['uName'], false, $err);
}else{
printMeat($user['uName'], false, "");
}
printFooter();
}else{
dump("HOBA: No YEOLDE session found");
printLoginFailure();
}
}else{
dump("HOBA: No cookie set");
if(isset($_POST['YeOldeLogin'])){ // Handle traditional logins
dump("HOBA: Initiating YeOlde Login");
if(isset($_POST['YeOldeUser']) && isset($_POST['YeOldePassword'])){
$uid = dbCheckUserPass($_POST['YeOldeUser'], $_POST['YeOldePassword'], false);
if(! $uid === false){
$t = time() + $GLOBALS['sessionTimeout'];
$chocolate = getCookieVal($uid, $uid);
dbAddUserSession($uid, $chocolate, $t);
setUserCookie($chocolate, $t);
dump("HOBA: YeOlde Login Successful");
$user = dbGetUserByCookie($chocolate);
printHeader();
printMeat($user['uName'], false, "");
printFooter();
}else{
printLoginFailure("YeOlde Bad Username/Password");
}
}else{
printLoginFailure("YeOlde Missing Username/Password");
}
}
}
dbLogout();
?>