~vierbergenlars/sqlfs/1.x

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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
include('lib/mysqlfs.php');
$sqlfs=new mysqlfs(new mysqli('localhost','root','','sqlfs_v2'),'index');
$sqlfs->setuser('admin',9); //User admin, group 9
$sqlfs->valid_user('return true;'); //Allow every username
if(!isset($_GET['path'])) $_GET['path']='/';
$show_dir=false;
$show_file=false;
if(isset($_GET['action'])) {
	if($_GET['action']=="delete") {
		if($sqlfs->is_dir($_GET['path'])) {
			if($sqlfs->rmdir($_GET['path'])) {
				echo "Map gewist";
			}
			else {
				echo "Fout bij map wissen";
			}

		}
		else {
			if($sqlfs->unlink($_GET['path'])) {
				echo "Bestand gewist";
			}
			else {
				echo "Fout bij bestand wissen";
			}
		}
	$_GET['path']=dirname($_GET['path']);
	$show_dir=true;
	}
	if($_GET['action']=="new") {
		if($_GET['type']=="d") {
			if(!$sqlfs->file_exists($_GET['path'].'/'.$_GET['name'])) {
				if($sqlfs->mkdir($_GET['path'].'/'.$_GET['name'])) {
					echo "Map aangemaakt";
				}
				else {
					echo "Fout bij map aanmaken";
				}
			}
			else {
				echo "Bestand bestaat al";
			}
		$show_dir=true;
		}
		else {
			if(!$sqlfs->file_exists($_GET['path'].'/'.$_GET['name'])) {
				if($sqlfs->mkfile($_GET['path'].'/'.$_GET['name'])) {
					echo "Bestand aangemaakt";
				}
				else {
					echo "Fout bij bestand aanmaken";
				}
			}
			else {
				echo "Bestand bestaat al";
			}
		$show_dir=true;
		}
	}
	if($_GET['action']=="edit") {
		if($sqlfs->is_file($_GET['path'])&&!isset($_POST['abort'])) {
			if(isset($_POST['content'])) {
				if($sqlfs->file_put_contents($_GET['path'],$_POST['content'])) {
					echo "Bestand opgeslaan";
				}
				else {
					echo "Fout bij bestand opslaan";
				}
			}
			echo "
			<form action='?action=edit&path={$sqlfs->simplify_path($_GET['path'])}' method='POST'>
			<textarea name='content' style='width: 100%;height: 90%'>".htmlentities($sqlfs->file_get_contents($_GET['path']))."</textarea>
			<input type='submit' style='width: 50%;height: 10%'><input type='submit' style='width: 50%;height: 10%' name='abort' value='Annuleren'>
			</form>
			";
			$show_dir=false;
			$show_file=false;
		}
		else {
			if(!isset($_POST['abort'])) {
				echo "Het opgegeven pad is geen bestand!";
			}
			else {
				$_GET['path']=dirname($_GET['path']);
			}
			$show_dir=true;
		}
	}
	else if($_GET['action']=="chmod") {
		if(isset($_POST['mod'])) {
			if($sqlfs->chmod($_GET['path'],$_POST['mod'])) {
				echo "Bestand chmodded";
			}
			else {
				echo "Fout bij bestand chmodden";
			}
		}
		else {
			echo "
			<form action='?action=chmod&path={$sqlfs->simplify_path($_GET['path'])}' method='POST'>
			<input type='text' value='{$sqlfs->getinfo($_GET['path'],'rights')}' name='mod'>
			<input type='submit'>
			</form>
			";
		}
		$_GET['path']=dirname($_GET['path']);
		$show_dir=true;
	}
	else if($_GET['action']=="chown") {
		if(isset($_POST['user'])) {
			if($sqlfs->chown($_GET['path'],$_POST['user'])) {
				echo "Bestand chowned";
			}
			else {
				echo "Fout bij bestand chownen";
			}
		}
		else {
		echo "
			<form action='?action=chown&path={$sqlfs->simplify_path($_GET['path'])}' method='POST'>
			<input type='text' value='{$sqlfs->getinfo($_GET['path'],'owner')}' name='user'>
			<input type='submit'>
			</form>
			";
		}
		$_GET['path']=dirname($_GET['path']);
		$show_dir=true;
	}
	else if($_GET['action']=="chgrp") {
		if(isset($_POST['grp'])) {
			if($sqlfs->chgrp($_GET['path'],(int)$_POST['grp'])) {
				echo "Bestand chgrped";
			}
			else {
				echo "Fout bij bestand chgrpen";
			}
		}
		else {
		echo "
			<form action='?action=chgrp&path={$sqlfs->simplify_path($_GET['path'])}' method='POST'>
			<input type='text' value='{$sqlfs->getinfo($_GET['path'],'group')}' name='grp'>
			<input type='submit'>
			</form>
			";
		}
		$_GET['path']=dirname($_GET['path']);
		$show_dir=true;
	}
	else if($_GET['action']=="upload") {
		// Check if a file has been uploaded
		if(isset($_FILES['file'])) {
			// Make sure the file was sent without errors
			if($_FILES['file']['error'] == 0) {
				//Move uploaded file
				if($sqlfs->move_uploaded_file($_FILES['file']['tmp_name'],$_GET['path'].'/'.$_FILES['file']['name'])) {
					echo "Bestand geupload";
				}
				else {
					echo "Fout bij bestand aanmaken";
				}
			}
			else {
				echo 'Fout bij bestand verzenden';
			}
		}
		$show_dir=true;
	}
	else if($_GET['action']=="rename") {
		if(isset($_POST['newname'])) {
			if($sqlfs->rename($_GET['path'],$_POST['newname'])){
				echo "Bestand verplaatst";
			}
			else {
				echo "Fout bij bestand verplaatsen";
			}
		}
		else {
			echo "
			<form action='?action=rename&path={$sqlfs->simplify_path($_GET['path'])}' method='POST'>
			<input type='text' value='{$_GET['path']}' name='newname'>
			<input type='submit'>
			</form>
			";
		}
	$_GET['path']=dirname($_GET['path']);
	$show_dir=true;
	}
	else if($_GET['action']=="copy") {
		if(isset($_POST['dest'])) {
			if($sqlfs->copy($_GET['path'],$_POST['dest'])) {
				echo "Bestand gekopi&euml;rd";
			}
			else {
				echo "Fout bij bestand kopi&euml;ren";
			}
		}
		else {
			echo "
				<form action='?action=copy&path={$sqlfs->simplify_path($_GET['path'])}' method='POST'>
				<input type='text' value='{$_GET['path']}' name='dest'>
				<input type='submit'>
				</form>
			";
		}
	$show_dir=true;
	$_GET['path']=dirname($_GET['path']);
	}

}
else if($sqlfs->is_dir($_GET['path'])) {
	$show_dir=true;
}
else if($sqlfs->is_file($_GET['path'])) {
	$show_dir=false;
	$show_file=true;
}

