1 | var ip_format = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-4]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
---|
2 | var busyDOM;
|
---|
3 |
|
---|
4 | $(document).on('click', 'ul.tabs > li:not(.current)', function(event) {
|
---|
5 | $(this).addClass('current').siblings().removeClass('current')
|
---|
6 | .closest('div.section').children('div.box').hide().eq($(this).index()).css('display','inline-block').fadeIn(150, function() { $(this).trigger('onShow'); });
|
---|
7 | });
|
---|
8 |
|
---|
9 | document.addEventListener("DOMContentLoaded", () => {
|
---|
10 | busyDOM = getBusyOverlay($('.box').parent()[0], {opacity:0.6, text:'Загрузка', style:'color:#1f4e6b; font-weight: bold;'}, {color: '#1f4e6b', type:'circle', size:48});
|
---|
11 | });
|
---|
12 |
|
---|
13 | $(window).on('load', function() {
|
---|
14 | busyDOM.remove();
|
---|
15 | _ticker = new Ticker($('#ticker'));
|
---|
16 | _update_();
|
---|
17 | get_device();
|
---|
18 |
|
---|
19 | });
|
---|
20 |
|
---|
21 | jQuery.fn.extend({
|
---|
22 | alignCenter: function(x, y) {
|
---|
23 | return this.each(function() {
|
---|
24 | var w = $(this).width();
|
---|
25 | var h = $(this).height();
|
---|
26 | var W = $(window).width();
|
---|
27 | var H = $(window).height();
|
---|
28 | var SL = $(window).scrollLeft();
|
---|
29 | var ST = $(window).scrollTop();
|
---|
30 | if(x == undefined || y == undefined) {
|
---|
31 | x = $(window).width()/2 + SL;
|
---|
32 | y = $(window).height()/2.5 + ST;
|
---|
33 | }
|
---|
34 | var marginLeft = Math.max(SL, Math.min(W + SL, parseInt(x + w/2)) - w) + 'px';
|
---|
35 | var marginTop = Math.max(ST, Math.min(H + ST, parseInt(y + h/2)) - h) + 'px';
|
---|
36 | $(this).css({'left':marginLeft, 'top':marginTop});
|
---|
37 | });
|
---|
38 | }
|
---|
39 | });
|
---|
40 |
|
---|
41 | var dragging = {'on':false};
|
---|
42 | $(document).on( 'mousedown', 'div.popup_header', function(e) {
|
---|
43 | var popup = $(this).parent();
|
---|
44 | dragging.startLeft = parseInt(popup.css('left')) - e.pageX;
|
---|
45 | dragging.startTop = parseInt(popup.css('top')) - e.pageY;
|
---|
46 | dragging.obj = popup;
|
---|
47 | dragging.on = true;
|
---|
48 | $(document).on( 'mousemove', function(e) {
|
---|
49 | dragging.obj.css( {'left':dragging.startLeft + e.pageX, 'top':dragging.startTop + e.pageY} );
|
---|
50 | return false;
|
---|
51 | });
|
---|
52 | return false;
|
---|
53 | });
|
---|
54 |
|
---|
55 | $(document).on( 'mouseup', function(e) {
|
---|
56 | shiftSelectionStart = undefined;
|
---|
57 | if(dragging.on) {
|
---|
58 | $(document).off('mousemove');
|
---|
59 | dragging.on = false;
|
---|
60 | $(document.elementFromPoint(e.pageX-$(window).scrollLeft(), e.pageY-$(window).scrollTop())).trigger('drop', dragging.obj);
|
---|
61 | }
|
---|
62 | });
|
---|
63 |
|
---|
64 | $(document).on('keydown', function(event) {
|
---|
65 | if($('#popupStack div.popup').length > 0) {
|
---|
66 | if(event.keyCode === 27 && $('#popup div.dontclose').length == 0) {
|
---|
67 | closePopup();
|
---|
68 | return false;
|
---|
69 | }
|
---|
70 | if(event.keyCode === 13) {
|
---|
71 | var button = $('#popup button.default');
|
---|
72 | if(button.length == 1) {
|
---|
73 | button.click();
|
---|
74 | return false;
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 | });
|
---|
79 |
|
---|
80 | $(document).on('keypress', function(event) {
|
---|
81 | var id = event.target.id;
|
---|
82 | if(event.which == 0 || event.which == 8 || event.which == 13)
|
---|
83 | return true;
|
---|
84 | if($(event.target).hasClass('lat')) {
|
---|
85 | if(String.fromCharCode(event.which).search(/[a-z0-9_]/i) < 0)
|
---|
86 | return error(event.target, 'Допустимы только латинские буквы, цифры и символ "_"');
|
---|
87 | }
|
---|
88 | else if($(event.target).hasClass('lat_')) {
|
---|
89 | if(String.fromCharCode(event.which).search(/[a-z]/i) < 0)
|
---|
90 | return error(event.target, 'Допустимы только латинские буквы');
|
---|
91 | }
|
---|
92 | });
|
---|
93 |
|
---|
94 | $(document).on('click', '#exit', function(){
|
---|
95 | document.cookie = "password=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
|
---|
96 | documentReload();
|
---|
97 | })
|
---|
98 |
|
---|
99 | $(document).on('change', '#corr', function(){
|
---|
100 | if($('#corr').val() < -39)$('#corr').val(-39);
|
---|
101 | if($('#corr').val() > 72) $('#corr').val(72);
|
---|
102 | request({"cmd": "setRTCcorr","corr": Number($("#corr").val())});
|
---|
103 | })
|
---|
104 |
|
---|
105 | $(document).on('click', '#save', function(){
|
---|
106 | dialog("Вы действительно хотите сохранить текущую конфигурацию?", function() {
|
---|
107 | request({"cmd": "saveConfig"}, function(result, text){
|
---|
108 | if(result['status'] == 'ok') notice("Конфигурация успешно сохранена");
|
---|
109 | else if(result['status'] == 'error'){
|
---|
110 | if(result['error'] == 'save failed') notice("Ошибка сохранения конфигурации");
|
---|
111 | }
|
---|
112 | });
|
---|
113 | });
|
---|
114 | })
|
---|
115 |
|
---|
116 | $(document).on('click', 'ul.PLC-tabs-units > li:not(.current-units)', function(event) {
|
---|
117 | PLC_tabs_units(this);
|
---|
118 | PLC_get_block_param($("li.current-units").index(), true);
|
---|
119 | })
|
---|
120 |
|
---|
121 | $(document).on('click', '.other_butt', function(event){
|
---|
122 | var parentID = $(event.target).parent().attr('id');
|
---|
123 | if(parentID === 'btn_restart'){
|
---|
124 | dialog("Вы действительно хотите произвести перезапуск модуля S-port?", function(){
|
---|
125 | request({"cmd":"restart"});
|
---|
126 | $("ul.tabs > li").first().addClass('current').siblings().removeClass('current')
|
---|
127 | .closest('div.section').children('div.box').hide().eq($("ul.tabs > li").index()).css('display','inline-block').fadeIn(150, function() { $("ul.tabs > li").trigger('onShow'); });
|
---|
128 | });
|
---|
129 | }
|
---|
130 | else if(parentID === 'btn_ethernet'){
|
---|
131 | showPopup('ethernet');
|
---|
132 | var ctrl = getBusyOverlay($('#popup')[0], {opacity:0.6, text:'Подождите...', style:'color:#1f4e6b; font-weight: bold;'}, {color: '#1f4e6b', type:'circle', size:48});
|
---|
133 | request({"cmd":"getNet"}, function(result, text){
|
---|
134 | var net = result['net'];
|
---|
135 | $("#ethernet tr:eq(0) td:eq(1) input").val(net['MAC']);
|
---|
136 | $("#ethernet tr:eq(1) td:eq(1) input").val(net['ip']);
|
---|
137 | $("#ethernet tr:eq(2) td:eq(1) input").val(net['mask']);
|
---|
138 | $("#ethernet tr:eq(3) td:eq(1) input").val(net['gw']);
|
---|
139 | }).progress(function(x){x < 100 || ctrl.remove();});
|
---|
140 |
|
---|
141 | }
|
---|
142 | else if(parentID === 'btn_snmp'){
|
---|
143 | showPopup('snmp');
|
---|
144 | var ctrl = getBusyOverlay($('#popup')[0], {opacity:0.6, text:'Подождите...', style:'color:#1f4e6b; font-weight: bold;'}, {color: '#1f4e6b', type:'circle', size:48});
|
---|
145 | request({"cmd":"getSnmp"}, function(result, text){
|
---|
146 | if(result['status'] == 'ok'){
|
---|
147 | $("#snmp-version select:eq(0)").val(result['version']);
|
---|
148 | $("#community input[type = text]").val(result['community']);
|
---|
149 | var trap = result['trap'];
|
---|
150 | $("#traps input[type = checkbox]")[0].checked = trap['enable'];
|
---|
151 | $("#traps input[type = text]").prop('disabled', !trap['enable']);
|
---|
152 | $("#traps input[type = text]:eq(1)").val(trap['community']);
|
---|
153 | $("#traps input[type = text]:eq(0)").val(trap['ip']);
|
---|
154 | }
|
---|
155 | }).progress(function(x){x < 100 || ctrl.remove();});;
|
---|
156 | }
|
---|
157 | else if(parentID === 'btn_changePass'){
|
---|
158 | showPopup('changePass');
|
---|
159 | var cookies = getCookies();
|
---|
160 | $('#popup .popup_header p').html(cookies['login']);
|
---|
161 | $('#popup .popup_header input[type = password]').val("");
|
---|
162 | }
|
---|
163 | });
|
---|
164 |
|
---|
165 | $(document).on('focus or click', '#net_settings tr:eq(1) input[type = text]', function(){
|
---|
166 | if($('#net_settings tr:eq(1) input[type = text]').val().length == 0)
|
---|
167 | $('#net_settings tr:eq(1) input[type = text]').val('255.255.255.0');
|
---|
168 | });
|
---|
169 |
|
---|
170 | $(document).on("keyup", ".ip_mask", function(){
|
---|
171 | if($(this).val().match(ip_format)) $(this).css({'border': '0.1em solid green'});
|
---|
172 | else $(this).css({'border': '0.1em solid red'});
|
---|
173 | })
|
---|
174 |
|
---|
175 | $(document).on("blur", ".ip_mask", function(){
|
---|
176 | if(!($(this).val().match(ip_format))) $(this).val("");
|
---|
177 | $(this).css({'border': '0.1em solid #AAA'});
|
---|
178 | })
|
---|
179 |
|
---|
180 | $(document).on('click', 'ul.tabs > li:not(.current)', function(event) {
|
---|
181 | if($(event.target).parent().attr('id') === 'tabsFirs'){
|
---|
182 | switch($(this).index()){
|
---|
183 | case 0:
|
---|
184 | PLC_tabs_units($("ul.PLC-tabs-units > li").first());
|
---|
185 | PLC_getBlockslist(true);
|
---|
186 | break;
|
---|
187 | case 1:
|
---|
188 | request({"cmd": "getRTCcorr"}, function(result, text){
|
---|
189 | if(result['status'] == 'ok') $("#corr").val(result['corr']);
|
---|
190 | });
|
---|
191 | break;
|
---|
192 | case 2:
|
---|
193 | request({"cmd": "getVersion"}, function(result, text){
|
---|
194 | if(result['status'] == 'ok') $('#version span').html('<b>' + result['ver'] + '.' + result['subVer'] + '</b>');
|
---|
195 | });
|
---|
196 | break;
|
---|
197 | }
|
---|
198 | }
|
---|
199 | });
|
---|
200 |
|
---|
201 | $(document).on('change', '#inputNameUnit', function () {
|
---|
202 | if($('#route_name').length){
|
---|
203 | $('#route_name').html('"' + $('#inputNameUnit').val() + '"');
|
---|
204 | }
|
---|
205 | });
|
---|
206 |
|
---|
207 | $(document).on('change', '#popup #table_route select', function (event) {
|
---|
208 | if (event.target.id == 'id_sel') return;
|
---|
209 | var num = event.target.id.replace("sel_route_", "");
|
---|
210 | if ($('#popup #' + event.target.id)[0].selectedIndex != 3) {
|
---|
211 | $('#popup #table_route tr:eq(0) td:eq(' + (num) + ') #id_block').remove();
|
---|
212 | return;
|
---|
213 | }
|
---|
214 | PLC_route_add_select(num);
|
---|
215 | });
|
---|
216 |
|
---|
217 | var route = Array();
|
---|
218 | $(document).on('click', '#route_settings', function(event){
|
---|
219 | showPopup('PLC_route');
|
---|
220 | $('#table_route tr:eq(0) td:eq(0) b').html($('.PLC-tabs-units li:eq(0) .sect_name p').text() + '<br>' + $('.PLC-tabs-units li:eq(0) .sect_ip p').text());
|
---|
221 | $('#popup .popup_header p').html(' "' + $('#inputNameUnit').val()+ '"');
|
---|
222 | if(route.length > 0){
|
---|
223 | var isEht = 0;
|
---|
224 | for(var i = 1, cnt = 0; i <= route[0]; i++){
|
---|
225 | if((route[i] & 0x0F) > 0){
|
---|
226 | if(isEht) {PLC_route_add_select(cnt > 2 ? i + 1 : i, route[i] & 0x0F); isEht = 0;}
|
---|
227 | else PLC_add_route('route_add', route[i] & 0x0F);
|
---|
228 | }
|
---|
229 | else {
|
---|
230 | PLC_add_route('route_add', 4);
|
---|
231 | isEht = 1;
|
---|
232 | }
|
---|
233 | if(++cnt == route[0]) break;
|
---|
234 | if(((route[i] & 0xF0) >> 4) > 0){
|
---|
235 | if(isEht) {PLC_route_add_select(cnt > 2 ? i + 1 : i, (route[i] & 0xF0) >> 4); isEht = 0;}
|
---|
236 | else PLC_add_route('route_add', (route[i] & 0xF0) >> 4);
|
---|
237 | }
|
---|
238 | else {
|
---|
239 | PLC_add_route('route_add', 4);
|
---|
240 | isEht = 1;
|
---|
241 | }
|
---|
242 | if(++cnt == route[0]) break;
|
---|
243 | }
|
---|
244 | }
|
---|
245 | });
|
---|
246 |
|
---|
247 | $(document).on('click', '#enable-all-poll input[type = checkbox]', function (event) {
|
---|
248 | request({"cmd": "enableAllPool","enable": $(this)[0].checked}, function(result, text){
|
---|
249 | if(result['status'] == 'ok'){
|
---|
250 | if($('#enable-all-poll input[type = checkbox]')[0].checked) $('#plc h3').removeClass('hidden');
|
---|
251 | else $('#plc h3').addClass('hidden');
|
---|
252 | }
|
---|
253 | });
|
---|
254 | });
|
---|
255 |
|
---|
256 | $(document).on('click', '#traps input[type = checkbox]', function (event) {
|
---|
257 | $("#traps input[type = text]").prop('disabled', !$(this)[0].checked);
|
---|
258 | if(!$(this)[0].checked) $("#traps input[type = text]").val("");
|
---|
259 | });
|
---|
260 |
|
---|
261 | $(document).on('mouseenter or mouseleave', '.parent li', function (event) {
|
---|
262 | $(this).find(".child").stop().slideToggle(300);
|
---|
263 | });
|
---|
264 |
|
---|
265 | $(document).on('click', '#enable-ntp', function (event) {
|
---|
266 | if($('#enable-ntp')[0].checked) {
|
---|
267 | $("#ip-ntp").prop('disabled', false);
|
---|
268 | $("#poll-ntp").prop('disabled', false);
|
---|
269 | }
|
---|
270 | else {
|
---|
271 | $("#ip-ntp").prop('disabled', true);
|
---|
272 | $("#poll-ntp").prop('disabled', true);
|
---|
273 | }
|
---|
274 |
|
---|
275 | });
|
---|
276 | /*##############################################################################*/
|
---|
277 |
|
---|
278 | function edit_user(){
|
---|
279 | var cookies = getCookies();
|
---|
280 | showPopup('editUser');
|
---|
281 | $('#popup .popup_header p').html(cookies['login']);
|
---|
282 | }
|
---|
283 | /****************** Таймер **************/
|
---|
284 | function _update_() {
|
---|
285 | var deferred = $.Deferred();
|
---|
286 | deferred.promise()
|
---|
287 | .then(PLC_get_block_param($("li.current-units").index()))
|
---|
288 | .then(getTime)
|
---|
289 | .then(getTemp)
|
---|
290 | .always(function(){setTimeout(_update_, 1000);});
|
---|
291 | deferred.resolve();
|
---|
292 | }
|
---|
293 | /**************** Запрос температуры S-port *******************/
|
---|
294 | var lastReqTemp = 0;
|
---|
295 |
|
---|
296 | function getTemp(force_request){
|
---|
297 | if($('#popup div.login').is(':visible'))return;
|
---|
298 | if((force_request) || (new Date().getTime() - lastReqTemp >= 60000)){
|
---|
299 | lastReqTemp = new Date().getTime();
|
---|
300 | request({"cmd": "getTemp"}, function(result, text){
|
---|
301 | if(result['status'] === 'ok'){
|
---|
302 | if(result['temp'] != 'missing')$('#boardName').attr("title","Температура " + result['temp']);
|
---|
303 | else $('#boardName').removeAttr("title");
|
---|
304 | }
|
---|
305 | });
|
---|
306 | }
|
---|
307 | }
|
---|
308 | /**************** Запрос девайса S-port *******************/
|
---|
309 | function get_device(){
|
---|
310 | request({"cmd": "getDevice"},function(result, text){
|
---|
311 | if(result['status'] == 'ok'){
|
---|
312 | $('#boardName').text(result['name']);
|
---|
313 | document.title = result['name'];
|
---|
314 | switch(Number(result['type'])){
|
---|
315 | case 16:
|
---|
316 | $('.box #plc').removeClass('hidden');
|
---|
317 | $('#tabsFirs li.current').html('PLC блоки');
|
---|
318 | request({"cmd": "enableAllPool"},function(result, text){
|
---|
319 | if(result['status'] == 'ok') $('#enable-all-poll input[type = checkbox]')[0].checked = result['enable'];
|
---|
320 | if(result['enable']) $('#plc h3').removeClass('hidden');
|
---|
321 | });
|
---|
322 | PLC_getBlockslist(true);
|
---|
323 | break;// PLC
|
---|
324 | }
|
---|
325 | getTemp(true);
|
---|
326 | }
|
---|
327 | });
|
---|
328 | }
|
---|
329 | /********** Изменение пароля пользователя **************/
|
---|
330 | function changePass(){
|
---|
331 | var current = $('#popup #tablePass tr:eq(0) td:eq(1) input').val();
|
---|
332 | var new1 = $('#popup #tablePass tr:eq(1) td:eq(1) input').val();
|
---|
333 | var new2 = $('#popup #tablePass tr:eq(2) td:eq(1) input').val();
|
---|
334 | if(new1 != new2) return critical('Новые пароли не совпадают');
|
---|
335 | request({"cmd": "changePass", "user":$('#popup .popup_header p').text(),
|
---|
336 | "current": (current.length > 0) ? MD5(current) : "", "new":(new1.length > 0) ? MD5(new1) : ""}, function(result, text){
|
---|
337 | if(result['status'] == 'error'){
|
---|
338 | if(result['error'] == 'password change error')critical('Ошибка смены пароля');
|
---|
339 | }
|
---|
340 | else if(result['status'] == 'ok') login();
|
---|
341 | });
|
---|
342 | closePopup();
|
---|
343 | }
|
---|
344 | /********** Установка настроек snmp **************/
|
---|
345 | function setSnmp(){
|
---|
346 | if($("#community input[type = text]").val() == 0)return critical("<b>community</b> не может быть пустым");
|
---|
347 | else if($("#community input[type = text]").val().length > 16)return critical("<b>community</b> не может содержать более 16 символов");
|
---|
348 | else if($("#community input[type = text]").val().match(/[^a-z]/i))return critical("<b>community</b> не может содержать русские символы");
|
---|
349 |
|
---|
350 | if($("#traps input[type = checkbox]")[0].checked){
|
---|
351 | if(!ip_format.test($('#traps input[type = text]:eq(0)').val())) return critical("Некорректно введены настройки сети");
|
---|
352 | if($("#traps input[type = text]:eq(1)").val() == 0)return critical("<b>community</b> не может быть пустым");
|
---|
353 | else if($("#traps input[type = text]:eq(1)").val().length > 16)return critical("<b>community</b> не может содержать более 16 символов");
|
---|
354 | else if($("#traps input[type = text]:eq(1)").val().match(/[^a-z]/i))return critical("<b>community</b> не может содержать русские символы");
|
---|
355 | }
|
---|
356 |
|
---|
357 | request({"cmd":"setSnmp", "version": Number($("#snmp-version select:eq(0)").val()), "community":$("#community input[type = text]").val(), "trap":{"enable":$("#traps input[type = checkbox]")[0].checked,
|
---|
358 | "ip":$("#traps input[type = text]:eq(0)").val(), "community":$("#traps input[type = text]:eq(1)").val()}}, function(result, text){
|
---|
359 | if(result['status'] == 'ok')closePopup();
|
---|
360 | });
|
---|
361 | }
|
---|
362 | /********** Установка настроек Ethernet **************/
|
---|
363 | function setNet(){
|
---|
364 | if((ip_format.test($('#ethernet tr:eq(1) td:eq(1) input').val())) && (ip_format.test($('#ethernet tr:eq(2) td:eq(1) input').val())) &&
|
---|
365 | (ip_format.test($('#ethernet tr:eq(3) td:eq(1) input').val()))){
|
---|
366 | request({"cmd":"setNet","net":{"ip" : $("#ethernet tr:eq(1) td:eq(1) input").val(),
|
---|
367 | "mask" : $("#ethernet tr:eq(2) td:eq(1) input").val(), "gw" : $("#ethernet tr:eq(3) td:eq(1) input").val()}
|
---|
368 | });
|
---|
369 | window.location.href = 'http://' + $("#ethernet tr:eq(1) td:eq(1) input").val() + '/';
|
---|
370 | }
|
---|
371 | else critical("Некорректно введены настройки сети");
|
---|
372 | }
|
---|
373 | /*********** Состояние отправки данных ***************/
|
---|
374 | function Ticker(img) {
|
---|
375 | this.state = 0;
|
---|
376 | this.timer = 0;
|
---|
377 | this.started = false;
|
---|
378 | this.images = ['empty.png','arrowup.png','hourglass.png','delete.png','arrowdown.png','success.png'];
|
---|
379 | this.cache = new Array(this.images.length);
|
---|
380 | for(var i in this.images) { this.cache[i] = new Image; this.cache[i].src = 'img/'+this.images[i]; }
|
---|
381 |
|
---|
382 | var _this = this;
|
---|
383 | $(document).ajaxStart(function() { _this.started = true; });
|
---|
384 | $(document).ajaxStop(function() { _this.started = false; });
|
---|
385 | $(document).ajaxSend(function() { _this.toState(1); });
|
---|
386 | $(document).ajaxError(function() { _this.toState(3); });
|
---|
387 | $(document).ajaxSuccess(function() { _this.toState(4); });
|
---|
388 |
|
---|
389 | this.toState = function(s) {
|
---|
390 | if(s >= 6) return false;
|
---|
391 | clearTimeout(this.timer);
|
---|
392 | this.state = s;
|
---|
393 | img.attr('src','img/'+this.images[s]);
|
---|
394 | var to = ([0, 700, 20000, 0, 700, 5000])[s];
|
---|
395 | if(to > 0) { this.timer = setTimeout(function() { _this.timeout(); }, to); }
|
---|
396 | };
|
---|
397 |
|
---|
398 | this.timeout = function() {
|
---|
399 | this.timer = 0;
|
---|
400 | this.toState(([0, 2, 3, 3, (this.started ? 2 : 5), 0])[this.state]);
|
---|
401 | };
|
---|
402 | }
|
---|
403 | /****************** Изменение NTP сервера **********************/
|
---|
404 | function editNTP(){
|
---|
405 | showPopup('ntp');
|
---|
406 | if(($('.sync-time tr:eq(0) td:eq(1)').text() != '-') && ($('.sync-time tr:eq(0) td:eq(1)').text().length > 0))
|
---|
407 | $('#popupStack div.popup input[type = text]').val($('.sync-time tr:eq(0) td:eq(1)').text());
|
---|
408 | }
|
---|
409 | /****************** Установка NTP сервера **********************/
|
---|
410 | function setNTP(){
|
---|
411 | if((ip_format.test($('#ip-ntp').val())) || ($('#ip-ntp').val().length == 0)) {
|
---|
412 | request({'cmd':'setNTP','ip':$('#popupStack div.popup input[type = text]').val()},
|
---|
413 | function(result, text){
|
---|
414 | if(result['status'] == 'ok') closePopup();
|
---|
415 | });
|
---|
416 | }
|
---|
417 | else critical("Некорректно введен IP адрес");
|
---|
418 | }
|
---|
419 | /****************** Получение времени **********************/
|
---|
420 | function getTime(){
|
---|
421 | const options = {year: 'numeric', month: 'long', day: 'numeric' };
|
---|
422 |
|
---|
423 | if($('#clock:visible').length > 0 ){
|
---|
424 | var d = new Date();
|
---|
425 |
|
---|
426 | $('#pc-date').html(d.toLocaleDateString(undefined, options));
|
---|
427 | $('#pc-time').html(d.toLocaleTimeString('it-IT'));
|
---|
428 | request({"cmd": "getRTC"}, function(result, text){
|
---|
429 | if(result['status'] == 'ok'){
|
---|
430 | var rtc = new Date(result['time'] * 1000);
|
---|
431 | $('#rtc-date').html(rtc.toLocaleDateString(undefined, options));
|
---|
432 | $('#rtc-time').html(rtc.toLocaleTimeString('it-IT'));
|
---|
433 |
|
---|
434 | if(result['bl'])$('.rtc-bat').css({'display':'block'});
|
---|
435 | else $('.rtc-bat').css({'display':'none'});
|
---|
436 |
|
---|
437 | if(result['ip'] != '0.0.0.0'){
|
---|
438 | $('.sync-time tr:eq(0) td:eq(1)').text(result['ip']);
|
---|
439 | $('.sync-time tr:eq(1) td:eq(1)').text(result['stratum']);
|
---|
440 | $('.sync-time tr:eq(2) td:eq(1)').text(result['poll']);
|
---|
441 | $('.sync-time tr:eq(3) td:eq(1)').text(result['reach']);
|
---|
442 | }
|
---|
443 | else {
|
---|
444 | $('.sync-time tr:eq(0) td:eq(1)').text('-');
|
---|
445 | $('.sync-time tr:eq(1) td:eq(1)').text('-');
|
---|
446 | $('.sync-time tr:eq(2) td:eq(1)').text('-');
|
---|
447 | $('.sync-time tr:eq(3) td:eq(1)').text('-');
|
---|
448 | }
|
---|
449 | }
|
---|
450 | });
|
---|
451 | }
|
---|
452 | }
|
---|
453 | /****************** Запись времени **********************/
|
---|
454 | function sendTime(){
|
---|
455 | request({"cmd": "setRTC","time": parseInt(Date.now() / 1000, 10)});
|
---|
456 | }
|
---|
457 | /*############################################################################################*/
|
---|
458 | /*######################################### PLC ##############################################*/
|
---|
459 | /***************** Создание вкладок слева PLC *******************/
|
---|
460 | function PLC_add_block(tabsUnitsPer){
|
---|
461 | if ($("ul.PLC-tabs-units > li").last().index() == 3) return;
|
---|
462 | $('.PLC-tabs-units').append('<li><div class="sect_name"><div id="state_block" style="background:darkgray;" title="Статус: Отсутствует"></div><p>Имя блока</p></div><div class="sect_ip"><p>IP блока</p></div></li>');
|
---|
463 | if (tabsUnitsPer) PLC_tabs_units($("ul.PLC-tabs-units > li").last());
|
---|
464 | if ($("ul.PLC-tabs-units > li").last().index() == 3) $('#PLC_addBlock').remove(); // удаляем иконку +
|
---|
465 | }
|
---|
466 | /*************** Удаление вкладок слева PLC ****************/
|
---|
467 | function PLC_remove_block(){
|
---|
468 | var del_block = $("li.current-units").index();
|
---|
469 | if(del_block == 0) return;
|
---|
470 |
|
---|
471 | dialog("Удалить блок из мониторинга SNMP?", function(){
|
---|
472 | request({"cmd":"PLCrmBlock", "unit":del_block}, function(result, text){
|
---|
473 | if(result['status'] == 'ok'){
|
---|
474 | $("ul.PLC-tabs-units > li").last().remove();
|
---|
475 | PLC_tabs_units($("ul.PLC-tabs-units > li").last());
|
---|
476 | if ($("ul.PLC-tabs-units > li").last().index() == 2) $('#blockBtn').append('<button type = "button" id = "PLC_addBlock" onclick="return PLC_BlockEdit(true)"><p>+</p></button>');
|
---|
477 | PLC_tabs_units($("ul.PLC-tabs-units > li").first());
|
---|
478 | PLC_getBlockslist(true);
|
---|
479 | }
|
---|
480 | });
|
---|
481 | });
|
---|
482 | }
|
---|
483 | /********** Переход с одной вкладки слева на другую PLC***********/
|
---|
484 | function PLC_tabs_units(element){
|
---|
485 | $(element).addClass('current-units').siblings().removeClass('current-units');
|
---|
486 | $("#nameUnit").text($(".PLC-tabs-units li:eq("+ $("li.current-units").index() +") p:eq(0)").text());
|
---|
487 | if ($("li.current-units").index() == 0) $("#PLC_block_rm").addClass('hidden');
|
---|
488 | else $("#PLC_block_rm").removeClass('hidden');
|
---|
489 | }
|
---|
490 | /******************** Запрос колличество блоков PLC******************/
|
---|
491 | function PLC_getBlockslist(force_request){
|
---|
492 | var stat = Array();
|
---|
493 | if((force_request) || ($('#plc:visible').length > 0)){
|
---|
494 | request({"cmd":"PLCgetBlockslist"}, function(result, text){
|
---|
495 | if(result['status'] == 'ok'){
|
---|
496 | for (i = 0; i < result['list'][0]; i++)stat[i] = $('.PLC-tabs-units li:eq('+ (i) +') #state_block').css('background'); //+ result['list'][i + 1][0] +
|
---|
497 | for (; $('.PLC-tabs-units').find('li').length > result['list'][0];)PLC_remove_block();
|
---|
498 | for (i = 0; i < result['list'][0]; i++){
|
---|
499 | if((i > 0) && ($('.PLC-tabs-units').find('li').length < result['list'][0]))PLC_add_block(false);
|
---|
500 | $('.PLC-tabs-units li:eq('+ (i) +') #state_block').css('background', stat[i]);
|
---|
501 | if(result['list'][i + 1][0].length > 0) $(".PLC-tabs-units li:eq("+ (i) +") .sect_name p").text(result['list'][i + 1][0]);
|
---|
502 | else $(".PLC-tabs-units li:eq("+ (i) +") .sect_name p").text("Имя блока");
|
---|
503 | if (result['list'][i + 1][1].length > 0)$(".PLC-tabs-units li:eq("+ (i) +") .sect_ip p").text(result['list'][i + 1][1]);
|
---|
504 | else $(".PLC-tabs-units li:eq("+ (i) +") .sect_ip p").text("IP блока");
|
---|
505 | }
|
---|
506 | $("#nameUnit").text($(".PLC-tabs-units li:eq("+ $("li.current-units").index() +") .sect_name p").text());
|
---|
507 |
|
---|
508 | PLC_get_block_param($("li.current-units").index(), true);
|
---|
509 | }
|
---|
510 | });
|
---|
511 | }
|
---|
512 | }
|
---|
513 | /****************** Запрос динамических параметров блока PLC *********************/
|
---|
514 | var lastReqBlockParam = 0;
|
---|
515 |
|
---|
516 | function PLC_get_block_param(unit, force_request){
|
---|
517 | if(($('#plc:visible').length > 0) && ($('#popup:visible').length == 0)){
|
---|
518 | if((force_request) || (new Date().getTime() - lastReqBlockParam >= 3000)){
|
---|
519 | lastReqBlockParam = new Date().getTime();
|
---|
520 | var massHFval1Ru = Array("Нет сигнала", "Перегрузка", "Активация", "Прием данных");
|
---|
521 | var massHFval2Ru = Array("Аналог", "Транзит", "Цифр.ведущий", "Цифр.ведомый");
|
---|
522 | var massUMalarmRu = Array("ОК", "Обрыв линии", "Обрыв ФПРД", "Нет вх. сигнала", "Перегрев");
|
---|
523 | var massMSRMNT = Array("", "", "", "kHz", "kHz", "dBm", "dB", "kb/s", "kb/s", "dB", "dB", "", "", "");
|
---|
524 | var type_prm = Array("Несоглас.", "Соглас.");
|
---|
525 | var att_prm = Array("0 dB", "-6 dB", "-12 dB", "-18 dB", "-24 dB");
|
---|
526 | request({"cmd": "PLCblockParams","unit": unit}, function(result, text){
|
---|
527 | if(result['status'] === 'ok'){
|
---|
528 | var unit = result['unit'];
|
---|
529 | $("#common tr:eq(1) td:eq(1)").text(type_prm[result['filter'][0]]);
|
---|
530 | $("#common tr:eq(2) td:eq(1)").text(att_prm[result['filter'][1]]);
|
---|
531 | if(result['power'] == 0) $("#common tr:eq(3) td:eq(1)").text("n/a");
|
---|
532 | else $("#common tr:eq(3) td:eq(1)").text(result['power'] + " W");
|
---|
533 | if (result['vers'] == 0)$("#common tr:eq(0) td:eq(1)").text("-");
|
---|
534 | else $("#common tr:eq(0) td:eq(1)").text(result['vers']);
|
---|
535 |
|
---|
536 | for (i = 0; i < result['HF'].length; i++){
|
---|
537 | var HF = result['HF'][i];
|
---|
538 | for(q = 0; q < HF.length; q++) {
|
---|
539 | if (q == 0){
|
---|
540 | if (HF[q]) $("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").text("Включен");
|
---|
541 | else $("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").text("Выключен");
|
---|
542 | }
|
---|
543 | else if (q == 1 && (HF[q] in massHFval1Ru)){
|
---|
544 | if (HF[q] < 3 && HF[0])$("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").css(HF[0] ? {"color":"red"} : {"color":"#777"});
|
---|
545 | else $("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").css(HF[0] ? {"color":"black"} : {"color":"#777"});
|
---|
546 | if(HF[0])$("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").text(massHFval1Ru[HF[q]]);
|
---|
547 | else $("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").text("-");
|
---|
548 | }
|
---|
549 | else if (q == 2 && (HF[q] in massHFval2Ru)){
|
---|
550 | if(HF[0])$("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").text(massHFval2Ru[HF[q]]);
|
---|
551 | else $("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").text("-");
|
---|
552 | }
|
---|
553 | else if (HF[0] == true){
|
---|
554 | if(q > 2 && q < 5) $("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").text((HF[q] - 2) + " - " + (HF[q] + 2) + " " + massMSRMNT[q]);
|
---|
555 | else if(HF[2] >= 2){
|
---|
556 | if (q > 4 && q < 11) $("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").text((HF[q]/10) + " " + massMSRMNT[q]);
|
---|
557 | else if(q == 11 )$("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").text((HF[q]) + " " + massMSRMNT[q]);
|
---|
558 | else if (q == 12) $("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").html(HF[q]/10 + " • 10<sup>"+HF[++q]+"</sup>");
|
---|
559 | }
|
---|
560 | else {
|
---|
561 | if (q > 4 && q < 7) $("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").text((HF[q]/10) + " " + massMSRMNT[q]);
|
---|
562 | else $("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").text("-");
|
---|
563 | }
|
---|
564 | }
|
---|
565 | else if (HF[0] == false)$("#vch"+(i + 1)+" tr:eq("+q+") td:eq(1)").text("-")
|
---|
566 | }
|
---|
567 | if(!HF[0]){
|
---|
568 | $("#comboHF_"+(i + 1)+"").css({"color":"#777"});
|
---|
569 | $("#vch"+(i + 1)+"").css({"color":"#777"});
|
---|
570 | }
|
---|
571 | else {
|
---|
572 | $("#comboHF_"+(i + 1)+"").css({"color":"black"});
|
---|
573 | $("#vch"+(i + 1)+"").css({"color":"black"});
|
---|
574 | }
|
---|
575 | }
|
---|
576 |
|
---|
577 | for (i = 0; i < result['pwrAmp'].length; i++){
|
---|
578 | var pwr = result['pwrAmp'][i];
|
---|
579 | if (!pwr[0]){ // отсутствует
|
---|
580 | $("#comboUM_" + (i + 1)).find('legend b').text("УМ02");
|
---|
581 | $("#um"+(i + 1)+" tr:eq(0) td:eq(1)").text("Отсутствует");
|
---|
582 | $("#um"+(i + 1)+" tr:eq(1) td:eq(1)").css({"color":"#777"});
|
---|
583 | for (q = 1; q < $("#um" + (i + 1)).find('tr').length; q++) $("#um"+(i + 1)+" tr:eq(" + q + ") td:eq(1)").text("-");
|
---|
584 | }
|
---|
585 | else {
|
---|
586 | $("#comboUM_" + (i + 1)).find('legend b').text("УМ02 v." + pwr[1]);
|
---|
587 | $("#um"+(i + 1)+" tr:eq(0) td:eq(1)").text("OK");
|
---|
588 | if (pwr[2] != 0) $("#um"+(i + 1)+" tr:eq(1) td:eq(1)").css({"color":"red"}); // авария
|
---|
589 | else $("#um"+(i + 1)+" tr:eq(1) td:eq(1)").css({"color":"black"});
|
---|
590 | if (pwr[2] in massUMalarmRu){
|
---|
591 | if(pwr[0])$("#um"+(i + 1)+" tr:eq(1) td:eq(1)").text(massUMalarmRu[pwr[2]]);
|
---|
592 | else $("#um"+(i + 1)+" tr:eq(1) td:eq(1)").text("-");
|
---|
593 | }
|
---|
594 | $("#um"+(i + 1)+" tr:eq(2) td:eq(1)").text(pwr[3] + " dBm");
|
---|
595 | $("#um"+(i + 1)+" tr:eq(3) td:eq(1)").html(pwr[4] + " ℃");
|
---|
596 | if(pwr[1] < 9) $("#um"+(i + 1)+" tr:eq(4) td:eq(1)").text("n/a");
|
---|
597 | else $("#um"+(i + 1)+" tr:eq(4) td:eq(1)").text((pwr[5] / 10) + " Vrms");
|
---|
598 | }
|
---|
599 | if(!pwr[0]){
|
---|
600 | $("#comboUM_"+(i + 1)).css({"color":"#777"});
|
---|
601 | $("#um"+(i + 1)).css({"color":"#777"});
|
---|
602 | }
|
---|
603 | else {
|
---|
604 | $("#comboUM_"+(i + 1)).css({"color":"black"});
|
---|
605 | $("#um"+(i + 1)).css({"color":"black"});
|
---|
606 | }
|
---|
607 | }
|
---|
608 | }
|
---|
609 | });
|
---|
610 | }
|
---|
611 | PLC_getAlarm(force_request);
|
---|
612 | }
|
---|
613 | }
|
---|
614 | /*************** Запрос состояния аварий PLC*******************/
|
---|
615 | var lastReqAlarm = 0;
|
---|
616 |
|
---|
617 | function PLC_getAlarm(force_request){
|
---|
618 | if($('#plc:visible').length > 0 ){
|
---|
619 | if((force_request) || (new Date().getTime() - lastReqAlarm >= 3000)){
|
---|
620 | lastReqAlarm = new Date().getTime();
|
---|
621 | request({"cmd": "PLCalarm"}, function(result, text){
|
---|
622 | if(result['status'] === 'ok'){
|
---|
623 | if(result['alarms'] != 'undifined'){
|
---|
624 | for(var i = 0; i < result['alarms'].length; i++){
|
---|
625 | switch(result['alarms'][i]){
|
---|
626 | case 0: $(".PLC-tabs-units li:eq("+ i +") #state_block").css({"background":"darkgreen"}).attr("title","Статус: OK"); break;
|
---|
627 | case 1: $(".PLC-tabs-units li:eq("+ i +") #state_block").css({"background":"darkgray"}).attr("title","Статус: Отсутствует"); break;
|
---|
628 | case 2: $(".PLC-tabs-units li:eq("+ i +") #state_block").css({"background":"red"}).attr("title","Статус: Авария"); break;
|
---|
629 | }
|
---|
630 | }
|
---|
631 | }
|
---|
632 | }
|
---|
633 | });
|
---|
634 | }
|
---|
635 | }
|
---|
636 | }
|
---|
637 | /*********************** Установка параметров блока PLC ********************/
|
---|
638 | function PLC_Set_Block(first){
|
---|
639 | if(($("li.current-units").index() === 0) || ((ip_format.test($('#net_settings tr:eq(0) td:eq(1) input').val())) &&
|
---|
640 | (ip_format.test($('#net_settings tr:eq(1) td:eq(1) input').val())) && (ip_format.test($('#net_settings tr:eq(2) td:eq(1) input').val())))){
|
---|
641 | if(($("#timePoll").val() < 1) || ($("#timePoll").val() > 30)){
|
---|
642 | $("#timePoll").val('5');
|
---|
643 | return critical("Время опроса блока должно быть от 1 до 30 секунд.");
|
---|
644 | }
|
---|
645 | if((route.length == 0) && ($("li.current-units").index() != 0))return critical("Не задан маршрут до блока.");
|
---|
646 |
|
---|
647 | if(first){
|
---|
648 | for(var i = 0; i < $('.PLC-tabs-units').find('li').length; i++){
|
---|
649 | if($('.PLC-tabs-units li:eq('+ i +') .sect_ip p').text() === $('#net_settings tr:eq(0) td:eq(1) input').val()) return critical("Введенный IP адрес уже используется.");
|
---|
650 | }
|
---|
651 | PLC_add_block(true);
|
---|
652 | }
|
---|
653 | var ctrl = getBusyOverlay($('#popup')[0], {opacity:0.6, text:'Запись...', style:'color:#1f4e6b; font-weight: bold;'}, {color: '#1f4e6b', type:'circle', size:48});
|
---|
654 | request({'cmd':'PLCsetBlock','unit':$("li.current-units").index()/*,'enable':true*/,'timePoll':Number($("#timePoll").val()),
|
---|
655 | "name": $("#inputNameUnit").val(), "ip": $("#net_settings input:eq(0)").val(),
|
---|
656 | "nm": $("#net_settings input:eq(1)").val(),"gw": $("#net_settings input:eq(2)").val(),
|
---|
657 | 'filter':[Number($("#receiver_settings select:eq(0)").val()), Number($("#receiver_settings select:eq(1)").val())],
|
---|
658 | 'route':JSON.parse(JSON.stringify(route))},
|
---|
659 | function(result, text){
|
---|
660 | if(result['status'] == 'ok') {
|
---|
661 | closePopup();
|
---|
662 | PLC_getBlockslist(true);
|
---|
663 | }
|
---|
664 | }).progress(function(x){x < 100 || ctrl.remove();});
|
---|
665 | }
|
---|
666 | else if($("li.current-units").index() > 0) critical("Некорректно введен IP адрес.");
|
---|
667 | }
|
---|
668 | /*********** Функция запроса и отображения настроек блока PLC ***************/
|
---|
669 | function PLC_BlockEdit(first){ // флаг first для создания блока впервые
|
---|
670 | showPopup('PLC_EditBlock');
|
---|
671 | $('#popup .popup_footer .default').remove();
|
---|
672 | if(!first){
|
---|
673 | $('#popup .popup_footer').prepend('<button class="default" onclick="return PLC_Set_Block(false)">Сохранить</button>');
|
---|
674 | $('#popup .popup_header p').text($('#inputNameUnit').text());
|
---|
675 | if ($('.current-units').index() == 0) {
|
---|
676 | $("#popup #net_settings input[type = text]").prop('disabled', true);
|
---|
677 | $("#popup #common_settings tr:eq(2)").css({"display":"none"});
|
---|
678 | }
|
---|
679 | else {
|
---|
680 | $("#popup #net_settings input[type = text]").prop('disabled', false);
|
---|
681 | $("#popup #common_settings tr:eq(2)").css({"display":"table-row"});
|
---|
682 | }
|
---|
683 | var ctrl = getBusyOverlay($('#popup')[0], {opacity:0.6, text:'Подождите...', style:'color:#1f4e6b; font-weight: bold;'}, {color: '#1f4e6b', type:'circle', size:48});
|
---|
684 | request({"cmd":"PLCgetBlock","unit":$("li.current-units").index()}, function(result, text){
|
---|
685 | var massHF = Array("", "ВЧ 1к.", "ВЧ 2к.", "ВЧ 3к.", "Eht.");
|
---|
686 | if(result['status'] == 'ok'){
|
---|
687 | $("#popup #inputNameUnit").val(result['name']);
|
---|
688 | $('#popup .popup_header p').html(' "' + result['name'] + '"');
|
---|
689 | if(result['timePoll'] == 0)$(".popup #timePoll").val('1');
|
---|
690 | else $("#popup #timePoll").val(result['timePoll']);
|
---|
691 | $("#receiver_settings select:eq(0)").val(result['filter'][0]);
|
---|
692 | $("#receiver_settings select:eq(1)").val(result['filter'][1]);
|
---|
693 | $("#popup #net_settings input:eq(0)").val(result['ip']);
|
---|
694 | $("#popup #net_settings input:eq(1)").val(result['nm']);
|
---|
695 | $("#popup #net_settings input:eq(2)").val(result['gw']);
|
---|
696 | if(result['route']){
|
---|
697 | var isEht = 0;
|
---|
698 | route = result['route'];
|
---|
699 | $('#popup div #main_route').empty();
|
---|
700 | if(route[0] == 0) {
|
---|
701 | $('#popup div #main_route').append('Маршрут не задан');
|
---|
702 | route.length = 0;
|
---|
703 | }
|
---|
704 | else {
|
---|
705 | for(var i = 1, cnt = 0; i <= route[0]; i++){
|
---|
706 | if((route[i] & 0x0F) > 0){
|
---|
707 | if(isEht) {$('#popup div #main_route').append('ID ' + String(route[i] & 0x0F) + ' '); isEht = 0;}
|
---|
708 | else $('#popup div #main_route').append(massHF[route[i] & 0x0F] + '→');
|
---|
709 | }
|
---|
710 | else {
|
---|
711 | $('#popup div #main_route').append(massHF[4] + '→');
|
---|
712 | isEht = 1;
|
---|
713 | }
|
---|
714 | if(++cnt == route[0]) break;
|
---|
715 |
|
---|
716 | if(((route[i] & 0xF0) >> 4) > 0){
|
---|
717 | if(isEht) {$('#popup div #main_route').append('ID ' + String((route[i] & 0xF0) >> 4)); isEht = 0;}
|
---|
718 | else $('#popup div #main_route').append(massHF[((route[i] & 0xF0) >> 4)] + '→');
|
---|
719 | }
|
---|
720 | else {
|
---|
721 | $('#popup div #main_route').append(massHF[4] + '→');
|
---|
722 | isEht = 1;
|
---|
723 | }
|
---|
724 | if(++cnt == route[0]) break;
|
---|
725 | }
|
---|
726 | $('#popup div #main_route').append('<p id="route_name"> "'+ $('.popup #inputNameUnit').val() + '"</p>');
|
---|
727 | }
|
---|
728 | }
|
---|
729 | }
|
---|
730 | }).progress(function(x){x < 100 || ctrl.remove();});
|
---|
731 | }
|
---|
732 | else {
|
---|
733 | $('#popup .popup_header').text('Добавление блока для мониторинга SNMP');
|
---|
734 | $("#popup #timePoll").val('5');
|
---|
735 | route.length = 0;
|
---|
736 | $('#popup div #main_route').text('Маршрут не задан');
|
---|
737 | $('#popup .popup_footer').prepend('<button class="default" onclick="return PLC_Set_Block(true)">Добавить</button>');
|
---|
738 | }
|
---|
739 | }
|
---|
740 | /***** Добавление селектора ID и выбор если требуется ******/
|
---|
741 | function PLC_route_add_select(num, index) {
|
---|
742 | $('#popup #table_route tr:eq(0) td:eq(' + (num) + ') div').append('<div id="id_block">ID<select id="id_sel"><option>1</option><option>2</option><option>3</option><option>4</option>\
|
---|
743 | <option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option>\
|
---|
744 | <option>13</option><option>14</option></select></div>');
|
---|
745 | if((index != 'undifined') && (index > 0))$('#popup #table_route tr:eq(0) td:eq(' + (num) + ') #id_sel option:eq('+ (index - 1) +')').prop('selected', true);
|
---|
746 | }
|
---|
747 | /*************** Добавление маршрута и выбор если требуется ****************/
|
---|
748 | function PLC_add_route(btn, index){
|
---|
749 | var total_cell = $('#popup #table_route >tbody >tr:first >td').length;
|
---|
750 | if (btn === 'route_add') {
|
---|
751 | var html_select = '<div class="cell_route"><select id="sel_route_' + (total_cell - 1) + '"><option>ВЧ 1к.</option><option>ВЧ 2к.</option><option>ВЧ 3к.</option><option>Eth.</option></select>→</div>';
|
---|
752 | $('#popup #table_route tr:eq(0) td:eq(' + (total_cell - 1) + ')').html(html_select).removeClass('btn_route');
|
---|
753 | if (total_cell == 9) $('#popup #table_route tr:last').append('<td class="btn_route"><div><img onclick="return PLC_add_route(\'route_del\')" src="img/del.ico" alt="add" title="Удалить узел"></div></td>');
|
---|
754 | else {
|
---|
755 | $('#popup #table_route tr:last').append('<td class="btn_route"><div><img onclick="return PLC_add_route(\'route_add\')" src="img/add.ico" alt="add" title="Добавить узел"><br><img onclick="return PLC_add_route(\'route_del\')" src="img/del.ico" alt="add" title="Удалить узел"></div></td>');
|
---|
756 | if((index != 'undifined') && (index > 0)) $('#popup #table_route tr:eq(0) td:eq(' + (total_cell - 1) + ') #sel_route_' + (total_cell - 1) + ' option:eq('+ (index - 1) +')').prop('selected', true);
|
---|
757 | }
|
---|
758 | }
|
---|
759 | if(btn === 'route_del'){
|
---|
760 | $('#popup #table_route tr:eq(0) td:eq(' + (total_cell - 1) + ')').remove();
|
---|
761 | if (total_cell != 3) $('#popup #table_route td:last').html('<div><img onclick="return PLC_add_route(\'route_add\')" src="img/add.ico" alt="add" title="Добавить узел"><br><img onclick="return PLC_add_route(\'route_del\')" src="img/del.ico" alt="add" title="Удалить узел"></div>').addClass('btn_route');
|
---|
762 | else $('#popup #table_route td:last').html('<div><img onclick="return PLC_add_route(\'route_add\')" src="img/add.ico" alt="add" title="Добавить узел"></div>').addClass('btn_route');
|
---|
763 | }
|
---|
764 | }
|
---|
765 | /***************** Установка маршрута из всплывающего окна ******************/
|
---|
766 | function PLC_set_route(){
|
---|
767 | var total_cell = $('#popup #table_route >tbody >tr:first >td').length - 2;
|
---|
768 | var cntNibble = 0, cntByte = 0;
|
---|
769 |
|
---|
770 | route.length = 0;
|
---|
771 | if(total_cell == 0) {closePopup(); return $('div #main_route').html('Маршрут не задан');}
|
---|
772 | else $('div #main_route').empty();
|
---|
773 |
|
---|
774 | for (i = 1; i < total_cell + 1; i++) {
|
---|
775 | cntByte = parseInt((cntNibble / 2) + 1, 10);
|
---|
776 | if ($('#popup #table_route tr:eq(0) td:eq(' + i + ') #sel_route_' + i)[0].selectedIndex == 3) {
|
---|
777 | $('div #main_route').append($('#popup #table_route tr:eq(0) td:eq(' + i + ') #sel_route_' + i).val() + '→');
|
---|
778 | $('div #main_route').append('ID' + $('#popup #table_route tr:eq(0) td:eq(' + i + ') #id_sel').val()+ ' ');
|
---|
779 | if (cntNibble % 2 == 0) {
|
---|
780 | route[cntByte] &= ~0xFF;
|
---|
781 | route[cntByte] |= ($('#popup #table_route tr:eq(0) td:eq(' + i + ') #id_sel')[0].selectedIndex + 1) << 4;
|
---|
782 | cntNibble++;
|
---|
783 | }
|
---|
784 | else {
|
---|
785 | route[cntByte] &= ~0xF0;
|
---|
786 | route[cntByte + 1] |= $('#popup #table_route tr:eq(0) td:eq(' + i + ') #id_sel')[0].selectedIndex + 1;
|
---|
787 | cntNibble++;
|
---|
788 | }
|
---|
789 | cntNibble++;
|
---|
790 | }
|
---|
791 | else {
|
---|
792 | $('div #main_route').append($('#popup #table_route tr:eq(0) td:eq(' + i + ') #sel_route_' + i).val()+ '→');
|
---|
793 | if (cntNibble % 2 == 0) route[cntByte] |= $('#popup #table_route tr:eq(0) td:eq(' + i + ') #sel_route_' + i)[0].selectedIndex + 1;
|
---|
794 | else route[cntByte] |= ($('#popup #table_route tr:eq(0) td:eq(' + i + ') #sel_route_' + i)[0].selectedIndex + 1) << 4;
|
---|
795 | cntNibble++;
|
---|
796 | }
|
---|
797 | }
|
---|
798 | route[0] = cntNibble;
|
---|
799 | route.fill(0, route.length, (route.length = 9));
|
---|
800 |
|
---|
801 | $('div #main_route').append('<p id="route_name">"'+ $('#inputNameUnit').val() + '"</p>');
|
---|
802 | closePopup();
|
---|
803 | }
|
---|
804 | /*########################################## END PLC ###################################*/
|
---|
805 | /*######################################################################################*/
|
---|
806 | /************** Вычисление hash MD5 ***********/
|
---|
807 | var MD5 = function(d){result = M(V(Y(X(d),8*d.length)));return result.toLowerCase()};
|
---|
808 | function M(d){for(var _,m="0123456789ABCDEF",f="",r=0;r<d.length;r++)_=d.charCodeAt(r),f+=m.charAt(_>>>4&15)+m.charAt(15&_);return f}
|
---|
809 | function X(d){for(var _=Array(d.length>>2),m=0;m<_.length;m++)_[m]=0;for(m=0;m<8*d.length;m+=8)_[m>>5]|=(255&d.charCodeAt(m/8))<<m%32;return _}
|
---|
810 | function V(d){for(var _="",m=0;m<32*d.length;m+=8)_+=String.fromCharCode(d[m>>5]>>>m%32&255);return _}
|
---|
811 | function Y(d,_){d[_>>5]|=128<<_%32,d[14+(_+64>>>9<<4)]=_;for(var m=1732584193,f=-271733879,r=-1732584194,i=271733878,n=0;n<d.length;n+=16){var h=m,t=f,g=r,e=i;f=md5_ii(f=md5_ii(f=md5_ii(f=md5_ii(f=md5_hh(f=md5_hh(f=md5_hh(f=md5_hh(f=md5_gg(f=md5_gg(f=md5_gg(f=md5_gg(f=md5_ff(f=md5_ff(f=md5_ff(f=md5_ff(f,r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+0],7,-680876936),f,r,d[n+1],12,-389564586),m,f,d[n+2],17,606105819),i,m,d[n+3],22,-1044525330),r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+4],7,-176418897),f,r,d[n+5],12,1200080426),m,f,d[n+6],17,-1473231341),i,m,d[n+7],22,-45705983),r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+8],7,1770035416),f,r,d[n+9],12,-1958414417),m,f,d[n+10],17,-42063),i,m,d[n+11],22,-1990404162),r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+12],7,1804603682),f,r,d[n+13],12,-40341101),m,f,d[n+14],17,-1502002290),i,m,d[n+15],22,1236535329),r=md5_gg(r,i=md5_gg(i,m=md5_gg(m,f,r,i,d[n+1],5,-165796510),f,r,d[n+6],9,-1069501632),m,f,d[n+11],14,643717713),i,m,d[n+0],20,-373897302),r=md5_gg(r,i=md5_gg(i,m=md5_gg(m,f,r,i,d[n+5],5,-701558691),f,r,d[n+10],9,38016083),m,f,d[n+15],14,-660478335),i,m,d[n+4],20,-405537848),r=md5_gg(r,i=md5_gg(i,m=md5_gg(m,f,r,i,d[n+9],5,568446438),f,r,d[n+14],9,-1019803690),m,f,d[n+3],14,-187363961),i,m,d[n+8],20,1163531501),r=md5_gg(r,i=md5_gg(i,m=md5_gg(m,f,r,i,d[n+13],5,-1444681467),f,r,d[n+2],9,-51403784),m,f,d[n+7],14,1735328473),i,m,d[n+12],20,-1926607734),r=md5_hh(r,i=md5_hh(i,m=md5_hh(m,f,r,i,d[n+5],4,-378558),f,r,d[n+8],11,-2022574463),m,f,d[n+11],16,1839030562),i,m,d[n+14],23,-35309556),r=md5_hh(r,i=md5_hh(i,m=md5_hh(m,f,r,i,d[n+1],4,-1530992060),f,r,d[n+4],11,1272893353),m,f,d[n+7],16,-155497632),i,m,d[n+10],23,-1094730640),r=md5_hh(r,i=md5_hh(i,m=md5_hh(m,f,r,i,d[n+13],4,681279174),f,r,d[n+0],11,-358537222),m,f,d[n+3],16,-722521979),i,m,d[n+6],23,76029189),r=md5_hh(r,i=md5_hh(i,m=md5_hh(m,f,r,i,d[n+9],4,-640364487),f,r,d[n+12],11,-421815835),m,f,d[n+15],16,530742520),i,m,d[n+2],23,-995338651),r=md5_ii(r,i=md5_ii(i,m=md5_ii(m,f,r,i,d[n+0],6,-198630844),f,r,d[n+7],10,1126891415),m,f,d[n+14],15,-1416354905),i,m,d[n+5],21,-57434055),r=md5_ii(r,i=md5_ii(i,m=md5_ii(m,f,r,i,d[n+12],6,1700485571),f,r,d[n+3],10,-1894986606),m,f,d[n+10],15,-1051523),i,m,d[n+1],21,-2054922799),r=md5_ii(r,i=md5_ii(i,m=md5_ii(m,f,r,i,d[n+8],6,1873313359),f,r,d[n+15],10,-30611744),m,f,d[n+6],15,-1560198380),i,m,d[n+13],21,1309151649),r=md5_ii(r,i=md5_ii(i,m=md5_ii(m,f,r,i,d[n+4],6,-145523070),f,r,d[n+11],10,-1120210379),m,f,d[n+2],15,718787259),i,m,d[n+9],21,-343485551),m=safe_add(m,h),f=safe_add(f,t),r=safe_add(r,g),i=safe_add(i,e)}return Array(m,f,r,i)}
|
---|
812 | function md5_cmn(d,_,m,f,r,i){return safe_add(bit_rol(safe_add(safe_add(_,d),safe_add(f,i)),r),m)}
|
---|
813 | function md5_ff(d,_,m,f,r,i,n){return md5_cmn(_&m|~_&f,d,_,r,i,n)}
|
---|
814 | function md5_gg(d,_,m,f,r,i,n){return md5_cmn(_&f|m&~f,d,_,r,i,n)}
|
---|
815 | function md5_hh(d,_,m,f,r,i,n){return md5_cmn(_^m^f,d,_,r,i,n)}
|
---|
816 | function md5_ii(d,_,m,f,r,i,n){return md5_cmn(m^(_|~f),d,_,r,i,n)}
|
---|
817 | function safe_add(d,_){var m=(65535&d)+(65535&_);return(d>>16)+(_>>16)+(m>>16)<<16|65535&m}
|
---|
818 | function bit_rol(d,_){return d<<_|d>>>32-_}
|
---|
819 | /***************** Получаем cookie ******************/
|
---|
820 | function getCookies() {
|
---|
821 | var pairs = document.cookie.split(';');
|
---|
822 | var cookies = {};
|
---|
823 | for(var i in pairs) {
|
---|
824 | try {
|
---|
825 | var pair = pairs[i].trim().split('=');
|
---|
826 | if(pair.length == 2)
|
---|
827 | cookies[encodeURIComponent(pair[0])] = encodeURIComponent(pair[1]);
|
---|
828 | } catch(e) {}
|
---|
829 | }
|
---|
830 | return cookies;
|
---|
831 | }
|
---|
832 | /************ Показываем окно логина ********************/
|
---|
833 | function login(){
|
---|
834 | if($('#popup div.login').is(':visible'))return;
|
---|
835 | showPopup('login');
|
---|
836 | $('#popup input.lat').focus();
|
---|
837 | }
|
---|
838 | /****************** Авторизация *******************/
|
---|
839 | function auth(){
|
---|
840 | var passMD5="";
|
---|
841 | if($("#incorrectLogin").length > 0)$("#incorrectLogin").empty();
|
---|
842 | if($('#login input[type = text]').val().length === 0) $("#incorrectLogin").append("Ошибка: пустое имя пользователя").css({'color':'red'});
|
---|
843 | else {
|
---|
844 |
|
---|
845 | if(($('#login input[type = text]').val().length > 16) || ($('#login input[type = password]').val().length > 16)) {
|
---|
846 | $("#incorrectLogin").append("Ошибка: имя пользователя или пароль<br>более 16 символов").css({'color':'red'});
|
---|
847 | return;
|
---|
848 | }
|
---|
849 |
|
---|
850 | if($("#login input[type = text]").val().match(/[^a-z0-9_]/i)) {
|
---|
851 | $("#incorrectLogin").append("Ошибка: имя пользователя не может <br>содержать русские символы").css({'color':'red'});
|
---|
852 | return;
|
---|
853 | }
|
---|
854 |
|
---|
855 | if($('#login input[type = password]').val().length > 0) passMD5 = MD5($('#login input[type = password]').val());
|
---|
856 | else passMD5 = "";
|
---|
857 | $("#incorrectLogin").append("Выполняется вход...").css({'color':'black'});
|
---|
858 | request({"cmd":"login","user":""+$('#login input[type = text]').val()+"",
|
---|
859 | "password":""+passMD5+""}, function(result, text){
|
---|
860 | if(result['status'] == 'ok'){
|
---|
861 | documentReload();
|
---|
862 | //closePopup();
|
---|
863 | //get_device();
|
---|
864 | }
|
---|
865 | else if(result['status'] === 'error'){
|
---|
866 | if($("#incorrectLogin").length > 0)$("#incorrectLogin").empty();
|
---|
867 | if(result['error'] === 'incorrect login attempt')$("#incorrectLogin").append("Ошибка: неверное имя или пароль").css({'color':'red'});
|
---|
868 | }
|
---|
869 | });
|
---|
870 | }
|
---|
871 | };
|
---|
872 | /**************** Всплывающее окно ошибки ******************************/
|
---|
873 | function error(obj, text) {
|
---|
874 | $(obj).nextAll('label.error').remove();
|
---|
875 | var label = $('<label class="error">'+text+'</label>');
|
---|
876 | $(obj).after(label);
|
---|
877 | setTimeout(function() { label.remove(); }, 2500);
|
---|
878 | return false;
|
---|
879 | }
|
---|
880 | /**************** Всплывающие окна ******************************/
|
---|
881 | function showPopup(popup_type, x, y) {
|
---|
882 | $('#popupStack div.popup').removeAttr('id');
|
---|
883 | var html = $('#popup_' + popup_type).html();
|
---|
884 | $('#popupStack').append('<div class="popupGroup"><div class="backgr"></div><div class="popup overlay" id="popup">'+html+'</div></div>');
|
---|
885 | var popup = $.extend($('#popup'), {close:function(){
|
---|
886 | var was_active = (this.attr('id') === 'popup');
|
---|
887 | this.closest('div.popupGroup').remove();
|
---|
888 | if(was_active)
|
---|
889 | $('#popupStack div.popup:last').attr('id', 'popup');
|
---|
890 | this.closed = true;
|
---|
891 | if(this.deferred && this.deferred.state() == 'pending') this.deferred.resolve();
|
---|
892 | return this;
|
---|
893 | }});
|
---|
894 | var deferred = $.Deferred();
|
---|
895 | deferred.promise(popup);
|
---|
896 | popup.deferred = deferred;
|
---|
897 | popup.find(':input:visible:enabled').focus();
|
---|
898 | return popup.data('popup', popup).alignCenter(x, y);
|
---|
899 | }
|
---|
900 |
|
---|
901 | function closePopup(id) {
|
---|
902 | (id || $('#popup').data('popup')).close();
|
---|
903 | }
|
---|
904 |
|
---|
905 | function notice(text, hdr) {
|
---|
906 | return myDialog(text, [{text:'Закрыть',defaction:true}], {header:(hdr || 'Уведомление')});
|
---|
907 | }
|
---|
908 |
|
---|
909 | function critical(text, hdr) {
|
---|
910 | return myDialog(text, [{text:'Закрыть',defaction:true}], {header:(hdr || 'Ошибка'),img:'img/critical.png'});
|
---|
911 | }
|
---|
912 |
|
---|
913 | function dialog(content, onYes, onNo, options) {
|
---|
914 | return myDialog(content, [{text:'Да',handler:onYes,defaction:true},{text:'Нет',handler:onNo}], $.extend({img:'img/question.png'}, options));
|
---|
915 | }
|
---|
916 |
|
---|
917 | function warning(text, hdr) {
|
---|
918 | return myDialog(text, [{text:'Закрыть',defaction:true}], {header:(hdr || 'Предупреждение'),img:'img/warning.png'});
|
---|
919 | }
|
---|
920 |
|
---|
921 | function myDialog(content, buttons, opt) {
|
---|
922 | var popup = showPopup();
|
---|
923 | popup.html('<div class="popup_body"><div class="middle content">'+content+'</div></div><div class="popup_footer"></div>');
|
---|
924 | if(opt) {
|
---|
925 | if(opt['header'])
|
---|
926 | popup.prepend($('<div class="popup_header"> '+opt['header']+' </div>'));
|
---|
927 | if(opt['img'])
|
---|
928 | $('#popup .popup_body').prepend($('<div class="middle"><img src="'+opt['img']+'" alt=""></div>'));
|
---|
929 | }
|
---|
930 | for(var i in buttons) {
|
---|
931 | var btn = buttons[i];
|
---|
932 | var b = $('<button>'+btn['text']+'</button>')
|
---|
933 | .on('click', (function(h,popup,dontClose) { return function() { if(h) { h(popup); } if(!h || !dontClose) { popup.close(); } }; })(btn['handler'], popup, btn['dontClose']));
|
---|
934 | if(btn['defaction'])
|
---|
935 | b.addClass('default');
|
---|
936 | if(btn['img'])
|
---|
937 | b.prepend($('<img src="'+btn['img']+'" alt="">').css('margin-right', 4)).css('padding-left', 0);
|
---|
938 | $('#popup div.popup_footer').append(b);
|
---|
939 | }
|
---|
940 | popup.find(':input:visible:enabled').focus();
|
---|
941 | return popup.alignCenter();
|
---|
942 | }
|
---|
943 |
|
---|
944 | function documentReload() {
|
---|
945 | document.location.href = document.location.href.split('?')[0].replace(/#$/,'');
|
---|
946 | }
|
---|
947 |
|
---|
948 | function request(datain, success, error, deferred) {
|
---|
949 |
|
---|
950 |
|
---|
951 |
|
---|
952 | var data = $.extend(true, {}, datain);
|
---|
953 |
|
---|
954 | console.log("request" + JSON.stringify(data));
|
---|
955 |
|
---|
956 | var defer = deferred || new $.Deferred;
|
---|
957 | $.ajax({
|
---|
958 | type: 'POST',
|
---|
959 | url: 'api.c',
|
---|
960 | cache: false,
|
---|
961 | contentType: 'application/json; charset=UTF-8',
|
---|
962 | data: JSON.stringify(data),
|
---|
963 | dataType: 'json'
|
---|
964 | }).done( function(result, text) {
|
---|
965 | if(result) {
|
---|
966 | console.log(result);
|
---|
967 | if(result['status']){
|
---|
968 | if(result['status'] === 'error'){
|
---|
969 | defer.notify(100);
|
---|
970 | if(result['error'] === 'not logged in'){
|
---|
971 | login();
|
---|
972 | return;
|
---|
973 | }
|
---|
974 | else if((result['error'] === 'incorrect login attempt') || (result['error'] === 'password change error')) {
|
---|
975 | success(result, text);
|
---|
976 | return;
|
---|
977 | }
|
---|
978 | else if(result['error'] === 'access denied')result['error'] = 'доступ запрещен';
|
---|
979 | if(result['cmd'] == '') result['cmd'] = data['cmd'];
|
---|
980 | critical(result['cmd']+': '+result['error'], "Ошибка");
|
---|
981 | defer.reject(result);
|
---|
982 | if(error) error(result, text);
|
---|
983 | }
|
---|
984 | else {
|
---|
985 | defer.notify(100);
|
---|
986 | if(success) success(result, text);
|
---|
987 | defer.resolve(result);
|
---|
988 | }
|
---|
989 | }
|
---|
990 | } else { defer.notify(100); defer.reject(); }
|
---|
991 | }).fail(function(){ defer.notify(100); defer.reject(); });
|
---|
992 | return defer.promise();
|
---|
993 | }
|
---|