summaryrefslogtreecommitdiff
path: root/index.php
blob: 5d4e1f37fdcd2409b518536c1db12e5327f7447d (plain)
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
<?php

if (!array_key_exists('what',$_GET)) {
?>
<html>
<body>
  <a href="?what=all">all info</a><br>
  <a href="?what=pause">pause</a><br>
  <a href="lists.php">lists</a><br>
</body>
</html>
<?php
  die();
}

$max_line_len = 50;

function crypt_status() {
  return trim(shell_exec("cryptstatus"));
}

function details() {
  global $max_line_len;
  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);
    if (substr($line,0,6)=="File: ")
      $file = basename(substr($line,6));
    if (substr($line,0,10)=="TimeLeft: ")
      $time = substr($line,10);
  }
  $max_file_len = $max_line_len - 4 - strlen($state) - strlen($time);
  if (strlen($file) > $max_file_len)
    $file = "..." . substr($file,3-$max_file_len);
  return $state . " " . $file . " (" . $time . ")";
}

function list_info() {
  global $max_line_len;
  $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)
    $list = "..." . substr($list,3-$max_list_len);
  return $list . " (" . $cnt . ")";
}

function print_redirect() {
?>
<html><head><meta http-equiv="refresh" content="0; url=/" /></head></html>
<?php
}

switch ($_GET["what"]) {
  case "all":
    print list_info() . "<br>\n";
    print details() . "<br>\n";
    print crypt_status();
    break;
  case "info":
    print list_info();
    break;
  case "details":
    print details();
    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"];
      if (preg_match("/^\d+$/", $i) == 1) {
        shell_exec("playlist " . $i);
      }
    }
    print_redirect();
    break;
  default:
    die();
}