-
Notifications
You must be signed in to change notification settings - Fork 167
/
switcher.php
140 lines (118 loc) · 4.68 KB
/
switcher.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
// security protection
defined('_we_are_one') || die('Direct access not allowed.');
function switcher($page)
{
global $is_logged_in, $is_admin, $is_verified;
try {
$lock = false;
if (!preg_match("/^[0-9_a-z]*$/", $page))
$page = 'junk';
// delay showing the header when logging in until we know whether the login worked or not
if ($page != 'download' && $page != 'login' && $page != 'graph')
show_header($page, $is_logged_in);
if ($is_logged_in)
get_user_lock($lock = $is_logged_in);
addlog(LOG_SWITCHER, sprintf("[%s] visit page '%s'", getenv("REMOTE_ADDR"), $page));
switch($page) {
////////////////////////////////////////////////////////////////////////
// for general consumption
////////////////////////////////////////////////////////////////////////
case '404':
case 'graph':
case 'help':
case 'news':
case 'orderbook':
case 'test':
case 'trade':
case 'view_trades':
include("$page.php");
break;
////////////////////////////////////////////////////////////////////////
// for logged in users only
////////////////////////////////////////////////////////////////////////
case 'api':
case 'deposit':
case 'identity':
case 'place_order':
case 'profile':
case 'statement':
case 'turn_on_duo':
case 'view_order':
case 'view_request':
case 'withdraw':
if ($is_logged_in)
include("$page.php");
else
log_badpage($page);
break;
////////////////////////////////////////////////////////////////////////
// for admin only
////////////////////////////////////////////////////////////////////////
case 'add_cash':
case 'bank':
case 'commission':
case 'docs':
case 'download':
case 'freeze':
case 'users':
if ($is_admin)
include("$page.php");
else
log_badpage($page);
break;
case 'login':
if (!$is_logged_in) {
include("login.php");
// we just tried to log in, so check whether or not it worked before showing the footer
get_login_status();
} else {
addlog(LOG_LOGIN, " already logged in");
log_badpage($page);
}
break;
case 'logout':
setcookie('autologin', FALSE, time() - 60*60*24*365);
logout();
default:
sleep(3);
log_badpage($page);
break;
}
// debugging for session stuff
if (0) {
echo "<div class='content_box'>\n";
echo "<h3>Debug</h3>\n";
echo "<p>\n";
echo "session id: ", session_id(), "<br/>\n";
echo "session age: ", time() - $_SESSION['creation_time'], " seconds<br/>\n";
if (isset($inactivity)) echo "you were inactive for $inactivity seconds<br/>\n";
echo "MAX_IDLE_MINUTES_BEFORE_LOGOUT = ", MAX_IDLE_MINUTES_BEFORE_LOGOUT, " minutes = ", MAX_IDLE_MINUTES_BEFORE_LOGOUT * 60, " seconds<br/>\n";
echo "MAX_SESSION_ID_LIFETIME = ", MAX_SESSION_ID_LIFETIME, " minutes = ", MAX_SESSION_ID_LIFETIME * 60, " seconds<br/>\n";
echo "</p></div>\n";
}
}
catch (Error $e) {
global $shown_header;
report_exception($e, SEVERITY::ERROR);
// Same as below, but flag + log this for review,
if (!$shown_header) show_header($page, $is_logged_in);
echo "<div class='content_box'><h3>{$e->getTitle()}</h3>";
echo "<p>{$e->getMessage()}</p></div>";
}
catch (Problem $e) {
global $shown_header;
if (!$shown_header) show_header($page, $is_logged_in);
echo "<div class='content_box'><h3>{$e->getTitle()}</h3>";
echo "<p>{$e->getMessage()}</p></div>";
}
catch (Exception $e) {
global $shown_header;
if (!$shown_header) show_header($page, $is_logged_in);
echo "<div class='content_box'><h3>Technical difficulties</h3>";
echo "<p>{$e->getMessage()}</p></div>";
}
show_footer($is_logged_in, $is_admin, $is_verified);
if ($lock) release_lock($lock);
}
?>