-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patholt.php
221 lines (209 loc) · 7.69 KB
/
olt.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
<?php
include ("header.php");
include ("common.php");
include ("navigation.php");
include ("classes/olt_class.php");
include ("classes/snmp_class.php");
if ($user_class < "6")
exit();
$olt_obj = new olt();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// ADD OLT
if ($olt_obj->getSubmit() == "ADD") {
if (!empty($olt_obj->getName()) && !empty($olt_obj->getOlt_ip_address()) && !empty($olt_obj->getSnmp_community_ro()) && !empty($olt_obj->getSnmp_community_rw()) && !empty($olt_obj->getOlt_model())) {
$error = $olt_obj->create_olt();
if (isset($error)) {
echo $error;
}else{
echo "<center><div class=\"bg-success text-white\">OLT added Succesfully</div></center>";
}
} else {
echo "<center><div class=\"bg-danger text-white\">ERROR: Name, OLT IP_Address, RO and RW Communities and OLT Model are required fields!</div></center>";
}
}
// EDIT OLT
if ($olt_obj->getSubmit() == "EDIT") {
if (!empty($olt_obj->getOlt_id()) && !empty($olt_obj->getName()) && !empty($olt_obj->getOlt_ip_address()) && !empty($olt_obj->getSnmp_community_ro()) && !empty($olt_obj->getSnmp_community_rw()) && !empty($olt_obj->getOlt_model())) {
$error = $olt_obj->edit_olt();
if (isset($error)) {
echo $error;
}else{
print "<center><div class=\"bg-success text-white\">OLT Edited Succesfully</div></center>";
}
} else {
echo "<center><div class=\"bg-danger text-white\">ERROR: Name, OLT IP_Address, RO and RW Communities and OLT Model are required fields! Or you are missing OLT_ID!</div></center>";
}
}
// DELETE OLT
if ($olt_obj->getSubmit() == "DELETE") {
if (!empty($olt_obj->getOlt_id())) {
$error = $olt_obj->delete_olt();
if (isset($error)) {
echo $error;
}else{
print "<center><div class=\"bg-success text-white\">OLT Deleted Succesfully</div></center>";
}
} else {
echo "<center><div class=\"bg-danger text-white\">ERROR: OLT_ID missing!</div></center>";
}
}
//SAVE OLT CONFIG
if ($olt_obj->getSubmit() == "SAVE") {
if (!empty($olt_obj->getOlt_id())) {
$error = $olt_obj->save_olt();
if (isset($error)) {
echo $error;
}else{
print "<center><div class=\"bg-success text-white\">OLT Config Saved Succesfully</div></center>";
}
} else {
echo "<center><div class=\"bg-danger text-white\">ERROR: OLT_ID missing!</div></center>";
}
}
}
?>
<div class="container">
<div class="text-center">
<div class="page-header">
<h2>OLT Configuration</h2>
</div>
</div>
<div class=row>
<div class="text-center">
<div class="table-responsive">
<table class="table table-bordered table-condensed table-hover">
<thead>
<tr>
<th>Name</th>
<th>Model</th>
<th>IP Address</th>
<th>R/O</th>
<th>R/W</th>
<th>Status</th>
<th>Temp</th>
<th>CPU</th>
<th>Uptime</th>
<th>Backup</th>
<th>Info</th>
<th>Config</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
$rows = $olt_obj->build_table_olt();
foreach ($rows as $row) {
$snmp_obj = new snmp_oid();
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
$session = new SNMP(SNMP::VERSION_2C, $row['IP_ADDRESS'], $row['RO'], 1500000, 3);
if ($row['TYPE'] == "XGSPON") {
$status = $session->get($snmp_obj->get_pon_oid("olt_status_oid", "XGSPON_OLT"));
}else{
$status = $session->get($snmp_obj->get_pon_oid("olt_status_oid", "OLT"));
}
$temp = '';
$save = '';
$cpu = '';
$sysuptime = '';
$slot = '';
$total_cpu = "";
if ($status) {
$status = "<font color=green>Online</font>";
$session = new SNMP(SNMP::VERSION_2C, $row['IP_ADDRESS'], $row['RO']);
if ($row['TYPE'] == "XGSPON") {
$temp = $session->get($snmp_obj->get_pon_oid("olt_temp_oid", "XGSPON_OLT"));
}else{
$temp = $session->get($snmp_obj->get_pon_oid("olt_temp_oid", "OLT"));
}
if ($temp > '65') {
$temp = "<font color=red>" . $temp . "\xc2\xb0C</font>";
}else {
$temp = $temp . "\xc2\xb0C";
}
snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
snmp_set_quick_print(TRUE);
snmp_set_enum_print(TRUE);
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
$session = new SNMP(SNMP::VERSION_1, $row['IP_ADDRESS'], $row['RO']);
if ($row['TYPE'] == "XGSPON") {
$olt_cpu_oid = $snmp_obj->get_pon_oid("olt_cpu_oid", "XGSPON_OLT");
}else{
$olt_cpu_oid = $snmp_obj->get_pon_oid("olt_cpu_oid", "OLT");
}
$cpus = $session->walk($olt_cpu_oid);
foreach ($cpus as $cpu_oid => $cpu) {
$slot = str_replace($olt_cpu_oid, '', substr($cpu_oid, 0, -1));
$slot = str_replace('.','',$slot);
if ($row['TYPE'] == "XGSPON")
$cpu = $cpu/100;
if ($cpu > '50') {
$cpu = "Slot" . $slot . ": <font color=red>" . $cpu . "%</font>";
}else{
$cpu = "Slot" . $slot . ": " . $cpu . "%";
}
$total_cpu = $total_cpu . $cpu . "<br>";
}
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
$session = new SNMP(SNMP::VERSION_2C, $row['IP_ADDRESS'], $row['RO']);
if ($row['TYPE'] == "XGSPON") {
$sysuptime = $session->get($snmp_obj->get_pon_oid("sys_uptime_oid", "XGSPON_OLT"));
}else{
$sysuptime = $session->get($snmp_obj->get_pon_oid("sys_uptime_oid", "OLT"));
}
$sysuptime_days = floor($sysuptime/(100*3600*24));
$sysuptime_hours = $sysuptime/(100*3600)%24;
$sysuptime_minutes = $sysuptime/(100*60)%60;
$sysuptime = $sysuptime_days . " day(s) " . $sysuptime_hours . " hour(s) " . $sysuptime_minutes . " minutes";
$save = '<form action="olt.php" method="post"><input type="hidden" name="olt_id" value="' . $row['ID'] .'"><button type="submit" class="btn btn-default" name="SUBMIT" value="SAVE">SAVE</button></form>';
}else{
$status = "<font color=red>Offline</font>";
}
// print "<tr><td>" . $row{'NAME'} . "</td><td>" .$row{'OLT_NAME'} . "</td><td>" . $row{'IP_ADDRESS'} . "</td><td>" . $row{'RO'} . "</td><td>" . $row{'RW'} . "</td><td>" . $status . "</td><td>" . $temp . "</td><td>" . $cpu . "</td><td>" . $save . "</td></tr>";
?>
<tr>
<td><?php echo $row['NAME']; ?></td>
<td><?php echo $row['OLT_NAME']; ?></td>
<td><?php echo $row['IP_ADDRESS']; ?></td>
<td><?php echo $row['RO']; ?></td>
<td><?php echo $row['RW']; ?></td>
<td><?php echo $status; ?></td>
<td><?php echo $temp; ?></td>
<td><?php echo $total_cpu; ?></td>
<td><?php echo $sysuptime; ?></td>
<td><?php echo $row['BACKUP_NAME']; ?></td>
<td><?php echo "<a href=\"olt_details.php?id=" . $row['ID'] . "\">"; ?><button type="button" class="btn btn-default">INFO</button></a></td>
<td><?php echo $save; ?></td>
<td><button type="button" class="btn btn-default" onClick="getOlt('<?php echo $row['ID']; ?>');">EDIT</button></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="text-center">
<button type="button" class="btn btn-info" onClick="getOlt();">ADD NEW OLT</button>
</div>
</div>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">OLT</h4>
</div>
<div class="modal-body" id="modalbody">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>