From c3e8204542012d0a7bb228c195af11fc251019c6 Mon Sep 17 00:00:00 2001 From: akuker Date: Fri, 7 Aug 2020 11:34:07 -0500 Subject: [PATCH] Started moving actions into a single php file to simplify things --- src/php/lib_rascsi.php | 137 ++++++++++--------- src/php/rascsi.php | 162 ++++++++++++---------- src/php/rascsi_action.php | 279 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 443 insertions(+), 135 deletions(-) create mode 100644 src/php/rascsi_action.php diff --git a/src/php/lib_rascsi.php b/src/php/lib_rascsi.php index 52cecf2c..28476e60 100644 --- a/src/php/lib_rascsi.php +++ b/src/php/lib_rascsi.php @@ -1,4 +1,3 @@ - @@ -7,64 +6,64 @@ '; - echo ' '; - echo '

RaSCSI - 68kmla Edition

'; - echo ' '; - echo '
'; - echo ' '; - echo '

'.time().'

'; - echo '
'; - echo ' '; - echo ' '; - echo ' '; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo '

RaSCSI - 68kmla Edition

'. PHP_EOL; + echo '
'. PHP_EOL; + echo ' '. PHP_EOL; + echo '

'.time().'

'. PHP_EOL; + echo '
'. PHP_EOL; + echo '
'. PHP_EOL; //echo(exec('whoami')); } function html_generate_scsi_id_select_list(){ - echo ''. PHP_EOL; foreach(range(0,7) as $id){ - echo ''; + echo ''. PHP_EOL; } - echo ''; + echo ''. PHP_EOL; } function html_generate_scsi_type_select_list(){ - echo ''. PHP_EOL; $options = array("Hard Disk", "CD-ROM", "Zip Drive", "Ethernet Tap", "Filesystem Bridge"); foreach($options as $type){ - echo ''; + echo ''. PHP_EOL; } - echo ''; + echo ''. PHP_EOL; } function html_generate_warning($message){ - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo '
'; - echo ' '.$message.''; - echo '
'; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo '
'. PHP_EOL; + echo ' '.$message.''. PHP_EOL; + echo '
'. PHP_EOL; } function html_generate_success_message(){ - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo '
'; - echo ' Success!'; - echo '
'; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo '
'. PHP_EOL; + echo ' Success!'. PHP_EOL; + echo '
'. PHP_EOL; } function html_generate_ok_to_go_home(){ - echo '
'; - echo ' '; - echo '
'; + echo '
'. PHP_EOL; + echo ' '. PHP_EOL; + echo '
'. PHP_EOL; } @@ -72,15 +71,15 @@ function current_rascsi_config() { $raw_output = shell_exec("/usr/local/bin/rasctl -l"); $rasctl_lines = explode(PHP_EOL, $raw_output); - echo '
'; - echo '

Current RaSCSI Configuration

'; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; + echo '
'. PHP_EOL; + echo '

Current RaSCSI Configuration

'. PHP_EOL; + echo '
SCSI IDTypeImage FileActions
'. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; $scsi_ids = array(); @@ -108,31 +107,43 @@ function current_rascsi_config() { foreach (range(0,7) as $id){ - echo ' '; - echo ' '; - echo ' '; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; if(isset($scsi_ids[$id])) { - echo ' '; - echo ' '; - echo ' '; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; } else { - echo ' '; - echo ' '; - echo ' '; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; } - echo ' '; - echo ' '; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; } - echo '
SCSI IDTypeImage FileActions
'.$id.'
'.$id.''.$scsi_ids[$id]['type'].''.$scsi_ids[$id]['file'].''; - echo ' '; - echo ' '; - echo ' '.$scsi_ids[$id]['type'].''.$scsi_ids[$id]['file'].''. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo '
'. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo '
'. PHP_EOL; + echo '
--'; - echo ' '; - echo ' --'. PHP_EOL; + echo '
'. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo ' '. PHP_EOL; + echo '
'. PHP_EOL; + echo '
'; + echo ''. PHP_EOL; } function get_all_files() { @@ -189,4 +200,4 @@ function type_string_to_rasctl_type($typestr){ -?> +?> \ No newline at end of file diff --git a/src/php/rascsi.php b/src/php/rascsi.php index 5090682b..f412e977 100644 --- a/src/php/rascsi.php +++ b/src/php/rascsi.php @@ -1,4 +1,3 @@ - @@ -7,71 +6,58 @@ - - - - - + function add_device(id) { + var url = "add_device.php?id=" + encodeURIComponent(id); + window.location.href = url; + } + + function remove_device(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"; + 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"); + } + + + + For now, shutdown is disabled...."; - echo 'exec("sudo /sbin/shutdown -s -t 0");'; - } - current_rascsi_config(); ?> -
+

