/[cvs]/nfo/php/scripts/gdwebint/public_html/index.php
ViewVC logotype

Annotation of /nfo/php/scripts/gdwebint/public_html/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Fri Apr 1 02:12:46 2005 UTC (19 years, 4 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +3 -3 lines
+ Feature: Activate specified playlist (via gdkeypad.pl)

1 joko 1.1 <?php
2    
3     require 'inc/main.inc.php';
4    
5     /*
6    
7     Developer:
8     How to fetch the output of the sudo-command?
9    
10     */
11    
12     # shutdown the machine
13     if ($_GET['mode'] == "shutdown") {
14     # use shutdown command?
15     $use = readConfig("common_shutdown_use");
16     if ($use) {
17     # read shutdown command from <webint>
18     $shutdown = readConfig("common_shutdown");
19     if (!$shutdown) openError("Cannot read the 'shutdown'-command from the database!",lastURI());
20     }
21     else {
22     # get player id
23     $playerid = readPlayerID();
24     if (isIdentical($playerid,false)) openError("Error while trying to read the player-ID.",lastURI());
25    
26     # read shutdown command from <parameter>
27     $res = mysql_query("select value from parameter where name='shutdowncmd' and playerid={$playerid}");
28     if (!$res || mysql_num_rows($res) != 1) openError("Error while reading 'shutdown'-commands from database.",lastURI());
29     else $shutdown = mysql_result($res,0);
30     }
31    
32     # get commands
33     $commands = explode("\n",$shutdown);
34    
35     # execute commands
36     foreach($commands as $command) {
37     $command = trim($command);
38     exec($command);
39     }
40    
41     # after executing, the machine will shutdown
42     # and is no longer available
43    
44     # if the command was not successful, go to
45     # the last page
46     header("Location: index.php?sid={$_GET['sid']}"); exit;
47     }
48    
49     # (re-)start the gd-server script
50     else if ($_GET['mode'] == "start" || $_GET['mode'] == "restart") {
51     # get start/stop command
52     $start = readConfig("common_gddstart");
53     $stop = readConfig("common_gddstop");
54     if (!$start || !$stop) openError("Cannot read the 'start'/'stop'-command from the database!",lastURI());
55    
56     # check whether the script is running
57     $out = exec("ps -A | grep 'gdd.pl'");
58     $running = !empty($out);
59    
60     # execute stop-commands
61     if ($running) {
62     # get commands
63     $stop = explode("\n",$stop);
64    
65     # execute commands
66     foreach($stop as $command) {
67     $command = trim($command);
68     exec($command);
69     }
70     }
71    
72     # execute start-commands
73     $start = explode("\n",$start);
74    
75     # execute commands
76     foreach($start as $command) {
77     $command = trim($command);
78     exec($command);
79     }
80    
81     # redirect
82     header("Location: index.php?sid={$_GET['sid']}"); exit;
83     }
84    
85     # stop the gd-server script
86     if ($_GET['mode'] == "stop") {
87     # get stop command
88     $stop = readConfig("common_gddstop");
89     if (!$stop) openError("Cannot read the 'stop'-command from the database!",lastURI());
90    
91     # check whether the script is running
92     $out = exec("ps -A | grep 'gdd.pl'");
93     $running = !empty($out);
94    
95     # execute stop-commands
96     if ($running) {
97     # get commands
98     $stop = explode("\n",$stop);
99    
100     # execute commands
101     foreach($stop as $command) {
102     $command = trim($command);
103     exec($command);
104     }
105     }
106    
107     # redirect
108     header("Location: index.php?sid={$_GET['sid']}"); exit;
109     }
110    
111     # show inner-player
112     else if ($_GET['mode'] == "player") {
113     # if $command is set,
114     # execute this command
115     if (isset($_GET['command']) && isset($_GET['isreal'])) {
116 joko 1.3 $supported = array("play","pause","stop","next","prev", "pl_activate");
117 joko 1.1 foreach($supported as $cmd) {
118     if ($_GET['command'] == $cmd) {
119     $supported = true;
120     break;
121     }
122     }
123    
124     if (!$supported) openError("The selected command (".$_GET['command'].") is not (yet) supported.",lastURI());
125    
126     # get player
127     $player = readPlayer();
128     if (!$player) openError("Unable to read player.",lastURI());
129    
130     # execute command
131 joko 1.2 //$command = "sudo -u music /home/music/bin/gdkeypad.pl {$player['ipaddr']} {$player['id']} 0 {$_GET['command']} > /dev/null";
132 joko 1.3 $command = "sudo -u music -H sh -c \". ~/.bashrc; /home/music/bin/gdkeypad.pl {$player['ipaddr']} {$player['id']} 0 {$_GET['command']} {$_GET['command_arg']} > /dev/null\"";
133 joko 1.2 if ($_GET['debug']) print "$command<br/>";
134     if (!readConfig("common_isdemo")) exec($command);
135 joko 1.1
136     # relocate
137     if ($_GET['isreal']) header("Location: index.php?mode=player&sid={$_GET['sid']}");
138     else header("Location: ".lastURI());
139    
140     # bye!
141     exit;
142     }
143     else {
144     # variable $playing already loaded in
145     # the init-script (init.inc.php)
146    
147     $tpl->display("index.player.tpl");
148     }
149     }
150    
151     # show legend
152     else if ($_GET['mode'] == "legend") {
153     # set up icons
154     $icons = array(
155     array("delete-file", "icon.delete.file.gif", "Deletes a file, album or playlist (with content files) from the filesystem, the database and all playlists. You cannot undo this deletion!"),
156     array("delete-entry", "icon.delete.entry.gif", "Delete only the database entry of the selected file/album/playlist, but not the file or the entry in the tracks-table."),
157     array("edit", "icon.edit.gif", "Change the details of a file, an album or a playlist."),
158     array("activate", "icon.activate.gif", "Activate the current playlist. If a playlist is active, you can add files or albums with the icon below."),
159     array("add", "icon.add.gif", "Add a file or an album to the current active playlist. The active playlist is marked with the icon above."),
160     array("play", "icon.play.gif", "Play the selected file, album or playlist. If you use the checkboxes, you can play multiple playlists, albums or files."),
161     array("show", "icon.show.gif", "Use this icon to show the current playlist, album or track in the browse panel or in a specific panel."),
162     array("shuffle", "icon.shuffle.gif", "This icon allows you to shuffle the selected playlist ro bring the tracks in a random order.")
163     );
164    
165     # make key-array from number-array
166     foreach($icons as $icon) $legend[] = array("name"=>$icon[0],"src"=>$icon[1],"description"=>$icon[2]);
167    
168     # assign / display
169     $tpl->assign("ptitle","Legend");
170     $tpl->assign("legend",$legend);
171     $tpl->assign("highlight",$_GET['highlight']);
172    
173     regURI();
174     $tpl->display("index.legend.tpl");
175     }
176    
177     # main window
178     else {
179     # breadcrumb
180     $breadcrumb = array(
181     "Home" => "index.php?sid={$sid}"
182     );
183    
184     # statistics / from database
185     $res = mysql_query("select count(*) from tracks");
186     $trackcount = mysql_result($res,0);
187    
188     $res = mysql_query("select sum(length) from tracks");
189     $length = mysql_result($res,0);
190    
191     $res = mysql_query("select count(*) from album");
192     $albumcount = mysql_result($res,0);
193    
194     $res = mysql_query("select count(*) from playlist");
195     $playlistcount = mysql_result($res,0);
196    
197     # statistics / from file-system
198     if (readConfig('customize_home_filesize_show') || $_GET['mode'] == "filesize") {
199     exec("du -s ".PATH_RELATIVE_MUSICHOME."/??/",$out);
200     if (is_array($out) && count($out) > 0) {
201     $totalsize = 0; foreach($out as $line) {
202     if (!preg_match("/([0-9]*)\t".PATH_RELATIVE_MUSICHOME."\/([0-9]{2})/",$line, $match) || !is_array($match) || count($match) != 3) continue;
203    
204     $totalsize += $match[1];
205     $folders[] = array(
206     "name" => $match[2],
207     "size" => $match[1]
208     );
209     }
210     $totalsize = formatSize($totalsize);
211     $tpl->assign("filesize_show",true);
212     } else $totalsize = "n/a";
213     }
214    
215     # check for new inbox files
216     $inboxfiles = readInbox(true);
217    
218     # assign
219     $tpl->assign("trackcount",$trackcount);
220     $tpl->assign("length",$length);
221     $tpl->assign("albumcount",$albumcount);
222     $tpl->assign("playlistcount",$playlistcount);
223     $tpl->assign("totalsize",$totalsize);
224     $tpl->assign("inboxfiles",$inboxfiles);
225    
226     $out = exec("ps -A | grep 'gdd.pl'");
227     $serverstatus = !empty($out);
228    
229     # assign / display
230     $tpl->assign("ptitle","Home");
231     $tpl->assign("breadcrumb",$breadcrumb);
232    
233     $tpl->assign("serverstatus",$serverstatus);
234    
235     regURI();
236     $tpl->display("index.tpl");
237     }
238    
239 joko 1.3 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed