This commit is contained in:
2023-01-28 20:14:55 +01:00
commit ff5ba6fe94
14 changed files with 653 additions and 0 deletions

4
.gitignore vendored Normal file

@ -0,0 +1,4 @@
secrets/*
!secrets/.htaccess
streamy/*
!streamy/.htaccess

115
admin.php Executable file

@ -0,0 +1,115 @@
<?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($_SESSION["kod"]) && !empty($_SESSION['listeners']) && !empty($_SESSION["inicialyOriginal"]))
{
$kod = $_SESSION['kod'];
$fol = 'streamy/' . $kod . '/';
$chata = $fol . 'chat.txt';
$configa = $fol . 'config.json';
$jsonobj = file_get_contents($configa);
$config = json_decode($jsonobj, false);
if (file_exists($chata) && $_SESSION["inicialyOriginal"] == $config->adminpwd)
{
if (!empty($_GET["onlyconns"])){
if (!empty($_SESSION["kod"]) && !empty($_SESSION['listeners']) && !empty($_SESSION['inicialy']))
{
$connsa = $fol . 'people.json';
if (file_exists($connsa))
{
$connections = json_decode(file_get_contents($connsa), true);
$connadm = '
<table style="width:100%">
<tr><th>Iniciály</th><th>Počúvajúci</th><th>Dátum a čas pripojenia</th><th>Dátum a čas keepalive</th><th>IP adresa</th></tr>
';
foreach($connections as $key => $value) {
$connadm = $connadm . '<tr><td>' . $value["inicialy"] . '</td>' . '<td>' . $value["listeners"] . '</td>' . '<td>' . $value["date"] . '</td>' . '<td>' . $value["dateping"] . '</td>' . '<td>' . $value["ip"] . '</td></tr>';
}
$connadm = $connadm . '</table>';
echo $connadm;
}
}
}
else{
$cnt = 1;
$chatdat = explode("\n", file_get_contents($chata));
if (!empty($_GET['delete'])&&!empty($_POST['delete'])){
if($_POST['delete'] == "*"){
file_put_contents($chata, "");
}
else{
$chatxx = "";
array_splice($chatdat, $_POST['delete']-1, 1);
foreach($chatdat as $line){
if ($line != ""){
$chatxx = $chatxx . $line . "\n";
}
}
file_put_contents($chata, $chatxx);
$chatdat = explode("\n", file_get_contents($chata));
}
}
else{
$chatadm = '
<table style="width:100%">
';
foreach($chatdat as $line){
if ($cnt < sizeof($chatdat)){
$chatadm = $chatadm . '<tr><td>' . $line . '</td><td><button onclick="deleteit('.$cnt.')">Zmazať</button></td></tr>';
}
$cnt++;
}
$chatadm = $chatadm . '</table>';
if (!empty($_GET['onlytable'])){
echo $chatadm;
}
else{
$dats = file_get_contents("templates/admin.html");
$dats = str_replace('__VLOZ_CHAT_ADMIN_TABULKU__', $chatadm , $dats);
$dats = str_replace('__VLOZ_URL_AUDIA__', $config->url , $dats);
$dats = str_replace('__VLOZ_TYP_AUDIA__', $config->type , $dats);
$dats = str_replace('__VLOZ_ROK__', date("Y"), $dats);
echo $dats;
}
}
}
}
else {
echo '
<script>
window.location.href = "index.php";
</script>
';
}
}
else {
echo '
<script>
window.location.href = "index.php";
</script>
';
}
?>

2
assets/jquery.js vendored Executable file

File diff suppressed because one or more lines are too long

5
assets/pico.css Executable file

File diff suppressed because one or more lines are too long

BIN
favicon.ico Normal file

Binary file not shown.

After

Width: 64px  |  Height: 64px  |  Size: 13 KiB

163
index.php Executable file

@ -0,0 +1,163 @@
<?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"));
}
}
?>

1
secrets/.htaccess Executable file

@ -0,0 +1 @@
Deny from all

35
streamadd.php Executable file

@ -0,0 +1,35 @@
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$heslo = trim($_POST['heslo']);
if (password_verify($heslo, file_get_contents("secrets/AdminPwdHash"))) {
$kod = $_POST['kod'];
$url = $_POST['url'];
$type = $_POST['type'];
$adminpwd = $_POST['adminpwd'];
$fol = 'streamy/' . $kod . '/';
$address1 = $fol . 'config.json';
$address2 = $fol . 'chat.txt';
$address3 = $fol . 'people.json';
$address4 = $fol . 'id.txt';
if (file_exists($address1)) {
echo ("Stream existuje!");
} else {
mkdir($fol);
$myObj = array(
"url" => $url,
"type" => $type,
"adminpwd" => $adminpwd
);
$myJson = json_encode($myObj);
file_put_contents($address1, $myJson);
file_put_contents($address2, '');
file_put_contents($address3, "{}");
file_put_contents($address4, "1");
echo "Stream pridaný";
}
} else {
echo "Zlé heslo.";
}
}
echo str_replace("__VLOZ_ROK__", date("Y"), file_get_contents("templates/streamadd.html"));
?>

1
streamy/.htaccess Executable file

@ -0,0 +1 @@
Deny from all

1
templates/.htaccess Executable file

@ -0,0 +1 @@
Require all denied

97
templates/admin.html Executable file

@ -0,0 +1,97 @@
<!DOCTYPE html>
<html>
<head>
<script src=assets/jquery.js> </script>
<script>
function deleteit(indexik){
$.post("admin.php?delete=1",
{
delete: indexik
},
function(data, status){
updateTable();
});
}
$(function() {
function Ping() {
$.get("index.php?keepalive=1", function(data, status){
});
}
Ping();
setInterval(function(){ Ping(); }, 60000);
function updateTable(){
$.get("admin.php?onlytable=1", function(data, status){
$("#chattablicka").html(data);
});
}
setInterval(updateTable, 5000);
updateTable();
function updateConns(){
$.get("admin.php?onlyconns=1", function(data, status){
$("#connections").html(data);
});
}
setInterval(updateConns, 30000);
updateConns();
$("#send").click(function(){
data = $("#ins").val();
if(data != ""){
$.post("index.php?chat=1&send=1",
{
text: data
},
function(data2, status){
});
}
$("#ins").val("");
});
$("#ins").keyup(function(event) {
if (event.keyCode === 13) {
$("#send").click();
}
});
});
</script>
<meta charset="UTF-8">
<link rel="stylesheet" href="assets/pico.css">
<title>Administrácia</title>
<style>
table, th, td {
border: 2px solid;
border-collapse: collapse;
}
.headingac {
font-size: 64px;
}
</style>
</head>
<body>
<p class="headingac">Vysielanie</p>
<audio controls src="__VLOZ_URL_AUDIA__" id="audioplayer" type="__VLOZ_TYP_AUDIA__" preload="none"></audio>
<br>
<a href="index.php?logout=1">
<p>Odhlásiť sa</p>
</a>
<a href="__VLOZ_URL_AUDIA__.m3u" download target="_blank">
<p>Playlist na stiahnutie</p>
</a>
<a href="index.php">
<p>Obyčajný prehrávač</p>
</a>
<p class="headingac">Pripojenia:</p>
<div id="connections"></div>
<br>
<p class="headingac">Chat admin:</p>
<button onclick="deleteit('*')">Zmazať všetko</button>
<br>
<div id="chattablicka"></div><br>
<input id="ins"></input>
<button id="send">Odoslať</button>
<br>
<p>© BRN Systems __VLOZ_ROK__</p>
</body>
</html>

107
templates/login.html Executable file

@ -0,0 +1,107 @@
<!DOCTYPE html>
<html>
<head>
<title>Prihlásenie</title>
<link rel="stylesheet" href="assets/pico.css">
<meta charset="utf-8">
</meta>
<script src="assets/jquery.js"></script>
<style>
#error{
display: none;
color: #CC0000;
position: absolute;
top: 0;
right: 50%;
}
</style>
<script>
$(function() {
$("#kod").focus();
var kod = "";
var inic = "";
var listeners = "";
$("#next").click(function() {
$("#error").hide();
kod = $("#kod").val();
$.post("index.php?verify=1",
{
kod: kod
},
function(data, status){
if (data == "verified"){
$("#firstQuestion").fadeOut("slow", function(){
$("#secondQuestion").fadeIn("slow", function(){
$("#ini").focus();
});
});
}
else{
$("#error").fadeIn();
}
});
});
$("#back").click(function() {
$("#secondQuestion").fadeOut("slow", function(){
$("#firstQuestion").fadeIn("slow", function(){
$("#kod").focus();
});
});
});
$("#send").click(function() {
inic = $("#ini").val();
listeners = $("#listeners").val();
$.post("index.php",
{
kod: kod,
listeners: listeners,
ini: inic
},
function(data, status){
location.reload();
});
});
$("#kod").keyup(function(event) {
if (event.keyCode === 13) {
$("#next").click();
}
});
$("#ini").keyup(function(event) {
if (event.keyCode === 13) {
$("#listeners").focus();
}
});
$("#listeners").keyup(function(event) {
if (event.keyCode === 13) {
$("#send").click();
}
});
});
</script>
</head>
<body>
<form method="post">
<div id="firstQuestion">
<p id="error">Zlý kód</p>
<label id="kodik" for="kod">Kód:<br></label>
<input type="text" id="kod" placeholder="Kód" name="kod" required>
<br>
<button id="next" type="button">Ďalej</button>
<br>
<p>© BRN Systems __VLOZ_ROK__</p>
</div>
<div id="secondQuestion" style="display: none;">
<label for="ini">Iniciály:<br></label>
<input type="text" id="ini" placeholder="Iniciály" name="ini" required autofocus>
<br>
<label for="listeners">Počet počúvajúcich:<br></label>
<input type="text" id="listeners" placeholder="Počet počúvajúcich" name="listeners" required>
<br>
<button id="send" type="button">Prihlásiť sa</button><button id="back" type="button">Späť</button>
<br>
<p>© BRN Systems __VLOZ_ROK__</p>
</div>
</form>
</body>
</html>

91
templates/player.html Executable file

@ -0,0 +1,91 @@
<!DOCTYPE html>
<html>
<head>
<script src=assets/jquery.js> </script>
<meta charset="UTF-8">
<link rel="stylesheet" href="assets/pico.css">
<title>Vysielanie</title>
<script>
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
$(document).ready(function(){
function Getc() {
$.get("index.php?chat=1", function(data, status){
$("#chatbox").val(data);
});
}
Getc();
setInterval(function(){ Getc(); }, 5000);
function Ping() {
$.get("index.php?keepalive=1", function(data, status){
});
}
Ping();
setInterval(function(){ Ping(); }, 60000);
$("#send").click(function(){
data = $("#ins").val();
Getc();
if(data != ""){
$.post("index.php?chat=1&send=1",
{
text: data
},
function(data2, status){
var chatmsgs = $("#chatbox").val();
chatmsgs = chatmsgs + '• ' + getCookie("inicialy") + ':' + data + "\n";
$("#chatbox").val(chatmsgs);
});
}
$("#ins").val("");
});
$("#ins").keyup(function(event) {
if (event.keyCode === 13) {
$("#send").click();
}
});
});
</script>
<style>
.headingac {
font-size: 64px;
}
</style>
</head>
<body>
<p class="headingac">Vysielanie</p>
<audio controls src="__VLOZ_URL_AUDIA__" id="audioplayer" type="__VLOZ_TYP_AUDIA__" preload="none"></audio>
<br>
<a href="index.php?logout=1">
<p>Odhlásiť sa</p>
</a>
<a href="__VLOZ_URL_AUDIA__.m3u" download target="_blank">
<p>Playlist na stiahnutie</p>
</a>
__VLOZ_ADMIN_LINK__
<div id="chat">
<textarea rows=5 id="chatbox" readonly></textarea><br>
<input id="ins"></input>
<button id="send">Odoslať</button>
</div>
<p>© BRN Systems __VLOZ_ROK__</p>
</body>
</html>

31
templates/streamadd.html Executable file

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<script src=assets/jquery.js> </script>
<meta charset="UTF-8">
<link rel="stylesheet" href="assets/pico.css">
<title>Pridanie streamu</title>
<body>
<form method="post">
Kód:<br>
<input type="text" name="kod">
<br>
Adresa zvuku:<br>
<input type="text" name="url">
<br>
Typ zvuku:<br>
<input type="radio" name="type" value="audio/mpeg">mp3
<input type="radio" name="type" value="audio/ogg">ogg
<br>
<br>
Administračné heslo streamu:<br>
<input type="text" name="adminpwd">
Heslo prevádzkovateľa:<br>
<input type="text" name="heslo">
<br>
<input type="submit" value="pridať">
<br>
<p>© BRN Systems __VLOZ_ROK__</p>
</form>
</body>
</html>