main.js 70 KB

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