-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
169 lines (159 loc) · 3.7 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
<?php
require_once(__DIR__ . "/global.php");
require_once(__DIR__ . "/mail.php");
session_start();
HtmlHeader("HOME");
if (IsLoggedIn())
{
global $username;
$username = $_SESSION['Username'];
LoginIndex();
}
else
{
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;
if (!empty($_GET['action']))
{
$action = isset($_GET['action'])? $_GET['action'] : '';
$action = (string)$action;
if ($action === "mail")
{
$mail_status = SendMailConfig($_SESSION['Mail'], $_SESSION['Username']) . "</br>";
?>
<div class="login-page">
<div class="form">
<form action="index.php" method="post" class="login-form">
<a>
Mail status:</br>
<?php echo $mail_status; ?></br>
</a>
<button type="submit">okay</button>
<p class="message">All done? <a href="logout.php">Log out</a></p>
</form>
</div>
</div>
<?php
}
if ($action === "create")
{
$db = new PDO(DATABASE_PATH);
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$stmt = $db->prepare('SELECT * FROM Accounts WHERE Username = ? ');
$stmt->execute(array($_SESSION['Username']));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($rows)
{
$total_vpns = $rows[0]['NumVPNS'];
}
$total_vpns += 1;
if ($total_vpns >= 10)
{
?>
<div class="login-page">
<div class="form">
<form action="index.php" class="login-form">
<a><?php echo "Created maximum of $total_vpns vpns"; ?></br></a>
<button type="submit">menu</button>
<p class="message">All done? <a href="logout.php">Log out</a></p>
</form>
</div>
</div>
<?php
fok();
}
$cert_name = $_SESSION['Username'] . "-" . $total_vpns;
$shell_str = "sudo " . TEST_VPN_DIR . "adduser-vpn.sh $cert_name";
$out = shell_exec($shell_str);
//echo "exec:</br>$shell_str</br>out:</br> $out";
$current_date = date("Y-m-d H:i:s");
$stmt = $db->prepare('UPDATE Accounts SET NumVPNS = ?, LastVPN = ? WHERE Username = ? ');
$stmt->execute(array($total_vpns, $current_date, $_SESSION['Username']));
?>
<div class="login-page">
<div class="form">
<form action="index.php" class="login-form">
<a><?php echo "Created $total_vpns / 10 VPNS"; ?></br></a>
<a>Press button to go back to menu</br></a>
<button type="submit">menu</button>
<p class="message">All done? <a href="logout.php">Log out</a></p>
</form>
</div>
</div>
<?php
}
}
else
{
?>
<div class="login-page">
<div class="form">
<a>
Press buttons to either create a new config</br>
or send existing ones to your mail</br>
</a>
<button onclick="window.location.href='index.php?action=mail'">Mail</button>
<form action="index.php?action=create" method="post" class="login-form">
<button type="submit">create</button>
<p class="message">All done? <a href="logout.php">Log out</a></p>
</form>
</div>
</div>
<?php
}
?>
<div class="certs-dl">
<?php
$aConfig = $_SESSION['Config'];
for ($i=0;$i<10;$i++)
{
$cert_file=CERT_PATH . $_SESSION['Username'] . "-" . $i . ".ovpn";
if (file_exists($cert_file))
{
$cfg_name = $aConfig[$i];
if ($cfg_name === "")
{
echo "
<button id=\"btn-fix\" onclick=\"window.location.href='download.php?id=$i'\"> download $username-$i.ovpn </button>
";
}
else
{
echo "
<button id=\"btn-fix\" onclick=\"window.location.href='download.php?id=$i'\"> download $cfg_name.ovpn </button>
";
}
if (IS_RENAME)
{
echo "
<button id=\"btn-fix\" onclick=\"window.location.href='rename.php?id=$i'\">rename</button>
";
}
}
else
{
//echo "$cert_file is not there<br>";
}
}
?>
</div>
<?php
}
?>