Translated to Englished and fixed handling of files without an extension

This commit is contained in:
Tony Kuker 2020-07-25 21:40:03 -05:00
parent 3dc38ea959
commit 5794e56477
2 changed files with 78 additions and 74 deletions

View File

@ -1,6 +1,7 @@
MIT License MIT License
Copyright (c) 2019 ztto Copyright (c) 2019 ztto
Copyright (c) 2020 akuker
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -9,41 +9,41 @@ header( 'Cache-Control: post-check=0, pre-check=0', FALSE );
// HTTP/1.0 // HTTP/1.0
header( 'Pragma: no-cache' ); header( 'Pragma: no-cache' );
define("IMAGE_PATH", "/home/pi/rasimg/"); define("IMAGE_PATH", "/home/pi/");
define("PROCESS_PATH", "/usr/local/bin/"); define("PROCESS_PATH", "/usr/local/bin/");
define("PROCESS_NAME1", "rasctl"); define("PROCESS_NAME1", "rasctl");
define("PROCESS_NAME2", "rascsi"); define("PROCESS_NAME2", "rascsi");
// 初期設定 // Initial Settings
$hdType = array("HDS", "HDN", "HDI", "NHD", "HDA"); $hdType = array("HDS", "HDN", "HDI", "NHD", "HDA");
$moType = array("MOS"); $moType = array("MOS");
$cdType = array("ISO"); $cdType = array("ISO");
$path = IMAGE_PATH; $path = IMAGE_PATH;
// パラメタチェック // parameter check
if(isset($_GET['shutdown'])){ if(isset($_GET['shutdown'])){
// 電源断 // Power Down
exec("sudo shutdown now"); exec("sudo shutdown now");
} else if(isset($_GET['reboot'])){ } else if(isset($_GET['reboot'])){
// 再起動 // Reboot
exec("sudo shutdown -r now"); exec("sudo shutdown -r now");
} else if(isset($_GET['start'])){ } else if(isset($_GET['start'])){
// 起動 // Startup
$command = "sudo ".PROCESS_PATH.PROCESS_NAME2." 2>/dev/null"; $command = "sudo ".PROCESS_PATH.PROCESS_NAME2." 2>/dev/null";
exec($command . " > /dev/null &"); exec($command . " > /dev/null &");
// 1.0s // 1.0s
sleep(1); sleep(1);
// 情報表示 // Information Display
infoOut(); infoOut();
} else if(isset($_GET['stop'])){ } else if(isset($_GET['stop'])){
// 終了 // End
$command = "sudo pkill ".PROCESS_NAME2; $command = "sudo pkill ".PROCESS_NAME2;
$output = array(); $output = array();
$ret = null; $ret = null;
exec($command, $output, $ret); exec($command, $output, $ret);
// 0.5s // 0.5s
usleep(500000); usleep(500000);
// 情報表示 // Information Display
infoOut(); infoOut();
} else if(isset($_GET['param'])){ } else if(isset($_GET['param'])){
$param = $_GET['param']; $param = $_GET['param'];
@ -54,60 +54,60 @@ if(isset($_GET['shutdown'])){
$output = array(); $output = array();
$ret = null; $ret = null;
exec($command, $output, $ret); exec($command, $output, $ret);
// 情報表示 // File mount
infoOut(); infoOut();
} else if($param[0] === 'mountm') { } else if($param[0] === 'mountm') {
// ファイル接続 // File Connection
$path = $param[2]; $path = $param[2];
$command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c attach -t mo -f '.$param[2].$param[3]; $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c attach -t mo -f '.$param[2].$param[3];
$output = array(); $output = array();
$ret = null; $ret = null;
exec($command, $output, $ret); exec($command, $output, $ret);
// 情報表示 // Information Display
infoOut(); infoOut();
} else if($param[0] === 'mountc') { } else if($param[0] === 'mountc') {
// ファイル接続 // File connection
$path = $param[2]; $path = $param[2];
$command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c attach -t cd -f '.$param[2].$param[3]; $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c attach -t cd -f '.$param[2].$param[3];
$output = array(); $output = array();
$ret = null; $ret = null;
exec($command, $output, $ret); exec($command, $output, $ret);
// 情報表示 // Information Display
infoOut(); infoOut();
} else if($param[0] === 'umount') { } else if($param[0] === 'umount') {
// ファイル切断 // File disconnect
$command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c detatch -t hd'; $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c detatch -t hd';
$output = array(); $output = array();
$ret = null; $ret = null;
exec($command, $output, $ret); exec($command, $output, $ret);
// 情報表示 // Information Display
infoOut(); infoOut();
} else if($param[0] === 'insertm') { } else if($param[0] === 'insertm') {
// ファイル挿入 // Insert file
$command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c insert -t mo -f '.$param[2].$param[3]; $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c insert -t mo -f '.$param[2].$param[3];
$output = array(); $output = array();
$ret = null; $ret = null;
exec($command, $output, $ret); exec($command, $output, $ret);
// 情報表示 // Information Display
infoOut(); infoOut();
} else if($param[0] === 'insertc') { } else if($param[0] === 'insertc') {
// ファイル挿入 // Insert file
$command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c insert -t cd -f '.$param[2].$param[3]; $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c insert -t cd -f '.$param[2].$param[3];
$output = array(); $output = array();
$ret = null; $ret = null;
exec($command, $output, $ret); exec($command, $output, $ret);
// 情報表示 // Information Display
infoOut(); infoOut();
} else if($param[0] === 'eject') { } else if($param[0] === 'eject') {
// ファイル排出 // Eject file
$command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c eject'; $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c eject';
$output = array(); $output = array();
$ret = null; $ret = null;
exec($command, $output, $ret); exec($command, $output, $ret);
// 情報表示 // Information Display
infoOut(); infoOut();
} else if($param[0] === 'dir') { } else if($param[0] === 'dir') {
// ディレクトリ表示 // Directory display
$pos = strrpos($param[1], ".."); $pos = strrpos($param[1], "..");
if($pos !== false) { if($pos !== false) {
$pos1 = strrpos($param[1], "/", -5); $pos1 = strrpos($param[1], "/", -5);
@ -115,7 +115,7 @@ if(isset($_GET['shutdown'])){
} else { } else {
$path = $param[1]; $path = $param[1];
} }
// データ表示 // Data display
dataOut($path, $hdType, $moType, $cdType); dataOut($path, $hdType, $moType, $cdType);
} }
} else { } else {
@ -154,37 +154,37 @@ if(isset($_GET['shutdown'])){
echo ' }'; echo ' }';
echo '};'; echo '};';
echo '</script></head><body>'; echo '</script></head><body>';
// 情報表示 // Information Display
infoOut(); infoOut();
// SCSI操作 // SCSI Operation
echo '<p><div>Scsi取り外し/排出</div>'; echo '<p><div>Scsi Remove/Eject</div>';
scsiOut($path); scsiOut($path);
// データ表示 // Data display
echo '<p><div>Image操作</div>'; echo '<p><div>Image Operations</div>';
dataOut($path, $hdType, $moType, $cdType); dataOut($path, $hdType, $moType, $cdType);
// 起動/停止 // Start / Stop
// echo '<p><div>RASCSI 起動/停止</div>'; // echo '<p><div>RASCSI Start/Stop</div>';
// rascsiStartStop(); // rascsiStartStop();
// 再起動/電源断 // Reboot / Power down
echo '<p><div>Raspberry Pi 再起動/電源断</div>'; echo '<p><div>Raspberry Pi Reboot / Power down</div>';
raspiRebootShut(); raspiRebootShut();
} }
// 情報表示 // Information Display
function infoOut() { function infoOut() {
echo '<div id="info">'; echo '<div id="info">';
// プロセス確認 // Process confirmation
echo '<p><div>プロセス状況:'; echo '<p><div>Process status:';
$result = exec("ps -aef | grep ".PROCESS_NAME2." | grep -v grep", $output); $result = exec("ps -aef | grep ".PROCESS_NAME2." | grep -v grep", $output);
if(empty($output)) { if(empty($output)) {
echo '停止中</div>'; echo 'Stopping</div>';
} else { } else {
echo '起動中</div>'; echo 'Starting</div>';
$command = PROCESS_PATH.PROCESS_NAME1.' -l'; $command = PROCESS_PATH.PROCESS_NAME1.' -l';
$output = array(); $output = array();
$ret = null; $ret = null;
@ -196,14 +196,14 @@ function infoOut() {
echo '</div>'; echo '</div>';
} }
// SCSI操作 // SCSI Operation
function scsiOut() { function scsiOut() {
echo '<input type="radio" name="mode" onclick="chMode()" value="mu" checked>接続/切断'; echo '<input type="radio" name="mode" onclick="chMode()" value="mu" checked>Connect/Disconnect';
echo '<input type="radio" name="mode" onclick="chMode()" value="ie">挿入/排出'; echo '<input type="radio" name="mode" onclick="chMode()" value="ie">Insert/Eject';
echo '<table border="0">'; echo '<table border="0">';
echo '<tr>'; echo '<tr>';
// SCSI?排出/切断 // SCSI Eject / Disconnect
echo '<td>'; echo '<td>';
echo '<select id="ejectSelect">'; echo '<select id="ejectSelect">';
echo '<option value="0">SCSI0</option>'; echo '<option value="0">SCSI0</option>';
@ -215,9 +215,9 @@ function scsiOut() {
echo '</select>'; echo '</select>';
echo '</td>'; echo '</td>';
// SCSI?切断 // SCSI Disconnect
echo '<td>'; echo '<td>';
echo '<input type="button" class="mu" value="切断" onclick="'; echo '<input type="button" class="mu" value="Disconnect" onclick="';
echo 'var req = new XMLHttpRequest();'; echo 'var req = new XMLHttpRequest();';
echo 'req.onreadystatechange = function(){'; echo 'req.onreadystatechange = function(){';
echo ' if(req.readyState == 4){'; echo ' if(req.readyState == 4){';
@ -230,9 +230,9 @@ function scsiOut() {
echo 'req.send(null);"/>'; echo 'req.send(null);"/>';
echo '</td>'; echo '</td>';
// SCSI?排出 // SCSI Eject
echo '<td>'; echo '<td>';
echo '<input type="button" class="ie" value="排出" onclick="'; echo '<input type="button" class="ie" value="Eject" onclick="';
echo 'var req = new XMLHttpRequest();'; echo 'var req = new XMLHttpRequest();';
echo 'req.onreadystatechange = function(){'; echo 'req.onreadystatechange = function(){';
echo ' if(req.readyState == 4){'; echo ' if(req.readyState == 4){';
@ -249,13 +249,13 @@ function scsiOut() {
echo '</table>'; echo '</table>';
} }
// データ表示 // Data display
function dataOut($path, $hdType, $moType, $cdType) { function dataOut($path, $hdType, $moType, $cdType) {
$array_dir = array(); $array_dir = array();
$array_file1 = array(); $array_file1 = array();
$array_file2 = array(); $array_file2 = array();
$array_file3 = array(); $array_file3 = array();
// フォルダチェック // Folder Check
if($dir = opendir($path)) { if($dir = opendir($path)) {
while(($file = readdir($dir)) !== FALSE) { while(($file = readdir($dir)) !== FALSE) {
$file_path = $path.$file; $file_path = $path.$file;
@ -264,22 +264,25 @@ function dataOut($path, $hdType, $moType, $cdType) {
($file === '..')) { ($file === '..')) {
continue; continue;
} }
//ディレクトリを表示 //Show directory
if($file !== '.') { if($file !== '.') {
$array_dir[] = $file; $array_dir[] = $file;
} }
} else { } else {
//ファイルを表示 //Show files
$path_data = pathinfo($file); $path_data = pathinfo($file);
$ext = strtoupper($path_data['extension']); if(array_key_exists('extension',$path_data))
if(in_array($ext, $hdType)) { {
$array_file1[] = $file; $ext = strtoupper($path_data['extension']);
} if(in_array($ext, $hdType)) {
if(in_array($ext, $moType)) { $array_file1[] = $file;
$array_file2[] = $file; }
} if(in_array($ext, $moType)) {
if(in_array($ext, $cdType)) { $array_file2[] = $file;
$array_file3[] = $file; }
if(in_array($ext, $cdType)) {
$array_file3[] = $file;
}
} }
} }
} }
@ -292,10 +295,10 @@ function dataOut($path, $hdType, $moType, $cdType) {
echo '<table id="table" border="0">'; echo '<table id="table" border="0">';
foreach ($array_dir as $file) { foreach ($array_dir as $file) {
//ディレクトリを表示 //Show directory
echo '<tr>'; echo '<tr>';
echo '<td>'; echo '<td>';
echo '<input type="button" value="変更" onclick="'; echo '<input type="button" value="Change" onclick="';
echo 'var req = new XMLHttpRequest();'; echo 'var req = new XMLHttpRequest();';
echo 'req.onreadystatechange = function(){'; echo 'req.onreadystatechange = function(){';
echo ' if(req.readyState == 4){'; echo ' if(req.readyState == 4){';
@ -331,7 +334,7 @@ function dataOut($path, $hdType, $moType, $cdType) {
echo '</td>'; echo '</td>';
echo '<td>'; echo '<td>';
echo '<input type="button" class="mu" value="接続" onclick="'; echo '<input type="button" class="mu" value="Connect" onclick="';
echo 'var req = new XMLHttpRequest();'; echo 'var req = new XMLHttpRequest();';
echo 'req.onreadystatechange = function(){'; echo 'req.onreadystatechange = function(){';
echo ' if(req.readyState == 4){'; echo ' if(req.readyState == 4){';
@ -365,7 +368,7 @@ function dataOut($path, $hdType, $moType, $cdType) {
echo '</td>'; echo '</td>';
echo '<td>'; echo '<td>';
echo '<input type="button" class="mu" value="接続" onclick="'; echo '<input type="button" class="mu" value="Connect" onclick="';
echo 'var req = new XMLHttpRequest();'; echo 'var req = new XMLHttpRequest();';
echo 'req.onreadystatechange = function(){'; echo 'req.onreadystatechange = function(){';
echo ' if(req.readyState == 4){'; echo ' if(req.readyState == 4){';
@ -379,7 +382,7 @@ function dataOut($path, $hdType, $moType, $cdType) {
echo '</td>'; echo '</td>';
echo '<td>'; echo '<td>';
echo '<input type="button" class="ie" value="挿入" onclick="'; echo '<input type="button" class="ie" value="Insert" onclick="';
echo 'var req = new XMLHttpRequest();'; echo 'var req = new XMLHttpRequest();';
echo 'req.onreadystatechange = function(){'; echo 'req.onreadystatechange = function(){';
echo ' if(req.readyState == 4){'; echo ' if(req.readyState == 4){';
@ -413,7 +416,7 @@ function dataOut($path, $hdType, $moType, $cdType) {
echo '</td>'; echo '</td>';
echo '<td>'; echo '<td>';
echo '<input type="button" class="mu" value="接続" onclick="'; echo '<input type="button" class="mu" value="Connect" onclick="';
echo 'var req = new XMLHttpRequest();'; echo 'var req = new XMLHttpRequest();';
echo 'req.onreadystatechange = function(){'; echo 'req.onreadystatechange = function(){';
echo ' if(req.readyState == 4){'; echo ' if(req.readyState == 4){';
@ -427,7 +430,7 @@ function dataOut($path, $hdType, $moType, $cdType) {
echo '</td>'; echo '</td>';
echo '<td>'; echo '<td>';
echo '<input type="button" class="ie" value="挿入" onclick="'; echo '<input type="button" class="ie" value="Insert" onclick="';
echo 'var req = new XMLHttpRequest();'; echo 'var req = new XMLHttpRequest();';
echo 'req.onreadystatechange = function(){'; echo 'req.onreadystatechange = function(){';
echo ' if(req.readyState == 4){'; echo ' if(req.readyState == 4){';
@ -449,9 +452,9 @@ function dataOut($path, $hdType, $moType, $cdType) {
} }
} }
// 起動/停止 // Start / Stop
function rascsiStartStop() { function rascsiStartStop() {
// 起動 // Startup
echo '<input type="button" value="起動" onclick="'; echo '<input type="button" value="起動" onclick="';
echo 'var req = new XMLHttpRequest();'; echo 'var req = new XMLHttpRequest();';
echo 'req.onreadystatechange = function(){'; echo 'req.onreadystatechange = function(){';
@ -463,7 +466,7 @@ function rascsiStartStop() {
echo '};'; echo '};';
echo 'req.open(\'GET\',\'index.php?start=0\',true);'; echo 'req.open(\'GET\',\'index.php?start=0\',true);';
echo 'req.send(null);"/>'; echo 'req.send(null);"/>';
// 停止 // Stop
echo '<input type="button" value="停止" onclick="'; echo '<input type="button" value="停止" onclick="';
echo 'var req = new XMLHttpRequest();'; echo 'var req = new XMLHttpRequest();';
echo 'req.onreadystatechange = function(){'; echo 'req.onreadystatechange = function(){';
@ -477,10 +480,10 @@ function rascsiStartStop() {
echo 'req.send(null);"/>'; echo 'req.send(null);"/>';
} }
// 再起動/電源断 // Reboot / Power down
function raspiRebootShut() { function raspiRebootShut() {
// 再起動 // Reboot
echo '<input type="button" value="再起動" onclick="'; echo '<input type="button" value="Reboot" onclick="';
echo 'var req = new XMLHttpRequest();'; echo 'var req = new XMLHttpRequest();';
echo 'req.onreadystatechange = function(){'; echo 'req.onreadystatechange = function(){';
echo ' if(req.readyState == 4){'; echo ' if(req.readyState == 4){';
@ -491,8 +494,8 @@ function raspiRebootShut() {
echo '};'; echo '};';
echo 'req.open(\'GET\',\'index.php?reboot=0\',true);'; echo 'req.open(\'GET\',\'index.php?reboot=0\',true);';
echo 'req.send(null);"/>'; echo 'req.send(null);"/>';
// 電源断 // Power Down
echo '<input type="button" value="電源断" onclick="'; echo '<input type="button" value="Power off" onclick="';
echo 'var req = new XMLHttpRequest();'; echo 'var req = new XMLHttpRequest();';
echo 'req.onreadystatechange = function(){'; echo 'req.onreadystatechange = function(){';
echo ' if(req.readyState == 4){'; echo ' if(req.readyState == 4){';