mirror of
https://github.com/akuker/RASCSI.git
synced 2024-12-28 08:30:21 +00:00
Moved several php functions to a library that can be reused. Updated to use css for styles
This commit is contained in:
parent
9d94cdeec6
commit
a30889f7c1
144
src/php/lib_rascsi.php
Normal file
144
src/php/lib_rascsi.php
Normal file
@ -0,0 +1,144 @@
|
||||
|
||||
<!-- PHP source code for controlling the RaSCSI - 68kmla edition with a web interface. -->
|
||||
<!-- Copyright (c) 2020 akuker -->
|
||||
<!-- Distributed under the BSD-3 Clause License -->
|
||||
|
||||
<!-- Note: the origina rascsi-php project was under MIT license.-->
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
function html_generate_header(){
|
||||
echo ' <table width="100%" >';
|
||||
echo ' <tr style="background-color: black;">';
|
||||
echo ' <td style="background-color: black;"><a href=http://github.com/akuker/RASCSI><h1>RaSCSI - 68kmla Edition</h1></a></td>';
|
||||
echo ' <td style="background-color: black;">';
|
||||
echo ' <form action="/rascsi.php">';
|
||||
echo ' <input type="submit" value="Refresh"/>';
|
||||
echo ' </form>';
|
||||
echo ' </td>';
|
||||
echo ' </tr>';
|
||||
echo ' </table>';
|
||||
echo 'Debug timestamp: ';
|
||||
$t=time();
|
||||
echo($t . "<br>");
|
||||
echo(exec('whoami'));
|
||||
}
|
||||
|
||||
function html_generate_scsi_id_select_list(){
|
||||
echo '<select>';
|
||||
foreach(range(0,7) as $id){
|
||||
echo '<option value="'.$id.'">'.$id.'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
}
|
||||
|
||||
function html_generate_scsi_type_select_list(){
|
||||
echo '<select>';
|
||||
$options = array("Hard Disk", "CD-ROM", "Zip Drive", "Ethernet Tap", "Filesystem Bridge");
|
||||
foreach($options as $type){
|
||||
echo '<option value="'.$type.'">'.$type.'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
}
|
||||
function current_rascsi_config() {
|
||||
$raw_output = shell_exec("/usr/local/bin/rasctl -l");
|
||||
$rasctl_lines = explode(PHP_EOL, $raw_output);
|
||||
|
||||
echo ' <br>';
|
||||
echo ' <h2>Current RaSCSI Configuration</h2>';
|
||||
echo ' <table border="black">';
|
||||
echo ' <tr>';
|
||||
echo ' <td><b>SCSI ID</b></td>';
|
||||
echo ' <td><b>Type</b></td>';
|
||||
echo ' <td><b>Image File</b></td>';
|
||||
echo ' <td><b>Actions</b></td>';
|
||||
echo ' </tr>';
|
||||
|
||||
$scsi_ids = array();
|
||||
|
||||
foreach ($rasctl_lines as $current_line)
|
||||
{
|
||||
if(strlen($current_line) === 0){
|
||||
continue;
|
||||
}
|
||||
if(strpos($current_line, '+----') === 0){
|
||||
continue;
|
||||
|
||||
}
|
||||
if(strpos($current_line, '| ID | UN') === 0){
|
||||
continue;
|
||||
}
|
||||
$segments = explode("|", $current_line);
|
||||
|
||||
$id_config = array();
|
||||
$id_config['id'] = trim($segments[1]);
|
||||
$id_config['type'] = trim($segments[3]);
|
||||
$id_config['file'] = trim($segments[4]);
|
||||
|
||||
$scsi_ids[$id_config['id']] = $id_config;
|
||||
}
|
||||
|
||||
|
||||
foreach (range(0,7) as $id){
|
||||
echo ' <tr>';
|
||||
echo ' <form>';
|
||||
echo ' <td style="text-align:center">'.$id.'</td>';
|
||||
if(isset($scsi_ids[$id]))
|
||||
{
|
||||
echo ' <td style="text-align:center">'.$scsi_ids[$id]['type'].'</td>';
|
||||
echo ' <td>'.$scsi_ids[$id]['file'].'</td>';
|
||||
echo ' <td>';
|
||||
echo ' <input type="button" value="Eject" onClick="eject_image(\''.$id.'\',\''.$scsi_ids[$id]['file'].'\')"/>';
|
||||
echo ' <input type="button" value="Disconnect" onClick="remove_device('.$id.')"/>';
|
||||
echo ' </td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
echo ' <td style="text-align:center">-</td>';
|
||||
echo ' <td>-</td>';
|
||||
echo ' <td>';
|
||||
echo ' <input type="button" value="Connect New Device" onClick="attach_device('.$id.')"/>';
|
||||
echo ' </td>';
|
||||
|
||||
}
|
||||
echo ' </form>';
|
||||
echo ' </tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
function get_all_files()
|
||||
{
|
||||
$raw_ls_output = shell_exec('ls --time-style="+\"%Y-%m-%d %H:%M:%S\"" -alh --quoting-style=c /home/pi/images/');
|
||||
return $raw_ls_output;
|
||||
}
|
||||
|
||||
function mod_date_from_ls($value){
|
||||
$ls_pieces = explode("\"", $value);
|
||||
if(count($ls_pieces)<1){
|
||||
return "";
|
||||
}
|
||||
return $ls_pieces[1];
|
||||
}
|
||||
function file_name_from_ls($value){
|
||||
$ls_pieces = explode("\"", $value);
|
||||
if(count($ls_pieces) < 4){
|
||||
return "";
|
||||
}
|
||||
return $ls_pieces[3];
|
||||
}
|
||||
function file_size_from_ls($value){
|
||||
$ls_pieces = explode("\"", $value);
|
||||
$file_props = preg_split("/\s+/", $ls_pieces[0]);
|
||||
return $file_props[4];
|
||||
}
|
||||
function file_category_from_file_name($value){
|
||||
if(strpos($value,".iso") > 0){
|
||||
return "CD-ROM Image";
|
||||
}
|
||||
if(strpos($value,".hda") > 0){
|
||||
return "Hard Disk Image";
|
||||
}
|
||||
return "Unknown type: " . $value;
|
||||
}
|
||||
?>
|
@ -8,7 +8,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<link rel="stylesheet" href="rascsi_styles.css">
|
||||
<script>
|
||||
function compute(f) {
|
||||
if (confirm("Are you sure?"))
|
||||
@ -40,141 +40,32 @@ function delete_file(f){
|
||||
}
|
||||
|
||||
</script>
|
||||
<style>h1{
|
||||
color:white;
|
||||
font-size:20px;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
background-color: black;
|
||||
}</style>
|
||||
<style>h2{
|
||||
color:black;
|
||||
font-size:16px;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
background-color: white;
|
||||
margin: 0px;
|
||||
}</style>
|
||||
</style>
|
||||
<style>body{
|
||||
color:black;
|
||||
font-family:Arial, Helvetica, sans-serif;
|
||||
background-color: white;
|
||||
}</style>
|
||||
<STYLE>A {text-decoration: none;} </STYLE>
|
||||
<style>table,tr,td {
|
||||
border: 1px solid black;
|
||||
border-collapse:collapse;
|
||||
margin: none;
|
||||
font-family:Arial, Helvetica, sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%" >
|
||||
<tr style="background-color: black;">
|
||||
<td style="background-color: black;"><a href=http://github.com/akuker/RASCSI><h1>RaSCSI - 68kmla Edition</h1></a></td>
|
||||
<td style="background-color: black;">
|
||||
<form action="/rascsi.php">
|
||||
<input type="submit" value="Refresh"/>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
echo "Debug timestamp:";
|
||||
$t=time();
|
||||
echo($t . "<br>");
|
||||
|
||||
include 'lib_rascsi.php';
|
||||
html_generate_header();
|
||||
|
||||
|
||||
// parameter check
|
||||
if(isset($_GET['restart_rascsi_service'])){
|
||||
// Restart the RaSCSI service
|
||||
echo 'exec("sudo systemctl restart rascsi.service");';
|
||||
exec("sudo /bin/systemctl restart rascsi.service");
|
||||
} else if(isset($_GET['stop_rascsi_service'])){
|
||||
// Stop the RaSCSI Service
|
||||
echo 'exec("sudo systemctl stop rascsi.service");';
|
||||
exec("sudo /bin/systemctl stop rascsi.service");
|
||||
} else if(isset($_GET['reboot_rasbperry_pi'])){
|
||||
// Reboot the Raspberry Pi
|
||||
echo 'exec("sudo shutdown -r -t 0");';
|
||||
exec("sudo /sbin/reboot");
|
||||
} else if(isset($_GET['shutdown_raspberry_pi'])){
|
||||
// Shut down the Raspberry Pi
|
||||
echo 'exec("sudo shutdown -s -t 0");';
|
||||
// Shut down the Raspberry Pi
|
||||
echo "<h1>For now, shutdown is disabled....</h1>";
|
||||
echo 'exec("sudo /sbin/shutdown -s -t 0");';
|
||||
}
|
||||
|
||||
current_rascsi_config();
|
||||
|
||||
|
||||
|
||||
function current_rascsi_config() {
|
||||
$raw_output = shell_exec("/usr/local/bin/rasctl -l");
|
||||
$rasctl_lines = explode(PHP_EOL, $raw_output);
|
||||
|
||||
echo ' <br>';
|
||||
echo ' <h2>Current RaSCSI Configuration</h2>';
|
||||
echo ' <table border="black">';
|
||||
echo ' <tr>';
|
||||
echo ' <td><b>SCSI ID</b></td>';
|
||||
echo ' <td><b>Type</b></td>';
|
||||
echo ' <td><b>Image File</b></td>';
|
||||
echo ' <td><b>Actions</b></td>';
|
||||
echo ' </tr>';
|
||||
|
||||
$scsi_ids = array();
|
||||
|
||||
foreach ($rasctl_lines as $current_line)
|
||||
{
|
||||
if(strlen($current_line) === 0){
|
||||
continue;
|
||||
}
|
||||
if(strpos($current_line, '+----') === 0){
|
||||
continue;
|
||||
|
||||
}
|
||||
if(strpos($current_line, '| ID | UN') === 0){
|
||||
continue;
|
||||
}
|
||||
$segments = explode("|", $current_line);
|
||||
|
||||
$id_config = array();
|
||||
$id_config['id'] = trim($segments[1]);
|
||||
$id_config['type'] = trim($segments[3]);
|
||||
$id_config['file'] = trim($segments[4]);
|
||||
|
||||
$scsi_ids[$id_config['id']] = $id_config;
|
||||
}
|
||||
|
||||
|
||||
foreach (range(0,7) as $id){
|
||||
echo ' <tr>';
|
||||
echo ' <form>';
|
||||
echo ' <td style="text-align:center">'.$id.'</td>';
|
||||
if(isset($scsi_ids[$id]))
|
||||
{
|
||||
echo ' <td style="text-align:center">'.$scsi_ids[$id]['type'].'</td>';
|
||||
echo ' <td>'.$scsi_ids[$id]['file'].'</td>';
|
||||
echo ' <td>';
|
||||
echo ' <input type="button" value="Eject" onClick="eject_image(\''.$id.'\',\''.$scsi_ids[$id]['file'].'\')"/>';
|
||||
echo ' <input type="button" value="Disconnect" onClick="remove_device('.$id.')"/>';
|
||||
echo ' </td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
echo ' <td style="text-align:center">-</td>';
|
||||
echo ' <td>-</td>';
|
||||
echo ' <td>';
|
||||
echo ' <input type="button" value="Connect New Device" onClick="attach_device('.$id.')"/>';
|
||||
echo ' </td>';
|
||||
|
||||
}
|
||||
echo ' </form>';
|
||||
echo ' </tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
function get_all_files()
|
||||
{
|
||||
$raw_ls_output = shell_exec('ls --time-style="+\"%Y-%m-%d %H:%M:%S\"" -alh --quoting-style=c /home/pi/images/');
|
||||
return $raw_ls_output;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<br>
|
||||
@ -184,26 +75,15 @@ function get_all_files()
|
||||
<tr style="border: none">
|
||||
<td style="border: none">SCSI ID:</td>
|
||||
<td style="border: none">
|
||||
<select>
|
||||
<option value="0">0</option>
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="3">3</option>
|
||||
<option value="4">4</option>
|
||||
<option value="5">5</option>
|
||||
<option value="6">6</option>
|
||||
<option value="7">7</option>
|
||||
</select>
|
||||
<?php
|
||||
html_generate_scsi_id_select_list();
|
||||
?>
|
||||
</td>
|
||||
<td style="border: none">Device:</td>
|
||||
<td style="border: none">
|
||||
<select>
|
||||
<option value="hard_disk">Hard Disk</option>
|
||||
<option value="cd_rom">CD-ROM</option>
|
||||
<option value="zip_drive" disabled>Zip Drive</option>
|
||||
<option value="ethernet_tap" disabled>Ethernet Tap</option>
|
||||
<option value="filesystem_bridge" disabled>Filesystem Bridge</option>
|
||||
</select>
|
||||
<?php
|
||||
html_generate_scsi_type_select_list();
|
||||
?>
|
||||
</td>
|
||||
<td style="border: none">File:</td>
|
||||
<td style="border: none">
|
||||
@ -211,7 +91,7 @@ function get_all_files()
|
||||
<?php
|
||||
$all_files = get_all_files();
|
||||
foreach(explode(PHP_EOL, $all_files) as $this_file){
|
||||
if(strpos($current_line, 'total') === 0){
|
||||
if(strpos($this_file, 'total') === 0){
|
||||
continue;
|
||||
}
|
||||
$file_name = file_name_from_ls($this_file);
|
||||
@ -225,29 +105,6 @@ function get_all_files()
|
||||
|
||||
echo '<option value="'.$file_name.'">'.$file_name.'</option>';
|
||||
}
|
||||
|
||||
function mod_date_from_ls($value){
|
||||
$ls_pieces = explode("\"", $value);
|
||||
return $ls_pieces[1];
|
||||
}
|
||||
function file_name_from_ls($value){
|
||||
$ls_pieces = explode("\"", $value);
|
||||
return $ls_pieces[3];
|
||||
}
|
||||
function file_size_from_ls($value){
|
||||
$ls_pieces = explode("\"", $value);
|
||||
$file_props = preg_split("/\s+/", $ls_pieces[0]);
|
||||
return $file_props[4];
|
||||
}
|
||||
function file_category_from_file_name($value){
|
||||
if(strpos($value,".iso") > 0){
|
||||
return "CD-ROM Image";
|
||||
}
|
||||
if(strpos($value,".hda") > 0){
|
||||
return "Hard Disk Image";
|
||||
}
|
||||
return "Unknown type: " . $value;
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
|
28
src/php/rascsi_styles.css
Normal file
28
src/php/rascsi_styles.css
Normal file
@ -0,0 +1,28 @@
|
||||
body {
|
||||
color: black;
|
||||
background-color: white;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
text-decoration:none;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: white;
|
||||
font-size:20px;
|
||||
background-color:black;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: black;
|
||||
font-size:16px;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
table, tr, td {
|
||||
border: 1px solid black;
|
||||
border-collapse:collapse;
|
||||
margin: none;
|
||||
}
|
Loading…
Reference in New Issue
Block a user