main.js 69 KB

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