163 lines
5.7 KiB
PHP
Executable File
163 lines
5.7 KiB
PHP
Executable File
<?php
|
|
$cookieParams = session_get_cookie_params();
|
|
$cookieParams['samesite'] = "Lax";
|
|
session_set_cookie_params($cookieParams);
|
|
session_start();
|
|
|
|
if (!empty($_SESSION["kod"]) && !empty($_SESSION['listeners']) && !empty($_SESSION['inicialy']))
|
|
{
|
|
$kod = $_SESSION['kod'];
|
|
$fol = 'streamy/' . $kod . '/';
|
|
$connsa = $fol . 'people.json';
|
|
|
|
if (file_exists($connsa))
|
|
{
|
|
$connections = json_decode(file_get_contents($connsa), true);
|
|
foreach($connections as $key => $value) {
|
|
if((time() - $value['timestamp']) > 300){
|
|
unset($connections[$key]);
|
|
}
|
|
}
|
|
file_put_contents($connsa, json_encode($connections));
|
|
}
|
|
}
|
|
|
|
if (!empty($_GET['logout']))
|
|
{
|
|
$connections = json_decode(file_get_contents($connsa), true);
|
|
unset($connections[session_id()]);
|
|
file_put_contents($connsa, json_encode($connections));
|
|
$_SESSION["kod"] = '';
|
|
$_SESSION["listeners"] = '';
|
|
$_SESSION['inicialy'] = '';
|
|
session_destroy();
|
|
session_unset();
|
|
setcookie("inicialy", "", 1);
|
|
echo '
|
|
<script>
|
|
window.location.href = "index.php";
|
|
</script>
|
|
';
|
|
}
|
|
elseif (!empty($_GET['verify'])&&!empty($_POST['kod'])){
|
|
if ($_GET['verify'] == 1){
|
|
$fol = 'streamy/' . $_POST['kod'] . '/';
|
|
$configa = $fol . 'config.json';
|
|
if (file_exists($configa))
|
|
{
|
|
echo "verified";
|
|
}
|
|
else{
|
|
echo "unverified";
|
|
}
|
|
}
|
|
}
|
|
elseif (!empty($_GET['keepalive'])){
|
|
$connections = json_decode(file_get_contents($connsa), true);
|
|
$connections[session_id()]["timestamp"] = time();
|
|
$connections[session_id()]["dateping"] = date("Y.n.d H:i:s");
|
|
file_put_contents($connsa, json_encode($connections));
|
|
}
|
|
elseif (!empty($_GET['chat'])){
|
|
if (!empty($_SESSION["kod"]) && !empty($_SESSION['listeners']) && !empty($_SESSION['inicialy']))
|
|
{
|
|
$kod = $_SESSION['kod'];
|
|
$fol = 'streamy/' . $kod . '/';
|
|
$chata = $fol . 'chat.txt';
|
|
|
|
if (file_exists($chata))
|
|
{
|
|
if (!empty($_GET['send'])){
|
|
$data = '• ' . $_SESSION['inicialy'] . ':' . $_POST['text'] . "\n";
|
|
file_put_contents($chata, $data, FILE_APPEND);
|
|
}
|
|
else{
|
|
echo file_get_contents($chata);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!empty($_POST['kod']) && !empty($_POST['listeners']) && !empty($_POST['ini'])){
|
|
|
|
$fol = 'streamy/' . $_POST['kod'] . '/';
|
|
$configa = $fol . 'config.json';
|
|
$ida = $fol . 'id.txt';
|
|
$connsa = $fol . 'people.json';
|
|
if (file_exists($configa))
|
|
{
|
|
$jsonobj = file_get_contents($configa);
|
|
$config = json_decode($jsonobj, false);
|
|
|
|
$inicialy = str_replace($config->adminpwd, "admin", $_POST['ini']);
|
|
|
|
$_SESSION["kod"] = $_POST['kod'];
|
|
$_SESSION['listeners'] = $_POST['listeners'];
|
|
$_SESSION["inicialyOriginal"] = $_POST['ini'];
|
|
$_SESSION['inicialy'] = $inicialy;
|
|
setcookie("inicialy", $inicialy);
|
|
|
|
$connections = json_decode(file_get_contents($connsa), true);
|
|
$temparray = array("dateping"=>date("Y.n.d H:i:s"), "date"=>date("Y.n.d H:i:s"), "timestamp"=>time(), "listeners"=>$_SESSION['listeners'], "inicialy"=>$_SESSION['inicialy'], "ip"=>$_SERVER["REMOTE_ADDR"]);
|
|
$connections[session_id()] = $temparray;
|
|
file_put_contents($connsa, json_encode($connections));
|
|
|
|
$data = 'OK: ' . date("Y.n.d H:i:s") . "," . $_POST['listeners'] . "," . $inicialy . "," . $_SERVER['REMOTE_ADDR'] . "\n";
|
|
file_put_contents($fol . 'log.txt', $data, FILE_APPEND);
|
|
echo '
|
|
<script>
|
|
location.reload();
|
|
</script>
|
|
';
|
|
}
|
|
else
|
|
{
|
|
$data = 'ERR: ' . date("Y.n.d H:i:s") . "," . $_POST['listeners'] . "," . $_POST['ini'] . "," . $_SERVER['REMOTE_ADDR'] . "\n";
|
|
file_put_contents($fol . 'log.txt', $data, FILE_APPEND);
|
|
$_SESSION["kod"] = '';
|
|
$_SESSION['listeners'] = '';
|
|
$_SESSION['inicialy'] = '';
|
|
$_SESSION["id"] = 0;
|
|
echo '
|
|
<script>
|
|
location.reload();
|
|
</script>
|
|
';
|
|
session_destroy();
|
|
}
|
|
}
|
|
elseif (!empty($_SESSION['listeners']) && !empty($_SESSION['inicialy']) && !empty($_SESSION['kod'])){
|
|
$fol = 'streamy/' . $_SESSION['kod'] . '/';
|
|
$configa = $fol . 'config.json';
|
|
$ida = $fol . 'id.txt';
|
|
if (file_exists($configa))
|
|
{
|
|
$jsonobj = file_get_contents($configa);
|
|
$config = json_decode($jsonobj, false);
|
|
|
|
$kod = $_SESSION['kod'];
|
|
$fol = 'streamy/' . $kod . '/';
|
|
|
|
$url = $config->url;
|
|
$type = $config->type;
|
|
$year = date("Y");
|
|
|
|
$player = file_get_contents("templates/player.html");
|
|
$player = str_replace('__VLOZ_URL_AUDIA__', $url , $player);
|
|
$player = str_replace('__VLOZ_TYP_AUDIA__', $type , $player);
|
|
$player = str_replace('__VLOZ_ROK__', $year, $player);
|
|
if($_SESSION["inicialyOriginal"] == $config->adminpwd){
|
|
$player = str_replace('__VLOZ_ADMIN_LINK__', '<a href="admin.php">Administrácia</a>', $player);
|
|
}
|
|
else{
|
|
$player = str_replace('__VLOZ_ADMIN_LINK__', "" , $player);
|
|
}
|
|
echo($player);
|
|
}
|
|
}
|
|
else{
|
|
echo str_replace("__VLOZ_ROK__", date("Y"), file_get_contents("templates/login.html"));
|
|
}
|
|
}
|
|
?>
|