This repository has been archived by the owner on Sep 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
controlpannel.php
91 lines (84 loc) · 2.89 KB
/
controlpannel.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
<?php
include('bgProcess.class.php');
function tempdir($dir=false,$prefix='php') {
$tempfile=tempnam(sys_get_temp_dir(),'');
if (file_exists($tempfile)) { unlink($tempfile); }
mkdir($tempfile);
if (is_dir($tempfile)) { return $tempfile; }
}
$dictsDir = 'dicts/';
$allowedExts = array('dic', 'txt', 'gz', 'bz2', '7z');
$maxsize = 100*1024*1024;
if (isset($_FILES['file'])){
$MESSAGE = '';
function log_message($str){
global $MESSAGE;
$MESSAGE .= $str."\n";
}
$error = true;
$allowedTypes = array('text/plain', 'application/x-gzip');
$fna = explode('.', $_FILES['file']['name']);
$extension = end($fna);
if ($_FILES['file']['error'] > 0){
log_message('Return Code: ' . $_FILES['file']['error'] );
}else{
log_message('Upload: ' . $_FILES['file']['name'] );
log_message('Type: ' . $_FILES['file']['type'] );
log_message('Size: ' . ($_FILES['file']['size'] / 1024 / 1024) . ' MB');
//~ log_message('Temp file: ' . $_FILES['file']['tmp_name'] );
if (($_FILES['file']['size'] < $maxsize) && in_array($extension, $allowedExts)){
switch($extension){
case 'txt':
if (file_exists($dictsDir . $_FILES['file']['name'])){
log_message($_FILES['file']['name'] . ' already exists. ');
}else{
$res = move_uploaded_file($_FILES['file']['tmp_name'], $dictsDir . basename($_FILES['file']['name'], '.txt').'.dic');
if ($res){
log_message('Stored as: ' . $dictsDir . basename($_FILES['file']['name'], '.txt').'.dic');
$error = false;
}
}
break;
case 'dic':
if (file_exists($dictsDir . $_FILES['file']['name'])){
log_message($_FILES['file']['name'] . ' already exists. ');
}else{
$res = move_uploaded_file($_FILES['file']['tmp_name'], $dictsDir . basename($_FILES['file']['name']));
if ($res){
log_message('Stored as: ' . $dictsDir . $_FILES['file']['name']);
$error = false;
}
}
break;
case 'gz':
case 'bz2':
$tmpdir = tempdir();
exec('tar - xf '.escapeshellarg($_FILES['file']['tmp_name']).' -C '.$tmpdir, $output, $ret_value);
if ($ret_value == 0){
log_message('Extracted to: ' . $tmpdir);
foreach(glob($tmpdir.'/*.dic') as $file){
$ret = rename($file, $dictsDir.basename($file));
log_message('Stored as: '.$dictsDir.basename($file));
}
$error = false;
}
break;
case '7z':
$tmpdir = tempdir();
exec('7zr e -o'.$tmpdir.' -y '.escapeshellarg($_FILES['file']['tmp_name']), $output, $ret_value);
if ($ret_value == 0){
log_message('Extracted to: ' . $tmpdir);
foreach(glob($tmpdir.'/*.dic') as $file){
$ret = rename($file, $dictsDir.basename($file));
log_message('Stored as:'.$dictsDir.basename($file));
}
$error = false;
}
break;
}
}else{
log_message('Invalid file (extention, size, etc. does not match policy)');
}
}
}
require('view/controlPannelView.php');