-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpost.php
151 lines (137 loc) · 4.69 KB
/
post.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
<?php
include_once("lib/ca_func.php");
include_once("lib/database.php");
if (isset($_POST['addRT'])) {
if (! add_route_table($_POST['rtID'], $_POST['rtName'], $_POST['rtDesc'])) {
header("Location: /?page=routes");
}
}
if (isset($_POST['addSwitch'])) {
add_switch($_POST['switchName'], $_POST['switchType'], $_POST['uplinkType'], $_POST['uplinkIface'], $_POST['uplinkSwitch'], $_POST['uplinkVlan']);
header("Location: /?page=settings");
}
if (isset($_POST['addVPNCA'])) {
# Create openssl private key
$key = ca_make_key(2048);
$subj = ca_set_subject($_POST['caCountry'], $_POST['caState'], $_POST['caOrg']);
if (file_put_contents("/tmp/key.pem", $key) === strlen($key)) {
ca_make_cacert("/tmp/key.pem", "/tmp/ca_cert.pem", $subj);
$cert = file_get_contents("/tmp/ca_cert.pem");
# Remove our temp files
unlink("/tmp/ca_cert.pem");
unlink("/tmp/key.pem");
if (! add_vpn_ca($_POST['caName'], $key, $cert, $_POST['caCountry'], $_POST['caState'], $_POST['caOrg'])) {
$redirect = "/?page=vpn";
header("Location: $redirect");
}
} else {
print("Write key to file failed.");
}
}
if (isset($_POST['addVPNCert'])) {
# Create openssl private key
$key = ca_make_key(2048);
if (file_put_contents("/tmp/svrkey.pem", $key) === strlen($key)) {
$cacert = ca_get_cert($_POST['certCA']);
file_put_contents("/tmp/cacert.pem", $cacert);
$index = ca_get_index($_POST['certCA']);
file_put_contents("/tmp/index.txt", $index);
$serial = ca_get_serial($_POST['certCA']);
file_put_contents("/tmp/serial", $serial);
$cakey = ca_get_key($_POST['certCA']);
file_put_contents("/tmp/cakey.pem", $cakey);
# Create Server Certificate
$svrcrt = ca_make_svrcert("/tmp/svrkey.pem", $_POST['certName']);
# Remove CA files
unlink("/tmp/cacert.pem");
unlink("/tmp/cakey.pem");
# Update CA database and serial
$index = file_get_contents("/tmp/index.txt");
ca_set_index($_POST['certCA'], $index);
unlink("/tmp/index.txt");
$serial = file_get_contents("/tmp/serial");
ca_set_serial($_POST['certCA'], $serial);
unlink("/tmp/serial");
# Add VPN Certificate to list
if (! add_vpn_cert($_POST['certName'], $_POST['certCA'], $svrcrt, $key)) {
$redirect = "/?page=vpn";
header("Location: $redirect");
}
}
}
if (isset($_POST['addVPNServer'])) {
# Create diffie hellman dhparam file
$dhparam = ca_make_dh(2048);
if (! add_vpn_server($_POST['serverName'], $dhparam, $_POST['serverProto'], $_POST['serverPort'], $_POST['serverNetwork'], $_POST['serverMask'], $_POST['serverCA'], $_POST['serverDesc'])) {
$redirect = "/?page=vpn";
header("Location: $redirect");
} else {
?>
<h1>An error occurred</h1>
<?php
}
}
if (isset($_POST['delVPNCert'])) {
if (! del_vpn_cert($_POST['certName'])) {
$redirect = "/?page=vpn";
header("Location: $redirect");
} else {
?>
<h1>An error occurred</h1>
<?php
}
}
if (isset($_POST['delVlan'])) {
if (! del_vlan($_POST['switchId'], $_POST['vlanId'])) {
$redirect = "/?page=switch&anchor=" . $_POST['switchId'];
header("Location: $redirect");
} else {
?>
<h1>An error occurred</h1>
<?php
}
}
if (isset($_POST['addVlan'])) {
if (! add_vlan($_POST['switchName'], $_POST['vlanID'], $_POST['ipAddress'], $_POST['maskLength'], $_POST['rtTable'], $_POST['vlanDesc'])) {
$redirect = "/?page=switch&anchor=" . $_POST['switchName'];
header("Location: $redirect");
print "Redirecting to $redirect...";
} else {
?>
<h1>An error occurred</h1>
<?php
}
}
if (isset($_POST['saveHASettings'])) {
if ($_POST['ha_enable'] == "on") {
set_setting("ha_enable", "1");
} else {
set_setting("ha_enable", "0");
}
set_setting("ha_mode", $_POST['ha_mode']);
header("Location: /?page=settings");
}
if (isset($_POST['saveSettings'])) {
set_setting("install_type", $_POST['install_type']);
header("Location: /?page=settings");
}
if (isset($_POST['json'])) {
if ($_POST['json'] == "getVLANs") {
$vlans = get_switch_vlans($_POST['switch']);
print json_encode($vlans);
return;
} elseif ($_POST['json'] == "getSettings") {
$settings = get_settings();
print json_encode($settings);
return;
} elseif ($_POST['json'] == "getSwitches") {
$switches = get_switches();
print json_encode($switches);
return;
} elseif ($_POST['json'] == "getRouteTables") {
$rt = get_rt_tables();
print json_encode($rt);
return;
}
}
?>