forked from Chocobozzz/OpenVPN-Admin
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
226 lines (193 loc) · 7.91 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
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
<?php
session_start();
require(dirname(__FILE__) . '/include/functions.php');
require(dirname(__FILE__) . '/include/connect.php');
// first time install
if(($_SERVER[REQUEST_URI] != "/index.php?installation") && (isInstalled($bdd) == false)) {
header("Location: index.php?installation");
exit(-1);
}
// Disconnecting ?
if(isset($_GET['logout'])){
session_destroy();
header("Location: .");
exit(-1);
}
// Read ovpn file contents
$ovpn_filename= file_get_contents("./client-conf/windows/filename");
// Get the Windows instruction file
if(isset($_POST['windows_instruction_get'])) {
$download_file_name1 = "Download and install the OpenVPN GUI (Windows).pdf";
$file_folder1 = "windows";
$file_full_path1 = './client-conf/' . $file_folder1 . '/' . $download_file_name1;
header("Content-type: application/pdf");
header("Content-disposition: attachment; filename=$download_file_name1");
header("Pragma: no-cache");
header("Expires: 0");
readfile($file_full_path1);
exit;
}
// Get the MAC instruction file
if(isset($_POST['mac_instruction_get'])) {
$download_file_name2 = "Download and install the OpenVPN GUI (MAC).pdf";
$file_folder2 = "osx-viscosity";
$file_full_path2 = './client-conf/' . $file_folder2 . '/' . $download_file_name2;
header("Content-type: application/pdf");
header("Content-disposition: attachment; filename=$download_file_name2");
header("Pragma: no-cache");
header("Expires: 0");
readfile($file_full_path2);
exit;
}
// Get configuration file from admin page
if(isset($_GET['admin_configuration_get']) && !empty($_SESSION['admin_id']) ) {
$file_name = "client.ovpn";
$file_folder = "windows";
$file_full_path = './client-conf/' . $file_folder . '/' . $file_name;
header("Content-type: application/ovpn");
header("Content-disposition: attachment; filename=$ovpn_filename.ovpn");
header("Pragma: no-cache");
header("Expires: 0");
readfile($file_full_path);
exit;
}
// Get the configuration files from configuration page
if(isset($_POST['configuration_get'], $_POST['configuration_username'], $_POST['configuration_pass']) && !empty($_POST['configuration_pass'])) {
$req = $bdd->prepare('SELECT * FROM user WHERE user_id = ?');
$req->execute(array($_POST['configuration_username']));
$data = $req->fetch();
// Error ?
if($data && passEqual($_POST['configuration_pass'], $data['user_pass'])) {
$file_name = "client.ovpn";
$file_folder = "windows";
$file_full_path = './client-conf/' . $file_folder . '/' . $file_name;
header("Content-type: application/ovpn");
header("Content-disposition: attachment; filename=$ovpn_filename.ovpn");
header("Pragma: no-cache");
header("Expires: 0");
readfile($file_full_path);
exit;
}
else {
$error = true;
}
}
// Admin login attempt ?
else if(isset($_POST['admin_login'], $_POST['admin_username'], $_POST['admin_pass']) && !empty($_POST['admin_pass'])){
$req = $bdd->prepare('SELECT * FROM admin WHERE admin_id = ?');
$req->execute(array($_POST['admin_username']));
$data = $req->fetch();
// Error ?
if($data && passEqual($_POST['admin_pass'], $data['admin_pass'])) {
$_SESSION['admin_id'] = $data['admin_id'];
header("Location: index.php?admin");
exit(-1);
}
else {
$error = true;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>OpenVPN-Admin</title>
<link rel="stylesheet" href="vendor/bootstrap/dist/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="vendor/x-editable/dist/bootstrap3-editable/css/bootstrap-editable.css" type="text/css" />
<link rel="stylesheet" href="vendor/bootstrap-table/dist/bootstrap-table.min.css" type="text/css" />
<link rel="stylesheet" href="vendor/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css" type="text/css" />
<link rel="stylesheet" href="vendor/bootstrap-table/dist/extensions/filter-control/bootstrap-table-filter-control.css" type="text/css" />
<link rel="stylesheet" href="css/index.css" type="text/css" />
<link rel="icon" type="image/png" href="css/icon.png">
</head>
<body class='container-fluid'>
<?php
// --------------- INSTALLATION ---------------
if(isset($_GET['installation'])) {
if(isInstalled($bdd) == true) {
printError('OpenVPN-admin is already installed. Redirection.');
header( "refresh:3;url=index.php?admin" );
exit(-1);
}
// If the user sent the installation form
if(isset($_POST['admin_username'])) {
$admin_username = $_POST['admin_username'];
$admin_pass = $_POST['admin_pass'];
$admin_repeat_pass = $_POST['repeat_admin_pass'];
if($admin_pass != $admin_repeat_pass) {
printError('The passwords do not correspond. Redirection.');
header( "refresh:3;url=index.php?installation" );
exit(-1);
}
// Create the initial tables
$migrations = getMigrationSchemas();
foreach ($migrations as $migration_value) {
$sql_file = dirname(__FILE__) . "/sql/schema-$migration_value.sql";
try {
$sql = file_get_contents($sql_file);
$bdd->exec($sql);
}
catch (PDOException $e) {
printError($e->getMessage());
exit(1);
}
unlink($sql_file);
// Update schema to the new value
updateSchema($bdd, $migration_value);
}
// Generate the hash
$hash_pass = hashPass($admin_pass);
// Insert the new admin
$req = $bdd->prepare('INSERT INTO admin (admin_id, admin_pass) VALUES (?, ?)');
$req->execute(array($admin_username, $hash_pass));
rmdir(dirname(__FILE__) . '/sql');
printSuccess('Well done, OpenVPN-Admin is installed. Redirection.');
header( "refresh:3;url=index.php?admin" );
}
// Print the installation form
else {
require(dirname(__FILE__) . '/include/html/menu.php');
require(dirname(__FILE__) . '/include/html/form/installation.php');
}
exit(-1);
}
// --------------- CONFIGURATION ---------------
if(!isset($_GET['admin'])) {
if(isset($error) && $error == true)
printError('Login error');
require(dirname(__FILE__) . '/include/html/menu.php');
require(dirname(__FILE__) . '/include/html/form/configuration.php');
}
// --------------- LOGIN ---------------
else if(!isset($_SESSION['admin_id'])){
if(isset($error) && $error == true)
printError('Login error');
require(dirname(__FILE__) . '/include/html/menu.php');
require(dirname(__FILE__) . '/include/html/form/login.php');
}
// --------------- GRIDS ---------------
else{
?>
<nav class="navbar navbar-default">
<div class="row col-md-12">
<div class="col-md-6">
<p class="navbar-text signed">Signed in as <?php echo $_SESSION['admin_id']; ?>
</div>
<div class="col-md-6">
<a class="navbar-text navbar-right" href="index.php?logout" title="Logout"><button class="btn btn-danger">Logout <span class="glyphicon glyphicon-off" aria-hidden="true"></span></button></a>
<a class="navbar-text navbar-right" href="index.php" title="Configuration"><button class="btn btn-default">Configurations</button></a>
<a class="navbar-text navbar-right" href="index.php?admin_configuration_get" title="Get Config File"><button class="btn btn-default">Get Config File</button></a>
</p>
</div>
</div>
</nav>
<?php
require(dirname(__FILE__) . '/include/html/grids.php');
}
?>
<div id="message-stage">
<!-- used to display application messages (failures / status-notes) to the user -->
</div>
</body>
</html>