-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackup.php
More file actions
74 lines (69 loc) · 1.5 KB
/
backup.php
File metadata and controls
74 lines (69 loc) · 1.5 KB
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
<?php
include dirname(__FILE__)."/session.php";
include_once dirname(__FILE__)."/conf.php";
include_once dirname(__FILE__)."/functions.php";
$json = new stdClass();
if( true
&& isset($_POST['username'])
&& isset($_POST['password'])
&& isset($_POST['remote_dir'])
&& isset($_FILES['file']['tmp_name'])
)
{
$uid = trim($_POST['username']);
$pas = trim($_POST['password']);
$userid = "";
if(strlen($cfg->users))
{
if(HTPasswd::auth($uid, $pas, $cfg->users))
{
$userid = $uid;
}
}
if(!$userid)
{
$json = array(
'response_code'=>'002',
'response_text'=>'Unauthorized',
'data'=>new StdClass()
);
}
else
{
$remote_dir = @$_POST['remote_dir'];
$target_dir = rtrim($cfg->rootdir, "/")."/".ltrim($remote_dir, "/");
if(!file_exists($target_dir))
{
mkdir($target_dir, 0755);
}
$basename = basename($_FILES['file']['name']);
$target_path = $target_dir."/".$basename;
if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path))
{
unset($json);
$json = array(
'response_code'=>'001',
'response_text'=>'File uploaded successfully',
'data'=>array(
'file_name'=>$basename,
'target_path'=>$target_path
)
);
}
else
{
unset($json);
$json = array(
'response_code'=>'000',
'response_text'=>'Sorry, file not uploaded, please try again',
'data'=>array(
'file_name'=>$basename,
'target_path'=>$target_path
)
);
}
}
header("Content-type: application/json");
echo json_encode($json);
}
?>