Newer
Older
/*
WiSP User Logs
Copyright (C) 2007-2009, AllWorldIT
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
function showWiSPUserLogsWindow(id) {
// Calculate dates we going to need
var today = new Date();
var firstOfMonth = today.getFirstDateOfMonth();
var firstOfNext = today.getLastDateOfMonth().add(Date.DAY, 1);
var formID = Ext.id();
var formAfterID = Ext.id();
var formBeforeID = Ext.id();
var formSearchButtonID = Ext.id();
var summaryFormID = Ext.id();
var summaryTotalID = Ext.id();
var wispUserLogsWindow = new Ext.ux.GenericGridWindow(
// Window config
{
title: 'Logs',
layout:'border',
height: 480,
width: 700,
minHeight: 480,
minWidth: 700,
closable: true,
plain: true,
uxItems: [
{
xtype: 'form',
title: 'Search',
region: 'west',
border: true,
frame: true,
defaultType: 'datefield',
height: 180,
width: 320,
labelWidth: 100,
items: [
{
name: 'after',
width: 180,
fieldLabel: 'From',
vtype: 'daterange',
format: 'Y-m-d',
value: firstOfMonth,
name: 'before',
width: 180,
fieldLabel: 'To',
vtype: 'daterange',
format: 'Y-m-d',
value: firstOfNext,
handler: function() {
// Pull in window, grid & form
var grid = Ext.getCmp(wispUserLogsWindow.gridPanelID);
var form = Ext.getCmp(formID);
// Grab store
var store = grid.getStore();
// Grab timestamp filter
var gridFilters = grid.filters;
var timestampFilter = gridFilters.getFilter('EventTimestamp');
// Grab form fields
var afterField = Ext.getCmp(formAfterID);
var beforeField = Ext.getCmp(formBeforeID);
// Set filter values from form
timestampFilter.setValue({
after: afterField.getValue(),
before: beforeField.getValue()
});
// Trigger store reload
store.reload();
}
}
],
buttonAlign: 'center'
},
{
xtype: 'form',
region: 'center',
split: true,
border: true,
autoScroll: true,
defaultType: 'textarea',
height: 180,
width: 400,
labelWidth: 80,
items: [
{
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
name: 'summaryTotal',
readOnly: true,
height: 139,
width: 275,
fieldLabel: 'Summary',
fieldClass: 'font-family: monospace; font-size: 10px;',
value: ''
}
]
}
]
},
// Grid config
{
region: 'south',
width: 700,
border: true,
// Column model
colModel: new Ext.grid.ColumnModel([
{
header: "ID",
hidden: true,
dataIndex: 'ID'
},
{
header: "Timestamp",
sortable: true,
dataIndex: 'EventTimestamp'
},
{
header: "Status",
sortable: true,
hidden: true,
dataIndex: 'AcctStatusType'
},
{
header: "Service Type",
sortable: true,
dataIndex: 'ServiceType'
},
{
header: "Framed Protocol",
sortable: true,
dataIndex: 'FramedProtocol'
},
{
header: "NAS Port Type",
hidden: true,
dataIndex: 'NASPortType'
},
{
header: "Calling Station",
sortable: true,
dataIndex: 'CallingStationID'
},
{
header: "Called Station",
hidden: true,
dataIndex: 'CalledStationID'
},
{
header: "Session ID",
hidden: true,
dataIndex: 'AcctSessionID'
},
{
header: "IP Address",
hidden: true,
dataIndex: 'FramedIPAddress'
},
{
header: "Input Mbyte",
dataIndex: 'AcctInputMbyte'
},
{
header: "Output Mbyte",
dataIndex: 'AcctOutputMbyte'
},
{
header: "Session Uptime",
dataIndex: 'AcctSessionTime'
},
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
{
header: "Term. Reason",
dataIndex: 'ConnectTermReason'
}
])
},
// Store config
{
baseParams: {
ID: id,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUserLogs',
SOAPFunction: 'getWiSPUserLogs',
SOAPParams: 'ID,__search'
}
},
// Filter config
{
filters: [
{type: 'numeric', dataIndex: 'ID'},
{
type: 'date',
format: 'Y-m-d H:i:s',
dataIndex: 'EventTimestamp',
value: {
after: firstOfMonth,
before: firstOfNext
}
},
{type: 'numeric', dataIndex: 'AcctStatusType'},
{type: 'numeric', dataIndex: 'ServiceType'},
{type: 'numeric', dataIndex: 'FramedProtocol'},
{type: 'numeric', dataIndex: 'NASPortType'},
{type: 'string', dataIndex: 'NASPortID'},
{type: 'string', dataIndex: 'CallingStationID'},
{type: 'string', dataIndex: 'CalledStationID'},
{type: 'string', dataIndex: 'AcctSessionID'},
{type: 'string', dataIndex: 'FramedIPAddress'},
{type: 'numeric', dataIndex: 'AcctInputMbyte'},
{type: 'numeric', dataIndex: 'AcctOutputMbyte'},
{type: 'string', dataIndex: 'ConnectTermReason'}
]
}
);
// Grab store
var store = Ext.getCmp(wispUserLogsWindow.gridPanelID).getStore();
store.on('load',function() {
var inputTotal = store.sum('AcctInputMbyte');
var outputTotal = store.sum('AcctOutputMbyte');
var afterField = (Ext.getCmp(formAfterID)).getValue();
var beforeField = (Ext.getCmp(formBeforeID)).getValue();
// Mask parent window
wispUserLogsWindow.getEl().mask();
uxAjaxRequest(
wispUserLogsWindow,
{
params: {
From: afterField,
To: beforeField,
ID: id,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'WiSPUserLogs',
SOAPFunction: 'getWiSPUserLogsSummary',
SOAPParams: '0:ID,0:From,0:To'
},
customSuccess: function (result) {
response = Ext.decode(result.responseText);
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// Traffic variables
var trafficCap = response.data.trafficCap; // value of -1: prepaid
var trafficCurrentTopupUsed = response.data.trafficCurrentTopupUsed; // value of -1: no current topup
var trafficCurrentTopupCap = response.data.trafficCurrentTopupCap; // value of -1: no current topup
var trafficTopupRemaining = response.data.trafficTopupRemaining;
// Uptime variables
var uptimeCap = response.data.uptimeCap; // value of -1: prepaid
var uptimeCurrentTopupUsed = response.data.uptimeCurrentTopupUsed; // value of -1: no current topup
var uptimeCurrentTopupCap = response.data.uptimeCurrentTopupCap; // value of -1: no current topup
var uptimeTopupRemaining = response.data.uptimeTopupRemaining;
// Total up traffic
var trafficTotalAllowed;
var validTrafficTopups;
if (trafficCurrentTopupCap > 0) {
validTrafficTopups = trafficCurrentTopupCap;
validTrafficTopups += trafficTopupRemaining;
} else {
validTrafficTopups = trafficTopupRemaining;
}
if (trafficCap < 0) {
trafficTotalAllowed = validTrafficTopups;
} else {
trafficTotalAllowed = trafficCap + validTrafficTopups;
}
// Traffic usage
var trafficUsage = inputTotal + outputTotal;
// Total up uptime
var uptimeTotalAllowed;
var validUptimeTopups;
if (uptimeCurrentTopupCap > 0) {
validUptimeTopups = uptimeCurrentTopupCap;
validUptimeTopups += uptimeTopupRemaining;
} else {
validUptimeTopups = uptimeTopupRemaining;
}
if (uptimeCap < 0) {
uptimeTotalAllowed = validUptimeTopups;
} else {
uptimeTotalAllowed = uptimeCap + validUptimeTopups;
}
// Get summary field
var form = Ext.getCmp(summaryFormID);
var summaryTotal = Ext.getCmp(summaryTotalID);
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
// Format string before printing
var trafficString = '';
// Prepaid traffic
if (trafficCap == -1) {
trafficCap = 'Prepaid';
trafficString += sprintf(' Traffic\nCap: %s MB Topup: %d MB\n'+
'Usage: %d/%d MB\n=====================================\n',
trafficCap,validTrafficTopups,trafficUsage,trafficTotalAllowed);
// Uncapped traffic
} else if (trafficCap == 0) {
trafficString += sprintf(' Traffic\nCap: Uncapped Used: %d\n=====================================n',
trafficUsage);
// Capped traffic
} else {
trafficString += sprintf(' Traffic\nCap: %d MB Topup: %d MB\n'+
'Usage: %d/%d MB\n=====================================\n',
trafficCap,validTrafficTopups,trafficUsage,trafficTotalAllowed);
}
// Format string before printing
var uptimeString = '';
// Prepaid uptime
if (uptimeCap == -1) {
uptimeCap = 'Prepaid';
uptimeString += sprintf(' Uptime\nCap: %s MB Topup: %d MB\n'+
'Usage: %d/%d MB',
uptimeCap,validUptimeTopups,uptimeTotal,uptimeTotalAllowed);
// Uncapped uptime
} else if (uptimeCap == 0) {
uptimeString += sprintf(' Uptime\nCap: Uncapped Used: %d',
uptimeTotal);
// Capped uptime
} else {
uptimeString += sprintf(' Uptime\nCap: %d MB Topup: %d MB\n'+
'Usage: %d/%d MB',
uptimeCap,validUptimeTopups,uptimeTotal,uptimeTotalAllowed);
}
summaryTotal.setValue(trafficString+uptimeString);
},
failure: function (result) {
Ext.MessageBox.alert('Failed', 'Couldn\'t fetch data: '+result.date);