From 3dc38ea9598087723e685378e0f2c66571203934 Mon Sep 17 00:00:00 2001 From: Tony Kuker Date: Sat, 25 Jul 2020 21:36:35 -0500 Subject: [PATCH] Baseline version of index.php from https://github.com/ztto/rascsi-php --- src/php/LICENSE | 21 ++ src/php/index.php | 509 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 530 insertions(+) create mode 100644 src/php/LICENSE create mode 100644 src/php/index.php diff --git a/src/php/LICENSE b/src/php/LICENSE new file mode 100644 index 00000000..e7c31cdf --- /dev/null +++ b/src/php/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 ztto + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/php/index.php b/src/php/index.php new file mode 100644 index 00000000..d478e0cf --- /dev/null +++ b/src/php/index.php @@ -0,0 +1,509 @@ +/dev/null"; + exec($command . " > /dev/null &"); + // 1.0s + sleep(1); + // 情報表示 + infoOut(); +} else if(isset($_GET['stop'])){ + // 終了 + $command = "sudo pkill ".PROCESS_NAME2; + $output = array(); + $ret = null; + exec($command, $output, $ret); + // 0.5s + usleep(500000); + // 情報表示 + infoOut(); +} else if(isset($_GET['param'])){ + $param = $_GET['param']; + if($param[0] === 'mounth') { + // ファイルマウント + $path = $param[2]; + $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c attach -t hd -f '.$param[2].$param[3]; + $output = array(); + $ret = null; + exec($command, $output, $ret); + // 情報表示 + infoOut(); + } else if($param[0] === 'mountm') { + // ファイル接続 + $path = $param[2]; + $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c attach -t mo -f '.$param[2].$param[3]; + $output = array(); + $ret = null; + exec($command, $output, $ret); + // 情報表示 + infoOut(); + } else if($param[0] === 'mountc') { + // ファイル接続 + $path = $param[2]; + $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c attach -t cd -f '.$param[2].$param[3]; + $output = array(); + $ret = null; + exec($command, $output, $ret); + // 情報表示 + infoOut(); + } else if($param[0] === 'umount') { + // ファイル切断 + $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c detatch -t hd'; + $output = array(); + $ret = null; + exec($command, $output, $ret); + // 情報表示 + infoOut(); + } else if($param[0] === 'insertm') { + // ファイル挿入 + $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c insert -t mo -f '.$param[2].$param[3]; + $output = array(); + $ret = null; + exec($command, $output, $ret); + // 情報表示 + infoOut(); + } else if($param[0] === 'insertc') { + // ファイル挿入 + $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c insert -t cd -f '.$param[2].$param[3]; + $output = array(); + $ret = null; + exec($command, $output, $ret); + // 情報表示 + infoOut(); + } else if($param[0] === 'eject') { + // ファイル排出 + $command = PROCESS_PATH.PROCESS_NAME1.' -i '.$param[1].' -c eject'; + $output = array(); + $ret = null; + exec($command, $output, $ret); + // 情報表示 + infoOut(); + } else if($param[0] === 'dir') { + // ディレクトリ表示 + $pos = strrpos($param[1], ".."); + if($pos !== false) { + $pos1 = strrpos($param[1], "/", -5); + $path = substr($param[1], 0, $pos1)."/"; + } else { + $path = $param[1]; + } + // データ表示 + dataOut($path, $hdType, $moType, $cdType); + } +} else { + echo ''; + echo ''; + // 情報表示 + infoOut(); + + // SCSI操作 + echo '

Scsi取り外し/排出
'; + scsiOut($path); + + // データ表示 + echo '

Image操作
'; + dataOut($path, $hdType, $moType, $cdType); + + // 起動/停止 +// echo '

RASCSI 起動/停止
'; +// rascsiStartStop(); + + // 再起動/電源断 + echo '

Raspberry Pi 再起動/電源断
'; + raspiRebootShut(); + +} + +// 情報表示 +function infoOut() { + echo '
'; + // プロセス確認 + echo '

プロセス状況:'; + $result = exec("ps -aef | grep ".PROCESS_NAME2." | grep -v grep", $output); + if(empty($output)) { + echo '停止中
'; + } else { + echo '起動中
'; + $command = PROCESS_PATH.PROCESS_NAME1.' -l'; + $output = array(); + $ret = null; + exec($command, $output, $ret); + foreach ($output as $line){ + echo '
'.$line.'
'; + } + } + echo ''; +} + +// SCSI操作 +function scsiOut() { + echo '接続/切断'; + echo '挿入/排出'; + + echo ''; + echo ''; + // SCSI?排出/切断 + echo ''; + + // SCSI?切断 + echo ''; + + // SCSI?排出 + echo ''; + + echo ''; + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'; +} + +// データ表示 +function dataOut($path, $hdType, $moType, $cdType) { + $array_dir = array(); + $array_file1 = array(); + $array_file2 = array(); + $array_file3 = array(); + // フォルダチェック + if($dir = opendir($path)) { + while(($file = readdir($dir)) !== FALSE) { + $file_path = $path.$file; + if(!is_file($file_path)) { + if(($path === IMAGE_PATH) && + ($file === '..')) { + continue; + } + //ディレクトリを表示 + if($file !== '.') { + $array_dir[] = $file; + } + } else { + //ファイルを表示 + $path_data = pathinfo($file); + $ext = strtoupper($path_data['extension']); + if(in_array($ext, $hdType)) { + $array_file1[] = $file; + } + if(in_array($ext, $moType)) { + $array_file2[] = $file; + } + if(in_array($ext, $cdType)) { + $array_file3[] = $file; + } + } + } + closedir($dir); + + sort($array_dir); + sort($array_file1); + sort($array_file2); + sort($array_file3); + + echo ''; + foreach ($array_dir as $file) { + //ディレクトリを表示 + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + $cnt = 0; + foreach ($array_file1 as $file) { + $cnt++; + echo ''; + echo ''; + + echo ''; + + echo ''; + echo ''; + } + + foreach ($array_file2 as $file) { + $cnt++; + echo ''; + echo ''; + + echo ''; + + echo ''; + + echo ''; + echo ''; + } + + foreach ($array_file3 as $file) { + $cnt++; + echo ''; + echo ''; + + echo ''; + + echo ''; + + echo ''; + echo ''; + } + echo '
'; + echo ''; + echo ''; + echo ''; + echo '
'.$file.'
'; + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'.$file.'
'; + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'.$file.'
'; + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'.$file.'
'; + echo '
'; + } +} + +// 起動/停止 +function rascsiStartStop() { + // 起動 + echo ''; + // 停止 + echo ''; +} + +// 再起動/電源断 +function raspiRebootShut() { + // 再起動 + echo ''; + // 電源断 + echo ''; + + echo ''; +} +?>