if($show_dir) {
	$dir=$sqlfs->readdir_full($_GET['path']);
	echo "<h1>Index of /{$sqlfs->simplify_path($_GET['path'])}</h1>";
	echo "
	<form action='?' method='GET'>
	<input type='hidden' name='action' value='new'>
	<input type='hidden' name='path' value='{$sqlfs->simplify_path($_GET['path'])}'>
	<select name='type'>
	<option value='d'>Map</option>
	<option value='f'>Bestand</option>
	</select>
	<input type='text' name='name' value=''>
	<input type='submit' value='Aanmaken'>
	</form>
	";
	echo "
	<form action='?action=upload&path={$sqlfs->simplify_path($_GET['path'])}' method='POST' enctype='multipart/form-data'>
	<input type='file' name='file'>
	<input type='submit' value='Upload'>
	</form>
	";
	echo "<table><thead><tr><th>Name</th><th>Rechten</th><th>Owner</th><th>Group</th><th>Bewerkt</th><th>Grootte</th><th>Acties</th></tr><tr><th colspan='5'><hr></th></tr></thead><tbody>";
	foreach($dir as $value) {
		echo "<tr><td>[{$value['type']}] <a href='?path={$sqlfs->simplify_path($_GET['path'])}/{$value['filename']}'>{$value['filename']}</a></td><td>{$value['rights']}</td><td>{$value['owner']}</td><td>{$value['group']}</td><td>{$value['time']}</td><td>{$sqlfs->sizetohuman($value['size'])}</td><td>
			<a href='?path={$sqlfs->simplify_path($_GET['path'])}/{$value['filename']}&action=delete'>Wissen</a>".(($value['type']=='f')?" <a href='?path={$sqlfs->simplify_path($_GET['path'])}/{$value['filename']}&action=edit'>Bewerken</a>":"")." <a href='?path={$sqlfs->simplify_path($_GET['path'])}/{$value['filename']}&action=chmod'>Chmod</a> <a href='?path={$sqlfs->simplify_path($_GET['path'])}/{$value['filename']}&action=chown'>Chown</a> <a href='?path={$sqlfs->simplify_path($_GET['path'])}/{$value['filename']}&action=chgrp'>Chgrp</a> <a href='?path={$sqlfs->simplify_path($_GET['path'])}/{$value['filename']}&action=rename'>Hernoemen</a> <a href='?path={$sqlfs->simplify_path($_GET['path'])}/{$value['filename']}&action=copy'>Kopi&euml;ren</a></td></tr>";
		}
	echo "</tbody></table>";
}
else if($show_file) {
	ob_clean();
	$fileinfo=$sqlfs->getinfo($_GET['path']);
	header("Content-Type: ".$fileinfo['mime']);
	header("Content-Length: ".$fileinfo['size']);
	header("Last-Modified: ".$fileinfo['time']);
	header("Content-Disposition: attachment; filename=\"" . $fileinfo['filename'] . "\"");
	echo $sqlfs->file_get_contents($_GET['path']);
}
?>