-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpodcasts.php
More file actions
116 lines (102 loc) · 2.58 KB
/
podcasts.php
File metadata and controls
116 lines (102 loc) · 2.58 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
<?php // -*- php -*-
function get_tags() {
$tags = array();
$dh = opendir(".");
while (($tag = readdir($dh)) !== false) {
if (substr($tag, -4) != ".tag")
continue;
if (substr($tag, 0, 1) == ".")
continue;
$id = substr($tag, 0, -4);
if (!file_exists($id . ".mp3"))
continue;
$tags[] = $tag;
}
closedir($dh);
return $tags;
}
$fh = fopen("../podcasts.cfg", "r");
if (!$fh) {
trigger_error("open failed in |" . getcwd() . "|");
exit;
}
$dir = trim(fgets($fh));
$pass = trim(fgets($fh));
fclose($fh);
if (!chdir($dir)) {
trigger_error("chdir '$dir' failed in |" . getcwd() . "|");
exit;
}
// Don't require a password for 'polled' so pod-poll doesn't need it
if (isset($_GET["polled"])) {
header("Content-type: text/plain");
echo count(get_tags()), " ", file_get_contents("polled");
exit;
}
// Password check.
if (!isset($_GET["p"])) {
trigger_error("Access denied");
exit;
}
if ($_GET["p"] != $pass) {
trigger_error("Access denied: |" . $_GET["p"] . "|");
exit;
}
if (isset($_GET["get"])) {
$id = $_GET["get"];
if (strstr($id, "/") !== false) {
trigger_error("Invalid ID '$id'");
exit;
}
$file = $id . ".mp3";
if (!file_exists($file)) {
trigger_error("File does not exist '$file'");
exit;
}
header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . basename($file));
header("Content-Transfer-Encoding: binary");
header("Expires: 0");
header("Cache-Control: must-revalidate");
header("Pragma: public");
header("Content-Length: " . filesize($file));
readfile($file);
exit;
}
if (isset($_GET["rm"])) {
$id = $_GET["rm"];
if (strstr($id, "/") !== false) {
trigger_error("Invalid ID '$id'");
exit;
}
unlink($id . ".mp3");
unlink($id . ".tag");
header("Content-type: text/plain");
echo "OK\n";
exit;
}
$dh = opendir(".");
if (!$dh) {
trigger_error("opendir failed");
exit;
}
$tags = get_tags();
// remaining seconds
if (isset($_GET["r"]))
file_put_contents("polled", $_GET["r"] . " OK\n");
$since = false;
if (isset($_GET["s"]))
$since = $_GET["s"];
header("Content-type: text/plain");
$newest = -1;
foreach ($tags as $tag) {
$mtime = filemtime($tag);
$newest = max($newest, $mtime);
if ($since === false || $mtime > $since) {
readfile($tag);
echo "\n";
}
}
echo "OK\t$newest\n";
?>