main.js 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123
  1. function $(id) {return document.getElementById(id);}
  2. // ############### Mobile Device ################
  3. if (window.screen.width < 769) {
  4. $('nav').style.display = 'none';
  5. }
  6. $('menu-icon').onclick = function(){
  7. $('nav').style.display = $('nav').style.display == 'none' ? 'block' : 'none';
  8. };
  9. //########## Main Page Alert Handler ############
  10. // fadeIn animation special for alerts
  11. function fadeIns(el){
  12. el.style.opacity = 0;
  13. (function fade() {
  14. var val = parseFloat(el.style.opacity);
  15. if (((val += 0.03) > 1) !== true) {
  16. el.style.opacity = val;
  17. var request = window.requestFrame('request');
  18. request(fade);
  19. }
  20. })();
  21. }
  22. var ac = $('AC'),
  23. dc = $('DC'),
  24. in_cur = $('in_cur'),
  25. out_cur = $('out_cur'),
  26. in_freq = $('in_freq'),
  27. out_freq = $('out_freq'),
  28. pwr = $('pwr'),
  29. bat_cap = $('bat_cap'),
  30. inner_temp = $('inner_temp'),
  31. battimeleft = $('bat_time_left'),
  32. // alarm = $('alarm'),
  33. sPower = $('sPower'),
  34. sBattery = $('sBattery');
  35. var battempCtrlChecked;
  36. function dataFadeIn(){
  37. var x = [
  38. ac,
  39. dc,
  40. in_cur,
  41. out_cur,
  42. in_freq,
  43. out_freq,
  44. pwr,
  45. bat_cap,
  46. inner_temp,
  47. battimeleft,
  48. sPower,
  49. sBattery
  50. ];
  51. for (var i = 0; i < x.length; i++){
  52. fadeIns(x[i]);
  53. }
  54. }
  55. // Alarm colors
  56. var ALARM_RED = '#ff5050',
  57. ALARM_YELLOW = '#f0ad4e',
  58. ALARM_GREEN = '#33cc00';
  59. //########## Settings Inform Boxes ############
  60. function HTMLcreate(htmlStr) {
  61. var frag = document.createDocumentFragment(),
  62. temp = document.createElement('div');
  63. temp.innerHTML = htmlStr;
  64. while (temp.firstChild) {
  65. frag.appendChild(temp.firstChild);
  66. }
  67. return frag;
  68. }
  69. // fade in animation
  70. function fadeIn(el, display){
  71. el.style.opacity = 0;
  72. el.style.display = display || 'block';
  73. (function fade() {
  74. var val = parseFloat(el.style.opacity);
  75. if (((val += 0.05) > 1) !== true) {
  76. el.style.opacity = val;
  77. var request = window.requestFrame('request');
  78. request(fade);
  79. }
  80. })();
  81. }
  82. //########## Settings Form ############
  83. function formValidation(){
  84. $('validation-box').innerHTML = '';
  85. var read_community,write_community,managerIP,managerIP2,managerIP3,managerIP4,managerIP5,
  86. ipaddr, gw, mask, tn_port, wtl_ip1, wtl_ip2, wtl_ip3, wtl_ip4, wtl_ip5, ups_cell_min, ups_cell_max/*, ntpservip*/;
  87. read_community = $('read_community');
  88. write_community = $('write_community');
  89. managerIP = $('managerIP');
  90. managerIP2 = $('managerIP2');
  91. managerIP3 = $('managerIP3');
  92. managerIP4 = $('managerIP4');
  93. managerIP5 = $('managerIP5');
  94. ipaddr = $('ipaddr');
  95. gw = $('gw');
  96. mask = $('mask');
  97. tn_port = $('tn_port');
  98. ssh_port = $('ssh_port');
  99. wtl_ip1 = $('wtl_ip1');
  100. wtl_ip2 = $('wtl_ip2');
  101. wtl_ip3 = $('wtl_ip3');
  102. wtl_ip4 = $('wtl_ip4');
  103. wtl_ip5 = $('wtl_ip5');
  104. ups_cell_min = +$('ups_cell_min').children[0].value;
  105. ups_cell_max = +$('ups_cell_max').children[0].value;
  106. // ntpservip = $('ntpservip');
  107. var flag = true;
  108. if (!$('dhcp').checked) {
  109. if(!ValidateIPaddress(ipaddr, ' IP-адрес устройства')) flag = false;
  110. if(!ValidateIPaddress(gw, ' IP-адрес шлюза')) flag = false;
  111. if(!ValidateIPaddress(mask, 'а Маска подсети')) flag = false;
  112. }
  113. if ($('tn_enabled').checked) {
  114. if(!ValidateNumber(tn_port, ' Порт Telnet')) flag = false;
  115. }
  116. if ($('ssh_enabled').checked) {
  117. if(!ValidateNumber(ssh_port, ' Порт SSH')) flag = false;
  118. }
  119. if ($('ssh_enabled').checked && $('tn_enabled').checked) {
  120. if (ssh_port.value == tn_port.value) {
  121. var warn = document.createElement('li');
  122. warn.innerHTML = 'Одинаковые поты Telnet и SSH!';
  123. $('validation-box').appendChild(warn);
  124. flag = false;
  125. }
  126. }
  127. if(ups_cell_min > ups_cell_max) {
  128. var warn = document.createElement('li');
  129. warn.innerHTML = 'Минимальное напряжение на ячейке не может быть больше максимального!';
  130. $('validation-box').appendChild(warn);
  131. flag = false;
  132. }
  133. if(!ValidateIPaddress(managerIP, ' Сервер SNMP 1')) flag = false;
  134. if(!ValidateAlphanumericPlus(read_community, 'Read Community')) flag = false;
  135. if(!ValidateAlphanumericPlus(write_community, 'Write Community')) flag = false;
  136. if(!ValidateIPaddress(managerIP2, ' Сервер SNMP 2')) flag = false;
  137. if(!ValidateIPaddress(managerIP3, ' Сервер SNMP 3')) flag = false;
  138. if(!ValidateIPaddress(managerIP4, ' Сервер SNMP 4')) flag = false;
  139. if(!ValidateIPaddress(managerIP5, ' Сервер SNMP 5')) flag = false;
  140. if(!ValidateCIDRIPaddress(wtl_ip1, ' Маска/IP-адреса 1 белого списка')) flag = false;
  141. if(!ValidateCIDRIPaddress(wtl_ip2, ' Маска/IP-адреса 2 белого списка')) flag = false;
  142. if(!ValidateCIDRIPaddress(wtl_ip3, ' Маска/IP-адреса 3 белого списка')) flag = false;
  143. if(!ValidateCIDRIPaddress(wtl_ip4, ' Маска/IP-адреса 4 белого списка')) flag = false;
  144. if(!ValidateCIDRIPaddress(wtl_ip5, ' Маска/IP-адреса 5 белого списка')) flag = false;
  145. if ($('ntp-inp') && !$('ntp-inp').disabled) {
  146. if(!ValidateIPaddress($('ntp-inp'), ' IP адрес NTP сервера')) flag = false;
  147. }
  148. return flag;
  149. }
  150. function ValidateIPaddress(ipaddress, z) {
  151. var warn = document.createElement('li');
  152. warn.innerHTML = 'Неправильно задан' + z + '!';
  153. if (/^(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-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress.value)) {
  154. return true;
  155. }
  156. $('validation-box').appendChild(warn);
  157. return false;
  158. }
  159. function ValidateCIDRIPaddress(ipaddress, z) {
  160. var warn = document.createElement('li');
  161. warn.innerHTML = 'Неправильно задан' + z + '!';
  162. if (/^(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-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/?([0-9]|[1-2][0-9]|3[0-2])$/.test(ipaddress.value) || !ipaddress.value) {
  163. return true;
  164. }
  165. $('validation-box').appendChild(warn);
  166. return false;
  167. }
  168. function ValidateNumber(n, z) {
  169. var warn = document.createElement('li');
  170. warn.innerHTML = 'Неправильно задан' + z + '!';
  171. if(/^-?[\d.]+(?:e-?\d+)?$/.test(n.value)) {
  172. return true;
  173. }
  174. $('validation-box').appendChild(warn);
  175. return false;
  176. }
  177. function ValidateAlphanumeric(uadd, z) {
  178. var warn = document.createElement('li');
  179. var letter = /^[0-9a-zA-Z]+$/;
  180. warn.innerHTML = 'Поле ' + z + ' может содержать только латинские буквы и цифры';
  181. if (letter.test(uadd.value)) {return true;}
  182. $('validation-box').appendChild(warn);
  183. return false;
  184. }
  185. function ValidateAlphanumericPlus(uadd, z) {
  186. var warn = document.createElement('li');
  187. var letter = /^[0-9a-zA-Z\-_]+$/;
  188. warn.innerHTML = 'Поле ' + z + ' может содержать только латинские буквы, цифры и символы -_';
  189. if (letter.test(uadd.value)) {return true;}
  190. $('validation-box').appendChild(warn);
  191. return false;
  192. }
  193. function validateUpload(oForm) {
  194. var file = oForm.elements.datafile.files[0];
  195. var fnmreg = /^.{1,}\.crt$/g;
  196. if (file && fnmreg.test(file.name) ) {
  197. upload(file);
  198. } else {
  199. alert('Файл сертификата не указан или не валиден!');
  200. }
  201. return false;
  202. }
  203. function submitForms() {
  204. if (confirm('Вы уверены что хотите применить настройки?')) {
  205. if ($('ntp-inp')) {
  206. $('ntpservip').options[3].value = $('ntp-inp').value;
  207. }
  208. if (formValidation()) {
  209. $('form1').submit();
  210. }
  211. else{
  212. $('validation-box').style.display = 'block';
  213. }
  214. }
  215. }
  216. function upload(file) {
  217. var fl = new FormData();
  218. fl.append('file', file);
  219. var xhr = new XMLHttpRequest();
  220. xhr.open('POST', '/srv_crt_upload.cgi', true);
  221. // обработчик для закачки
  222. xhr.upload.onprogress = function(event) {
  223. var progress = Math.floor((event.loaded / event.total) * 100);
  224. console.log(progress + '%');
  225. };
  226. xhr.onload = xhr.onerror = function() {
  227. if (this.status == 200) {
  228. if (+xhr.responseText == '1') {
  229. alert('Успешно');
  230. window.location.reload();
  231. } else {
  232. alert('Ошибка установки сертификата');
  233. }
  234. } else {
  235. alert('Ошибка ' + this.status);
  236. }
  237. };
  238. xhr.send(fl);
  239. }
  240. function checkPWD(){
  241. // $('checkUpdatePass').style.display = 'none';
  242. $('count-wrap').style.display = 'block';
  243. $('countdown').style.display = 'block';
  244. countdown();
  245. }
  246. function checkChangePWD(){
  247. var user = $('changePasswordUser').value;
  248. var oldpass = $('oldpwd').value;
  249. var newpass = $('newpwd').value;
  250. var newpassrepeat = $('newpwdrepeat').value;
  251. var letter = /^[0-9a-zA-Z.,/\\\-_*#()[\]+:'"@!^%&?|${}`~<>]+$/;
  252. if (oldpass.length === 0 || newpass.length === 0 || newpassrepeat.length === 0){
  253. alert('Поля не заполнены!');
  254. } else if (newpass !== newpassrepeat){
  255. alert('Поля с новым паролем не совпадают!');
  256. $('oldpwd').value = '';
  257. $('newpwd').value = '';
  258. $('newpwdrepeat').value = '';
  259. } else if (user === ''){
  260. alert('Не выбран пользователь для которого необходимо сменить пароль!');
  261. } else {
  262. if (letter.test(oldpass) && letter.test(newpass) && letter.test(newpassrepeat)) {
  263. loadXMLDoc('changepwd.cgi?username=' + encodeURIComponent(user) + '&oldpass=' + encodeURIComponent(oldpass) + '&newpass=' + encodeURIComponent(newpass), 'GET', function(){
  264. alert(this.responseText);
  265. window.location.reload();
  266. });
  267. } else {
  268. alert('Пароль задан неправильно');
  269. $('oldpwd').value = '';
  270. $('newpwd').value = '';
  271. $('newpwdrepeat').value = '';
  272. }
  273. }
  274. }
  275. function timesetType(el) {
  276. if (el.selectedIndex === 0) {
  277. $('ntpservip_l').className += ' hidden';
  278. $('ntpservip').className += ' hidden';
  279. $('ntpservip').setAttribute('disabled', 'disabled');
  280. if ($('ntp-inp')) {
  281. $('ntp-inp').className += ' hidden';
  282. $('ntp-inp').setAttribute('disabled', 'disabled');
  283. }
  284. $('lastsynctime_l').className += ' hidden';
  285. $('lastsynctime').className += ' hidden';
  286. // -----------------
  287. $('date_l').className = 'col span_1_of_2';
  288. $('date').className = 'form-control';
  289. $('time_l').className = 'col span_1_of_2';
  290. $('time').className = 'form-control';
  291. $('date').removeAttribute('disabled');
  292. $('time').removeAttribute('disabled');
  293. } else {
  294. $('ntpservip_l').className = 'col span_1_of_2';
  295. $('ntpservip').className = 'form-control';
  296. $('ntpservip').removeAttribute('disabled');
  297. if ($('ntp-inp')) {
  298. $('ntp-inp').className = 'form-control';
  299. $('ntp-inp').removeAttribute('disabled');
  300. }
  301. $('lastsynctime_l').className = 'col span_1_of_2';
  302. $('lastsynctime').className = 'form-control';
  303. // -------------
  304. $('date_l').className += ' hidden';
  305. $('date').className += ' hidden';
  306. $('time_l').className += ' hidden';
  307. $('time').className += ' hidden';
  308. $('date').setAttribute('disabled', 'disabled');
  309. $('time').setAttribute('disabled', 'disabled');
  310. }
  311. }
  312. function countdown(rel) {
  313. var countDown = 10;
  314. setInterval(function () {
  315. if (countDown == 1 && rel === true) {
  316. location.reload(true);
  317. }
  318. else if (countDown == 1 && rel !== true){
  319. window.location.href = 'http:' + window.location.origin.substring(window.location.protocol.length);
  320. }
  321. if (countDown > 0){countDown--;}
  322. $('count-number').innerHTML = countDown;
  323. return countDown;
  324. }, 1000);
  325. }
  326. function dhcpState() {
  327. if ($('dhcp').checked) {
  328. $('ipaddr').setAttribute('disabled', 'disabled');
  329. $('gw').setAttribute('disabled', 'disabled');
  330. $('mask').setAttribute('disabled', 'disabled');
  331. } else {
  332. $('ipaddr').removeAttribute('disabled');
  333. $('gw').removeAttribute('disabled');
  334. $('mask').removeAttribute('disabled');
  335. }
  336. }
  337. function telnetState() {
  338. if (!$('tn_enabled').checked) {
  339. $('tn_port').setAttribute('disabled', 'disabled');
  340. } else {
  341. $('tn_port').removeAttribute('disabled');
  342. }
  343. }
  344. function sshState() {
  345. if (!$('ssh_enabled').checked) {
  346. $('ssh_port').setAttribute('disabled', 'disabled');
  347. } else {
  348. $('ssh_port').removeAttribute('disabled');
  349. }
  350. }
  351. //########## Info Form Validation ############
  352. function infoValidation(){
  353. var sysname, owner, sysLocation,comment;
  354. sysname = $('sysname').value,
  355. owner = $('owner').value,
  356. sysLocation = $('sysLocation').value,
  357. comment = $('comment').value;
  358. var flag = true;
  359. if(!ValidateAlphanumeric2(sysname, 'Название устройства')){flag = false;}
  360. if(!ValidateAlphanumeric2(owner, 'Владелец')){flag = false;}
  361. if(!ValidateAlphanumeric2(sysLocation, 'Местоположение')){flag = false;}
  362. if(!ValidateAlphanumeric2(comment, 'Комментарии')){flag = false;}
  363. return flag;
  364. }
  365. function ValidateAlphanumeric2(uadd, z) {
  366. var warn = document.createElement('li');
  367. // var letter = /^[0-9a-zA-Z]+[^\u0430-\u044f\u0410-\u042f\u0451\u0401\?]+$/m;
  368. var letter = /^[0-9a-zA-Z.,/\-_*#()[\]+=;:'"@!^%&?|${}`~<>]+$/m;
  369. warn.innerHTML = 'Поле ' + z + ' может содержать только латинские буквы, цифры и символы .,/-_*#()[]+=;:\'"@!^%&?|${}`~<>';
  370. if (letter.test(uadd) || !uadd) {
  371. return true;
  372. }
  373. $('validation-box').appendChild(warn);
  374. return false;
  375. }
  376. function submitInfo() {
  377. if (confirm('Вы уверены что хотите применить изменения?')) {
  378. if (infoValidation()) {
  379. $('SNMPinfo').submit();
  380. // loadXMLDoc('info.cgi?owner='+ $('owner').value + '&sysLocation='+ $('location').value + '&comment='+ decodeURIComponent($('comment').value), 'GET', function(){
  381. // console.log('Сохранено');
  382. // });
  383. }
  384. else {
  385. $('validation-box').style.display = 'block';
  386. }
  387. }
  388. }
  389. function getJSON(url, successHandler, errorHandler) {
  390. var xhr;
  391. xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new window.ActiveXObject('Microsoft.XMLHTTP');
  392. xhr.open('GET', url, true);
  393. xhr.onreadystatechange = function () {
  394. var status;
  395. var data;
  396. if (xhr.readyState == 4) {
  397. status = xhr.status;
  398. if (status == 200) {
  399. data = JSON.parse(xhr.responseText);
  400. successHandler(data);
  401. } else {
  402. errorHandler(status);
  403. }
  404. }
  405. };
  406. xhr.send();
  407. }
  408. function updatepage(){
  409. var loc = location.pathname.slice(1, -5);
  410. switch(loc){
  411. case 'settings':
  412. setTimeout(settingsGET, 1000);
  413. break;
  414. case 'snmp':
  415. createSNMP('snmp_list');
  416. break;
  417. case 'history':
  418. getPage($('currentpage').value);
  419. break;
  420. }
  421. }
  422. function getCGI(url) {
  423. var xmlhttp;
  424. var q;
  425. if (url == 'reset.cgi') {
  426. q = confirm('Вы уверены что хотите сбросить в заводские настройки?');
  427. }
  428. if (url == 'reboot.cgi') {
  429. q = confirm('Вы уверены что хотите перезагрузить устройство?');
  430. }
  431. if (url == 'update.cgi') {
  432. q = confirm('Вы уверены что хотите обновить прошивку устройства?');
  433. }
  434. if (q) {
  435. if (window.XMLHttpRequest) {
  436. xmlhttp = new XMLHttpRequest();
  437. } else {
  438. xmlhttp = new window.ActiveXObject('Microsoft.XMLHTTP');
  439. }
  440. // xmlhttp.onreadystatechange = true;
  441. xmlhttp.open('GET', url, true);
  442. xmlhttp.send();
  443. return true;
  444. }
  445. // else {alert(a);}
  446. }
  447. function Alarm(bitmask, num) {
  448. // Bit mask format DEC <NUMBER>
  449. var answ = (bitmask & (1 << num)) >> num;
  450. return answ;
  451. }
  452. function setIcons(containerID, icnName) {
  453. $(containerID).innerHTML ='';
  454. var icons = typeof icnName === 'string' ? [icnName] : icnName;
  455. for (var i = 0; i < icons.length; i++) {
  456. var icnContainer = document.createElement('i');
  457. icnContainer.innerHTML = Icons[icons[i]]['icn'];
  458. icnContainer.style.paddingLeft = '10px';
  459. icnContainer.title = Icons[icons[i]]['title'];
  460. $(containerID).appendChild(icnContainer);
  461. }
  462. }
  463. function paramsRefresh() {
  464. getJSON('getJson.cgi'+'?'+Math.random(), function (data) {
  465. var alrm = +data.u_alarm;
  466. var ma = +data.m_alarm;
  467. var pstate = [];
  468. var bstate = [];
  469. var ups_bypass = Alarm(alrm, 5),
  470. ups_alarm = Alarm(alrm, 4) || Alarm(alrm, 7),
  471. ups_standby = Alarm(alrm, 3),
  472. ups_shutdown = Alarm(alrm, 1),
  473. bat_low = Alarm(alrm, 6),
  474. bat_test = Alarm(alrm, 2),
  475. bat_exp = Alarm(ma, 6);
  476. // PPS
  477. $('AC').innerHTML = parseFloat(data.AC) + ' В';
  478. $('AC').style.color = Alarm(alrm, 7) ? ALARM_RED : ALARM_GREEN;
  479. $('DC').innerHTML = parseFloat(data.DC) + ' В';
  480. $('DC').style.color = Alarm(ma, 7) ? ALARM_RED : ALARM_GREEN;
  481. $('in_cur').innerHTML = parseFloat(data.in_cur) + ' А';
  482. $('in_cur').style.color = Alarm(alrm, 7) ? ALARM_RED : ALARM_GREEN;
  483. $('out_cur').innerHTML = parseFloat(data.out_cur) + ' А';
  484. $('out_cur').style.color = Alarm(ma, 7) ? ALARM_RED : ALARM_GREEN;
  485. $('in_freq').innerHTML = parseFloat(data.in_freq) + ' Гц';
  486. $('in_freq').style.color = Alarm(alrm, 7) ? ALARM_RED : ALARM_GREEN;
  487. $('out_freq').innerHTML = parseFloat(data.out_freq) + ' Гц';
  488. $('out_freq').style.color = Alarm(ma, 7) ? ALARM_RED : ALARM_GREEN;
  489. $('pwr').innerHTML = parseFloat(data.pwr) + ' %';
  490. $('pwr').style.color = Alarm(ma, 0) ? ALARM_RED : ALARM_GREEN;
  491. $('pmode').innerHTML = ups_bypass ? 'Bypass' : 'Boost or Buck';
  492. // State
  493. ups_alarm ? pstate.push('exclamination') : pstate.push('normal');
  494. // ups_standby ? pstate.push('clock') : null;
  495. ups_shutdown ? pstate.push('shutdown') : null;
  496. !Alarm(ma, 3) && !bat_low ? bstate.push('normal') : null;
  497. Alarm(ma, 3) ? bstate.push('exclamination') : null;
  498. bat_low ? bstate.push('batteryLow') : null;
  499. bat_test ? bstate.push('batTest') : null;
  500. setIcons('pstate_icons', pstate);
  501. setIcons('bstate_icons', bstate);
  502. // ACB
  503. $('bat_cap').innerHTML = parseFloat(data.bat_cap) + ' А·ч';
  504. $('bat_volt').innerHTML = parseFloat(data.bat_volt) + ' В';
  505. $('bat_volt').style.color = bat_low ? ALARM_RED : ALARM_GREEN;
  506. $('bat_rem_cap').innerHTML = parseFloat(data.bat_rem_cap) + ' %';
  507. $('bat_rem_cap').style.color = bat_low ? ALARM_RED : ALARM_GREEN;
  508. $('inner_temp').innerHTML = parseFloat(data.inner_temp) + ' °C';
  509. $('inner_temp').style.color = Alarm(ma, 1) || Alarm(ma, 5) ? ALARM_RED : ALARM_GREEN;
  510. $('bat_time_left').innerHTML = parseFloat(data.bat_time_left) + ' мин';
  511. $('bat_time_left').style.color = bat_low ? ALARM_RED : ALARM_GREEN;
  512. $('bat_exp').innerHTML = data.bat_exp;
  513. $('bat_exp').style.color = bat_exp ? ALARM_RED : ALARM_GREEN;
  514. // checkState();
  515. window.setCookie('netsettings_changed', data.netsettings_changed);
  516. window.setCookie('device-error', Alarm(ma, 2));
  517. checkNotify();
  518. setTimeout(paramsRefresh, 1000);
  519. }, function (status) {
  520. if (status !== 0){
  521. alert('Не удалось получить данные.');
  522. setTimeout(paramsRefresh, 15000);
  523. }
  524. });
  525. }
  526. var mint;
  527. //########## History ############
  528. var ctrl_inputs = [
  529. 'h_param_',
  530. 'h_event_',
  531. 'h_datetime_'
  532. ];
  533. function getPage(pn){
  534. getJSON('history.cgi?page=' + pn, function(data){
  535. $('history_data').textContent = '';
  536. var n = data.page;
  537. $('currentpage').value = pn;
  538. $('pagelimit').innerHTML = data.pages;
  539. for (var i in n){
  540. var tr = document.createElement('tr');
  541. for (var num = 0; num < ctrl_inputs.length; num++) {
  542. var td = document.createElement('td');
  543. td.innerHTML = n[i].split(';')[num];
  544. td.id = ctrl_inputs[num] + i;
  545. tr.appendChild(td);
  546. }
  547. $('history_data').appendChild(tr);
  548. }
  549. window.setCookie('netsettings_changed', data.netsettings_changed);
  550. checkNotify();
  551. clearTimeout(mint);
  552. mint = setTimeout(history_dataref, 5000);
  553. }, function(){
  554. $('table').display = 'none';
  555. $('content').innerHTML =
  556. '<h1>Журнал событий</h1>'+
  557. '<div class="panel panel-default">'+
  558. '<div class="panel-heading">Ошибка</div>'+
  559. '<p style="text-align: center;">Данные отсутствуют.</p>'+
  560. '</div>';
  561. });
  562. }
  563. function history_dataref() {
  564. var pn = parseInt($('currentpage').value);
  565. getJSON('history.cgi?page=' + pn, function(data) {
  566. var p = data.page;
  567. for (var j in p) {
  568. for (var num = 0; num < ctrl_inputs.length; num++) {
  569. $(ctrl_inputs[num] + j).innerHTML = p[j].split(';')[num];
  570. }
  571. $('pagelimit').innerHTML = data.pages;
  572. }
  573. clearTimeout(mint);
  574. mint = setTimeout(history_dataref, 5000);
  575. });
  576. }
  577. function nextPage(){
  578. var next = parseInt($('currentpage').value);
  579. if (next < parseInt($('pagelimit').textContent)) {
  580. next = next + 1;
  581. getPage(next);
  582. }
  583. }
  584. function prevPage(){
  585. var prev = parseInt($('currentpage').value);
  586. if (prev != 1) {
  587. prev = prev - 1;
  588. getPage(prev);
  589. }
  590. }
  591. //########## UPS History ############
  592. var ups_inputs = [
  593. { id: 'h_inputv_', unit: ' В', parse: 'float' },
  594. { id: 'h_inputfv_', unit: ' В', parse: 'float' },
  595. { id: 'h_outputv_', unit: ' В', parse: 'float' },
  596. { id: 'h_outputc_', unit: '%', parse: 'float' },
  597. { id: 'h_inputf_', unit: ' Гц', parse: 'float' },
  598. { id: 'h_batv_', unit: ' В', parse: 'float' },
  599. { id: 'h_temp_', unit: ' °C', parse: 'float' },
  600. { id: 'h_status_', unit: '', parse: 'string' },
  601. { id: 'h_time_', unit: '', parse: 'string' }
  602. ];
  603. function getUPSPage(pn){
  604. getJSON('ups_history.cgi?page=' + pn, function(data){
  605. $('history_data').textContent = '';
  606. var n = data.page;
  607. $('currentpage').value = pn;
  608. $('pagelimit').innerHTML = data.pages;
  609. for (var i in n){
  610. var tr = document.createElement('tr');
  611. for (var num = 0; num < ups_inputs.length; num++) {
  612. var td = document.createElement('td');
  613. td.innerHTML = ups_inputs[num].parse === 'float' ? parseFloat(n[i].split(';')[num]) + ups_inputs[num].unit : n[i].split(';')[num] + ups_inputs[num].unit;
  614. td.id = ups_inputs[num].id + i;
  615. tr.appendChild(td);
  616. }
  617. $('history_data').appendChild(tr);
  618. }
  619. window.setCookie('netsettings_changed', data.netsettings_changed);
  620. checkNotify();
  621. clearTimeout(mint);
  622. mint = setTimeout(ups_history_dataref, 5000);
  623. }, function(){
  624. $('table').display = 'none';
  625. $('content').innerHTML =
  626. '<h1>Журнал событий</h1>'+
  627. '<div class="panel panel-default">'+
  628. '<div class="panel-heading">Ошибка</div>'+
  629. '<p style="text-align: center;">Данные отсутствуют.</p>'+
  630. '</div>';
  631. });
  632. }
  633. function ups_history_dataref() {
  634. var pn = parseInt($('currentpage').value);
  635. getJSON('ups_history.cgi?page=' + pn, function(data) {
  636. var p = data.page;
  637. for (var j in p) {
  638. for (var num = 0; num < ups_inputs.length; num++) {
  639. $(ups_inputs[num].id + j).innerHTML = ups_inputs[num].parse === 'float' ? parseFloat(p[j].split(';')[num]) + ups_inputs[num].unit : p[j].split(';')[num] + ups_inputs[num].unit;
  640. }
  641. $('pagelimit').innerHTML = data.pages;
  642. }
  643. clearTimeout(mint);
  644. mint = setTimeout(ups_history_dataref, 5000);
  645. });
  646. }
  647. function nextUPSPage(){
  648. var next = parseInt($('currentpage').value);
  649. if (next < parseInt($('pagelimit').textContent)) {
  650. next = next + 1;
  651. getUPSPage(next);
  652. }
  653. }
  654. function prevUPSPage(){
  655. var prev = parseInt($('currentpage').value);
  656. if (prev != 1) {
  657. prev = prev - 1;
  658. getUPSPage(prev);
  659. }
  660. }
  661. function utf8_decode (s) {
  662. var bb = '', c = 0;
  663. for (var i = 0; i < s.length; i++) {
  664. c = s.charCodeAt(i);
  665. if (c > 127) {
  666. if (c > 1024) {
  667. if (c == 1025) {
  668. c = 1016;
  669. } else if (c == 1105) {
  670. c = 1032;
  671. }
  672. bb += String.fromCharCode(c - 848);
  673. }
  674. } else {
  675. bb += s.charAt(i);
  676. }
  677. }
  678. return bb;
  679. }
  680. function msieversion() {
  681. var ua = window.navigator.userAgent;
  682. var msie = ua.indexOf('MSIE ');
  683. if (msie != -1 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) /*If IE, return version number*/ return true;
  684. return false;
  685. }
  686. function blobLoad(requestUrl, fileName, buttonID){
  687. if(isMobile.iOS()){
  688. alert('На данном устройстве сохранение не доступно.');
  689. return false;
  690. }
  691. var old = $(buttonID).children[0].textContent;
  692. var pgFlag = 'Обработка';
  693. var pgFlagLen = pgFlag.length;
  694. var d = new Date();
  695. var fName;
  696. if (fileName === 'settings.dat') {
  697. fName = fileName;
  698. } else {
  699. fName = d.getDate()+'_'+(d.getMonth()+1)+'_'+d.getHours()+d.getMinutes() + '_' + fileName;
  700. }
  701. var xhr = new XMLHttpRequest();
  702. var fURL = requestUrl.split('.').pop() == 'cgi' ? requestUrl+'?' : requestUrl+'&';
  703. xhr.open('GET', fURL+'_='+ new Date().getTime());
  704. xhr.responseType = 'blob';
  705. $(buttonID).setAttribute('disabled', 'disabled');
  706. xhr.addEventListener('load', function(){
  707. $(buttonID).children[1].style.width = 0;
  708. $(buttonID).children[0].textContent = old;
  709. $(buttonID).removeAttribute('disabled');
  710. });
  711. xhr.onload = function(){
  712. if (this.status === 200) {
  713. var blob = this.response;
  714. if(msieversion()){
  715. if (window.navigator.msSaveOrOpenBlob) {
  716. window.navigator.msSaveOrOpenBlob(blob, fName);
  717. } else {
  718. var IEwindow = window.open(requestUrl);
  719. }
  720. } else {
  721. var objectUrl = URL.createObjectURL(blob);
  722. var uri = objectUrl;
  723. var link = document.createElement('a');
  724. link.href = uri;
  725. link.style = 'visibility:hidden';
  726. link.download = fName;
  727. document.body.appendChild(link);
  728. link.click();
  729. document.body.removeChild(link);
  730. }
  731. }
  732. };
  733. xhr.onprogress = function(event) {
  734. $(buttonID).children[0].textContent = parseInt((event.loaded / event.total) * 100) + '%';
  735. $(buttonID).children[1].style.width = parseInt((event.loaded / event.total) * 100) + '%';
  736. };
  737. xhr.send();
  738. }
  739. var isMobile = {
  740. Android: function() {
  741. return navigator.userAgent.match(/Android/i);
  742. },
  743. BlackBerry: function() {
  744. return navigator.userAgent.match(/BlackBerry/i);
  745. },
  746. iOS: function() {
  747. return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  748. },
  749. Opera: function() {
  750. return navigator.userAgent.match(/Opera Mini/i);
  751. },
  752. Windows: function() {
  753. return navigator.userAgent.match(/IEMobile/i);
  754. },
  755. any: function() {
  756. return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
  757. }
  758. };
  759. function checkOther(ele) {
  760. if (ele.selectedIndex == 3) {
  761. var newInput = document.createElement('input');
  762. newInput.type = 'text';
  763. newInput.className = 'form-control';
  764. newInput.id = 'ntp-inp';
  765. newInput.value = ntpservipValue;
  766. newInput.style.marginTop = '10px';
  767. ele.parentNode.insertBefore(newInput, ele.nextSibling);
  768. }
  769. else if ($('ntp-inp')) {
  770. var d = $('ntp-inp');
  771. ele.parentNode.removeChild(d);
  772. }
  773. }
  774. // ################################################################################
  775. function fillTempRange(id, min, max) {
  776. var obj = $(id);
  777. for (var i = min; i <= max; i++) {
  778. var opt = document.createElement('option');
  779. opt.value = i;
  780. opt.text = i;
  781. obj.appendChild(opt);
  782. }
  783. }
  784. function settingsGET(){
  785. getJSON('settings.cgi', function(data) {
  786. //SNMP params
  787. //
  788. $('managerIP').value = data.managerIP;
  789. $('read_community').value = data.read_community;
  790. $('write_community').value = data.write_community;
  791. $('managerIP2').value = data.managerIP2;
  792. $('managerIP3').value = data.managerIP3;
  793. $('managerIP4').value = data.managerIP4;
  794. $('managerIP5').value = data.managerIP5;
  795. // Network params
  796. $('ipaddr').value = data.ipaddr;
  797. $('gw').value = data.gw;
  798. $('mask').value = data.mask;
  799. $('dhcp').checked = data.dhcp;
  800. // Alarms
  801. fillTempRange('temp_high', 40, 80);
  802. fillTempRange('temp_low', -40, 0);
  803. fillTempRange('loadvolt_high', 60, 120);
  804. fillTempRange('mainvolt_low', 110, 200);
  805. fillTempRange('mainvolt_high', 220, 250);
  806. $('temp_high').value = data.temp_high;
  807. $('temp_low').value = data.temp_low;
  808. temp_hist = new SpinBox('temp_hist', {
  809. 'name':'temp_hist','minimum':0.5,'maximum':2.0,'step':0.1,'decimals':1, 'value': data.temp_hist
  810. });
  811. $('loadvolt_high').value = data.loadvolt_high;
  812. loadvolt_hist = new SpinBox('loadvolt_hist', {
  813. 'name':'loadvolt_hist','minimum':0.5,'maximum':2.0,'step':0.1,'decimals':1, 'value': data.loadvolt_hist
  814. });
  815. $('mainvolt_low').value = data.mainvolt_low;
  816. $('mainvolt_high').value = data.mainvolt_high;
  817. mainvolt_hist = new SpinBox('mainvolt_hist', {
  818. 'name':'mainvolt_hist','minimum':10,'maximum':30,'step':1, 'value': data.mainvolt_hist
  819. });
  820. // Whitelist
  821. $('wtl_ip1').value = data.wtl_ip1;
  822. $('wtl_ip2').value = data.wtl_ip2;
  823. $('wtl_ip3').value = data.wtl_ip3;
  824. $('wtl_ip4').value = data.wtl_ip4;
  825. $('wtl_ip5').value = data.wtl_ip5;
  826. $('tn_enabled').checked = data.tn_enabled;
  827. $('tn_port').value = data.tn_port;
  828. $('ssh_enabled').checked = data.ssh_enabled;
  829. $('ssh_port').value = data.ssh_port;
  830. $("bat_prod").value = data.bat_prod;
  831. ups_max_power = new SpinBox('ups_max_power', {
  832. 'value': data.ups_max_power,
  833. 'name':'ups_max_power',
  834. 'minimum':400,
  835. 'maximum':10000,
  836. 'step':50
  837. });
  838. ups_cell_min = new SpinBox('ups_cell_min', {
  839. 'value': data.ups_cell_min,
  840. 'name':'ups_cell_min',
  841. 'minimum':0,
  842. 'maximum':3.0,
  843. 'decimals':2,
  844. 'step':0.01
  845. });
  846. ups_cell_max = new SpinBox('ups_cell_max', {
  847. 'value': data.ups_cell_max,
  848. 'name':'ups_cell_max',
  849. 'minimum':0,
  850. 'maximum':3.0,
  851. 'decimals':2,
  852. 'step':0.01
  853. });
  854. bat_exp = new SpinBox('bat_exp', {
  855. 'value': data.bat_exp,
  856. 'name':'bat_exp',
  857. 'minimum':1,
  858. 'maximum':10,
  859. 'step':1
  860. });
  861. bat_cap = new SpinBox('bat_cap', {
  862. 'value': data.bat_cap,
  863. 'name':'bat_cap',
  864. 'minimum':1,
  865. 'maximum':200,
  866. 'step':1
  867. });
  868. bat_charge = new SpinBox('bat_charge', {
  869. 'value': data.bat_charge,
  870. 'name':'bat_charge',
  871. 'minimum':12,
  872. 'maximum':240,
  873. 'step':12
  874. });
  875. sshState();
  876. // DateTime
  877. if (data.ntpservip != $('ntpservip').options[0].value &&
  878. data.ntpservip != $('ntpservip').options[1].value &&
  879. data.ntpservip != $('ntpservip').options[2].value )
  880. {
  881. var newInput = document.createElement('input');
  882. newInput.type = 'text';
  883. newInput.className = 'form-control';
  884. newInput.id = 'ntp-inp';
  885. newInput.style.marginTop = '10px';
  886. $('ntpservip').options[3].selected = 'selected';
  887. $('ntpservip').options[3].value = data.ntpservip;
  888. $('ntpservip').parentNode.insertBefore(newInput, $('ntpservip').nextSibling);
  889. window.ntpservipValue = data.ntpservip;
  890. newInput.value = window.ntpservipValue;
  891. } else {
  892. window.ntpservipValue = data.ntpservip;
  893. $('ntpservip').value = window.ntpservipValue;
  894. }
  895. $('utc').value = data.utc;
  896. $('date').value = data.date;
  897. $('time').value = data.time;
  898. $('lastsynctime').value = data.lastsynctime;
  899. $('ntp').value = data.ntp;
  900. dhcpState();
  901. telnetState();
  902. timesetType($('ntp'));
  903. window.setCookie('netsettings_changed', data.netsettings_changed);
  904. checkNotify();
  905. }, function() {
  906. alert('Не удалось получить данные.');
  907. });
  908. }
  909. function batTest(options) {
  910. this.options = (options ? options : {});
  911. if (this.options.time) {
  912. if (typeof this.options.time !== 'number' && this.options.time > 99) {
  913. return alert('Ошибка заданного времени');
  914. }
  915. }
  916. var str = '';
  917. for (var option in options) {
  918. str += option + '=' + options[option] + '&';
  919. }
  920. str = str.slice(0, -1);
  921. var url = 'bat_test.cgi';
  922. loadXMLDoc(url + '?' + str, 'GET', function(){
  923. this.responseText ? alert(this.responseText) : null;
  924. });
  925. }
  926. function UPSPowerOff(options) {
  927. this.options = (options ? options : {});
  928. if (typeof this.options.after !== 'number' && this.options.after > 9999) {
  929. return alert('Ошибка заданного времени отключения');
  930. }
  931. var str = '';
  932. for (var option in options) {
  933. str += option + '=' + options[option] + '&';
  934. }
  935. str = str.slice(0, -1);
  936. var url = 'ups_power.cgi';
  937. loadXMLDoc(url + '?' + str, 'GET', function(){
  938. this.responseText ? alert(this.responseText) : null;
  939. });
  940. }
  941. var apply_settings = new NotificationBox('apply-settings',
  942. {
  943. 'message': 'Внимание, для применения сетевых настроек необходимо их подтвердить. Иначе они будут сброшены в течение 10 минут.',
  944. 'bgcolor':'#ffcc00',
  945. 'textcolor': '#333',
  946. 'url': 'confirm.cgi',
  947. 'show': window.getCookie('role') < 2
  948. });
  949. var device_error = new NotificationBox('device-error',
  950. {
  951. 'message': 'Внимание, связь с ИБП не установлена!',
  952. 'bgcolor':'#ec0035',
  953. 'textcolor': '#fff'
  954. });
  955. // ################################################################################
  956. function infoGet() {
  957. getJSON('info.cgi', function(data) {
  958. // Cotroller Info
  959. $('uptime').innerHTML = data.uptime;
  960. $('model').innerHTML = data.model;
  961. $('prodate').innerHTML = data.prodate;
  962. $('fwversion').innerHTML = data.fwversion;
  963. $('macaddr').innerHTML = data.macaddr;
  964. $('serno').innerHTML = data.serno;
  965. $('ups_fwversion').innerHTML = data.ups_fwversion;
  966. $('ups_sn').innerHTML = data.ups_sn;
  967. $('ups_model').innerHTML = data.ups_model;
  968. var info_labels = {
  969. sysname: ['Название устройства', data.sysname, 19],
  970. owner: ['Владелец', data.owner, 49],
  971. sysLocation:['Местоположение', data.sysLocation, 109],
  972. comment: ['Комментарии', data.comment, 109]
  973. };
  974. for (var i in info_labels) {
  975. var row = document.createElement('tr');
  976. var label = document.createElement('td');
  977. label.innerHTML = info_labels[i][0];
  978. var val = document.createElement('td');
  979. val.id = i+'_wr';
  980. if (getCookie('role') <= 1) {
  981. var inp = document.createElement('input');
  982. inp.type = 'text';
  983. inp.id = i;
  984. inp.name = i;
  985. inp.className = 'form-control';
  986. inp.maxLength = info_labels[i][2];
  987. inp.value = info_labels[i][1];
  988. val.appendChild(inp);
  989. } else {
  990. val.innerHTML = info_labels[i][1];
  991. }
  992. row.appendChild(label);
  993. row.appendChild(val);
  994. $('ctrl_info').appendChild(row);
  995. }
  996. if (getCookie('role') <= 1) {
  997. var sbmt = document.createElement('button');
  998. sbmt.className = 'btn btn-primary-inverted';
  999. sbmt.type = 'button';
  1000. sbmt.setAttribute('onclick', 'submitInfo(); return false;');
  1001. sbmt.innerHTML = 'Сохранить';
  1002. $('SNMPinfo').appendChild(sbmt);
  1003. }
  1004. window.setCookie('netsettings_changed', data.netsettings_changed);
  1005. checkNotify();
  1006. }, function() {
  1007. alert('Не удалось получить данные.');
  1008. });
  1009. }
  1010. // ################################################################################
  1011. /*
  1012. SpinBox.js
  1013. Implements a spin box interface for a text field
  1014. Created by Stephen Morley - http://code.stephenmorley.org/ - and released under
  1015. the terms of the CC0 1.0 Universal legal code:
  1016. http://creativecommons.org/publicdomain/zero/1.0/legalcode
  1017. */
  1018. /* Creates a spin box. The parameter is:
  1019. *
  1020. * container - either the DOM node to contain the spin box or the ID of the node
  1021. * options - an object containing various parameters; this optional parameter
  1022. * defaults to the empty object
  1023. *
  1024. * The options object may contain the following keys:
  1025. *
  1026. * className - a class name to apply to the container; the class name with the
  1027. * suffixes 'Up' and 'Down' will be applied to the up and down
  1028. * buttons. The default value is 'spinBox'.
  1029. * value - the initial value for the spin box. The default is 0 (subject to
  1030. * restrictions on the minimum and maximum value) if the input
  1031. * element did not already exist, or the existing value if the input
  1032. * element did already exist.
  1033. * step - the value by which to increment or decrement the value. The
  1034. * default value is 1.
  1035. * minimum - the minimum allowed value. The default is not to have a minimum
  1036. * value.
  1037. * maximum - the maximum allowed value. The default is not to have a maximum
  1038. * value.
  1039. * decimals - the number of decimal places allowed. The default is 0.
  1040. * name - input name attribute.
  1041. *
  1042. * Note that the minimum, maximum, and decimal places restrictions are enforced
  1043. * for values set by the spin box, but a value outside of these restrictions may
  1044. * be typed by the user.
  1045. */
  1046. function SpinBox(container, options) {
  1047. // fetch the DOM node if a string was supplied
  1048. if (typeof container == 'string') {
  1049. container = document.getElementById(container);
  1050. container.innerHTML = '';
  1051. }
  1052. // store the options and set the default values
  1053. this.options = (options ? options : {});
  1054. if (!('className' in this.options)) this.options.className = 'spinBox';
  1055. if (!('step' in this.options)) this.options.step = 1;
  1056. if (!('decimals' in this.options)) this.options.decimals = 0;
  1057. // check whether the input field should be created
  1058. var inputs = container.getElementsByTagName('input');
  1059. if (inputs.length === 0) {
  1060. // create the input node
  1061. this.input = document.createElement('input');
  1062. this.input.setAttribute('minimum', this.options.minimum);
  1063. this.input.setAttribute('maximum', this.options.maximum);
  1064. this.setValue('value' in this.options ? this.options.value : 0);
  1065. this.setName('name' in this.options ? this.options.name : '');
  1066. container.appendChild(this.input);
  1067. } else {
  1068. // store a reference to the input node
  1069. this.input = inputs[0];
  1070. this.setValue(this.options.value ? this.options.value : this.input.value);
  1071. }
  1072. // create the up button
  1073. var upButton = document.createElement('span');
  1074. upButton.appendChild(document.createElement('span'));
  1075. upButton.innerHTML = '+';
  1076. container.appendChild(upButton);
  1077. // create the down button
  1078. var downButton = document.createElement('span');
  1079. downButton.appendChild(document.createElement('span'));
  1080. downButton.innerHTML = '-';
  1081. container.appendChild(downButton);
  1082. // apply the classes
  1083. container.className += ' ' + this.options.className;
  1084. upButton.className = this.options.className + 'Up';
  1085. downButton.className = this.options.className + 'Down';
  1086. // add the listeners
  1087. this.addEventListener(this.input, 'mousewheel', this.handleMouseWheel, [], true);
  1088. this.addEventListener(this.input, 'DOMMouseScroll', this.handleMouseWheel, [], true);
  1089. this.addEventListener(this.input, 'keydown', this.handleKeyDown, [], true);
  1090. this.addEventListener(this.input, 'keypress', this.handleKeyPress, [], true);
  1091. this.addEventListener(this.input, 'keyup', this.stop);
  1092. this.addEventListener(this.input, 'blur', this.loseFocus);
  1093. this.addEventListener(upButton, 'mousedown', this.start, [true]);
  1094. this.addEventListener(upButton, 'mouseup', this.stop);
  1095. this.addEventListener(upButton, 'mouseout', this.stop);
  1096. this.addEventListener(downButton, 'mousedown', this.start, [false]);
  1097. this.addEventListener(downButton, 'mouseup', this.stop);
  1098. this.addEventListener(downButton, 'mouseout', this.stop);
  1099. }
  1100. /* Returns the current value. This will be a number, or the value NaN if the
  1101. * current contents of the input field do not start with a valid number.
  1102. */
  1103. SpinBox.prototype.getValue = function () {
  1104. // parse and return the value
  1105. return parseFloat(this.input.value);
  1106. };
  1107. SpinBox.prototype.loseFocus = function () {
  1108. if ('minimum' in this.options && this.input.value < this.options.minimum) this.input.value = this.options.minimum.toFixed(this.options.decimals ? this.options.decimals : 0);
  1109. if ('maximum' in this.options && this.input.value > this.options.maximum) this.input.value = this.options.maximum.toFixed(this.options.decimals ? this.options.decimals : 0);
  1110. };
  1111. SpinBox.prototype.setName = function (name) {
  1112. // asign input name
  1113. this.input.name = name;
  1114. };
  1115. /* Sets the value. Restrictions on the minimum and maximum value are enforced.
  1116. * The parameter is:
  1117. *
  1118. * value - the value
  1119. */
  1120. SpinBox.prototype.setValue = function (value) {
  1121. // ensure the value is within the permitted range
  1122. if ('minimum' in this.options) value = Math.max(this.options.minimum, value);
  1123. if ('maximum' in this.options) value = Math.min(this.options.maximum, value);
  1124. // store the sign
  1125. var sign = (value < 0 ? '-' : '');
  1126. value = Math.abs(value);
  1127. // determine the multiplier for rounding
  1128. var multiplier = Math.pow(10, this.options.decimals);
  1129. // split the value in to integer and fractional parts
  1130. value = Math.round(value * multiplier);
  1131. var integer = (value - value % multiplier) / multiplier;
  1132. var fractional = '' + value % multiplier;
  1133. // add leading zeros to the fractional part
  1134. while (fractional.length < this.options.decimals) {
  1135. fractional = '0' + fractional;
  1136. }
  1137. // set the value
  1138. this.input.value =
  1139. sign + integer + (this.options.decimals > 0 ? '.' + fractional : '');
  1140. // check whether the browser can dispatch events
  1141. if ('dispatchEvent' in this.input){
  1142. // create the event
  1143. try{
  1144. var event = new Event('change', {bubbles : true, cancelable : true});
  1145. }catch (e){
  1146. var event = document.createEvent('Event');
  1147. event.initEvent('change', true, true);
  1148. }
  1149. // dispatch the event
  1150. this.input.dispatchEvent(event);
  1151. }
  1152. };
  1153. /* Adds an event listener to a node. The event listener is bound to the current
  1154. * value of 'this'. The parameters are:
  1155. *
  1156. * node - the node
  1157. * event - the event name
  1158. * listener - the listener functions
  1159. * parameters - an array of additional parameters to pass to the listener;
  1160. * these are placed after the event parameter
  1161. * allowDefault - true if the default action should not be prevented
  1162. */
  1163. SpinBox.prototype.addEventListener = function (
  1164. node, event, listener, parameters, allowDefault) {
  1165. // store a reference to the 'this' object
  1166. var thisObject = this;
  1167. // create the bound listener
  1168. function boundListener(e) {
  1169. // get the event if it is not supplied
  1170. if (!e) e = window.event;
  1171. // call the listener
  1172. listener.apply(thisObject, [e].concat(parameters));
  1173. // prevent the default action if necessary
  1174. if (!allowDefault) {
  1175. if (e.preventDefault) {
  1176. e.preventDefault();
  1177. } else {
  1178. e.returnValue = false;
  1179. }
  1180. }
  1181. }
  1182. // add the event listener
  1183. if (node.addEventListener) {
  1184. node.addEventListener(event, boundListener, false);
  1185. } else {
  1186. node.attachEvent('on' + event, boundListener);
  1187. }
  1188. };
  1189. /* Handles a mouse wheel event by updating the value if the field is active. The
  1190. * parameter is:
  1191. *
  1192. * e - the event object
  1193. */
  1194. SpinBox.prototype.handleMouseWheel = function (e) {
  1195. // check whether the field is active
  1196. if (document.activeElement == this.input) {
  1197. // update the value
  1198. if (e.wheelDelta) {
  1199. this.start(e, e.wheelDelta > 1);
  1200. } else if (e.detail) {
  1201. this.start(e, e.detail < 1);
  1202. }
  1203. this.stop();
  1204. // prevent the default action
  1205. if (e.preventDefault) {
  1206. e.preventDefault();
  1207. } else {
  1208. e.returnValue = false;
  1209. }
  1210. }
  1211. };
  1212. /* Handles a key down event by starting updating if appropriate. The parameter
  1213. * is:
  1214. *
  1215. * e - the event object
  1216. */
  1217. SpinBox.prototype.handleKeyDown = function (e) {
  1218. // if the up or down keys were pressed, start updating
  1219. if (e.keyCode == 38) this.start(e, true);
  1220. if (e.keyCode == 40) this.start(e, false);
  1221. };
  1222. /* Handles a key press event by filtering out invalid characters. The parameter
  1223. * is:
  1224. *
  1225. * e - the event object
  1226. */
  1227. SpinBox.prototype.handleKeyPress = function (e) {
  1228. // determine the character code
  1229. var charCode = ('charCode' in e ? e.charCode : e.keyCode);
  1230. // allow special key presses
  1231. if (charCode === 0 || e.altKey || e.ctrlKey || e.metaKey) return;
  1232. // allow a minus sign if the value can be negative
  1233. if (charCode == 45 && (!('minimum' in this.options) || this.options.minimum < 0)) {
  1234. return;
  1235. }
  1236. // allow a decimal point if the value may contain decimals
  1237. if (charCode == 46 && this.options.decimals > 0) return;
  1238. // allow digits
  1239. if (charCode >= 48 && charCode <= 57) return;
  1240. // prevent the default action
  1241. if (e.preventDefault) {
  1242. e.preventDefault();
  1243. } else {
  1244. e.returnValue = false;
  1245. }
  1246. };
  1247. /* Starts updating the value. The parameters are:
  1248. *
  1249. * e - the event object
  1250. * up - true to increment the value, false to decrement the value
  1251. */
  1252. SpinBox.prototype.start = function (e, up) {
  1253. // if the field is disabled or we are already updating, return immediately
  1254. if (this.input.disabled || 'timeout' in this) return;
  1255. // set the update step
  1256. this.updateStep = (up ? this.options.step : -this.options.step);
  1257. // initialise the timeout delay
  1258. this.timeoutDelay = 500;
  1259. // update the value
  1260. this.update();
  1261. };
  1262. // Stops update the value.
  1263. SpinBox.prototype.stop = function () {
  1264. // clear the timeout if it exists
  1265. if ('timeout' in this) {
  1266. window.clearTimeout(this.timeout);
  1267. delete this.timeout;
  1268. }
  1269. };
  1270. // Updates the value.
  1271. SpinBox.prototype.update = function () {
  1272. // determine the current value
  1273. var value = parseFloat(this.input.value);
  1274. if (isNaN(value)) value = 0;
  1275. // update the value
  1276. this.setValue(value + this.updateStep);
  1277. // reduce the delay
  1278. this.timeoutDelay = Math.max(20, Math.floor(this.timeoutDelay * 0.9));
  1279. // call this function again
  1280. var thisObject = this;
  1281. this.timeout = window.setTimeout(function () { thisObject.update(); }, this.timeoutDelay);
  1282. };
  1283. /*
  1284. This code is from Dynamic Web Coding at dyn-web.com
  1285. Copyright 2009-12 by Sharon Paine
  1286. See Terms of Use at www.dyn-web.com/business/terms.php
  1287. regarding conditions under which you may use this code.
  1288. This notice must be retained in the code as is!
  1289. */
  1290. // DYN_WEB is namespace used for code from dyn-web.com
  1291. // replacing previous use of dw_ prefix for object names
  1292. var DYN_WEB = DYN_WEB || {};
  1293. DYN_WEB.Event = {
  1294. add: document.addEventListener ? function (obj, etype, fp, cap) {
  1295. cap = cap || false;
  1296. obj.addEventListener(etype, fp, cap);
  1297. } : function (obj, etype, fp) {
  1298. obj.attachEvent('on' + etype, fp);
  1299. },
  1300. remove: document.removeEventListener ? function (obj, etype, fp, cap) {
  1301. cap = cap || false;
  1302. obj.removeEventListener(etype, fp, cap);
  1303. } : function (obj, etype, fp) {
  1304. obj.detachEvent('on' + etype, fp);
  1305. },
  1306. DOMit: function (e) {
  1307. e = e ? e : window.event;
  1308. if (!e.target) e.target = e.srcElement;
  1309. if (!e.preventDefault) e.preventDefault = function () {
  1310. e.returnValue = false;
  1311. return false;
  1312. };
  1313. if (!e.stopPropagation) e.stopPropagation = function () {
  1314. e.cancelBubble = true;
  1315. };
  1316. return e;
  1317. },
  1318. getTarget: function (e) {
  1319. e = dw_Event.DOMit(e);
  1320. var tgt = e.target;
  1321. if (tgt.nodeType != 1) tgt = tgt.parentNode;
  1322. return tgt;
  1323. }
  1324. };
  1325. DYN_WEB.Cookie = {
  1326. set: function (name, value, days, path, domain, secure) {
  1327. var date, expires;
  1328. if (typeof days == 'number') {
  1329. date = new Date();
  1330. date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  1331. expires = date.toGMTString();
  1332. }
  1333. document.cookie = name + '=' + encodeURIComponent(value) + (
  1334. (expires) ? '; expires=' + expires : ''
  1335. ) + (
  1336. (path) ? '; path=' + path : ''
  1337. ) + (
  1338. (domain) ? '; domain=' + domain : ''
  1339. ) + (
  1340. (secure) ? '; secure' : '');
  1341. },
  1342. get: function (name) {
  1343. var c, cookies = document.cookie.split(/;\s/g);
  1344. for (var i = 0; cookies[i]; i++) {
  1345. c = cookies[i];
  1346. if (c.indexOf(name + '=') === 0) {
  1347. return decodeURIComponent(c.slice(name.length + 1, c.length));
  1348. }
  1349. }
  1350. return null;
  1351. },
  1352. del: function (name, path, domain) {
  1353. if (dw_Cookie.get(name)) {
  1354. document.cookie = name + '=' + (
  1355. (path) ? '; path=' + path : ''
  1356. ) + (
  1357. (domain) ? '; domain=' + domain : ''
  1358. ) + '; expires=Thu, 01-Jan-70 00:00:01 GMT';
  1359. }
  1360. }
  1361. };
  1362. if (!DYN_WEB.Util) {
  1363. DYN_WEB.Util = {
  1364. // add props of Obj2 to Obj1
  1365. augment: function (Obj1, Obj2) {
  1366. var prop;
  1367. for (prop in Obj2) {
  1368. if (Obj2.hasOwnProperty(prop) && !Obj1[prop]) {
  1369. Obj1[prop] = Obj2[prop];
  1370. }
  1371. }
  1372. },
  1373. $: function (id) {
  1374. return document.getElementById(id);
  1375. }
  1376. };
  1377. }
  1378. DYN_WEB.Tabs = (function () {
  1379. // obj holds props: id, useCookies, etc.
  1380. function Constr(obj) {
  1381. this.useCookies = obj.useCookies;
  1382. this.before_hide = obj.before_hide || function () {};
  1383. this.on_activate = obj.on_activate || function () {};
  1384. this.on_init = obj.on_init || function () {};
  1385. Constr.col[obj.id] = this;
  1386. Constr.init(obj.id);
  1387. }
  1388. Constr.col = {};
  1389. Constr.prototype = {
  1390. current: null // id of currently active pane
  1391. };
  1392. return Constr;
  1393. })();
  1394. (function () {
  1395. var Ut = DYN_WEB.Util,
  1396. Ev = DYN_WEB.Event,
  1397. Cookie = DYN_WEB.Cookie,
  1398. Tabs = DYN_WEB.Tabs;
  1399. Ut.augment(Tabs, {
  1400. // static props/methods for DYN_WEB.Tabs
  1401. setup: function () {
  1402. var obj, settings = [];
  1403. if (Tabs.hasBrowserSupport()) {
  1404. for (var i = 0; obj = arguments[i]; i++) {
  1405. if (obj.css) {
  1406. Ut.writeStyleSheet(obj.css);
  1407. }
  1408. settings[i] = obj; // save to pass to constructor onload
  1409. }
  1410. Ev.add(window, 'load', function () {
  1411. for (var i = 0; settings[i]; i++) {
  1412. new Tabs(settings[i]);
  1413. }
  1414. });
  1415. }
  1416. },
  1417. hasBrowserSupport: function () {
  1418. if (document.getElementById && document.getElementsByTagName && typeof decodeURI !== 'undefined' && (document.addEventListener || document.attachEvent)) {
  1419. return true;
  1420. }
  1421. return false;
  1422. },
  1423. init: function (tabsetId) {
  1424. var _this = Tabs.col[tabsetId],
  1425. links = Tabs.getTabs(tabsetId),
  1426. // code uses hash in tab links but tabs can also link to other pages
  1427. // so compare current location to link's href
  1428. loc = Ut.getURLtoHash(location),
  1429. lnk, pg, paneId, pane, sel, dflt, cur, c, q, hash;
  1430. q = Ut.getValueFromQueryString(tabsetId);
  1431. if (_this.useCookies) {
  1432. c = Tabs.checkCookie(tabsetId);
  1433. }
  1434. // tab in query string or cookie?
  1435. sel = q ? q : c ? c : null;
  1436. // add ids and event handlers to links ...
  1437. for (var i = 0; lnk = links[i]; i++) {
  1438. paneId = '', pane = ''; // reset
  1439. pg = Ut.getURLtoHash(lnk);
  1440. hash = Ut.getHash(lnk);
  1441. if (lnk.hash && (loc == pg)) { // has hash and points to current page
  1442. paneId = hash;
  1443. lnk.id = tabsetId + '__' + paneId; // double underscore between
  1444. }
  1445. // if tab associated with tabpane, set up onclick fn
  1446. if (paneId) {
  1447. try {
  1448. pane = Ut.$(paneId);
  1449. } catch (err) { // showClicked fn throws
  1450. }
  1451. // first tab/pane is default
  1452. if (!dflt) {
  1453. dflt = paneId;
  1454. }
  1455. // if set active in markup, hold as current
  1456. if (pane && Ut.hasClass(lnk, 'activeTab') && Ut.hasClass(pane, 'activePane')) {
  1457. _this.current = cur = paneId;
  1458. }
  1459. // to pass paneId, tabsetId to showClicked...
  1460. Ev.add(lnk, 'click', function (paneId, tabsetId) {
  1461. return function (e) {
  1462. Tabs.showClicked(e, paneId, tabsetId);
  1463. };
  1464. }(paneId, tabsetId));
  1465. }
  1466. }
  1467. // check if tab and pane for sel
  1468. if (sel && (lnk = Ut.$(tabsetId + '__' + sel)) && (pane = Ut.$(sel))) {
  1469. if (cur && cur !== sel) {
  1470. Tabs.hideCurrent(tabsetId, cur);
  1471. }
  1472. Ut.addClass(lnk, 'activeTab');
  1473. Ut.addClass(pane, 'activePane');
  1474. _this.current = sel;
  1475. } else if (!cur && dflt) {
  1476. Ut.addClass(Ut.$(tabsetId + '__' + dflt), 'activeTab');
  1477. Ut.addClass(Ut.$(dflt), 'activePane');
  1478. _this.current = dflt;
  1479. }
  1480. _this.on_init();
  1481. },
  1482. getTabs: function (id) {
  1483. var set = Ut.$(id),
  1484. list, links;
  1485. if (!set) {
  1486. throw new Error('No element matching tabset id found.');
  1487. return [];
  1488. }
  1489. list = Ut.getElementsByClassName('tabnavs', 'ul', set);
  1490. if (list.length === 0) {
  1491. throw new Error('No tabnavs were found in the tabset.');
  1492. return [];
  1493. }
  1494. links = list[0].getElementsByTagName('a');
  1495. return links;
  1496. },
  1497. showClicked: function (e, paneId, tabsetId) {
  1498. var tabId = tabsetId + '__' + paneId;
  1499. var _this = Tabs.col[tabsetId];
  1500. _this.before_hide(tabId, paneId, tabsetId);
  1501. Tabs.hideCurrent(tabsetId, _this.current);
  1502. Ut.addClass(Ut.$(tabId), 'activeTab');
  1503. try {
  1504. Ut.addClass(Ut.$(paneId), 'activePane');
  1505. } catch (err) {
  1506. throw new Error('showClicked can\'t find pane associated with tab. Check tab hash and pane id.');
  1507. return false;
  1508. }
  1509. _this.current = paneId;
  1510. if (_this.useCookies) {
  1511. Tabs.setCookie(tabsetId, paneId);
  1512. }
  1513. _this.on_activate(tabId, paneId, tabsetId);
  1514. if (e) {
  1515. Ev.DOMit(e);
  1516. e.preventDefault();
  1517. }
  1518. return false;
  1519. },
  1520. hideCurrent: function (tabsetId, cur) {
  1521. var tab = Ut.$(tabsetId + '__' + cur),
  1522. pane = Ut.$(cur);
  1523. Ut.removeClass(tab, 'activeTab');
  1524. Ut.removeClass(pane, 'activePane');
  1525. },
  1526. checkCookie: function (tabsetId) {
  1527. var c, cookies, tab_cookies = Cookie.get('dw_Tabs');
  1528. if (tab_cookies) {
  1529. cookies = tab_cookies.split(',');
  1530. for (var i = 0; cookies[i]; i++) {
  1531. c = cookies[i];
  1532. if (c.indexOf(tabsetId + ':') === 0) {
  1533. return decodeURI(c.slice(tabsetId.length + 1, c.length));
  1534. }
  1535. }
  1536. }
  1537. return null;
  1538. },
  1539. setCookie: function (tabsetId, paneId) {
  1540. // format for cookies (multiple tabsets supported): dw_Tabs=tabsetId:paneId,tabsetId:paneId;
  1541. var new_tab_cookies = '',
  1542. cookies,
  1543. tab_cookies = Cookie.get('dw_Tabs');
  1544. if (tab_cookies) {
  1545. cookies = tab_cookies.split(',');
  1546. for (var i = 0; cookies[i]; i++) {
  1547. if (cookies[i].indexOf(tabsetId + ':') === 0) {
  1548. cookies[i] = tabsetId + ':' + paneId;
  1549. new_tab_cookies = cookies.join(',');
  1550. break;
  1551. }
  1552. }
  1553. if (!new_tab_cookies) { // if no match for this tabsetId
  1554. new_tab_cookies = tab_cookies + ',' + tabsetId + ':' + paneId;
  1555. }
  1556. } else { // no dw_Tabs set yet
  1557. new_tab_cookies = tabsetId + ':' + paneId;
  1558. }
  1559. Cookie.set('dw_Tabs', new_tab_cookies, null, '/');
  1560. }
  1561. });
  1562. })();
  1563. // util
  1564. (function () {
  1565. var Ut = DYN_WEB.Util;
  1566. // add methods to DYN_WEB.Util
  1567. Ut.augment(Ut, {
  1568. trim: function (str) {
  1569. if (String.prototype.trim) {
  1570. return str.trim(); // ECMAScript 5
  1571. } else {
  1572. var re = /^\s+|\s+$/g;
  1573. return str.replace(re, '');
  1574. }
  1575. },
  1576. normalizeString: function (str) {
  1577. var re = /\s\s+/g;
  1578. return Ut.trim(str).replace(re, ' ');
  1579. },
  1580. hasClass: function (el, cl) {
  1581. var re = new RegExp('\\b' + cl + '\\b', 'i');
  1582. if (re.test(el.className)) {
  1583. return true;
  1584. }
  1585. return false;
  1586. },
  1587. addClass: function (el, cl) {
  1588. if (!Ut.hasClass(el, cl)) {
  1589. el.className = Ut.trim(el.className + ' ' + cl);
  1590. }
  1591. },
  1592. removeClass: function (el, cl) {
  1593. el.className = Ut.normalizeString(el.className.replace(cl, ' '));
  1594. },
  1595. getElementsByClassName: function (sClass, sTag, oCont) {
  1596. oCont = oCont ? oCont : document;
  1597. if (oCont.getElementsByClassName) {
  1598. return oCont.getElementsByClassName(sClass); // html5
  1599. } else {
  1600. sTag = sTag || '*';
  1601. var result = [],
  1602. re = new RegExp('\\b' + sClass + '\\b', 'i'),
  1603. list = oCont.getElementsByTagName(sTag);
  1604. for (var i = 0; list[i]; i++) {
  1605. if (re.test(list[i].className)) result.push(list[i]);
  1606. }
  1607. return result;
  1608. }
  1609. },
  1610. // obj: link or window.location
  1611. getValueFromQueryString: function (name, obj) {
  1612. obj = obj ? obj : window.location;
  1613. var pairs, set;
  1614. if (obj.search && obj.search.indexOf(name != -1)) {
  1615. pairs = obj.search.slice(1).split('&'); // name/value pairs
  1616. for (var i = 0; pairs[i]; i++) {
  1617. set = pairs[i].split('='); // Check each pair for match on name
  1618. if (set[0] == name && set[1]) {
  1619. return set[1];
  1620. }
  1621. }
  1622. }
  1623. return '';
  1624. },
  1625. getURLtoHash: function (obj) {
  1626. obj = obj ? obj : window.location;
  1627. var href = obj.href,
  1628. pt = href.indexOf('#'),
  1629. url = (pt != -1) ? href.slice(0, pt) : href; // remove hash from href
  1630. return url;
  1631. },
  1632. getHash: function (obj) {
  1633. obj = obj ? obj : window.location;
  1634. var hash = '';
  1635. if (obj.hash) { // some browsers say true if just #, some '' (ff)
  1636. hash = obj.hash.slice(1);
  1637. }
  1638. return hash;
  1639. },
  1640. // Alternate functions are available that use DOM methods instead of document.write
  1641. writeStyleSheet: function (file, bScreen) {
  1642. var screen = (bScreen !== false) ? '" media="screen" />\n' : '"/>\n';
  1643. document.write('\n<link rel="stylesheet" href="' + file + screen);
  1644. },
  1645. // used to set min-height (as on dyn-web home page)
  1646. writeStyleRule: function (rule, bScreen) {
  1647. var screen = (bScreen !== false) ? ' media="screen">' : '>';
  1648. document.write('\n<style type="text/css"' + screen + rule + '</style>');
  1649. }
  1650. });
  1651. })();
  1652. (function (window) {
  1653. /**
  1654. * @param {String} type - request | cancel | native.
  1655. * @return {Function} Timing function.
  1656. */
  1657. function requestFrame(type) {
  1658. // The only vendor prefixes required.
  1659. var vendors = ['moz', 'webkit'],
  1660. // Disassembled timing function abbreviations.
  1661. aF = 'AnimationFrame',
  1662. rqAF = 'Request' + aF,
  1663. // Final assigned functions.
  1664. assignedRequestAnimationFrame,
  1665. assignedCancelAnimationFrame,
  1666. // Initial time of the timing lapse.
  1667. previousTime = 0,
  1668. mozRAF = window.mozRequestAnimationFrame,
  1669. mozCAF = window.mozCancelAnimationFrame,
  1670. // Checks for firefox 4 - 10 function pair mismatch.
  1671. hasMozMismatch = mozRAF && !mozCAF,
  1672. func;
  1673. // Date.now polyfill, mainly for legacy IE versions.
  1674. if (!Date.now) {
  1675. Date.now = function() {
  1676. return new Date().getTime();
  1677. };
  1678. }
  1679. /**
  1680. * hasIOS6RequestAnimationFrameBug.
  1681. * @See {@Link https://gist.github.com/julienetie/86ac394ec41f1271ff0a}
  1682. * - for Commentary.
  1683. * @Copyright 2015 - Julien Etienne.
  1684. * @License: MIT.
  1685. */
  1686. function hasIOS6RequestAnimationFrameBug() {
  1687. var webkitRAF = window.webkitRequestAnimationFrame,
  1688. rAF = window.requestAnimationFrame,
  1689. // CSS/ Device with max for iOS6 Devices.
  1690. hasMobileDeviceWidth = screen.width <= 768 ? true : false,
  1691. // Only supports webkit prefixed requestAnimtionFrane.
  1692. requiresWebkitprefix = !(webkitRAF && rAF),
  1693. // iOS6 webkit browsers don't support performance now.
  1694. hasNoNavigationTiming = window.performance ? false : true,
  1695. iOS6Notice = 'setTimeout is being used as a substitiue for' +
  1696. 'requestAnimationFrame due to a bug within iOS 6 builds',
  1697. hasIOS6Bug = requiresWebkitprefix && hasMobileDeviceWidth &&
  1698. hasNoNavigationTiming;
  1699. function bugCheckresults(timingFnA, timingFnB, notice) {
  1700. if (timingFnA || timingFnB) {
  1701. console.warn(notice);
  1702. return true;
  1703. } else {
  1704. return false;
  1705. }
  1706. }
  1707. function displayResults() {
  1708. if (hasIOS6Bug) {
  1709. return bugCheckresults(webkitRAF, rAF, iOS6Notice);
  1710. } else {
  1711. return false;
  1712. }
  1713. }
  1714. return displayResults();
  1715. }
  1716. /**
  1717. * Native clearTimeout function.
  1718. * @return {Function}
  1719. */
  1720. function clearTimeoutWithId(id) {
  1721. clearTimeout(id);
  1722. }
  1723. /**
  1724. * Based on a polyfill by Erik, introduced by Paul Irish &
  1725. * further improved by Darius Bacon.
  1726. * @see {@link http://www.paulirish.com/2011/
  1727. * requestanimationframe-for-smart-animating}
  1728. * @see {@link https://github.com/darius/requestAnimationFrame/blob/
  1729. * master/requestAnimationFrame.js}
  1730. * @callback {Number} Timestamp.
  1731. * @return {Function} setTimeout Function.
  1732. */
  1733. function setTimeoutWithTimestamp(callback) {
  1734. var immediateTime = Date.now(),
  1735. lapsedTime = Math.max(previousTime + 16, immediateTime);
  1736. return setTimeout(function() {
  1737. callback(previousTime = lapsedTime);
  1738. },
  1739. lapsedTime - immediateTime);
  1740. }
  1741. /**
  1742. * Queries the native function, prefixed function
  1743. * or use the setTimeoutWithTimestamp function.
  1744. * @return {Function}
  1745. */
  1746. function queryRequestAnimationFrame() {
  1747. if (Array.prototype.filter) {
  1748. assignedRequestAnimationFrame = window['request' + aF] ||
  1749. window[vendors.filter(function(vendor) {
  1750. if (window[vendor + rqAF] !== undefined)
  1751. return vendor;
  1752. }) + rqAF] || setTimeoutWithTimestamp;
  1753. } else {
  1754. return setTimeoutWithTimestamp;
  1755. }
  1756. if (!hasIOS6RequestAnimationFrameBug()) {
  1757. return assignedRequestAnimationFrame;
  1758. } else {
  1759. return setTimeoutWithTimestamp;
  1760. }
  1761. }
  1762. /**
  1763. * Queries the native function, prefixed function
  1764. * or use the clearTimeoutWithId function.
  1765. * @return {Function}
  1766. */
  1767. function queryCancelAnimationFrame() {
  1768. var cancellationNames = [];
  1769. if (Array.prototype.map) {
  1770. vendors.map(function(vendor) {
  1771. return ['Cancel', 'CancelRequest'].map(
  1772. function(cancellationNamePrefix) {
  1773. cancellationNames.push(vendor +
  1774. cancellationNamePrefix + aF);
  1775. });
  1776. });
  1777. } else {
  1778. return clearTimeoutWithId;
  1779. }
  1780. /**
  1781. * Checks for the prefixed cancelAnimationFrame implementation.
  1782. * @param {Array} prefixedNames - An array of the prefixed names.
  1783. * @param {Number} i - Iteration start point.
  1784. * @return {Function} prefixed cancelAnimationFrame function.
  1785. */
  1786. function prefixedCancelAnimationFrame(prefixedNames, i) {
  1787. var cancellationFunction;
  1788. for (; i < prefixedNames.length; i++) {
  1789. if (window[prefixedNames[i]]) {
  1790. cancellationFunction = window[prefixedNames[i]];
  1791. break;
  1792. }
  1793. }
  1794. return cancellationFunction;
  1795. }
  1796. // Use truthly function
  1797. assignedCancelAnimationFrame = window['cancel' + aF] ||
  1798. prefixedCancelAnimationFrame(cancellationNames, 0) ||
  1799. clearTimeoutWithId;
  1800. // Check for iOS 6 bug
  1801. if (!hasIOS6RequestAnimationFrameBug()) {
  1802. return assignedCancelAnimationFrame;
  1803. } else {
  1804. return clearTimeoutWithId;
  1805. }
  1806. }
  1807. function getRequestFn() {
  1808. if (hasMozMismatch) {
  1809. return setTimeoutWithTimestamp;
  1810. } else {
  1811. return queryRequestAnimationFrame();
  1812. }
  1813. }
  1814. function getCancelFn() {
  1815. return queryCancelAnimationFrame();
  1816. }
  1817. function setNativeFn() {
  1818. if (hasMozMismatch) {
  1819. window.requestAnimationFrame = setTimeoutWithTimestamp;
  1820. window.cancelAnimationFrame = clearTimeoutWithId;
  1821. } else {
  1822. window.requestAnimationFrame = queryRequestAnimationFrame();
  1823. window.cancelAnimationFrame = queryCancelAnimationFrame();
  1824. }
  1825. }
  1826. /**
  1827. * The type value "request" singles out firefox 4 - 10 and
  1828. * assigns the setTimeout function if plausible.
  1829. */
  1830. switch (type) {
  1831. case 'request':
  1832. case '':
  1833. func = getRequestFn();
  1834. break;
  1835. case 'cancel':
  1836. func = getCancelFn();
  1837. break;
  1838. case 'native':
  1839. setNativeFn();
  1840. break;
  1841. default:
  1842. throw new Error('RequestFrame parameter is not a type.');
  1843. }
  1844. return func;
  1845. }
  1846. // Default to window as global
  1847. if (typeof window === 'object') {
  1848. window.requestFrame = requestFrame;
  1849. }
  1850. /* global-define */
  1851. }((typeof window === 'undefined' ? {} : window)));
  1852. // Icons
  1853. var Icons = {
  1854. clock: {
  1855. icn: '<svg width="20" height="20" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1024 544v448q0 14-9 23t-23 9h-320q-14 0-23-9t-9-23v-64q0-14 9-23t23-9h224v-352q0-14 9-23t23-9h64q14 0 23 9t9 23zm416 352q0-148-73-273t-198-198-273-73-273 73-198 198-73 273 73 273 198 198 273 73 273-73 198-198 73-273zm224 0q0 209-103 385.5t-279.5 279.5-385.5 103-385.5-103-279.5-279.5-103-385.5 103-385.5 279.5-279.5 385.5-103 385.5 103 279.5 279.5 103 385.5z" fill="'+ ALARM_YELLOW +'"/></svg>',
  1856. title: 'Режим ожидания'
  1857. },
  1858. exclamination: {
  1859. icn: '<svg width="20" height="20" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1088 1248v224q0 26-19 45t-45 19h-256q-26 0-45-19t-19-45v-224q0-26 19-45t45-19h256q26 0 45 19t19 45zm30-1056l-28 768q-1 26-20.5 45t-45.5 19h-256q-26 0-45.5-19t-20.5-45l-28-768q-1-26 17.5-45t44.5-19h320q26 0 44.5 19t17.5 45z" fill="'+ ALARM_RED +'"/></svg>',
  1860. title: 'Авария'
  1861. },
  1862. normal: {
  1863. icn: '<svg width="20" height="20" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1299 813l-422 422q-19 19-45 19t-45-19l-294-294q-19-19-19-45t19-45l102-102q19-19 45-19t45 19l147 147 275-275q19-19 45-19t45 19l102 102q19 19 19 45t-19 45zm141 83q0-148-73-273t-198-198-273-73-273 73-198 198-73 273 73 273 198 198 273 73 273-73 198-198 73-273zm224 0q0 209-103 385.5t-279.5 279.5-385.5 103-385.5-103-279.5-279.5-103-385.5 103-385.5 279.5-279.5 385.5-103 385.5 103 279.5 279.5 103 385.5z" fill="'+ ALARM_GREEN +'"/></svg>',
  1864. title: 'Норма'
  1865. },
  1866. shutdown: {
  1867. icn: '<svg width="20" height="20" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1664 896q0 156-61 298t-164 245-245 164-298 61-298-61-245-164-164-245-61-298q0-182 80.5-343t226.5-270q43-32 95.5-25t83.5 50q32 42 24.5 94.5t-49.5 84.5q-98 74-151.5 181t-53.5 228q0 104 40.5 198.5t109.5 163.5 163.5 109.5 198.5 40.5 198.5-40.5 163.5-109.5 109.5-163.5 40.5-198.5q0-121-53.5-228t-151.5-181q-42-32-49.5-84.5t24.5-94.5q31-43 84-50t95 25q146 109 226.5 270t80.5 343zm-640-768v640q0 52-38 90t-90 38-90-38-38-90v-640q0-52 38-90t90-38 90 38 38 90z" fill="'+ ALARM_RED +'"/></svg>',
  1868. title: 'Выключение'
  1869. },
  1870. batteryLow: {
  1871. icn: '<svg width="30" height="20" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1920 576q53 0 90.5 37.5t37.5 90.5v384q0 53-37.5 90.5t-90.5 37.5v160q0 66-47 113t-113 47h-1856q-66 0-113-47t-47-113v-960q0-66 47-113t113-47h1856q66 0 113 47t47 113v160zm0 512v-384h-128v-288q0-14-9-23t-23-9h-1856q-14 0-23 9t-9 23v960q0 14 9 23t23 9h1856q14 0 23-9t9-23v-288h128z" fill="'+ ALARM_RED +'"/></svg>',
  1872. title: 'Низкий уровень заряда'
  1873. },
  1874. batTest: {
  1875. icn: '<svg width="20" height="20" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1024 1408h640v-128h-640v128zm-384-512h1024v-128h-1024v128zm640-512h384v-128h-384v128zm512 832v256q0 26-19 45t-45 19h-1664q-26 0-45-19t-19-45v-256q0-26 19-45t45-19h1664q26 0 45 19t19 45zm0-512v256q0 26-19 45t-45 19h-1664q-26 0-45-19t-19-45v-256q0-26 19-45t45-19h1664q26 0 45 19t19 45zm0-512v256q0 26-19 45t-45 19h-1664q-26 0-45-19t-19-45v-256q0-26 19-45t45-19h1664q26 0 45 19t19 45z" fill="'+ ALARM_YELLOW +'"/></svg>',
  1876. title: 'Тестирование'
  1877. }
  1878. };