Image File Management

@@ -82,8 +68,8 @@ function delete_file(f){ - - + '; - echo ' '; + echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; - echo ' '; - echo ''; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ''; } ?>
Date Modified Actions
SD Card'.$file_name.''.file_size_from_ls($this_file).''.file_category_from_file_name($file_name).''.mod_date_from_ls($this_file).''; - echo ' '; - echo ' '; - echo '
@@ -135,18 +121,50 @@ function delete_file(f){
-

RaSCSI Service Status

-
- - +

Create New Empty HD Image

+ + +

-

Raspberry Pi Operations

-
- - -
+

RaSCSI Service Status

+ + + + + +
+
+ + +
+
+
+ + +
+
- - +
+

Raspberry Pi Operations

+ + + + + +
+
+ + +
+
+
+ + +
+
+ + + + \ No newline at end of file diff --git a/src/php/rascsi_action.php b/src/php/rascsi_action.php new file mode 100644 index 00000000..ae94d76c --- /dev/null +++ b/src/php/rascsi_action.php @@ -0,0 +1,279 @@ + + + + + + + + + + +'.PHP_EOL; + var_dump($_POST); + echo '
'.PHP_EOL; + + + if(isset($_POST['command'])) + { + echo 'Running command.... '.$_POST['command'].'

'.PHP_EOL; + switch(strtolower($_POST['command'])){ + case "eject_disk": + action_eject_disk(); + break; + case "remove_device": + action_remove_device(); + break; + case "connect_new_device": + action_connect_new_device(); + break; + case "insert_disk": + action_insert_disk(); + break; + case "delete_file": + action_delete_file(); + break; + case "create_new_image": + action_create_new_image(); + break; + case "restart_rascsi_service": + action_restart_rascsi_service(); + break; + case "stop_rascsi_service": + action_stop_rascsi_service(); + break; + case "reboot_raspberry_pi": + action_reboot_raspberry_pi(); + break; + case "shutdown_raspberry_pi": + action_shutdown_raspberry_pi(); + break; + default: + action_unknown_command(); + break; + } + } + +// // parameter check +// if(isset($_GET['restart_rascsi_service'])){ +// // Restart the RaSCSI service +// exec("sudo /bin/systemctl restart rascsi.service"); +// } else if(isset($_GET['stop_rascsi_service'])){ +// // Stop the RaSCSI Service +// exec("sudo /bin/systemctl stop rascsi.service"); +// } else if(isset($_GET['reboot_rasbperry_pi'])){ +// // Reboot the Raspberry Pi +// exec("sudo /sbin/reboot"); +// } else if(isset($_GET['shutdown_raspberry_pi'])){ +// // Shut down the Raspberry Pi +// echo "

For now, shutdown is disabled....

"; +// echo 'exec("sudo /sbin/shutdown -s -t 0");'; +// } + + + // // 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 '
'; + // echo 'Ran command:
'.$cmd.'
'; + // echo '
'; + // } + // // Check to see if the command succeeded + // if(strlen($result) > 0){ + // html_generate_warning($result); + // } + // else { + // html_generate_success_message(); + // } + // echo '
'; + // html_generate_ok_to_go_home(); + // } + // else { + // html_generate_add_new_device(trim($id)); + + + +function action_eject_disk(){} +function action_remove_device(){ + // Check to see if the user has confirmed + if(isset($_POST['confirmed'])){ + $command = 'rasctl -i '.$_POST['id'].' -c disconnect 2>&1'; + echo '

Go execute...... '.$command.PHP_EOL; + // exec($command, $retArray, $result); + // check_result($result, $command,$retArray); + html_generate_ok_to_go_home(); + } + else{ + 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.'); + } +} +// function action_connect_new_device(){} +function action_insert_disk(){} +function action_create_new_image(){} +function action_delete_file(){ + // Check to see if the user has confirmed + if(isset($_POST['confirmed'])){ + echo '
exec(rm '.$_POST['file'].')'.PHP_EOL; + html_generate_ok_to_go_home(); + } + else{ + check_are_you_sure('Are you sure you want to PERMANENTLY delete '.$_POST['file'].'?'); + } +} + +function action_restart_rascsi_service(){ + // Restart the RaSCSI service + $command = "sudo /bin/systemctl restart rascsi.service 2>&1"; + exec($command, $retArray, $result); + check_result($result, $command,$retArray); + html_generate_ok_to_go_home(); +} + +function action_stop_rascsi_service(){ + // Stop the RaSCSI service + $command = "sudo /bin/systemctl stop rascsi.service 2>&1"; + exec($command, $retArray, $result); + check_result($result, $command,$retArray); + html_generate_ok_to_go_home(); +} + +function action_reboot_raspberry_pi(){ + // Check to see if the user has confirmed + if(isset($_POST['confirmed'])){ + echo('
exec(sudo reboot)'); + // The unit should reboot at this point. Doesn't matter what we do now... + } + else{ + check_are_you_sure("Are you sure you want to reboot the Raspberry Pi?"); + } +} + +function action_shutdown_raspberry_pi(){ + // Check to see if the user has confirmed + if(isset($_POST['confirmed'])){ + echo('
exec(sudo shutdown -h now)'); + // The unit should reboot at this point. Doesn't matter what we do now... + html_generate_ok_to_go_home(); + } + else{ + check_are_you_sure("Are you sure you want to shut down the Raspberry Pi?"); + } +} + +function action_unknown_command(){ + echo '

Unknown command: '.$_POST['command'].'

'.PHP_EOL; + html_generate_ok_to_go_home(); +} + +function check_result($result,$command,$output){ + if(!$result){ + echo '

Command succeeded!

'.PHP_EOL; + } + else{ + echo '

Command failed!

'.PHP_EOL; + } + echo '
'.$command.''.PHP_EOL; + echo '
Output:'.PHP_EOL; + foreach($output as $line){ + echo '
Error message: '.$line.PHP_EOL; + } + echo '
'.PHP_EOL; +} + +function check_are_you_sure($prompt){ + echo '

'.$prompt.'

'; + echo ' '.PHP_EOL; + echo ' '.PHP_EOL; + echo ' '.PHP_EOL; + echo ' '.PHP_EOL; + echo ' '.PHP_EOL; + echo '
'.PHP_EOL; + echo '
'.PHP_EOL; + echo ' '.PHP_EOL; + echo '
'.PHP_EOL; + echo '
'.PHP_EOL; + echo '
'.PHP_EOL; + foreach($_POST as $key => $value){ + echo ''.PHP_EOL; + } + echo ' '.PHP_EOL; + echo ' '.PHP_EOL; + echo '
'.PHP_EOL; + echo '
'.PHP_EOL; +} + +function action_connect_new_device($id){ + echo '

Add New Device

'; + echo '
'; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo '
SCSI ID:'; + echo ' '; + echo $id; + echo ' Device:'; + html_generate_scsi_type_select_list(); + echo ' File:'; + echo ' '; + echo ' '; + echo ' '; + echo '
'; +} +?> + + +