This commit is contained in:
Tony Kuker
2020-08-02 18:27:38 -05:00
48 changed files with 141920 additions and 200 deletions

View File

@@ -1,5 +1,107 @@
<!-- PHP source code for controlling the RaSCSI - 68kmla edition with a web interface. -->
<!-- Copyright (c) 2020 akuker -->
<!-- Distributed under the BSD-3 Clause License -->
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="rascsi_styles.css">
</head>
<body>
<h1>I guess I should add a device</h1>
</body>
<?php
include 'lib_rascsi.php';
html_generate_header();
// Check if we're passed an ID
if(isset($_GET['id'])){
$id = $_GET['id'];
}
else {
html_generate_warning('Page opened without arguments');
}
if(isset($_GET['type'])){
$type = type_string_to_rasctl_type($_GET['type']);
if(strlen($type) < 1){
html_generate_warning('Unknown drive type: '.$_GET['type']);
}
$cmd = 'rasctl -i '.$id.' -c attach -t '.$type;
// Check to see if the file name is specified
if(isset($_GET['file'])){
if(strcasecmp($_GET['file'],"None") != 0)
{
$cmd = $cmd.' -f '.$FILE_PATH.'/'.$_GET['file'];
}
}
$result = "Command not ran.....";
// Go do the actual action
if(strlen($type) > 0){
$result = exec($cmd);
echo '<br>';
echo 'Ran command: <pre>'.$cmd.'</pre>';
echo '<br>';
}
// Check to see if the command succeeded
if(strlen($result) > 0){
html_generate_warning($result);
}
else {
html_generate_success_message();
}
echo '<br>';
html_generate_ok_to_go_home();
}
else {
html_generate_add_new_device(trim($id));
}
function html_generate_add_new_device($id){
echo '<h2>Add New Device</h2>';
echo '<form action=add_device.php method="GET">';
echo ' <table style="border: none">';
echo ' <tr style="border: none">';
echo ' <td style="border: none">SCSI ID:</td>';
echo ' <td style="border: none">';
echo ' <input type="hidden" name=id value="'.$id.'"/>';
echo $id;
echo ' </td>';
echo ' <td style="border: none">Device:</td>';
echo ' <td style="border: none">';
html_generate_scsi_type_select_list();
echo ' </td>';
echo ' <td style="border: none">File:</td>';
echo ' <td style="border: none">';
echo ' <select name="file">';
echo ' <option value="None">None</option>';
$all_files = get_all_files();
foreach(explode(PHP_EOL, $all_files) as $this_file){
if(strpos($this_file, 'total') === 0){
continue;
}
$file_name = file_name_from_ls($this_file);
if(strlen($file_name) === 0){
continue;
}
// Ignore files that start with a .
if(strpos($file_name, '.') === 0){
continue;
}
echo '<option value="'.$file_name.'">'.$file_name.'</option>';
}
echo ' </select>';
echo ' </td>';
echo ' <td style="border: none">';
echo ' <INPUT type="submit" value="Add"/>';
echo ' </td>';
echo ' </tr>';
echo ' </table>';
}
?>
</body>
</html>

39
src/php/disconnect.php Normal file
View File

@@ -0,0 +1,39 @@
<!-- PHP source code for controlling the RaSCSI - 68kmla edition with a web interface. -->
<!-- Copyright (c) 2020 akuker -->
<!-- Distributed under the BSD-3 Clause License -->
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="rascsi_styles.css">
</head>
<body>
<?php
include 'lib_rascsi.php';
html_generate_header();
if(isset($_GET['id'])){
// If we're passed an ID, then we should disconnect that
// device.
$cmd = "rasctl -i ".$_GET['id']." -c detach";
$result = exec($cmd);
echo '<br>';
echo 'Ran command: <pre>'.$cmd.'</pre>';
echo '<br>';
// Check to see if the command succeeded
if(strlen($result) > 0){
html_generate_warning($result);
}
else {
html_generate_success_message();
}
}
else {
html_generate_warning('Page opened without arguments');
}
echo '<br>';
html_generate_ok_to_go_home();
?>
</body>
</html>

View File

@@ -1,5 +1,39 @@
<!-- PHP source code for controlling the RaSCSI - 68kmla edition with a web interface. -->
<!-- Copyright (c) 2020 akuker -->
<!-- Distributed under the BSD-3 Clause License -->
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="rascsi_styles.css">
</head>
<body>
<h1>I guess I should eject something</h1>
<?php
include 'lib_rascsi.php';
html_generate_header();
if(isset($_GET['id'])){
// If we're passed an ID, then we should eject that
// device.
$cmd = "rasctl -i ".$_GET['id']." -c eject";
$result = exec($cmd);
echo '<br>';
echo 'Ran command: <pre>'.$cmd.'</pre>';
echo '<br>';
// Check to see if the command succeeded
if(strlen($result) > 0){
html_generate_warning($result);
}
else {
html_generate_success_message();
}
}
else {
html_generate_warning('Page opened without arguments');
}
echo '<br>';
html_generate_ok_to_go_home();
?>
</body>
</html>

