-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathAPI.php
More file actions
99 lines (89 loc) · 2.89 KB
/
Copy pathAPI.php
File metadata and controls
99 lines (89 loc) · 2.89 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
<?php
require_once __DIR__ . '/../objects/Login.php';
require_once __DIR__ . '/../objects/Encoder.php';
require_once __DIR__ . '/../objects/Streamer.php';
require_once __DIR__ . '/../objects/functions.php';
class API
{
static function checkCredentials()
{
$object = new stdClass();
$object->error = true;
$object->msg = '';
$object->login = new stdClass();
$object->login->user = @$_REQUEST['user'];
$object->login->siteURL = @$_REQUEST['siteURL'];
if (empty($object->login->user) || empty($_REQUEST['pass'])) {
$object->msg = 'User and Password can not be blank';
die(json_encode($object));
}
if (!Streamer::isURLAllowed($object->login->siteURL)) {
$object->msg = 'This streamer site is not allowed';
die(json_encode($object));
}
error_log('login.json: Login::run');
$loginResult = Login::run($object->login->user, $_REQUEST['pass'], $object->login->siteURL, @$_REQUEST['encodedPass']);
if ($loginResult === false) {
$object->msg = 'Your site is banned';
die(json_encode($object));
}
if (!empty($_SESSION['login'])) {
$object->login->streamers_id = intval($_SESSION['login']->streamers_id);
} else {
$object->msg = 'Unable to verify/login to streamer site';
die(json_encode($object));
}
return $object;
}
static function canChangeQueue($queue_id)
{
if (empty($_SESSION['login'])) {
return false;
}
$streamer = new Streamer($_SESSION['login']->streamers_id);
if (self::isAdmin()) {
return true;
}
$encoder = new Encoder($queue_id);
return $encoder->getStreamers_id() == $_SESSION['login']->streamers_id;
}
static function isAdmin()
{
if (empty($_SESSION['login'])) {
return false;
}
$streamer = new Streamer($_SESSION['login']->streamers_id);
return !empty($streamer->getIsAdmin());
}
static function cleanQueueArray($queue)
{
// Convert object to array if necessary
if (is_object($queue)) {
$queue = (array)$queue;
}
// Set videos_id
if (isset($queue['return_vars']->videos_id)) {
$queue['videos_id'] = $queue['return_vars']->videos_id;
}
$keep = array(
'id',
'created',
'modified',
'videos_id',
'priority',
'videoDownloadedLink',
'downloadedFileName',
'streamers_id',
'conversion',
'download',
'title',
);
// Clean the queue
foreach ($queue as $key => $value) {
if (!in_array($key, $keep)) {
unset($queue[$key]);
}
}
return $queue;
}
}