-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
111 lines (109 loc) · 2.74 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Encfs</title>
<style>
.umountForm{
display: inline-block;
margin-right: 15px;
}
.forms input[type="submit"]{
width: 100%;
}
.mountList li{
list-style-type: none;
}
.mountList{
padding-left: 0px;
white-space: nowrap;
}
</style>
</head>
<body>
<form method="POST" id="mount"></form>
<form method="POST" id="umount"></form>
<table class="forms">
<tr>
<td>Name of dir: </td>
<td><input type="text" name="name" required form="mount"/></td>
</tr>
<tr>
<td>Pass: </td>
<td><input type="password" name="pass" required form="mount"/></td>
</tr>
<tr>
<td>
<input type="hidden" name="umountAll" value="on" form="umount"/>
<input type="submit" value="all unmount" form="umount"/>
</td>
<td>
<input type="submit" value="mount" form="mount"/>
</td>
</tr>
</table>
<?php
$decryptDirs = "/var/www/example.com/public_html/DIR_WITH_THIS_SCRIPT/decrypt/";
$encryptDirs = array( //Name of dir's
"first" => "/mnt/abc/encrypted/",
"second" => "/path/to/encrypted/direction",
);
function randomString($length) {
$str = "";
$characters = array_merge(range('A','Z'), range('a','z'), range('0','9'));
$max = count($characters) - 1;
for ($i = 0; $i < $length; $i++) {
$rand = random_int(0, $max);
$str .= $characters[$rand];
}
return $str;
}
if(!empty($_POST["pass"])){
if(!array_key_exists($_POST["name"], $encryptDirs)){
echo "Error while mounting";//Not found directory
}else{
$dirName = randomString(64);
mkdir($decryptDirs.$dirName, 0700);
shell_exec('echo "'.$_POST["pass"].'" | encfs -S '.$encryptDirs[$_POST["name"]].' '.$decryptDirs.$dirName);
$checkMount = shell_exec('mount | grep "'.$decryptDirs.$dirName.'"');
if(empty($checkMount)){
rmdir($decryptDirs.$dirName);
echo "Error while mounting";
}else{
$_SESSION['decryptDirs'][] = $dirName;
}
}
}
if($_POST["umountAll"] == 'on'){
foreach($_SESSION['decryptDirs'] as $dir){
shell_exec('fusermount -u '.$decryptDirs.$dir);
rmdir($decryptDirs.$dir);
}
unset($_SESSION['decryptDirs']);
}
if(!empty($_POST["umount"])){
foreach($_SESSION['decryptDirs'] as $key => $dir){
if($dir == $_POST["umount"]){
shell_exec('fusermount -u '.$decryptDirs.$dir);
rmdir($decryptDirs.$dir);
unset($_SESSION['decryptDirs'][$key]);
break;
}
}
}
?>
<ul class="mountList">
<?php
if(!empty($_SESSION['decryptDirs'])){
foreach($_SESSION['decryptDirs'] as $temp){
echo '<li><form class="umountForm" method="POST"><input type="hidden" name="umount" value="'.$temp.'"/><input type="submit" value="x"/></form><a href="decrypt/'.$temp.'">'.$temp.'</a></li>';
}
}
?>
</ul>
</body>
</html>