mirror of
https://github.com/akuker/RASCSI.git
synced 2024-11-26 13:49:21 +00:00
Can now add, eject and disconnect devices
This commit is contained in:
parent
a30889f7c1
commit
a6d501b7e4
@ -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>
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="rascsi_styles.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>I guess I should add a device</h1>
|
<?php
|
||||||
</body>
|
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>
|
</html>
|
||||||
|
39
src/php/disconnect.php
Normal file
39
src/php/disconnect.php
Normal 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>
|
@ -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>
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="rascsi_styles.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
<body>
|
<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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$FILE_PATH='/home/pi/images';
|
||||||
|
|
||||||
function html_generate_header(){
|
function html_generate_header(){
|
||||||
echo ' <table width="100%" >';
|
echo ' <table width="100%" >';
|
||||||
@ -15,14 +16,12 @@ function html_generate_header(){
|
|||||||
echo ' <td style="background-color: black;">';
|
echo ' <td style="background-color: black;">';
|
||||||
echo ' <form action="/rascsi.php">';
|
echo ' <form action="/rascsi.php">';
|
||||||
echo ' <input type="submit" value="Refresh"/>';
|
echo ' <input type="submit" value="Refresh"/>';
|
||||||
|
echo ' <p style="color:white">'.time().'</p>';
|
||||||
echo ' </form>';
|
echo ' </form>';
|
||||||
echo ' </td>';
|
echo ' </td>';
|
||||||
echo ' </tr>';
|
echo ' </tr>';
|
||||||
echo ' </table>';
|
echo ' </table>';
|
||||||
echo 'Debug timestamp: ';
|
//echo(exec('whoami'));
|
||||||
$t=time();
|
|
||||||
echo($t . "<br>");
|
|
||||||
echo(exec('whoami'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function html_generate_scsi_id_select_list(){
|
function html_generate_scsi_id_select_list(){
|
||||||
@ -34,13 +33,41 @@ function html_generate_scsi_id_select_list(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function html_generate_scsi_type_select_list(){
|
function html_generate_scsi_type_select_list(){
|
||||||
echo '<select>';
|
echo '<select name=type>';
|
||||||
$options = array("Hard Disk", "CD-ROM", "Zip Drive", "Ethernet Tap", "Filesystem Bridge");
|
$options = array("Hard Disk", "CD-ROM", "Zip Drive", "Ethernet Tap", "Filesystem Bridge");
|
||||||
foreach($options as $type){
|
foreach($options as $type){
|
||||||
echo '<option value="'.$type.'">'.$type.'</option>';
|
echo '<option value="'.$type.'">'.$type.'</option>';
|
||||||
}
|
}
|
||||||
echo '</select>';
|
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() {
|
function current_rascsi_config() {
|
||||||
$raw_output = shell_exec("/usr/local/bin/rasctl -l");
|
$raw_output = shell_exec("/usr/local/bin/rasctl -l");
|
||||||
$rasctl_lines = explode(PHP_EOL, $raw_output);
|
$rasctl_lines = explode(PHP_EOL, $raw_output);
|
||||||
@ -98,7 +125,7 @@ function current_rascsi_config() {
|
|||||||
echo ' <td style="text-align:center">-</td>';
|
echo ' <td style="text-align:center">-</td>';
|
||||||
echo ' <td>-</td>';
|
echo ' <td>-</td>';
|
||||||
echo ' <td>';
|
echo ' <td>';
|
||||||
echo ' <input type="button" value="Connect New Device" onClick="attach_device('.$id.')"/>';
|
echo ' <input type="button" value="Connect New Device" onClick="add_device('.$id.')"/>';
|
||||||
echo ' </td>';
|
echo ' </td>';
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -109,7 +136,7 @@ function current_rascsi_config() {
|
|||||||
}
|
}
|
||||||
function get_all_files()
|
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/');
|
$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;
|
return $raw_ls_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,4 +168,25 @@ function file_category_from_file_name($value){
|
|||||||
}
|
}
|
||||||
return "Unknown type: " . $value;
|
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 "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -18,20 +18,23 @@ function compute(f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function eject_image(id,file){
|
function eject_image(id,file){
|
||||||
if(confirm("Not implemented yet.... would eject " + file + " from " + id))
|
var url = "eject.php?id=" + encodeURIComponent(id) + "&file=" + encodeURIComponent(file);
|
||||||
window.location = 'eject.php';
|
window.location.href = url;
|
||||||
}
|
}
|
||||||
function insert_image(id,file){
|
function insert_image(id,file){
|
||||||
if(confirm("Not implemented yet.... would insert " + file + " into " + id))
|
if(confirm("Not implemented yet.... would insert " + file + " into " + id))
|
||||||
alert("OK");
|
alert("OK");
|
||||||
}
|
}
|
||||||
function add_device(id){
|
function add_device(id){
|
||||||
if(confirm("Not implemented yet.... would add device id: " + id))
|
var url = "add_device.php?id=" + encodeURIComponent(id);
|
||||||
alert("OK");
|
window.location.href = url;
|
||||||
}
|
}
|
||||||
function remove_device(id){
|
function remove_device(id){
|
||||||
if(confirm("Not implemented yet.... would remove device id: " + id))
|
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";
|
||||||
alert("OK");
|
if(confirm(confirm_message)){
|
||||||
|
var url = "disconnect.php?id=" + encodeURIComponent(id);
|
||||||
|
window.location.href=url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_file(f){
|
function delete_file(f){
|
||||||
@ -69,61 +72,6 @@ function delete_file(f){
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<br>
|
<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">
|
|
||||||
<?php
|
|
||||||
html_generate_scsi_id_select_list();
|
|
||||||
?>
|
|
||||||
</td>
|
|
||||||
<td style="border: none">Device:</td>
|
|
||||||
<td style="border: none">
|
|
||||||
<?php
|
|
||||||
html_generate_scsi_type_select_list();
|
|
||||||
?>
|
|
||||||
</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($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>';
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</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>
|
<h2>Image File Management</h2>
|
||||||
<table border="black">
|
<table border="black">
|
||||||
<tr>
|
<tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user