mirror of
https://github.com/akuker/RASCSI.git
synced 2024-11-26 13:49:21 +00:00
Added functionality to create a new, empty hd image.
This commit is contained in:
parent
86bf896d66
commit
377da587b7
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$FILE_PATH='/home/pi/images'. PHP_EOL;
|
$FILE_PATH='/home/pi/images';
|
||||||
|
|
||||||
function html_generate_header(){
|
function html_generate_header(){
|
||||||
echo ' <table width="100%" >'. PHP_EOL;
|
echo ' <table width="100%" >'. PHP_EOL;
|
||||||
@ -14,7 +14,7 @@ function html_generate_header(){
|
|||||||
echo ' <td style="background-color: black;"><a href=http://github.com/akuker/RASCSI><h1>RaSCSI - 68kmla Edition</h1></a></td>'. PHP_EOL;
|
echo ' <td style="background-color: black;"><a href=http://github.com/akuker/RASCSI><h1>RaSCSI - 68kmla Edition</h1></a></td>'. PHP_EOL;
|
||||||
echo ' <td style="background-color: black;">'. PHP_EOL;
|
echo ' <td style="background-color: black;">'. PHP_EOL;
|
||||||
echo ' <form action="rascsi.php">'. PHP_EOL;
|
echo ' <form action="rascsi.php">'. PHP_EOL;
|
||||||
echo ' <input type="submit" value="Refresh"/>'. PHP_EOL;
|
echo ' <input type="submit" value="Go Home"/>'. PHP_EOL;
|
||||||
echo ' <p style="color:white">'.time().'</p>'. PHP_EOL;
|
echo ' <p style="color:white">'.time().'</p>'. PHP_EOL;
|
||||||
echo ' </form>'. PHP_EOL;
|
echo ' </form>'. PHP_EOL;
|
||||||
echo ' </td>'. PHP_EOL;
|
echo ' </td>'. PHP_EOL;
|
||||||
|
@ -9,43 +9,6 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" href="rascsi_styles.css">
|
<link rel="stylesheet" href="rascsi_styles.css">
|
||||||
<script>
|
|
||||||
function compute(f) {
|
|
||||||
if (confirm("Are you sure?"))
|
|
||||||
alert("Yes");
|
|
||||||
else
|
|
||||||
alert("No");
|
|
||||||
}
|
|
||||||
|
|
||||||
function eject_image(id, file) {
|
|
||||||
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) {
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -86,19 +49,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
echo '<tr>';
|
echo '<tr>'.PHP_EOL;
|
||||||
echo ' <form>';
|
echo ' <td>SD Card</td>'.PHP_EOL;
|
||||||
echo ' <td>SD Card</td>';
|
echo ' <td>'.$file_name.'</td>'.PHP_EOL;
|
||||||
echo ' <td>'.$file_name.'</td>';
|
echo ' <td>'.file_size_from_ls($this_file).'</td>'.PHP_EOL;
|
||||||
echo ' <td>'.file_size_from_ls($this_file).'</td>';
|
echo ' <td>'.file_category_from_file_name($file_name).'</td>'.PHP_EOL;
|
||||||
echo ' <td>'.file_category_from_file_name($file_name).'</td>';
|
echo ' <td>'.mod_date_from_ls($this_file).'</td>'.PHP_EOL;
|
||||||
echo ' <td>'.mod_date_from_ls($this_file).'</td>';
|
echo ' <td>'.PHP_EOL;
|
||||||
echo ' <td>';
|
echo ' <form action="rascsi_action.php" method="post">'.PHP_EOL;
|
||||||
echo ' <input type="button" value="Delete" onClick="delete_file(\''.$file_name.'\')" data-arg1="'.$file_name.'"/>';
|
echo ' <input type="hidden" name="command" value="delete_file"/>'.PHP_EOL;
|
||||||
echo ' <input type="button" value="Copy to RAM Disk" disabled/>';
|
echo ' <input type="hidden" name="file_name" value="'.$file_name.'"/>'.PHP_EOL;
|
||||||
echo ' </td>';
|
echo ' <input type="submit" value="Delete">'.PHP_EOL;
|
||||||
echo ' </form>';
|
echo ' </form>'.PHP_EOL;
|
||||||
echo '</tr>';
|
echo ' </td>'.PHP_EOL;
|
||||||
|
echo '</tr>'.PHP_EOL;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</table>
|
</table>
|
||||||
|
@ -13,15 +13,20 @@
|
|||||||
include 'lib_rascsi.php';
|
include 'lib_rascsi.php';
|
||||||
html_generate_header();
|
html_generate_header();
|
||||||
|
|
||||||
echo "Post values......................".PHP_EOL;
|
echo '<br>';
|
||||||
|
echo '<table>'.PHP_EOL;
|
||||||
|
echo ' <tr><td><p style="color:gray">Debug stuff</p></td></tr>'.PHP_EOL;
|
||||||
|
echo ' <tr><td>';
|
||||||
|
|
||||||
|
echo '<p style="color:gray">Post values......................'.PHP_EOL;
|
||||||
echo '<br> '.PHP_EOL;
|
echo '<br> '.PHP_EOL;
|
||||||
var_dump($_POST);
|
var_dump($_POST);
|
||||||
echo '<br>'.PHP_EOL;
|
echo '<br><br>Running command.... '.$_POST['command'].PHP_EOL;
|
||||||
|
echo '<br></p>'.PHP_EOL;
|
||||||
|
echo '</td></tr></table>';
|
||||||
|
|
||||||
if(isset($_POST['command']))
|
if(isset($_POST['command']))
|
||||||
{
|
{
|
||||||
echo 'Running command.... '.$_POST['command'].'<br><br>'.PHP_EOL;
|
|
||||||
switch(strtolower($_POST['command'])){
|
switch(strtolower($_POST['command'])){
|
||||||
case "eject_disk":
|
case "eject_disk":
|
||||||
action_eject_disk();
|
action_eject_disk();
|
||||||
@ -139,15 +144,54 @@ function action_remove_device(){
|
|||||||
}
|
}
|
||||||
// function action_connect_new_device(){}
|
// function action_connect_new_device(){}
|
||||||
function action_insert_disk(){}
|
function action_insert_disk(){}
|
||||||
function action_create_new_image(){}
|
function action_create_new_image(){
|
||||||
function action_delete_file(){
|
// If we already know the size & filename, we can go create the image...
|
||||||
// Check to see if the user has confirmed
|
if(isset($_POST['size']) && isset($_POST['file_name'])){
|
||||||
if(isset($_POST['confirmed'])){
|
$command = 'dd if=/dev/zero of='.$GLOBALS['FILE_PATH'].'/'.$_POST['file_name'].' bs=1M count='.$_POST['size'];
|
||||||
echo '<br>exec(rm '.$_POST['file'].')'.PHP_EOL;
|
exec($command, $retArray, $result);
|
||||||
|
echo '<br><br>'.$command.'<br><br>';
|
||||||
|
check_result($result, $command, $retArray);
|
||||||
html_generate_ok_to_go_home();
|
html_generate_ok_to_go_home();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
check_are_you_sure('Are you sure you want to PERMANENTLY delete '.$_POST['file'].'?');
|
echo '<h2>Create a new empty file</h2>'.PHP_EOL;
|
||||||
|
echo '<form action=rascsi_action.php method="post">'.PHP_EOL;
|
||||||
|
echo ' <input type="hidden" name="command" value="'.$_POST['command'].'"/>'.PHP_EOL;
|
||||||
|
echo ' <table style="border: none">'.PHP_EOL;
|
||||||
|
echo ' <tr style="border: none">'.PHP_EOL;
|
||||||
|
echo ' <td style="border: none">File Name:</td>'.PHP_EOL;
|
||||||
|
echo ' <td style="border: none">'.PHP_EOL;
|
||||||
|
echo ' <input type="text" name=file_name value="'.get_new_filename().'"/>'.PHP_EOL;
|
||||||
|
echo ' </td>'.PHP_EOL;
|
||||||
|
echo ' <td style="border: none"> Size:</td>'.PHP_EOL;
|
||||||
|
echo ' <td style="border: none">'.PHP_EOL;
|
||||||
|
echo ' <input type="number" name=size value="10""/>'.PHP_EOL;
|
||||||
|
echo ' </td>'.PHP_EOL;
|
||||||
|
echo ' <td style="border: none">MB</td>'.PHP_EOL;
|
||||||
|
echo ' <td style="border: none">'.PHP_EOL;
|
||||||
|
echo ' <input type="submit" name="create" value="Create New" />'.PHP_EOL;
|
||||||
|
echo ' </td>'.PHP_EOL;
|
||||||
|
echo ' </tr>'.PHP_EOL;
|
||||||
|
echo ' </table>'.PHP_EOL;
|
||||||
|
echo '</form>'.PHP_EOL;
|
||||||
|
echo '<br><i>Note: Creating a large file may take a long time!</i>'.PHP_EOL;
|
||||||
|
echo '<br><br>'.PHP_EOL;
|
||||||
|
echo '<form action="rascsi.php" method="post">'.PHP_EOL;
|
||||||
|
echo ' <input type="submit" name="cancel" value="Cancel" />'.PHP_EOL;
|
||||||
|
echo '</form>'.PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function action_delete_file(){
|
||||||
|
// Check to see if the user has confirmed
|
||||||
|
if(isset($_POST['confirmed'])){
|
||||||
|
$command = 'rm '.$GLOBALS['FILE_PATH'].'/'.$_POST['file_name'];
|
||||||
|
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 PERMANENTLY delete '.$_POST['file_name'].'?');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,18 +241,20 @@ function action_unknown_command(){
|
|||||||
|
|
||||||
function check_result($result,$command,$output){
|
function check_result($result,$command,$output){
|
||||||
if(!$result){
|
if(!$result){
|
||||||
echo '<br><h2>Command succeeded!<h2>'.PHP_EOL;
|
echo '<br><h2>Command succeeded!</h2>'.PHP_EOL;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
echo '<br><h2>Command failed!</h2>'.PHP_EOL;
|
echo '<br><h2>Command failed!</h2>'.PHP_EOL;
|
||||||
}
|
}
|
||||||
echo '<br><code>'.$command.'</code>'.PHP_EOL;
|
echo '<br><code>'.$command.'</code><br>'.PHP_EOL;
|
||||||
|
if(count($output) > 0){
|
||||||
echo '<br>Output:<code>'.PHP_EOL;
|
echo '<br>Output:<code>'.PHP_EOL;
|
||||||
foreach($output as $line){
|
foreach($output as $line){
|
||||||
echo '<br> Error message: '.$line.PHP_EOL;
|
echo '<br> Error message: '.$line.PHP_EOL;
|
||||||
}
|
}
|
||||||
echo '</code>'.PHP_EOL;
|
echo '</code>'.PHP_EOL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function check_are_you_sure($prompt){
|
function check_are_you_sure($prompt){
|
||||||
echo '<br><h2>'.$prompt.'</h2>'.PHP_EOL;
|
echo '<br><h2>'.$prompt.'</h2>'.PHP_EOL;
|
||||||
@ -225,7 +271,7 @@ function check_are_you_sure($prompt){
|
|||||||
echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>'.PHP_EOL;
|
echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>'.PHP_EOL;
|
||||||
}
|
}
|
||||||
echo ' <input type="hidden" name="confirmed" value="yes" />'.PHP_EOL;
|
echo ' <input type="hidden" name="confirmed" value="yes" />'.PHP_EOL;
|
||||||
echo ' <input type="submit" name="do_it" value="Do it!" />'.PHP_EOL;
|
echo ' <input type="submit" name="do_it" value="Yes" />'.PHP_EOL;
|
||||||
echo ' </form>'.PHP_EOL;
|
echo ' </form>'.PHP_EOL;
|
||||||
echo ' </td>'.PHP_EOL;
|
echo ' </td>'.PHP_EOL;
|
||||||
echo ' </tr>'.PHP_EOL;
|
echo ' </tr>'.PHP_EOL;
|
||||||
@ -276,6 +322,17 @@ function action_connect_new_device(){
|
|||||||
echo ' </tr>'.PHP_EOL;
|
echo ' </tr>'.PHP_EOL;
|
||||||
echo ' </table>'.PHP_EOL;
|
echo ' </table>'.PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_new_filename(){
|
||||||
|
// Try to find a new file name that doesn't exist.
|
||||||
|
$i=1;
|
||||||
|
while(file_exists($GLOBALS['FILE_PATH'].'/'.'new_file'.$i.'.hda'))
|
||||||
|
{
|
||||||
|
$i = $i+1;
|
||||||
|
}
|
||||||
|
return 'new_file'.$i.'.hda';
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user