/[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.1 - (hide annotations)
Fri Apr 1 00:29:34 2005 UTC (19 years, 3 months ago) by joko
Branch: MAIN
+ initial commit

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     $supported = array("play","pause","stop","next","prev");
117     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     if (!readConfig("common_isdemo")) exec("sudo -u music /home/music/bin/gdkeypad.pl {$player['ipaddr']} {$player['id']} 0 {$_GET['command']} > /dev/null");
132    
133     # relocate
134     if ($_GET['isreal']) header("Location: index.php?mode=player&sid={$_GET['sid']}");
135     else header("Location: ".lastURI());
136    
137     # bye!
138     exit;
139     }
140     else {
141     # variable $playing already loaded in
142     # the init-script (init.inc.php)
143    
144     $tpl->display("index.player.tpl");
145     }
146     }
147    
148     # show legend
149     else if ($_GET['mode'] == "legend") {
150     # set up icons
151     $icons = array(
152     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!"),
153     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."),
154     array("edit", "icon.edit.gif", "Change the details of a file, an album or a playlist."),
155     array("activate", "icon.activate.gif", "Activate the current playlist. If a playlist is active, you can add files or albums with the icon below."),
156     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."),
157     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."),
158     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."),
159     array("shuffle", "icon.shuffle.gif", "This icon allows you to shuffle the selected playlist ro bring the tracks in a random order.")
160     );
161    
162     # make key-array from number-array
163     foreach($icons as $icon) $legend[] = array("name"=>$icon[0],"src"=>$icon[1],"description"=>$icon[2]);
164    
165     # assign / display
166     $tpl->assign("ptitle","Legend");
167     $tpl->assign("legend",$legend);
168     $tpl->assign("highlight",$_GET['highlight']);
169    
170     regURI();
171     $tpl->display("index.legend.tpl");
172     }
173    
174     # main window
175     else {
176     # breadcrumb
177     $breadcrumb = array(
178     "Home" => "index.php?sid={$sid}"
179     );
180    
181     # statistics / from database
182     $res = mysql_query("select count(*) from tracks");
183     $trackcount = mysql_result($res,0);
184    
185     $res = mysql_query("select sum(length) from tracks");
186     $length = mysql_result($res,0);
187    
188     $res = mysql_query("select count(*) from album");
189     $albumcount = mysql_result($res,0);
190    
191     $res = mysql_query("select count(*) from playlist");
192     $playlistcount = mysql_result($res,0);
193    
194     # statistics / from file-system
195     if (readConfig('customize_home_filesize_show') || $_GET['mode'] == "filesize") {
196     exec("du -s ".PATH_RELATIVE_MUSICHOME."/??/",$out);
197     if (is_array($out) && count($out) > 0) {
198     $totalsize = 0; foreach($out as $line) {
199     if (!preg_match("/([0-9]*)\t".PATH_RELATIVE_MUSICHOME."\/([0-9]{2})/",$line, $match) || !is_array($match) || count($match) != 3) continue;
200    
201     $totalsize += $match[1];
202     $folders[] = array(
203     "name" => $match[2],
204     "size" => $match[1]
205     );
206     }
207     $totalsize = formatSize($totalsize);
208     $tpl->assign("filesize_show",true);
209     } else $totalsize = "n/a";
210     }
211    
212     # check for new inbox files
213     $inboxfiles = readInbox(true);
214    
215     # assign
216     $tpl->assign("trackcount",$trackcount);
217     $tpl->assign("length",$length);
218     $tpl->assign("albumcount",$albumcount);
219     $tpl->assign("playlistcount",$playlistcount);
220     $tpl->assign("totalsize",$totalsize);
221     $tpl->assign("inboxfiles",$inboxfiles);
222    
223     $out = exec("ps -A | grep 'gdd.pl'");
224     $serverstatus = !empty($out);
225    
226     # assign / display
227     $tpl->assign("ptitle","Home");
228     $tpl->assign("breadcrumb",$breadcrumb);
229    
230     $tpl->assign("serverstatus",$serverstatus);
231    
232     regURI();
233     $tpl->display("index.tpl");
234     }
235    
236     ?>

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