Repository navigation
Expand file tree
/
Copy pathdownload.php
More file actions
93 lines (86 loc) · 1.74 KB
/
Copy pathdownload.php
File metadata and controls
93 lines (86 loc) · 1.74 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
require_once(__DIR__ . "/global.php");
session_start();
if (IsLoggedIn())
{
global $username;
$username = $_SESSION['Username'];
LoginIndex();
}
else
{
HtmlHeader("download");
NotLoginIndex();
}
fok();
function NotLoginIndex()
{
?>
<div class="login-page">
<div class="form">
<form action="login.php" class="login-form">
<a>Please login first.</br></a>
<button type="submit">login</button>
</form>
</div>
</div>
<?php
}
function LoginIndex()
{
global $username;
$id=0;
$error="";
if (!empty($_GET['id']))
{
$id = isset($_GET['id'])? $_GET['id'] : 0;
if (!is_numeric($id))
{
$error="erronous id";
}
$id = (int)$id;
}
if ($error === "")
{
$cert_file=CERT_PATH . $username . "-" . $id . ".ovpn";
if (file_exists($cert_file))
{
$aConfig = $_SESSION['Config'];
$cert_name = $aConfig[$id];
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
if ($cert_name === "")
{
header('Content-Disposition: attachment; filename='.basename($cert_file));
} else {
header('Content-Disposition: attachment; filename='.$cert_name.'.ovpn');
}
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($cert_file));
ob_clean();
flush();
readfile($cert_file);
exit();
}
else
{
$error = "file not found";
}
}
HtmlHeader("download");
?>
<div class="login-page">
<div class="form">
<form action="index.php" method="post" class="login-form">
<a><?php if ($error === "") { echo "Downloaded c:"; } else { echo "error: $error"; } ?></br></a>
<button type="submit">back</button>
</form>
</div>
</div>
<?php
fok();
}
?>