summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2023-05-16 13:36:25 +0200
committerErich Eckner <git@eckner.net>2023-05-16 14:35:19 +0200
commit906e3c854f8d0a51a1892d571ce0d5606174eaed (patch)
treedf3b723c06919ccb084e574a311341d48fa3058e
parent8c939429bad4f1b73fc9e74a0f5f77a20f5a3db9 (diff)
downloadmocp-web-906e3c854f8d0a51a1892d571ce0d5606174eaed.tar.xz
geht jetzt, laggt aber noch ein bisschen
-rw-r--r--index.php111
1 files changed, 94 insertions, 17 deletions
diff --git a/index.php b/index.php
index 5d4e1f3..bf7ddb6 100644
--- a/index.php
+++ b/index.php
@@ -1,26 +1,81 @@
<?php
-if (!array_key_exists('what',$_GET)) {
+$privKey = "f1869e6cb93500215f5e1ef1fe552dbc76d036088b56c45b1bc32c54211f1c88f4429e138684b0c1a270fd71d3808d77771e0dbb90a0318eaf27d3747cd57f04";
+$pubKey = "f4429e138684b0c1a270fd71d3808d77771e0dbb90a0318eaf27d3747cd57f04";
+
+function client_identifier() {
+ return $_SERVER['SERVER_ADDR'] . " " . $_SERVER['REMOTE_ADDR'];
+}
+
+function zugriff_erlaubt() {
+ global $pubKey;
+ if ((preg_match("/^192\.168\.[01]\.3$/", $_SERVER["REMOTE_ADDR"]) == 1))
+ return true;
+ if (array_key_exists('key',$_GET)) {
+ $pubKey = hex2bin($pubKey);
+ return sodium_crypto_sign_open(hex2bin($_GET["key"]), $pubKey) == client_identifier();
+ }
+ return false;
+}
+
+function attach_key($delimiter = '&') {
+ if (!array_key_exists('key', $_GET))
+ return;
+ print $delimiter . 'key=' . $_GET['key'];
+}
+
+if (!zugriff_erlaubt()) {
?>
<html>
+<head>
+ <script src="/encrypt_key.js"></script>
+ <script>
+ window.sodium = {
+ onload: function (sodium) {
+ var sodium = sodium;
+ }
+ };
+ function update_key(form) {
+ privateKey = "<?php echo $privKey; ?>";
+ privateKey = encrypt_private_key(form.password.value, privateKey);
+ privateKey = sodium.from_hex(privateKey);
+ let msg = sodium.crypto_sign("<?php print client_identifier(); ?>", privateKey);
+ form.key.value = sodium.to_hex(msg);
+ }
+ </script>
+ <script src="/sodium.js" async></script>
+</head>
<body>
- <a href="?what=all">all info</a><br>
- <a href="?what=pause">pause</a><br>
- <a href="lists.php">lists</a><br>
+<form action="" id="form" method="get">
+Passwort: <input type="password" id="password" onchange="update_key(this.form);">
+<input type="hidden" name="key" id="key">
+<input type="submit" value="weiter"">
+</form>
</body>
</html>
<?php
die();
}
+$commands['stop'] = 'mocp -M ~musix/.moc -s';
+$commands['play'] = 'mocp -M ~musix/.moc -p';
+$commands['pause'] = 'mocp -M ~musix/.moc -G';
+$commands['next'] = 'mocp -M ~musix/.moc -f';
+$commands['prev'] = 'mocp -M ~musix/.moc -r';
+$commands['shuffle on'] = 'mocp -M ~musix/.moc -o shuffle';
+$commands['shuffle off'] = 'mocp -M ~musix/.moc -u shuffle';
+$commands['lauter'] = 'lautstaerke +5';
+$commands['viel lauter'] = 'lautstaerke +25';
+$commands['leiser'] = 'lautstaerke -5';
+$commands['viel leiser'] = 'lautstaerke -25';
+
$max_line_len = 50;
function crypt_status() {
return trim(shell_exec("cryptstatus"));
}
-function details() {
- global $max_line_len;
+function details($max_line_len = 0) {
foreach (explode("\n",shell_exec("mocp -M ~musix/.moc -i 2>/dev/null")) as $line) {
if (substr($line,0,7)=="State: ")
$state = substr($line,7);
@@ -30,25 +85,47 @@ function details() {
$time = substr($line,10);
}
$max_file_len = $max_line_len - 4 - strlen($state) - strlen($time);
- if (strlen($file) > $max_file_len)
+ if ($max_lin_len && (strlen($file) > $max_file_len))
$file = "..." . substr($file,3-$max_file_len);
return $state . " " . $file . " (" . $time . ")";
}
-function list_info() {
- global $max_line_len;
+function list_info($max_line_len = 0) {
$list = substr(shell_exec("head -n1 ~musix/.moc/_playlist.m3u"),0,-1);
$cnt = substr(shell_exec("wc -l < ~musix/.moc/Listen/" . $list),0,-1);
$max_list_len = $max_line_len - 3 - strlen($cnt);
- if (strlen($list) > $max_list_len)
+ if ($max_line_len && (strlen($list) > $max_list_len))
$list = "..." . substr($list,3-$max_list_len);
return $list . " (" . $cnt . ")";
}
function print_redirect() {
?>
-<html><head><meta http-equiv="refresh" content="0; url=/" /></head></html>
+<html><head><meta http-equiv="refresh" content="0; url=/<?php attach_key('?'); ?>" /></head></html>
+<?php
+}
+
+if (!array_key_exists('what',$_GET)) {
+?>
+<html>
+<body>
<?php
+ print list_info() . "<br>\n";
+ print details() . "<br>\n";
+?>
+ <a href="?what=all<?php attach_key(); ?>">all info</a><br>
+<?php
+ foreach ($commands as $key => $command) {
+ print ' <a href="?what=' . $key;
+ attach_key();
+ print '">' . $key . '</a><br>' . "\n";
+ }
+?>
+ <a href="lists.php">lists</a><br>
+</body>
+</html>
+<?php
+ die();
}
switch ($_GET["what"]) {
@@ -58,18 +135,14 @@ switch ($_GET["what"]) {
print crypt_status();
break;
case "info":
- print list_info();
+ print list_info($max_line_len);
break;
case "details":
- print details();
+ print details($max_line_len);
break;
case "crypt":
print crypt_status();
break;
- case "pause":
- shell_exec("mocp -M ~musix/.moc -G");
- print_redirect();
- break;
case "playlist":
if (array_key_exists("list",$_GET)) {
$i = $_GET["list"];
@@ -80,5 +153,9 @@ switch ($_GET["what"]) {
print_redirect();
break;
default:
+ if (array_key_exists($_GET["what"], $commands)) {
+ shell_exec($commands[$_GET["what"]]);
+ print_redirect();
+ }
die();
}