forked from spencerthayer/ezIPTV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
273 lines (273 loc) · 11.7 KB
/
index.php
File metadata and controls
273 lines (273 loc) · 11.7 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
ini_set("memory_limit", "256M");
error_reporting(E_ALL);
require("app/vars.php");
require("app/link.php");
require("app/db.php");
getGitBranch();
if (!file_exists(".htaccess")) {
header("location: ./setup");
die;
}
// ROUTING
$routes = array(
$pathRoot."/" => "indexController",
$pathRoot."/{a}" => "itemController",
$pathRoot."/{a}/all" => "allController",
$pathRoot."/{a}/csv" => "csvController",
$pathRoot."/{a}/delete" => "deleteData",
$pathRoot."/{a}/m3u" => "m3uController",
$pathRoot."/{a}/rss" => "rssController",
$pathRoot."/{a}/rss/epg" => "epgController",
$pathRoot."/{a}/update" => "updateData",
$pathRoot."/add" => "addController",
$pathRoot."/example" => "createExample",
$pathRoot."/f/{a}/",
$pathRoot."/f/{a}/edit" => "fileController",
$pathRoot."/f/{a}/delete" => "fileController",
$pathRoot."/f/{a}/update" => "fileController",
"/git" => "gitPull"
);
Link::all($routes);
// CRUD CONTROLLERS
class indexController {
function get(){
// echo "GET";
require("app/vars.php");
include("src/header.php");
listData();
include("src/footer.php");
}
function post(){
createData();
}
}
class itemController {
function get($a){
require("app/vars.php");
include("src/header.php");
include("app/views/item.php");
include("src/footer.php");
}
}
// VIEWS CONTROLLERS
function addController() {
header("location: ".url().ran(4,4)."");
}
function allController($a) {
header("Content-type: text/m3u");
header("Content-Disposition: attachment; filename=".$a.".m3u");
print "#EXTM3U"."\n";
include("app/views/m3u.php");
include("app/views/rss.php");
}
function createData(){
$db = new Db($_SERVER["DOCUMENT_ROOT"]."/data/data.json");
$data = array(
"uid" => $_POST["uid"],
"title" => $_POST["title"],
"csvUrl" => $_POST["csvUrl"],
"m3uUrl" => array_values(array_filter(explode(PHP_EOL, $_POST["m3uUrl"]))),
"rssUrl" => array_values(array_filter(explode(PHP_EOL, $_POST["rssUrl"])))
);
$db->insert($data);
header("location: ".url().$_POST["uid"]);
}
function readData($a){
$db = new Db($_SERVER["DOCUMENT_ROOT"]."/data/data.json");
$db->where("uid", $a);
// $db->order_by("_id", "DESC");
$data = $db->get();
foreach($data as $data) {
$uid = $data["uid"];
$title = $data["title"];
$csvUrl = $data["csvUrl"];
$m3uUrl = $data["m3uUrl"];
$rssUrl = $data["rssUrl"];
return compact("uid","title","csvUrl","m3uUrl","rssUrl");
}
}
function updateData($a){
// print_r($_POST);
$db = new Db($_SERVER["DOCUMENT_ROOT"]."/data/data.json");
$data = array(
"uid" => $_POST["uid"],
"title" => $_POST["title"],
"csvUrl" => $_POST["csvUrl"],
"m3uUrl" => array_values(array_filter(explode(PHP_EOL, $_POST["m3uUrl"]))),
"rssUrl" => array_values(array_filter(explode(PHP_EOL, $_POST["rssUrl"])))
);
$db->where("uid", $_POST["uid"]);
$db->update($data);
header("location: ".url().$_POST["uid"]);
}
function deleteData($a){
$u = getURI();
$db = new Db($_SERVER["DOCUMENT_ROOT"]."/data/data.json");
$db->where("uid", $u["path"]);
$db->delete();
header("location: ".url());
}
function createExample(){
$db = new Db($_SERVER["DOCUMENT_ROOT"]."/data/data.json");
$uid = ran(4,4);
$data = array(
"uid" => $uid,
"title" => ran(8,16),
"csvUrl" => "https://docs.google.com/spreadsheets/d/e/2PACX-1vRCK3VaABs6SlEL-nBXtbvDPhMkgbKpHKENGK_-1kOtkpUT2KSznjlTgCbmT2lcur9LinZRM7c-wDp-/pub?gid=878215409&single=true&output=csv",
"m3uUrl" => array (
"https://pastebin.com/raw/0AxHuqZv",
"https://pastebin.com/raw/jbqA0j82",
"https://pastebin.com/raw/EFjBwC9e"
),
"rssUrl" => array (
"https://democracynow.org/podcast-video.xml",
"https://podsync.net/1QPr",
"https://siftrss.com/f/d08JgNM5V3",
"https://siftrss.com/f/LbQX1zVA6z0",
"https://podsync.net/WQ2O",
"https://podsync.net/hH351ceab"
),
);
$db->insert($data);
header("location: ".url().$uid);
}
function csvController($a) {
include("app/views/csv.php");
}
function epgController($a) {
$epg = true;
header("Content-type: text/xml");
include("app/views/rss.php");
}
function m3uController($a) {
header("Content-type: text/m3u");
header("Content-Disposition: attachment; filename=".$a.".m3u");
print "#EXTM3U"."\n";
include("app/views/m3u.php");
}
function rssController($a) {
$epg = false;
header("Content-type: text/m3u");
header("Content-Disposition: attachment; filename=".$a.".m3u");
print "#EXTM3U"."\n";
include("app/views/rss.php");
}
// GENERAL FUNCTIONS
function ran($x,$y){
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
return substr(str_shuffle($chars),0,rand($x,$y));
}
function line($x){
return implode( "\n", $x );
}
function getAuth(){
$f = file_get_contents("data/settings.json");
$j = json_decode($f, true);
$l = $j["login"];
$p = $j["pass"];
return $l.":".$p;
}
function getURI(){
$protocol = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] !== "off" ? "https" : "http") . "://";
$server = $_SERVER["HTTP_HOST"];
$hostname = $protocol.$server;
$uri = $_SERVER['REQUEST_URI'];
$url = $protocol.$server.$uri;
$parseURL= parse_url($url, PHP_URL_PATH);
$uriPath = explode("/", trim($parseURL, "/"));
$path = $uriPath["0"];
return compact("protocol","server","hostname","path");
}
function url(){
$u = getURI();
$itemURL = $u["protocol"].getAuth()."@".$u["server"]."/";//.$v["uid"]."/";
return $itemURL;
}
function listData(){
echo "<div class=\"table-responsive\">
<table id=\"list\" class=\"table table-sm table-hover table-fixed\" cellspacing=\"0\" width=\"100%\">
<thead>
<tr>
<th style=\"width:6rem;\">UID</th>
<th class=\"th-sm\">TITLE</th>
<th class=\"th-sm\">CSV URL</th>
<th class=\"th-sm\">M3U URLs</th>
<th class=\"th-sm\">RSS URLs</th>
</tr>
</thead>
<tbody>"."\n";
$db = new Db($_SERVER["DOCUMENT_ROOT"]."/data/data.json");
$v = $db->get();
$u = getURI();
foreach($v as $v) {
$itemURL = $u["protocol"].getAuth()."@".$u["server"]."/".$v["uid"];
echo "\t\t\t".
"<tr>".
"<td onclick=\"location.href='".$v["uid"]."'\" style=\"cursor:pointer;\">".$v["uid"]."</a></td>".
"<td onclick=\"location.href='".$v["uid"]."'\" style=\"cursor:pointer;\">".$v["title"]."</a></td>".
"<td onclick=\"location.href='".$v["uid"]."'\" style=\"cursor:pointer;\">".$v["csvUrl"]."</a></td>".
"<td onclick=\"location.href='".$v["uid"]."'\" style=\"cursor:pointer;\">".line($v["m3uUrl"])."</a></td>".
"<td onclick=\"location.href='".$v["uid"]."'\" style=\"cursor:pointer;\">".line($v["rssUrl"])."</a></td>".
"</tr>\n";
// echo "\t\t\t".
// "<tr><td colspan=\"5\" class=\"off\" style=\"border: none !important;\">".
// "<ul class=\"nav nav-justified\">".
// "<li class=\"nav-item\"><a href=\"".$itemURL."/csv\" target=\"_blank\"><button type=\"button\" class=\"btn btn-sm white z-depth-0 waves-effect\">CSV</button></a></li>".
// "<li class=\"nav-item\"><a href=\"".$itemURL."/m3u\" target=\"_blank\"><button type=\"button\" class=\"btn btn-sm white z-depth-0 waves-effect\">M3U</button></a></li>".
// "<li class=\"nav-item\"><a href=\"".$itemURL."/rss\" target=\"_blank\"><button type=\"button\" class=\"btn btn-sm white z-depth-0 waves-effect\">RSS</button></a></li>".
// "<li class=\"nav-item\"><a href=\"".$itemURL."/rss/epg\" target=\"_blank\"><button type=\"button\" class=\"btn btn-sm white z-depth-0 waves-effect\">EPG</button></a></li>".
// "<li class=\"nav-item\"><a href=\"".$itemURL."/all\" target=\"_blank\"><button type=\"button\" class=\"btn btn-sm white z-depth-0 waves-effect\">ALL</button></a></li>".
// "</ul>".
// "</td></tr>\n";
// }
echo "\t\t\t".
"<tr class=\"off\"><td colspan=\"5\" class=\"off\" style=\"border: none !important;\">".
"<li class=\"url\"><a href=\"".$itemURL."/csv\" target=\"_blank\"><i class=\"fas fa-file-download\"></i> Download CSV:</a> ".
"<input type=\"text\" class=\"form-control\" value=\"".$itemURL."/csv\"/></li>".
"<li class=\"url\"><a href=\"".$itemURL."/m3u\" target=\"_blank\"><i class=\"fas fa-file-medical-alt\"></i> M3U url:</a> ".
"<input type=\"text\" class=\"form-control\" value=\"".$itemURL."/m3u\"/></li>".
"<li class=\"url\"><a href=\"".$itemURL."/rss\" target=\"_blank\"><i class=\"fas fa-rss\"></i> RSS M3U url:</a> ".
"<input type=\"text\" class=\"form-control\" value=\"".$itemURL."/rss\"/></li>".
"<li class=\"url\"><a href=\"".$itemURL."/rss/epg\" target=\"_blank\"><i class=\"far fa-file-code\"></i> RSS EPG url:</a> ".
"<input type=\"text\" class=\"form-control\" value=\"".$itemURL."/epg\"/></li>".
"<li class=\"url\"><a href=\"".$itemURL."/all\" target=\"_blank\"><i class=\"far fa-copy\"></i> M3U with RSS:</a> ".
"<input type=\"text\" class=\"form-control\" value=\"".$itemURL."/all\"/></li>".
"</td></tr>\n";
}
echo "</tbody>
</table>
</div>
</section>";
}
function gitPull(){
require("app/vars.php");
include("src/header.php");
// if (!is_dir(".git")) { }
$gitURL = "https://github.com/spencerthayer/ezIPTV";
$outputDir = exec("rm -rf .git");
$outputInit = exec("git init");
$outputAdd = exec("git remote add origin ".$gitURL.";");
$outputPull = exec("git fetch --all;git reset --hard origin/master;");
echo $root;
echo "<p><pre>".$outputDir."</pre></p>";
echo "<p><pre>".$outputInit."</pre></p>";
echo "<p><pre>".$outputAdd."</pre></p>";
echo "<p><pre>".$outputPull."</pre></p>";
echo "<p><a href=\"/\">RETURN TO APPLICATION</a></p>";
// header("location: /");
include("src/footer.php");
}
function getGitBranch() {
echo "<!-- ".exec("git branch -vv")." -->"."\n";
// $gitBasePath = '.git';
// $gitStr = file_get_contents($gitBasePath.'/HEAD');
// $gitBranchName = rtrim(preg_replace("/(.*?\/){2}/", '', $gitStr));
// $gitPathBranch = $gitBasePath.'/refs/heads/'.$gitBranchName;
// $gitHash = file_get_contents($gitPathBranch);
// $gitDate = date(DATE_ATOM, filemtime($gitPathBranch));
// "version date: ".$gitDate."\n".
// "branch: ".$gitBranchName."\n".
// "commit: ".$gitHash."\n".
}
?>