-
Notifications
You must be signed in to change notification settings - Fork 1
/
natrm.php
124 lines (106 loc) · 2.97 KB
/
natrm.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
<?php
/**
* Base file for HTML processing
*
* @author Gouverneur Thomas <[email protected]>
* @copyright Copyright (c) 2007-2008, Gouverneur Thomas
* @version 1.0
* @package html
* @subpackage base
* @category html
* @filesource
*/
require_once("./inc/config.inc.php");
require_once("./inc/config.inc.php");
require_once("./lib/html.lib.php");
require_once("./lib/autoload.lib.php");
/* sanitize _GET and _POST */
sanitizeArray($_GET);
sanitizeArray($_POST);
/* common to all pages */
$page = new Template("./tpl/main.tpl");
$head = new Template("./tpl/head.tpl");
$head->set("title", "m0n0wall Central Management Interface");
$head->set("subtitle", "NAT");
$head->set("pagename", "NAT");
$menu = new Template("./tpl/menu.tpl");
$menu->set("version", $config["version"]);
$foot = new Template("./tpl/foot.tpl");
$body = new Template("./tpl/message.tpl");
$body->set("pagename", "Remove NAT");
/* body */
$msg = null;
$error = null;
/* connect to the database: */
if (!@Mysql::getInstance()->connect()) {
$error = "Cannot connect to MySQL: ".Mysql::getInstance()->getError()." !!";
end_process();
}
$main = Main::getInstance();
if (getHTTPVar("mid")) {
$mono = new Monowall(getHTTPVar("mid"));
if (!$mono->fetchFromId()) {
$error = "Cannot find specified device in the database";
end_process();
}
} else {
$error = "No device selected for NAT entry deletion";
end_process();
}
if (getHTTPVar("nid") && getHTTPVar("type")) {
$nid = getHTTPVar("nid");
$type = getHTTPVar("type");
switch($type) {
case 1:
$nat = new RuleNat($nid);
break;
case 2:
$nat = new SrvNat($nid);
break;
case 3:
$nat = new O2ONat($nid);
break;
case 4:
$nat = new AdvNat($nid);
break;
}
$nat->fetchFromId();
if (!$nat->fetchFromId()) {
$error = "Can't find nat selected for deletion";
end_process();
}
} else {
$error = "No NAT specified for deletion";
end_process();
}
if (isset($nat)) {
if ($nat->idhost != $mono->id) {
$error = "The selected NAT entry is not owned by the specified device, abording deletion";
end_process();
}
$nat->delete();
$mono->updateChanged();
$msg = "NAT removed from device database...";
} else {
$error = "Error finding NAT entry...";
}
$link = array("href" => "viewnat.php?mid=".$mono->id."&type=".$type, "label" => "Return to NAT entry list");
end_process();
/* end process and exit script */
function end_process() {
global $body, $page, $form, $head, $menu, $foot, $msg, $error, $link, $list;
/* template processing */
$body->set("message", $msg);
$body->set("error", $error);
$body->set("link", $link);
$body->set("list", $list);
$body->set("form", $form);
$page->set("head", $head);
$page->set("menu", $menu);
$page->set("foot", $foot);
$page->set("body", $body);
echo $page->fetch();
@Mysql::getInstance()->disconnect();
exit(0);
}
?>