@@ -36,16 +36,16 @@ |
||
36 | 36 | <?php |
37 | 37 | // Generate the table with all of the file names in it..... |
38 | 38 | $all_files = get_all_files(); |
39 | - foreach(explode(PHP_EOL, $all_files) as $this_file){ |
|
40 | - if(strpos($this_file, 'total') === 0){ |
|
39 | + foreach (explode(PHP_EOL, $all_files) as $this_file) { |
|
40 | + if (strpos($this_file, 'total') === 0) { |
|
41 | 41 | continue; |
42 | 42 | } |
43 | 43 | $file_name = file_name_from_ls($this_file); |
44 | - if(strlen($file_name) === 0){ |
|
44 | + if (strlen($file_name) === 0) { |
|
45 | 45 | continue; |
46 | 46 | } |
47 | 47 | // Ignore file names that start with . |
48 | - if(strpos($file_name,".") === 0){ |
|
48 | + if (strpos($file_name, ".") === 0) { |
|
49 | 49 | continue; |
50 | 50 | } |
51 | 51 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | echo '<br>'; |
18 | 18 | |
19 | - if($GLOBALS['DEBUG_ENABLE']){ |
|
19 | + if ($GLOBALS['DEBUG_ENABLE']) { |
|
20 | 20 | echo '<table>'.PHP_EOL; |
21 | 21 | echo ' <tr><td><p style="color:gray">Debug stuff</p></td></tr>'.PHP_EOL; |
22 | 22 | echo ' <tr><td>'; |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | |
33 | 33 | $target_dir = $GLOBALS['FILE_PATH'].'/'; |
34 | 34 | $target_file = $target_dir.basename($_FILES['file_name']['name']); |
35 | - $upload_ok=1; |
|
36 | - $file_type = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); |
|
35 | + $upload_ok = 1; |
|
36 | + $file_type = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); |
|
37 | 37 | |
38 | - if(isset($_POST['submit'])) |
|
38 | + if (isset($_POST['submit'])) |
|
39 | 39 | { |
40 | 40 | // Check if file already exists |
41 | 41 | if ($upload_ok && (file_exists($target_file))) { |
@@ -45,17 +45,17 @@ discard block |
||
45 | 45 | |
46 | 46 | // Check file size. Limit is specified in lib_rascsi.php |
47 | 47 | if ($upload_ok && ($_FILES["file_name"]["size"] > $GLOBALS['MAX_UPLOAD_FILE_SIZE'])) { |
48 | - html_generate_warning("Error: your file is larger than the maximum size of " . $GLOBALS['MAX_UPLOAD_FILE_SIZE'] . "bytes"); |
|
48 | + html_generate_warning("Error: your file is larger than the maximum size of ".$GLOBALS['MAX_UPLOAD_FILE_SIZE']."bytes"); |
|
49 | 49 | $upload_ok = 0; |
50 | 50 | } |
51 | 51 | |
52 | 52 | // Allow certain file formats, also specified in lib_rascsi.php |
53 | - if($upload_ok && (!in_array(strtolower($file_type),$GLOBALS['ALLOWED_FILE_TYPES']))){ |
|
54 | - $error_string = 'File type "'. $file_type. '" is not currently allowed.'. |
|
53 | + if ($upload_ok && (!in_array(strtolower($file_type), $GLOBALS['ALLOWED_FILE_TYPES']))) { |
|
54 | + $error_string = 'File type "'.$file_type.'" is not currently allowed.'. |
|
55 | 55 | 'Only the following file types are allowed: <br>'. |
56 | 56 | '<ul>'.PHP_EOL; |
57 | - foreach($GLOBALS['ALLOWED_FILE_TYPES'] as $ft){ |
|
58 | - $error_string = $error_string. '<li>'.$ft.'</li>'.PHP_EOL; |
|
57 | + foreach ($GLOBALS['ALLOWED_FILE_TYPES'] as $ft) { |
|
58 | + $error_string = $error_string.'<li>'.$ft.'</li>'.PHP_EOL; |
|
59 | 59 | } |
60 | 60 | $error_string = $error_string.'</ul>'; |
61 | 61 | $error_string = $error_string.'<br>'; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | //Check if $upload_ok is set to 0 by an error |
67 | 67 | if ($upload_ok != 0) { |
68 | 68 | if (move_uploaded_file($_FILES["file_name"]["tmp_name"], $target_file)) { |
69 | - html_generate_success_message(basename( $_FILES["file_name"]["name"]). " has been uploaded."); |
|
69 | + html_generate_success_message(basename($_FILES["file_name"]["name"])." has been uploaded."); |
|
70 | 70 | } else { |
71 | 71 | html_generate_warning("There was an unknown error uploading your file."); |
72 | 72 | } |
@@ -25,12 +25,12 @@ |
||
25 | 25 | // https://stackoverflow.com/questions/53695187/php-function-that-shows-status-of-systemctl-service |
26 | 26 | $output = shell_exec("systemctl is-active rascsi"); |
27 | 27 | if (trim($output) == "active") { |
28 | - $color='green'; |
|
29 | - $text='Running'; |
|
28 | + $color = 'green'; |
|
29 | + $text = 'Running'; |
|
30 | 30 | } |
31 | - else{ |
|
32 | - $color='red'; |
|
33 | - $text='Stopped'; |
|
31 | + else { |
|
32 | + $color = 'red'; |
|
33 | + $text = 'Stopped'; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | echo '<body style="background-color: '.$color.';">'; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | html_generate_header(); |
16 | 16 | |
17 | 17 | echo '<br>'; |
18 | - if($GLOBALS['DEBUG_ENABLE']){ |
|
18 | + if ($GLOBALS['DEBUG_ENABLE']) { |
|
19 | 19 | echo '<table>'.PHP_EOL; |
20 | 20 | echo ' <tr><td><p style="color:gray">Debug stuff</p></td></tr>'.PHP_EOL; |
21 | 21 | echo ' <tr><td>'; |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | echo '</td></tr></table>'; |
29 | 29 | } |
30 | 30 | |
31 | - if(isset($_POST['command'])) |
|
31 | + if (isset($_POST['command'])) |
|
32 | 32 | { |
33 | - switch(strtolower($_POST['command'])){ |
|
33 | + switch (strtolower($_POST['command'])) { |
|
34 | 34 | case "eject_disk": |
35 | 35 | action_eject_disk(); |
36 | 36 | break; |
@@ -66,47 +66,47 @@ discard block |
||
66 | 66 | break; |
67 | 67 | } |
68 | 68 | } |
69 | - else{ |
|
69 | + else { |
|
70 | 70 | html_generate_warning("HTTP command was missing POST information. Are you trying to access this page directly? That won't work"); |
71 | 71 | echo "<br>".PHP_EOL; |
72 | 72 | html_generate_ok_to_go_home(); |
73 | 73 | } |
74 | 74 | |
75 | -function action_eject_disk(){ |
|
75 | +function action_eject_disk() { |
|
76 | 76 | $command = 'rasctl -i '.$_POST['id'].' -c eject 2>&1'.PHP_EOL; |
77 | 77 | exec($command, $retArray, $result); |
78 | - check_result($result, $command,$retArray); |
|
78 | + check_result($result, $command, $retArray); |
|
79 | 79 | html_generate_ok_to_go_home(); |
80 | 80 | } |
81 | 81 | |
82 | -function action_remove_device(){ |
|
82 | +function action_remove_device() { |
|
83 | 83 | // Check to see if the user has confirmed |
84 | - if(isset($_POST['confirmed'])){ |
|
84 | + if (isset($_POST['confirmed'])) { |
|
85 | 85 | $command = 'rasctl -i '.$_POST['id'].' -c disconnect 2>&1'.PHP_EOL; |
86 | 86 | exec($command, $retArray, $result); |
87 | - check_result($result, $command,$retArray); |
|
87 | + check_result($result, $command, $retArray); |
|
88 | 88 | html_generate_ok_to_go_home(); |
89 | 89 | } |
90 | - else{ |
|
91 | - check_are_you_sure('Are you sure you want to disconnect SCSI ID ' . $_POST['id'].'? If the host is running, this could cause undesirable behavior.'); |
|
90 | + else { |
|
91 | + check_are_you_sure('Are you sure you want to disconnect SCSI ID '.$_POST['id'].'? If the host is running, this could cause undesirable behavior.'); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | // function action_connect_new_device(){} |
95 | -function action_insert_disk(){ |
|
95 | +function action_insert_disk() { |
|
96 | 96 | $command = 'rasctl -i '.$_POST['id'].' -c insert -f '.$GLOBALS['FILE_PATH'].'/'.$_POST['file_name'].' 2>&1'.PHP_EOL; |
97 | 97 | exec($command, $retArray, $result); |
98 | - check_result($result, $command,$retArray); |
|
98 | + check_result($result, $command, $retArray); |
|
99 | 99 | html_generate_ok_to_go_home(); |
100 | 100 | } |
101 | -function action_create_new_image(){ |
|
101 | +function action_create_new_image() { |
|
102 | 102 | // If we already know the size & filename, we can go create the image... |
103 | - if(isset($_POST['size']) && isset($_POST['file_name'])){ |
|
103 | + if (isset($_POST['size']) && isset($_POST['file_name'])) { |
|
104 | 104 | $command = 'dd if=/dev/zero of='.$GLOBALS['FILE_PATH'].'/'.$_POST['file_name'].' bs=1M count='.$_POST['size']; |
105 | 105 | exec($command, $retArray, $result); |
106 | 106 | check_result($result, $command, $retArray); |
107 | 107 | html_generate_ok_to_go_home(); |
108 | 108 | } |
109 | - else{ |
|
109 | + else { |
|
110 | 110 | echo '<h2>Create a new empty file</h2>'.PHP_EOL; |
111 | 111 | echo '<form action=rascsi_action.php method="post">'.PHP_EOL; |
112 | 112 | echo ' <input type="hidden" name="command" value="'.$_POST['command'].'"/>'.PHP_EOL; |
@@ -135,92 +135,92 @@ discard block |
||
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | -function action_delete_file(){ |
|
138 | +function action_delete_file() { |
|
139 | 139 | // Check to see if the user has confirmed |
140 | - if(isset($_POST['confirmed'])){ |
|
140 | + if (isset($_POST['confirmed'])) { |
|
141 | 141 | $command = 'rm '.$GLOBALS['FILE_PATH'].'/'.$_POST['file_name']; |
142 | 142 | exec($command, $retArray, $result); |
143 | 143 | check_result($result, $command, $retArray); |
144 | 144 | html_generate_ok_to_go_home(); |
145 | 145 | } |
146 | - else{ |
|
146 | + else { |
|
147 | 147 | check_are_you_sure('Are you sure you want to PERMANENTLY delete '.$_POST['file_name'].'?'); |
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | -function action_restart_rascsi_service(){ |
|
151 | +function action_restart_rascsi_service() { |
|
152 | 152 | // Restart the RaSCSI service |
153 | 153 | $command = "sudo /bin/systemctl restart rascsi.service 2>&1"; |
154 | 154 | exec($command, $retArray, $result); |
155 | - check_result($result, $command,$retArray); |
|
155 | + check_result($result, $command, $retArray); |
|
156 | 156 | html_generate_ok_to_go_home(); |
157 | 157 | } |
158 | 158 | |
159 | -function action_stop_rascsi_service(){ |
|
159 | +function action_stop_rascsi_service() { |
|
160 | 160 | // Stop the RaSCSI service |
161 | 161 | $command = "sudo /bin/systemctl stop rascsi.service 2>&1"; |
162 | 162 | exec($command, $retArray, $result); |
163 | - check_result($result, $command,$retArray); |
|
163 | + check_result($result, $command, $retArray); |
|
164 | 164 | html_generate_ok_to_go_home(); |
165 | 165 | } |
166 | 166 | |
167 | -function action_reboot_raspberry_pi(){ |
|
167 | +function action_reboot_raspberry_pi() { |
|
168 | 168 | // Check to see if the user has confirmed |
169 | - if(isset($_POST['confirmed'])){ |
|
169 | + if (isset($_POST['confirmed'])) { |
|
170 | 170 | $command = "sleep 2 && sudo reboot 2>&1"; |
171 | 171 | exec($command, $retArray, $result); |
172 | 172 | // The unit should reboot at this point. Doesn't matter what we do now... |
173 | - check_result($result, $command,$retArray); |
|
173 | + check_result($result, $command, $retArray); |
|
174 | 174 | html_generate_ok_to_go_home(); |
175 | 175 | } |
176 | - else{ |
|
176 | + else { |
|
177 | 177 | check_are_you_sure("Are you sure you want to reboot the Raspberry Pi?"); |
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | -function action_shutdown_raspberry_pi(){ |
|
181 | +function action_shutdown_raspberry_pi() { |
|
182 | 182 | // Check to see if the user has confirmed |
183 | - if(isset($_POST['confirmed'])){ |
|
183 | + if (isset($_POST['confirmed'])) { |
|
184 | 184 | $command = "sleep 2 && sudo shutdown -h now 2>&1"; |
185 | 185 | exec($command, $retArray, $result); |
186 | 186 | // The unit should shutdown at this point. Doesn't matter what we do now... |
187 | - check_result($result, $command,$retArray); |
|
187 | + check_result($result, $command, $retArray); |
|
188 | 188 | html_generate_ok_to_go_home(); |
189 | 189 | } |
190 | - else{ |
|
190 | + else { |
|
191 | 191 | check_are_you_sure("Are you sure you want to shut down the Raspberry Pi?"); |
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | -function action_unknown_command(){ |
|
195 | +function action_unknown_command() { |
|
196 | 196 | html_generate_warning('<br><h2>Unknown command: '.$_POST['command'].'</h2>'); |
197 | 197 | html_generate_ok_to_go_home(); |
198 | 198 | } |
199 | 199 | |
200 | -function check_result($result,$command,$output){ |
|
201 | - if(!$result){ |
|
200 | +function check_result($result, $command, $output) { |
|
201 | + if (!$result) { |
|
202 | 202 | html_generate_success_message('Command succeeded!'); |
203 | 203 | } |
204 | - else{ |
|
204 | + else { |
|
205 | 205 | html_generate_warning('Command failed!'); |
206 | 206 | } |
207 | 207 | echo '<br><code>'.$command.'</code><br>'.PHP_EOL; |
208 | - if(count($output) > 0){ |
|
208 | + if (count($output) > 0) { |
|
209 | 209 | echo '<br>Output:<code>'.PHP_EOL; |
210 | - foreach($output as $line){ |
|
210 | + foreach ($output as $line) { |
|
211 | 211 | echo '<br> Error message: '.$line.PHP_EOL; |
212 | 212 | } |
213 | 213 | echo '</code>'.PHP_EOL; |
214 | 214 | } |
215 | 215 | } |
216 | 216 | |
217 | -function check_are_you_sure($prompt){ |
|
217 | +function check_are_you_sure($prompt) { |
|
218 | 218 | echo '<br><h2>'.$prompt.'</h2>'.PHP_EOL; |
219 | 219 | echo ' <table style="border: none">'.PHP_EOL; |
220 | 220 | echo ' <tr style="border: none">'.PHP_EOL; |
221 | 221 | echo ' <td style="border: none; vertical-align:top;">'.PHP_EOL; |
222 | 222 | echo ' <form action="rascsi_action.php" method="post">'.PHP_EOL; |
223 | - foreach($_POST as $key => $value){ |
|
223 | + foreach ($_POST as $key => $value) { |
|
224 | 224 | echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>'.PHP_EOL; |
225 | 225 | } |
226 | 226 | echo ' <input type="hidden" name="confirmed" value="yes" />'.PHP_EOL; |
@@ -236,18 +236,18 @@ discard block |
||
236 | 236 | echo '</table>'.PHP_EOL; |
237 | 237 | } |
238 | 238 | |
239 | -function action_connect_new_device(){ |
|
239 | +function action_connect_new_device() { |
|
240 | 240 | // If we already know the type & filename, we can go connect the device... |
241 | - if(isset($_POST['type']) && isset($_POST['file_name'])){ |
|
241 | + if (isset($_POST['type']) && isset($_POST['file_name'])) { |
|
242 | 242 | $command = 'rasctl -i '.$_POST['id'].' -c attach -t '.type_string_to_rasctl_type($_POST['type']); |
243 | - if($_POST['file_name'] != "None"){ |
|
243 | + if ($_POST['file_name'] != "None") { |
|
244 | 244 | $command = $command.' -f '.$GLOBALS['FILE_PATH'].'/'.$_POST['file_name']; |
245 | 245 | } |
246 | 246 | exec($command, $retArray, $result); |
247 | 247 | check_result($result, $command, $retArray); |
248 | 248 | html_generate_ok_to_go_home(); |
249 | 249 | } |
250 | - else{ |
|
250 | + else { |
|
251 | 251 | |
252 | 252 | |
253 | 253 | $id = $_POST['id']; |
@@ -280,12 +280,12 @@ discard block |
||
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
283 | -function get_new_filename(){ |
|
283 | +function get_new_filename() { |
|
284 | 284 | // Try to find a new file name that doesn't exist. |
285 | - $i=1; |
|
286 | - while(file_exists($GLOBALS['FILE_PATH'].'/'.'new_file'.$i.'.hda')) |
|
285 | + $i = 1; |
|
286 | + while (file_exists($GLOBALS['FILE_PATH'].'/'.'new_file'.$i.'.hda')) |
|
287 | 287 | { |
288 | - $i = $i+1; |
|
288 | + $i = $i + 1; |
|
289 | 289 | } |
290 | 290 | return 'new_file'.$i.'.hda'; |
291 | 291 | } |
@@ -6,41 +6,41 @@ discard block |
||
6 | 6 | |
7 | 7 | <?php |
8 | 8 | |
9 | -$DEBUG_ENABLE=0; |
|
10 | -$FILE_PATH='/home/pi/images'; |
|
9 | +$DEBUG_ENABLE = 0; |
|
10 | +$FILE_PATH = '/home/pi/images'; |
|
11 | 11 | // Limit the maximum upload file size to 1GB |
12 | -$MAX_UPLOAD_FILE_SIZE=1000000000; |
|
13 | -$ALLOWED_FILE_TYPES=array('iso','hda'); |
|
12 | +$MAX_UPLOAD_FILE_SIZE = 1000000000; |
|
13 | +$ALLOWED_FILE_TYPES = array('iso', 'hda'); |
|
14 | 14 | |
15 | -function html_generate_header(){ |
|
16 | - echo ' <table width="100%" >'. PHP_EOL; |
|
17 | - echo ' <tr style="background-color: black;">'. PHP_EOL; |
|
18 | - echo ' <td style="background-color: black;"><a href=http://github.com/akuker/RASCSI><h1>RaSCSI - 68kmla Edition</h1></a></td>'. PHP_EOL; |
|
19 | - echo ' <td style="background-color: black;">'. PHP_EOL; |
|
20 | - echo ' <form action="rascsi.php">'. PHP_EOL; |
|
21 | - echo ' <input type="submit" value="Go Home"/>'. PHP_EOL; |
|
22 | - if($GLOBALS['DEBUG_ENABLE']){ |
|
23 | - echo ' <p style="color:#595959">Debug Timestamp: '.time().'</p>'. PHP_EOL; |
|
15 | +function html_generate_header() { |
|
16 | + echo ' <table width="100%" >'.PHP_EOL; |
|
17 | + echo ' <tr style="background-color: black;">'.PHP_EOL; |
|
18 | + echo ' <td style="background-color: black;"><a href=http://github.com/akuker/RASCSI><h1>RaSCSI - 68kmla Edition</h1></a></td>'.PHP_EOL; |
|
19 | + echo ' <td style="background-color: black;">'.PHP_EOL; |
|
20 | + echo ' <form action="rascsi.php">'.PHP_EOL; |
|
21 | + echo ' <input type="submit" value="Go Home"/>'.PHP_EOL; |
|
22 | + if ($GLOBALS['DEBUG_ENABLE']) { |
|
23 | + echo ' <p style="color:#595959">Debug Timestamp: '.time().'</p>'.PHP_EOL; |
|
24 | 24 | } |
25 | - echo ' </form>'. PHP_EOL; |
|
26 | - echo ' </td>'. PHP_EOL; |
|
27 | - echo ' </tr>'. PHP_EOL; |
|
28 | - echo ' </table>'. PHP_EOL; |
|
25 | + echo ' </form>'.PHP_EOL; |
|
26 | + echo ' </td>'.PHP_EOL; |
|
27 | + echo ' </tr>'.PHP_EOL; |
|
28 | + echo ' </table>'.PHP_EOL; |
|
29 | 29 | //echo(exec('whoami')); |
30 | 30 | } |
31 | 31 | |
32 | -function html_generate_image_file_select_list(){ |
|
32 | +function html_generate_image_file_select_list() { |
|
33 | 33 | $all_files = get_all_files(); |
34 | - foreach(explode(PHP_EOL, $all_files) as $this_file){ |
|
35 | - if(strpos($this_file, 'total') === 0){ |
|
34 | + foreach (explode(PHP_EOL, $all_files) as $this_file) { |
|
35 | + if (strpos($this_file, 'total') === 0) { |
|
36 | 36 | continue; |
37 | 37 | } |
38 | 38 | $file_name = file_name_from_ls($this_file); |
39 | - if(strlen($file_name) === 0){ |
|
39 | + if (strlen($file_name) === 0) { |
|
40 | 40 | continue; |
41 | 41 | } |
42 | 42 | // Ignore files that start with a . |
43 | - if(strpos($file_name, '.') === 0){ |
|
43 | + if (strpos($file_name, '.') === 0) { |
|
44 | 44 | continue; |
45 | 45 | } |
46 | 46 | |
@@ -49,54 +49,54 @@ discard block |
||
49 | 49 | } |
50 | 50 | |
51 | 51 | |
52 | -function html_generate_scsi_id_select_list(){ |
|
53 | - echo '<select>'. PHP_EOL; |
|
54 | - foreach(range(0,7) as $id){ |
|
55 | - echo '<option value="'.$id.'">'.$id.'</option>'. PHP_EOL; |
|
52 | +function html_generate_scsi_id_select_list() { |
|
53 | + echo '<select>'.PHP_EOL; |
|
54 | + foreach (range(0, 7) as $id) { |
|
55 | + echo '<option value="'.$id.'">'.$id.'</option>'.PHP_EOL; |
|
56 | 56 | } |
57 | - echo '</select>'. PHP_EOL; |
|
57 | + echo '</select>'.PHP_EOL; |
|
58 | 58 | } |
59 | 59 | |
60 | -function html_generate_scsi_type_select_list(){ |
|
61 | - echo '<select name=type>'. PHP_EOL; |
|
60 | +function html_generate_scsi_type_select_list() { |
|
61 | + echo '<select name=type>'.PHP_EOL; |
|
62 | 62 | $options = array("Hard Disk", "CD-ROM", "Zip Drive", "Ethernet Tap", "Filesystem Bridge"); |
63 | - foreach($options as $type){ |
|
64 | - echo '<option value="'.$type.'">'.$type.'</option>'. PHP_EOL; |
|
63 | + foreach ($options as $type) { |
|
64 | + echo '<option value="'.$type.'">'.$type.'</option>'.PHP_EOL; |
|
65 | 65 | } |
66 | - echo '</select>'. PHP_EOL; |
|
66 | + echo '</select>'.PHP_EOL; |
|
67 | 67 | } |
68 | 68 | |
69 | -function html_generate_warning($message){ |
|
70 | - echo ' <table width="100%" >'. PHP_EOL; |
|
71 | - echo ' <tr style="background-color: red;">'. PHP_EOL; |
|
72 | - echo ' <td style="background-color: red;">'. PHP_EOL; |
|
73 | - echo ' <font size=+2>'.$message.'</font>'. PHP_EOL; |
|
74 | - echo ' </td>'. PHP_EOL; |
|
75 | - echo ' </tr>'. PHP_EOL; |
|
76 | - echo ' </table>'. PHP_EOL; |
|
69 | +function html_generate_warning($message) { |
|
70 | + echo ' <table width="100%" >'.PHP_EOL; |
|
71 | + echo ' <tr style="background-color: red;">'.PHP_EOL; |
|
72 | + echo ' <td style="background-color: red;">'.PHP_EOL; |
|
73 | + echo ' <font size=+2>'.$message.'</font>'.PHP_EOL; |
|
74 | + echo ' </td>'.PHP_EOL; |
|
75 | + echo ' </tr>'.PHP_EOL; |
|
76 | + echo ' </table>'.PHP_EOL; |
|
77 | 77 | } |
78 | 78 | |
79 | -function html_generate_success_message($message){ |
|
80 | - echo ' <table width="100%" >'. PHP_EOL; |
|
81 | - echo ' <tr style="background-color: green;">'. PHP_EOL; |
|
82 | - echo ' <td style="background-color: green;">'. PHP_EOL; |
|
83 | - echo ' <font size=+2>Success</font>'. PHP_EOL; |
|
84 | - echo ' </td>'. PHP_EOL; |
|
85 | - echo ' </tr>'. PHP_EOL; |
|
86 | - if(strlen($message) > 0){ |
|
87 | - echo ' <tr style="background-color: green;">'. PHP_EOL; |
|
88 | - echo ' <td style="background-color: green;">'. PHP_EOL; |
|
79 | +function html_generate_success_message($message) { |
|
80 | + echo ' <table width="100%" >'.PHP_EOL; |
|
81 | + echo ' <tr style="background-color: green;">'.PHP_EOL; |
|
82 | + echo ' <td style="background-color: green;">'.PHP_EOL; |
|
83 | + echo ' <font size=+2>Success</font>'.PHP_EOL; |
|
84 | + echo ' </td>'.PHP_EOL; |
|
85 | + echo ' </tr>'.PHP_EOL; |
|
86 | + if (strlen($message) > 0) { |
|
87 | + echo ' <tr style="background-color: green;">'.PHP_EOL; |
|
88 | + echo ' <td style="background-color: green;">'.PHP_EOL; |
|
89 | 89 | echo ' '.$message.PHP_EOL; |
90 | - echo ' </td>'. PHP_EOL; |
|
91 | - echo ' </tr>'. PHP_EOL; |
|
90 | + echo ' </td>'.PHP_EOL; |
|
91 | + echo ' </tr>'.PHP_EOL; |
|
92 | 92 | } |
93 | - echo ' </table>'. PHP_EOL; |
|
93 | + echo ' </table>'.PHP_EOL; |
|
94 | 94 | } |
95 | 95 | |
96 | -function html_generate_ok_to_go_home(){ |
|
97 | - echo ' <form action="rascsi.php">'. PHP_EOL; |
|
98 | - echo ' <input type="submit" value="OK"/>'. PHP_EOL; |
|
99 | - echo ' </form>'. PHP_EOL; |
|
96 | +function html_generate_ok_to_go_home() { |
|
97 | + echo ' <form action="rascsi.php">'.PHP_EOL; |
|
98 | + echo ' <input type="submit" value="OK"/>'.PHP_EOL; |
|
99 | + echo ' </form>'.PHP_EOL; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | |
@@ -104,29 +104,29 @@ discard block |
||
104 | 104 | $raw_output = shell_exec("/usr/local/bin/rasctl -l"); |
105 | 105 | $rasctl_lines = explode(PHP_EOL, $raw_output); |
106 | 106 | |
107 | - echo ' <br>'. PHP_EOL; |
|
108 | - echo ' <h2>Current RaSCSI Configuration</h2>'. PHP_EOL; |
|
109 | - echo ' <table border="black">'. PHP_EOL; |
|
110 | - echo ' <tr>'. PHP_EOL; |
|
111 | - echo ' <td><b>SCSI ID</b></td>'. PHP_EOL; |
|
112 | - echo ' <td><b>Type</b></td>'. PHP_EOL; |
|
113 | - echo ' <td><b>File</b></td>'. PHP_EOL; |
|
114 | - echo ' <td><b>File Ops</b></td>'. PHP_EOL; |
|
115 | - echo ' <td><b>Device Ops</b></td>'. PHP_EOL; |
|
116 | - echo ' </tr>'. PHP_EOL; |
|
107 | + echo ' <br>'.PHP_EOL; |
|
108 | + echo ' <h2>Current RaSCSI Configuration</h2>'.PHP_EOL; |
|
109 | + echo ' <table border="black">'.PHP_EOL; |
|
110 | + echo ' <tr>'.PHP_EOL; |
|
111 | + echo ' <td><b>SCSI ID</b></td>'.PHP_EOL; |
|
112 | + echo ' <td><b>Type</b></td>'.PHP_EOL; |
|
113 | + echo ' <td><b>File</b></td>'.PHP_EOL; |
|
114 | + echo ' <td><b>File Ops</b></td>'.PHP_EOL; |
|
115 | + echo ' <td><b>Device Ops</b></td>'.PHP_EOL; |
|
116 | + echo ' </tr>'.PHP_EOL; |
|
117 | 117 | |
118 | 118 | $scsi_ids = array(); |
119 | 119 | |
120 | 120 | foreach ($rasctl_lines as $current_line) |
121 | 121 | { |
122 | - if(strlen($current_line) === 0){ |
|
122 | + if (strlen($current_line) === 0) { |
|
123 | 123 | continue; |
124 | 124 | } |
125 | - if(strpos($current_line, '+----') === 0){ |
|
125 | + if (strpos($current_line, '+----') === 0) { |
|
126 | 126 | continue; |
127 | 127 | |
128 | 128 | } |
129 | - if(strpos($current_line, '| ID | UN') === 0){ |
|
129 | + if (strpos($current_line, '| ID | UN') === 0) { |
|
130 | 130 | continue; |
131 | 131 | } |
132 | 132 | $segments = explode("|", $current_line); |
@@ -140,67 +140,67 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | |
143 | - foreach (range(0,7) as $id){ |
|
144 | - echo ' <tr>'. PHP_EOL; |
|
145 | - echo ' <td style="text-align:center">'.$id.'</td>'. PHP_EOL; |
|
146 | - if(isset($scsi_ids[$id])) |
|
143 | + foreach (range(0, 7) as $id) { |
|
144 | + echo ' <tr>'.PHP_EOL; |
|
145 | + echo ' <td style="text-align:center">'.$id.'</td>'.PHP_EOL; |
|
146 | + if (isset($scsi_ids[$id])) |
|
147 | 147 | { |
148 | - echo ' <td style="text-align:center">'.$scsi_ids[$id]['type'].'</td>'. PHP_EOL; |
|
149 | - if(strtolower($scsi_ids[$id]['file']) == "no media"){ |
|
148 | + echo ' <td style="text-align:center">'.$scsi_ids[$id]['type'].'</td>'.PHP_EOL; |
|
149 | + if (strtolower($scsi_ids[$id]['file']) == "no media") { |
|
150 | 150 | echo ' <td>'.PHP_EOL; |
151 | - echo ' <form action="rascsi_action.php" method="post">'. PHP_EOL; |
|
151 | + echo ' <form action="rascsi_action.php" method="post">'.PHP_EOL; |
|
152 | 152 | echo ' <select name="file_name">'.PHP_EOL; |
153 | 153 | echo ' <option value="None">None</option>'.PHP_EOL; |
154 | 154 | html_generate_image_file_select_list(); |
155 | 155 | echo ' </select>'.PHP_EOL; |
156 | - echo ' <input type="hidden" name="command" value="insert_disk" />'. PHP_EOL; |
|
157 | - echo ' <input type="hidden" name="id" value="'.$id.'" />'. PHP_EOL; |
|
158 | - echo ' <input type="hidden" name="file" value="'.$scsi_ids[$id]['file'].'" />'. PHP_EOL; |
|
156 | + echo ' <input type="hidden" name="command" value="insert_disk" />'.PHP_EOL; |
|
157 | + echo ' <input type="hidden" name="id" value="'.$id.'" />'.PHP_EOL; |
|
158 | + echo ' <input type="hidden" name="file" value="'.$scsi_ids[$id]['file'].'" />'.PHP_EOL; |
|
159 | 159 | echo ' </td><td>'.PHP_EOL; |
160 | - echo ' <input type="submit" name="insert_disk" value="Insert" />'. PHP_EOL; |
|
161 | - echo ' </form>'. PHP_EOL; |
|
160 | + echo ' <input type="submit" name="insert_disk" value="Insert" />'.PHP_EOL; |
|
161 | + echo ' </form>'.PHP_EOL; |
|
162 | 162 | echo ' </td>'.PHP_EOL; |
163 | 163 | } |
164 | - else{ |
|
164 | + else { |
|
165 | 165 | // rascsi inserts "WRITEPROTECT" for the read-only drives. We want to display that differently. |
166 | - echo ' <form action="rascsi_action.php" method="post">'. PHP_EOL; |
|
167 | - echo ' <td>'.str_replace('(WRITEPROTECT)', '', $scsi_ids[$id]['file']). PHP_EOL; |
|
166 | + echo ' <form action="rascsi_action.php" method="post">'.PHP_EOL; |
|
167 | + echo ' <td>'.str_replace('(WRITEPROTECT)', '', $scsi_ids[$id]['file']).PHP_EOL; |
|
168 | 168 | echo ' </td><td>'.PHP_EOL; |
169 | - if(strtolower($scsi_ids[$id]['type']) == 'sccd'){ |
|
170 | - echo ' <input type="hidden" name="command" value="eject_disk" />'. PHP_EOL; |
|
171 | - echo ' <input type="hidden" name="id" value="'.$id.'" />'. PHP_EOL; |
|
172 | - echo ' <input type="hidden" name="file" value="'.$scsi_ids[$id]['file'].'" />'. PHP_EOL; |
|
173 | - echo ' <input type="submit" name="eject_disk" value="Eject" />'. PHP_EOL; |
|
169 | + if (strtolower($scsi_ids[$id]['type']) == 'sccd') { |
|
170 | + echo ' <input type="hidden" name="command" value="eject_disk" />'.PHP_EOL; |
|
171 | + echo ' <input type="hidden" name="id" value="'.$id.'" />'.PHP_EOL; |
|
172 | + echo ' <input type="hidden" name="file" value="'.$scsi_ids[$id]['file'].'" />'.PHP_EOL; |
|
173 | + echo ' <input type="submit" name="eject_disk" value="Eject" />'.PHP_EOL; |
|
174 | 174 | } |
175 | 175 | echo ' </td>'.PHP_EOL; |
176 | - echo ' </form>'. PHP_EOL; |
|
176 | + echo ' </form>'.PHP_EOL; |
|
177 | 177 | } |
178 | - echo ' <td>'. PHP_EOL; |
|
179 | - echo ' <form action="rascsi_action.php" method="post">'. PHP_EOL; |
|
180 | - echo ' <input type="hidden" name="command" value="remove_device" />'. PHP_EOL; |
|
181 | - echo ' <input type="hidden" name="id" value="'.$id.'" />'. PHP_EOL; |
|
182 | - echo ' <input type="submit" name="remove_device" value="Disconnect" />'. PHP_EOL; |
|
183 | - echo ' </form>'. PHP_EOL; |
|
184 | - echo ' </td>'. PHP_EOL; |
|
178 | + echo ' <td>'.PHP_EOL; |
|
179 | + echo ' <form action="rascsi_action.php" method="post">'.PHP_EOL; |
|
180 | + echo ' <input type="hidden" name="command" value="remove_device" />'.PHP_EOL; |
|
181 | + echo ' <input type="hidden" name="id" value="'.$id.'" />'.PHP_EOL; |
|
182 | + echo ' <input type="submit" name="remove_device" value="Disconnect" />'.PHP_EOL; |
|
183 | + echo ' </form>'.PHP_EOL; |
|
184 | + echo ' </td>'.PHP_EOL; |
|
185 | 185 | } |
186 | 186 | else |
187 | 187 | { |
188 | - echo ' <td style="text-align:center">-</td>'. PHP_EOL; |
|
189 | - echo ' <td>-</td>'. PHP_EOL; |
|
190 | - echo ' <td></td>'. PHP_EOL; |
|
191 | - echo ' <td>'. PHP_EOL; |
|
192 | - echo ' <form action="rascsi_action.php" method="post">'. PHP_EOL; |
|
193 | - echo ' <input type="hidden" name="command" value="connect_new_device" />'. PHP_EOL; |
|
194 | - echo ' <input type="hidden" name="id" value="'.$id.'" />'. PHP_EOL; |
|
195 | - echo ' <input type="submit" name="connect_new_device" value="Connect New" />'. PHP_EOL; |
|
196 | - echo ' </form>'. PHP_EOL; |
|
197 | - echo ' </td>'. PHP_EOL; |
|
188 | + echo ' <td style="text-align:center">-</td>'.PHP_EOL; |
|
189 | + echo ' <td>-</td>'.PHP_EOL; |
|
190 | + echo ' <td></td>'.PHP_EOL; |
|
191 | + echo ' <td>'.PHP_EOL; |
|
192 | + echo ' <form action="rascsi_action.php" method="post">'.PHP_EOL; |
|
193 | + echo ' <input type="hidden" name="command" value="connect_new_device" />'.PHP_EOL; |
|
194 | + echo ' <input type="hidden" name="id" value="'.$id.'" />'.PHP_EOL; |
|
195 | + echo ' <input type="submit" name="connect_new_device" value="Connect New" />'.PHP_EOL; |
|
196 | + echo ' </form>'.PHP_EOL; |
|
197 | + echo ' </td>'.PHP_EOL; |
|
198 | 198 | |
199 | 199 | } |
200 | - echo ' </form>'. PHP_EOL; |
|
201 | - echo ' </tr>'. PHP_EOL; |
|
200 | + echo ' </form>'.PHP_EOL; |
|
201 | + echo ' </tr>'.PHP_EOL; |
|
202 | 202 | } |
203 | - echo '</table>'. PHP_EOL; |
|
203 | + echo '</table>'.PHP_EOL; |
|
204 | 204 | } |
205 | 205 | function get_all_files() |
206 | 206 | { |
@@ -208,47 +208,47 @@ discard block |
||
208 | 208 | return $raw_ls_output; |
209 | 209 | } |
210 | 210 | |
211 | -function mod_date_from_ls($value){ |
|
211 | +function mod_date_from_ls($value) { |
|
212 | 212 | $ls_pieces = explode("\"", $value); |
213 | - if(count($ls_pieces)<1){ |
|
213 | + if (count($ls_pieces) < 1) { |
|
214 | 214 | return ""; |
215 | 215 | } |
216 | 216 | return $ls_pieces[1]; |
217 | 217 | } |
218 | -function file_name_from_ls($value){ |
|
218 | +function file_name_from_ls($value) { |
|
219 | 219 | $ls_pieces = explode("\"", $value); |
220 | - if(count($ls_pieces) < 4){ |
|
220 | + if (count($ls_pieces) < 4) { |
|
221 | 221 | return ""; |
222 | 222 | } |
223 | 223 | return $ls_pieces[3]; |
224 | 224 | } |
225 | -function file_size_from_ls($value){ |
|
225 | +function file_size_from_ls($value) { |
|
226 | 226 | $ls_pieces = explode("\"", $value); |
227 | 227 | $file_props = preg_split("/\s+/", $ls_pieces[0]); |
228 | 228 | return $file_props[4]; |
229 | 229 | } |
230 | -function file_category_from_file_name($value){ |
|
231 | - if(strpos($value,".iso") > 0){ |
|
230 | +function file_category_from_file_name($value) { |
|
231 | + if (strpos($value, ".iso") > 0) { |
|
232 | 232 | return "CD-ROM Image"; |
233 | 233 | } |
234 | - if(strpos($value,".hda") > 0){ |
|
234 | + if (strpos($value, ".hda") > 0) { |
|
235 | 235 | return "Hard Disk Image"; |
236 | 236 | } |
237 | - return "Unknown type: " . $value; |
|
237 | + return "Unknown type: ".$value; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | |
241 | 241 | |
242 | -function type_string_to_rasctl_type($typestr){ |
|
243 | - if(strcasecmp($typestr,"Hard Disk") == 0){ |
|
242 | +function type_string_to_rasctl_type($typestr) { |
|
243 | + if (strcasecmp($typestr, "Hard Disk") == 0) { |
|
244 | 244 | return "hd"; |
245 | 245 | } |
246 | - if(strcasecmp($typestr,"CD-ROM") == 0){ |
|
246 | + if (strcasecmp($typestr, "CD-ROM") == 0) { |
|
247 | 247 | return "cd"; |
248 | 248 | } |
249 | - if(strcasecmp($typestr,"Zip Drive") == 0){ |
|
249 | + if (strcasecmp($typestr, "Zip Drive") == 0) { |
|
250 | 250 | } |
251 | - if(strcasecmp($typestr,"Filesystem bridge") == 0){ |
|
251 | + if (strcasecmp($typestr, "Filesystem bridge") == 0) { |
|
252 | 252 | return "bridge"; |
253 | 253 | } |
254 | 254 | return ""; |