-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStreamer.php
More file actions
194 lines (164 loc) · 5.05 KB
/
Copy pathStreamer.php
File metadata and controls
194 lines (164 loc) · 5.05 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
<?php
require_once dirname(__FILE__) . '/Configuration.php';
class Streamer extends ObjectYPT {
protected $id, $siteURL, $user, $pass, $priority, $isAdmin, $created, $modified;
static function getSearchFieldsNames() {
return array('siteURL');
}
static function getTableName() {
return 'streamers';
}
private static function get($user, $siteURL) {
global $global;
$sql = "SELECT * FROM " . static::getTableName() . " WHERE user = '{$user}' AND lower(siteURL) = lower('{$siteURL}') LIMIT 1";
//echo $sql;exit;
$res = $global['mysqli']->query($sql);
if ($res) {
return $res->fetch_assoc();
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return false;
}
private static function getFirst() {
global $global;
$sql = "SELECT * FROM " . static::getTableName() . " LIMIT 1";
$res = $global['mysqli']->query($sql);
if ($res) {
return $res->fetch_assoc();
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return false;
}
static function getFirstURL() {
$row = static::getFirst();
return $row['siteURL'];
}
static function createIfNotExists($user, $pass, $siteURL, $encodedPass = false) {
if (!$encodedPass || $encodedPass === 'false') {
$pass = md5($pass);
}
if (substr($siteURL, -1) !== '/') {
$siteURL .= "/";
}
if ($row = static::get($user, $siteURL)) {
if (!empty($row['id'])) {
return $row['id'];
}
}
if (static::isURLAllowed($siteURL)) {
$config = new Configuration();
$s = new Streamer('');
$s->setUser($user);
$s->setPass($pass);
$s->setSiteURL($siteURL);
$s->setIsAdmin(0);
$s->setPriority($config->getDefaultPriority());
return $s->save();
} else {
return false;
}
}
function verify(){
$url = $this->getSiteURL();
$cacheFile = "/tmp/".md5($url)."_verify.log";
$lifetime = 3600;//1 hour
error_log("Verification Start {$url}");
$verifyURL = "";
if(!file_exists($cacheFile) || (((time() - $lifetime) <= filemtime($cacheFile)))){
error_log("Verification Creating the Cache {$url}");
$verifyURL = "https://search.youphptube.com/verify.php?url=". urlencode($url);
$result = url_get_contents($verifyURL);
file_put_contents($cacheFile, $result);
}else{
error_log("Verification GetFrom Cache {$url}");
$result = file_get_contents($cacheFile);
}
error_log("Verification Response ($verifyURL): {$result}");
return json_decode($result);
}
static function isURLAllowed($siteURL) {
if (substr($siteURL, -1) !== '/') {
$siteURL .= "/";
}
$config = new Configuration();
$urls = $config->getAllowedStreamersURL();
if (empty($urls)) {
return true;
}
$allowed = explode(PHP_EOL, $urls);
$return = false;
if (empty($allowed)) {
$return = true;
} else {
foreach ($allowed as $value) {
if (empty($value)) {
continue;
}
$value = trim($value);
if (substr($value, -1) !== '/') {
$value .= "/";
}
//var_dump($siteURL,$value);
error_log("$siteURL == $value");
if ($siteURL == $value) {
$return = true;
break;
}
}
}
return $return;
}
function getId() {
return $this->id;
}
function getSiteURL() {
return $this->siteURL;
}
function getUser() {
return $this->user;
}
function getPass() {
return $this->pass;
}
function getCreated() {
return $this->created;
}
function getModified() {
return $this->modified;
}
function setId($id) {
$this->id = $id;
}
function setSiteURL($siteURL) {
if (!empty($siteURL) && substr($siteURL, -1) !== '/') {
$siteURL .= "/";
}
$this->siteURL = $siteURL;
}
function setUser($user) {
$this->user = $user;
}
function setPass($pass) {
$this->pass = $pass;
}
function setCreated($created) {
$this->created = $created;
}
function setModified($modified) {
$this->modified = $modified;
}
function getPriority() {
return $this->priority;
}
function setPriority($priority) {
$this->priority = $priority;
}
function getIsAdmin() {
return $this->isAdmin;
}
function setIsAdmin($isAdmin) {
$this->isAdmin = $isAdmin;
}
}