192
src/php/lib_rascsi.php Normal file
View File

@@ -0,0 +1,192 @@
<!-- 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
$FILE_PATH='/home/pi/images';
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 ' <p style="color:white">'.time().'</p>';
echo ' </form>';
echo ' </td>';
echo ' </tr>';
echo ' </table>';
//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 name=type>';
$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 html_generate_warning($message){
echo ' <table width="100%" >';
echo ' <tr style="background-color: red;">';
echo ' <td style="background-color: red;">';
echo ' <font size=+4>'.$message.'</font>';
echo ' </td>';
echo ' </tr>';
echo ' </table>';
}
function html_generate_success_message(){
echo ' <table width="100%" >';
echo ' <tr style="background-color: green;">';
echo ' <td style="background-color: green;">';
echo ' <font size=+2>Success!</font>';
echo ' </td>';
echo ' </tr>';
echo ' </table>';
}
function html_generate_ok_to_go_home(){
echo ' <form action="/rascsi.php">';
echo ' <input type="submit" value="OK"/>';
echo ' </form>';
}
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="add_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 '.$GLOBALS['FILE_PATH']);
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;
}
function type_string_to_rasctl_type($typestr){
if(strcasecmp($typestr,"Hard Disk") == 0){
return "hd";
}
if(strcasecmp($typestr,"CD-ROM") == 0){
return "cd";
}
if(strcasecmp($typestr,"Zip Drive") == 0){
}
if(strcasecmp($typestr,"Filesystem bridge") == 0){
return "bridge";
}
return "";
}
?>

View File

@@ -8,7 +8,7 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="rascsi_styles.css">
<script>
function compute(f) {
if (confirm("Are you sure?"))
@@ -18,236 +18,60 @@ function compute(f) {
}
function eject_image(id,file){
if(confirm("Not implemented yet.... would eject " + file + " from " + id))
window.location = 'eject.php';
var url = "eject.php?id=" + encodeURIComponent(id) + "&file=" + encodeURIComponent(file);
window.location.href = url;
}
function insert_image(id,file){
if(confirm("Not implemented yet.... would insert " + file + " into " + id))
alert("OK");
}
function add_device(id){
if(confirm("Not implemented yet.... would add device id: " + id))
alert("OK");
var url = "add_device.php?id=" + encodeURIComponent(id);
window.location.href = url;
}
function remove_device(id){
if(confirm("Not implemented yet.... would remove device id: " + id))
alert("OK");
confirm_message = "Are you sure you want to disconnect ID " + id + "? This may cause unexpected behavior on the host computer if it is still running";
if(confirm(confirm_message)){
var url = "disconnect.php?id=" + encodeURIComponent(id);
window.location.href=url;
}
}
function delete_file(f){
if(confirm("Are you sure you want to delete "+f+"?"))
alert("OK");
}
</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>';
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);
echo ' <tr>';
echo ' <form>';
echo ' <td>'.trim($segments[1]).'</td>';
echo ' <td>'.trim($segments[3]).'</td>';
echo ' <td>'.trim($segments[4]).'</td>';
echo ' <td>';
echo ' <input type="button" value="Eject" onClick="eject_image(\''.trim($segments[1]).'\',\''.trim($segments[4]).'\')"/>';
echo ' <input type="button" value="Disconnect" onClick="remove_device('.trim($segments[1]).')"/>';
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>
<h2>Add New Device</h2>
<form action=rascsi.php>
<table style="border: none">
<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>
</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>
</td>
<td style="border: none">File:</td>
<td style="border: none">
<select>
<?php
$all_files = get_all_files();
foreach(explode(PHP_EOL, $all_files) as $this_file){
if(strpos($current_line, 'total') === 0){
continue;
}
$file_name = file_name_from_ls($this_file);
if(strlen($file_name) === 0){
continue;
}
// Ignore files that start with a .
if(strpos($file_name, '.') === 0){
continue;
}
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>
<td style="border: none">
<INPUT type="submit" value="Add" onClick="add_device(1)"/>
</td>
</tr>
</table>
<br>
<form>
<input type=button value="asdf" onClick="compute(this.form)"><br>
</form>
<h2>Image File Management</h2>
<table border="black">
<tr>

28
src/php/rascsi_styles.css Normal file
View 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;
}