-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.inc.php
More file actions
executable file
·158 lines (140 loc) · 2.84 KB
/
output.inc.php
File metadata and controls
executable file
·158 lines (140 loc) · 2.84 KB
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
<?php
/*
* Check if file was called directly and error out because file should never be called directly
*/
if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME'])){
$tmp = basename(__FILE__) . ':' . __LINE__;
error_log("[ LAKEBED ][ {$tmp} ] File was accessed directly, which should never happen.");
echo 'Something went terribly wrong. :(';
header('Status: 404 Not Found', false);
header('Location: https://lakebed.io', false);
die;
}
/*
* //class for everything ERRor related
*/
class output {
/*
* setup data stores
*/
public $browser_flag=0;
/*
* //func to error OUT
*/
function send(
$next_url=0, // string, server_url is automatically prepended. Used to direct to another front-end microservice
$http_code=401 // int, to control http code
){
/*
* disconnect from DB if connected
*/
if (!empty($_SERVER['class']['db'])){
unset($_SERVER['class']['db']);
}
/*
* init ret
*/
if (
(empty($_SERVER['return']))
||
(!is_array($_SERVER['return']))
){
$_SERVER['return']=array();
}
/*
* handle next URL
* and make sure its on the same server
*/
if (empty($_SERVER['return']['next_url'])){
$_SERVER['return']['next_url']='';
}
if (
(!empty($next_url))
&&
($next_url = trim($next_url, '/'))
){
$_SERVER['return']['next_url'] = $next_url;
//$_SERVER['return']['next_url'] = str_replace($_SERVER['class']['constants']->server_url, '', $_SERVER['return']['next_url']);
}
if (strpos($_SERVER['return']['next_url'], $_SERVER['class']['constants']->server_url) === 0){
$_SERVER['return']['next_url'] = substr_replace(
$_SERVER['return']['next_url'],
'',
0,
strlen($_SERVER['class']['constants']->server_url)
);
}
/*
* default success
*/
if (
(!isset($_SERVER['return']['success']))
||
($_SERVER['return']['success'] != 1)
){
$_SERVER['return']['success']=0;
}
/*
* header redirect if browser flag is set
*/
if (
(isset($this->browser_flag))
&&
($this->browser_flag)
){
if (
(!isset($_SERVER['return']['next_url']))
||
(!$_SERVER['return']['next_url'])
){
$_SERVER['return']['next_url']='/error';
}
$_SESSION['message']=$_SERVER['return']['message'];
header("Location:{$_SERVER['class']['constants']->server_url}/{$_SERVER['return']['next_url']}", false);
die;
}
/**
* handle http_code
*/
if (
(empty($http_code))
||
(!$http_code = ($http_code * 1))
||
(empty($http_code))
){
$http_code = 401;
}
/*
* output header info
*/
http_response_code($http_code);
header('Content-Type: application/json; charset=UTF-8', false);
header("HTTP/1.0 {$http_code} Found", false);
echo json_encode($_SERVER['return']);
die;
/*
* done //func
*/
}
/*
* done //class
*/
}
/*
* init //class
*/
if (
(!isset($_SERVER['class']))
||
(!is_array($_SERVER['class']))
){
$_SERVER['class']=array();
}
if (
(!isset($_SERVER['class']['output']))
||
(!$_SERVER['class']['output'])
){
$_SERVER['class']['output'] = new output;
}