This repository has been archived by the owner on Jan 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrest-listing.php
executable file
·156 lines (136 loc) · 4.65 KB
/
rest-listing.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* This is a soap endpoint for MiddMedia
*
* @package middmedia
*
* @copyright Copyright © 2005, Middlebury College
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
*
* @version $Id$
*/
/*********************************************************
* Setup stuff.
*********************************************************/
define("MYDIR",dirname(__FILE__));
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
$protocol = 'https';
else
$protocol = 'http';
define("MYPATH", $protocol."://".$_SERVER['HTTP_HOST'].str_replace(
"\\", "/",
dirname($_SERVER['PHP_SELF'])));
define("MYURL", MYPATH."/index.php");
require_once(dirname(__FILE__)."/main/include/libraries.inc.php");
require_once(dirname(__FILE__)."/main/include/setup.inc.php");
/*********************************************************
* Authentication
*********************************************************/
if (!isset($_SERVER['PHP_AUTH_USER']) || !$_SERVER['PHP_AUTH_USER'] || (isset($_SESSION['LastLoginTokens'])
&& md5($_SERVER['PHP_AUTH_USER'].$_SERVER['PHP_AUTH_PW'])
!= $_SESSION['LastLoginTokens']))
{
header("WWW-Authenticate: Basic realm=\"MiddMedia\"");
header('HTTP/1.0 401 Unauthorized');
print "Please Authenticate.";
exit;
}
$_SESSION['LastLoginTokens'] = md5($_SERVER['PHP_AUTH_USER'].$_SERVER['PHP_AUTH_PW']);
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
/*********************************************************
* Below here is just example stuff. Change to be implementation.
*********************************************************/
header('Content-Type: text/xml');
print "<response>";
try {
// Create a new manager for a username/password combo (username/shared key not yet implemented)
$manager = MiddMedia_Manager::forUsernamePassword($user, $pass);
// Get the personal directory
try {
$dir = $manager->getPersonalDirectory();
print "\n\t<directory
name=\"".$dir->getBaseName()."\"
rtmp_url=\"".$dir->getRtmpUrl()."\"
bytes_used=\"".$dir->getBytesUsed()."\"
bytes_available=\"".$dir->getBytesAvailable()."\"
type=\"personal\">";
foreach ($dir->getFiles() as $file) {
$primaryFormat = $file->getPrimaryFormat();
if ($primaryFormat->supportsHttp())
$httpUrl = $primaryFormat->getHttpUrl();
else
$httpUrl = '';
if ($primaryFormat->supportsRtmp())
$rtmpUrl = $primaryFormat->getRtmpUrl();
else
$rtmpUrl = '';
print "\n\t\t<file
name=\"".$file->getBaseName()."\"
http_url=\"".$httpUrl."\"
rtmp_url=\"".$rtmpUrl."\"
mime_type=\"".$primaryFormat->getMimeType()."\"
size=\"".$primaryFormat->getSize()."\"
modification_date=\"".$file->getModificationDate()->asString()."\"";
try {
print "\n\t\t\tcreator_name=\"".$file->getCreator()->getDisplayName()."\"";
} catch (OperationFailedException $e) {
} catch (UnimplementedException $e) {
}
// As an example, lets include the content of text-files.
if ($file->getMimeType() == 'text/plain') {
print "><![CDATA[";
print $file->getContents();
print "]]></file>";
} else {
print "/>";
}
}
print "\n\t</directory>";
} catch (PermissionDeniedException $e) {
}
// Get the shared directories
foreach ($manager->getSharedDirectories() as $dir) {
print "\n\t<directory
name=\"".$dir->getBaseName()."\"
rtmp_url=\"".$dir->getRtmpUrl()."\"
bytes_used=\"".$dir->getBytesUsed()."\"
bytes_available=\"".$dir->getBytesAvailable()."\"
type=\"shared\">";
foreach ($dir->getFiles() as $file) {
$primaryFormat = $file->getPrimaryFormat();
if ($primaryFormat->supportsHttp())
$httpUrl = $primaryFormat->getHttpUrl();
else
$httpUrl = '';
if ($primaryFormat->supportsRtmp())
$rtmpUrl = $primaryFormat->getRtmpUrl();
else
$rtmpUrl = '';
print "\n\t\t<file
name=\"".$file->getBaseName()."\"
http_url=\"".$httpUrl."\"
rtmp_url=\"".$rtmpUrl."\"
mime_type=\"".$primaryFormat->getMimeType()."\"
size=\"".$primaryFormat->getSize()."\"
modification_date=\"".$file->getModificationDate()->asString()."\"";
try {
print "\n\t\t\tcreator_name=\"".$file->getCreator()->getDisplayName()."\"";
} catch (OperationFailedException $e) {
} catch (UnimplementedException $e) {
}
// As an example, lets include the content of text-files.
if ($file->getMimeType() == 'text/plain') {
print "><![CDATA[";
print $file->getContents();
print "]]></file>";
} else {
print "/>";
}
}
print "\n\t</directory>";
}
} catch (Exception $e) {
print "\n\t<error type='".get_class($e)."'><![CDATA[".$e->getMessage()."]]></error>";
}
print "\n</response>";