-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.php
81 lines (73 loc) · 1.98 KB
/
cmd.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
define("PROCESS_PATH", "/usr/local/bin/");
define("PROCESS_NAME1", "fddctl");
define("PROCESS_NAME2", "fddemu");
define("PROCESS_NAME3", "fdxconv");
$fddType = array("XDF", "HDM", "2HD", "DUP", "IMG", "DIM", "D68", "D88", "D77");
if(isset($_GET['cmd'])){
switch ($_GET['cmd']) {
case 'fddemu':
$output = array();
$ret = null;
exec("sudo ".PROCESS_PATH.PROCESS_NAME2." 2>/dev/null > /dev/null &");
sleep(1);
break;
case 'list':
$output = array();
$ret = null;
exec(PROCESS_PATH.PROCESS_NAME1." -l",$output,$ret);
echo json_encode($output);
break;
case 'insert':
// ファイルinsert
$command = PROCESS_PATH.PROCESS_NAME1.' -i '.$_GET['drive'].' -c insert '.$_GET['file'];
$output = array();
$ret = null;
exec($command, $output, $ret);
break;
case 'eject':
// ファイルeject
$command = PROCESS_PATH.PROCESS_NAME1.' -i '.$_GET['drive'].' -c eject';
$output = array();
$ret = null;
exec($command, $output, $ret);
break;
case 'dir':
$path = $_GET['path'];
$queue = array();
$type = array();
$other_file = array();
if($dir = opendir($path)) {
while(($file = readdir($dir)) !== false) {
$file_path = $path.$file;
// directory判別
if (is_dir($file_path) && $file != '.' && $file !='..') {
// $queue[$file] = 'DIR';
$queue[] = array('file'=>$file,'ext'=>'DIR','path'=>$path); //連想配列で格納
} else
if(is_file($file_path)) {
// file一覧(とりあえずサブディレクトリは無視)
$path_data = pathinfo($file);
$ext = strtoupper($path_data['extension']); //拡張子を取得して大文字に変換
$queue[] = array('file'=>$file,'ext'=>$ext,'path'=>$path); //連想配列で格納
/*
if($ext === 'FDX') {
$queue[$file] = 'FDX';
} else if(in_array($ext, $fddType)) {
//$other_file[] = $file;
$queue[$file] = 'OTH';
}
*/
}
}
}
closedir($dir);
// ksort($queue);
echo json_encode($queue);
break;
default:
break;
// cmd error
}
}
?>