blob: 26a6084acbd0af39f5421144beac51000da0d18e [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001
2/*
3 *Login Variables
4 */
5var AuthQop,username="",passwd="",GnCount=1,Authrealm,Gnonce,nonce;
6var _resetTimeOut=600000;
7var authHeaderIntervalID = 0;
8
9/*
10 * clear the Authheader from the coockies
11 */
12function clearAuthheader() {
13 //clearing coockies
14 Authheader = "";
15 AuthQop = "";
16 username = "";
17 passwd = "";
18 GnCount = "";
19 Authrealm = "";
20 //window.location.reload();
21 window.location="index.html";
22}
23/*
24* Reset the authHeader
25*/
26function resetInterval() {
27 if(authHeaderIntervalID > 0)
28 clearInterval(authHeaderIntervalID);
29 authHeaderIntervalID = setInterval( "clearAuthheader()", _resetTimeOut);
30
31}
32
33
34/*
35 * Check the login responce as the 200 OK or not.
36 */
37function login_done(urlData) {
38 if(urlData.indexOf("200 OK") != -1 ) {
39 return true;
40 } else {
41 return false;
42 }
43}
44function getValue(authstr) {
45 var arr=authstr.split("=");
46 return arr[1].substring(1,arr[1].indexOf('\"',2) );
47}
48/*
49 * as name suggest it is function which does the authentication
50 * and put the AuthHeader in the Cookies. Uses Digest Auth method
51 */
52function doLogin(username1,passwd1) {
53 var url = window.location.protocol + "//" + window.location.host + "/login.cgi";
54 var loginParam = getAuthType(url);
55 //alert(loginParam);
56 if(loginParam!=null) {
57 var loginParamArray = loginParam.split(" ");
58 if(loginParamArray[0] =="Digest") {
59//nonce="718337c309eacc5dc1d2558936225417", qop="auth"
60 Authrealm = getValue(loginParamArray[1]);
61 nonce = getValue(loginParamArray[2]);
62 AuthQop = getValue(loginParamArray[3]);
63
64// alert("nonce :" + nonce);
65// alert("AuthQop :" + AuthQop);
66// alert("Authrealm :" + Authrealm);
67
68 username = username1;
69 passwd = passwd1;
70 var rand, date, salt, strResponse;
71
72 Gnonce = nonce;
73 var tmp, DigestRes;
74 var HA1, HA2;
75
76
77
78
79
80 HA1 = hex_md5(username+ ":" + Authrealm + ":" + passwd);
81 HA2 = hex_md5("GET" + ":" + "/cgi/xml_action.cgi");
82
83 rand = Math.floor(Math.random()*100001)
84 date = new Date().getTime();
85
86 salt = rand+""+date;
87 tmp = hex_md5(salt);
88 AuthCnonce = tmp.substring(0,16);
89
90
91 var strhex = hex(GnCount);
92 var temp = "0000000000" + strhex;
93 var Authcount = temp.substring(temp.length-8);
94 DigestRes = hex_md5(HA1 + ":" + nonce + ":" + Authcount + ":" + AuthCnonce + ":" + AuthQop + ":" + HA2);
95
96 url = window.location.protocol + "//" + window.location.host + "/login.cgi?Action=Digest&username="+username+"&realm="+Authrealm+"&nonce="+nonce+"&response="+DigestRes+"&qop="+AuthQop+"&cnonce="+AuthCnonce + "&nc="+Authcount+"&temp=marvell";
97 if(login_done(authentication(url))) {
98 strResponse = "Digest username=\"" + username + "\", realm=\"" + Authrealm + "\", nonce=\"" + nonce + "\", uri=\"" + "/cgi/protected.cgi" + "\", response=\"" + DigestRes + "\", qop=" + AuthQop + ", nc=00000001" + ", cnonce=\"" + AuthCnonce + "\"" ;
99
100 return 1;
101 } else {
102 // show error message...
103 return 0;
104 }
105
106 return strResponse;
107 }
108 }
109 return -1;
110}
111
112function getAuthHeader(requestType,file) {
113 var rand, date, salt, strAuthHeader;
114 var tmp, DigestRes,AuthCnonce_f;
115 var HA1, HA2;
116
117
118
119 HA1 = hex_md5(username+ ":" + Authrealm + ":" + passwd);
120 HA2 = hex_md5( requestType + ":" + "/cgi/xml_action.cgi");
121
122 rand = Math.floor(Math.random()*100001)
123 date = new Date().getTime();
124
125 salt = rand+""+date;
126 tmp = hex_md5(salt);
127 AuthCnonce_f = tmp.substring(0,16);
128 //AuthCnonce_f = tmp;
129
130 var strhex = hex(GnCount);
131 var temp = "0000000000" + strhex;
132 var Authcount = temp.substring(temp.length-8);
133 DigestRes =hex_md5(HA1 + ":" + nonce + ":" + Authcount + ":" + AuthCnonce_f + ":" + AuthQop + ":"+ HA2);
134
135
136 GnCount++;
137 strAuthHeader = "Digest " + "username=\"" + username + "\", realm=\"" + Authrealm + "\", nonce=\"" + nonce + "\", uri=\"" + "/cgi/xml_action.cgi" + "\", response=\"" + DigestRes + "\", qop=" + AuthQop + ", nc=" + Authcount + ", cnonce=\"" + AuthCnonce_f + "\"" ;
138 DigestHeader = strAuthHeader ;
139 return strAuthHeader;
140}
141
142
143function logOut() {
144 var host = window.location.protocol + "//" + window.location.host + "/";
145 var url = host+'xml_action.cgi?Action=logout';
146 $.ajax( {
147 type: "GET",
148 url: url,
149 dataType: "html",
150 async:false,
151 complete: function() {
152 clearAuthheader();
153 }
154 });
155}
156
157
158
159function getHeader (AuthMethod , file) {
160 var rand, date, salt, setResponse;
161 var tmp, DigestRes,AuthCnonce_f;
162 var HA1, HA2;
163
164 HA1 = hex_md5(username + ":" + Authrealm + ":" + passwd);
165 HA2 = hex_md5(AuthMethod + ":" + "/cgi/xml_action.cgi");
166
167 /*Generate random sequence for Cnonce*/
168 // Integer random = new Integer(Random.nextInt(2097152));
169 // Integer date = new Integer((int)(System.currentTimeMillis() + 24));
170 rand = Math.floor();
171 date = new Date().getTime();
172
173
174 salt = rand+""+date;
175 tmp = hex_md5(salt);
176 AuthCnonce = tmp.substring(0,16);
177 AuthCnonce_f = tmp;
178
179 var strhex = hex(GnCount);
180 var temp = "0000000000" + strhex;
181 var Authcount = temp.substring(temp.length-8);
182
183 DigestRes =hex_md5(HA1 + ":" + Gnonce + ":" + Authcount + ":" + AuthCnonce_f + ":" + AuthQop + ":"+ HA2);
184
185
186 ++GnCount;
187
188 if("GET" == AuthMethod) {
189 if("upgrade" == file) {
190 //setResponse = "/login.cgi?Action=Upload&file=" + file + "&username=" + username + "&realm=" + Authrealm + "&nonce=" + Gnonce + "&response=" + DigestRes + "&cnonce=" + AuthCnonce_f + "&nc=" + Authcount + "&qop=" + AuthQop + "&temp=marvell";
191 setResponse= "/xml_action.cgi?Action=Upload&file=upgrade&command="
192 } else if("config_backup" == file) {
193 setResponse= "/xml_action.cgi?Action=Upload&file=backfile&config_backup="
194 } else {
195 setResponse = "/login.cgi?Action=Download&file=" + file + "&username=" + username + "&realm=" + Authrealm + "&nonce=" + Gnonce + "&response=" + DigestRes + "&cnonce=" + AuthCnonce_f + "&nc=" + Authcount + "&qop=" + AuthQop + "&temp=marvell";
196 }
197 }
198
199 if("POST"==AuthMethod) {
200 setResponse = "/login.cgi?Action=Upload&file=" + file + "&username=" + username + "&realm=" + Authrealm + "&nonce=" + Gnonce + "&response=" + DigestRes + "&cnonce=" + AuthCnonce_f + "&nc=" + Authcount + "&qop=" + AuthQop + "&temp=marvell";
201 }
202
203 return setResponse;
204}
205
206/*
207 * return the cookie parameter is Coockie name
208 */
209function GetCookie(c_name) {
210 if (document.cookie.length>0) {
211 c_start=document.cookie.indexOf(c_name + "=");
212 if (c_start!=-1) {
213 c_start=c_start + c_name.length+1;
214 c_end=document.cookie.indexOf(";",c_start);
215 if (c_end==-1) c_end=document.cookie.length;
216 return unescape(document.cookie.substring(c_start,c_end));
217 }
218 }
219 return "";
220}
221/*
222 * set cookie of browser it has expiry days after which it expires
223 */
224function SetCookie(c_name,value,expiredays) {
225 var exdate=new Date();
226 exdate.setDate(exdate.getDate()+expiredays);
227 document.cookie=c_name+ "=" +escape(value)+
228 ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
229}
230
231
232
233function ElementLocaliztion(pElementArray) {
234 for(var i=0; i<pElementArray.length; i++) {
235 if(jQuery.i18n.prop(pElementArray[i].id)!=null)
236 document.getElementById(pElementArray[i].id).innerHTML = jQuery.i18n.prop(pElementArray[i].id);
237 }
238}
239function LocalElementById(elementId) {
240 if("input" == document.getElementById(elementId).tagName.toLowerCase()) {
241 document.getElementById(elementId).value = jQuery.i18n.prop(elementId);
242 } else {
243 document.getElementById(elementId).innerHTML = jQuery.i18n.prop(elementId);
244 }
245
246}
247
248function LocalElementByTagName(elementTagName) {
249 if("button" == elementTagName) {
250 $(":button").each(function() {
251 $(this).val(jQuery.i18n.prop($(this).attr("id")))
252 })
253 } else {
254 $(elementTagName).each(function() {
255 $(this).text(jQuery.i18n.prop($(this).attr("id")))
256 })
257 }
258}
259
260function LocalAllElement(){
261 $("[id^='lt_']").each(function() {
262 if("input" == document.getElementById($(this).attr("id")).tagName.toLowerCase()) {
263 $(this).val(jQuery.i18n.prop($(this).attr("id")));
264 }else{
265 $(this).text(jQuery.i18n.prop($(this).attr("id")));
266 }
267 });
268}
269
270
271
272
273function hex(d) {
274 var hD="0123456789ABCDEF";
275 var h = hD.substr(d&15,1);
276 while(d>15) {
277 d>>=4;
278 h=hD.substr(d&15,1)+h;
279 }
280 return h;
281
282}
283
284function clearTabaleRows(tableId) {
285
286 var i=document.getElementById(tableId).rows.length;
287 while(i!=1) {
288 document.getElementById(tableId).deleteRow(i-1);
289 i--;
290 }
291
292}
293
294
295
296/* Converts timezone offset expressed in minutes to string */
297function GetMachineTimezoneGmtOffsetStr(tzGmtOffset ) {
298 var gmtOffsetStr =""+ getAbsValue(tzGmtOffset/60);
299 var tempInt = tzGmtOffset;
300
301 if(tempInt < 0) {
302 tempInt = 0 - tempInt;
303 }
304
305 if(( tempInt % 60 ) != 0 ) {
306 gmtOffsetStr += ":" + ( tempInt % 60 );
307 }
308
309 //new XDialog("Error","gmt offset" + gmtOffsetStr ).alert();
310
311 return gmtOffsetStr;
312}
313/* Find out timezone offset settings from connected device. If dst is observed we should see
314 * difference in Jan and July timezone offset.Pick the max one */
315function GetMachineTimezoneGmtOffset() {
316 var rightNow = new Date();
317
318 var JanuaryFirst= new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0,0);
319 var JulyFirst= new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0,0);
320
321 var JanOffset,JulyOffset;
322 var tzGmtOffset;
323
324 JanOffset = JanuaryFirst.getTimezoneOffset();
325 JulyOffset = JulyFirst.getTimezoneOffset();
326
327 if(JulyOffset > JanOffset) {
328 tzGmtOffset= JulyOffset;
329 } else {
330 tzGmtOffset = JanOffset;
331 }
332
333 return tzGmtOffset;
334}
335
336/* Get the connected device's day light saving settings in string format e.g. M3.5.0 or J81 */
337function GetMachineTimezoneDstStartStr(StandardGMToffset) {
338 var rightNow = new Date();
339
340 var JanuaryFirst = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0,0);
341 var JulyFirst= new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0,0);
342 var HoursInSixMonths =((JulyFirst.getTime() - JanuaryFirst.getTime()) / (1000 * 60 * 60));
343 var dstStartStr = "";
344 var i ;
345 var JanOffset, JulyOffset;
346 var hourStart, hourEnd;
347
348 /* If there are dst settings to be considered we should get them by checking in 6 months time interval */
349 JanOffset = JanuaryFirst.getTimezoneOffset();
350 JulyOffset = JulyFirst.getTimezoneOffset();
351
352 if(JanOffset > JulyOffset) {
353 hourStart = 0;
354 hourEnd = HoursInSixMonths;
355 } else {
356 hourStart = HoursInSixMonths;
357 hourEnd = HoursInSixMonths * 2;
358 }
359
360
361 var tempDate = getDstStartTime(hourStart,hourEnd, rightNow.getYear(),StandardGMToffset);
362
363 if(tempDate != null) {
364 /* Dst setting string : M3.5.0 (Month of the year).(Week Of Month).(Day of Week)
365 * So We need to iterate over six months period for few years and find which week of month it is */
366
367 var changeWeek = getChangeWeek(hourStart,hourEnd, tempDate.getYear(),StandardGMToffset);
368
369 switch(changeWeek) {
370 case -1:
371 break;
372 case -2: // Some regions have fixed day for start of dst setting which is expressed with J
373 dstStartStr ="J" + (((tempDate.getTime()-JanuaryFirst.getTime())/(24 * 60 * 60* 1000) ) + 1);
374 break;
375 default:
376 dstStartStr = "M" + (tempDate.getMonth() + 1) + "." + changeWeek + "." + tempDate.getDay();
377 break;
378 }
379 }
380
381 return dstStartStr;
382}
383
384function getDstStartTime(hourStart,hourEnd, year,StandardGMToffset) {
385 /* Check at which hour timezone offset is different from standard timezone
386 * offset for that region. Thats the start of dst */
387
388 var i;
389 for(i = hourStart; i < hourEnd; i++) {
390 var dSampleDate = new Date(year,0, 1, 0, 0, 0,0);
391 dSampleDate.setHours(i);
392
393 var CurrentGMToffset = dSampleDate.getTimezoneOffset();
394
395 if(CurrentGMToffset < StandardGMToffset) {
396 return dSampleDate;
397 }
398 }
399 return null;
400
401}
402function setConnectedDeviceTimezoneStr(gmtOffset,dstStart,timezoneStringArray) {
403 var i,j;
404 var startIndex = -1;
405 var count = 0;
406 var index = -1;
407
408 var tempGmtString;
409 var tempDstString;
410
411 for(j = 0; j < timezoneStringArray[1].length ; j++) {
412 var charArr = toCharArray(timezoneStringArray[1][j]);
413 count = 0;
414 tempGmtString = "";
415 tempDstString = "";
416 startIndex = -1;
417
418 for(i = 0; i < timezoneStringArray[1][j].split(",",3)[0].length; i++) {
419 if(((charArr[i] >= '0') && (charArr[i] <= '9')) ||(charArr[i] == '-') || (charArr[i] == ':')) {
420 count++;
421 if(startIndex == -1) {
422 startIndex = i;
423 }
424 tempGmtString = tempGmtString + charArr[i];
425 }
426
427 }
428
429 if(tempGmtString == gmtOffset) {
430
431 if(timezoneStringArray[1][j].split(",",3).length > 1) {
432 tempDstString = timezoneStringArray[1][j].split(",",3)[1];
433 } else {
434 tempDstString = "";
435 }
436
437 if((dstStart.length == 0) && (tempDstString.length != 0)) {
438 //new XDialog("Error","gmt offset matched but dst settings did not match!" + dstStart + "__" + tempDstString).alert();
439 continue;
440 }
441
442 if(tempDstString.substring(0,dstStart.length) == dstStart) {
443 //new XDialog("Error","Found perfect timezone match with gmt and dst" + timezoneStringArray[1][j]).alert();
444 index = j;
445 break;
446 } else {
447 //new XDialog("Error","gmt offset matched but dst settings did not match!" + dstStart + "__" + tempDstString).alert();
448 continue;
449 }
450
451 } else {
452 //new XDialog("Error","gmt offset did not match!" + tempGmtString + "__" + gmtOffset).alert();
453 continue;
454 }
455
456 }
457
458 if(index == -1) {
459 //new XDialog("Error","Failed to get timezone settings from connected device").alert();
460 //new XDialog("Error","Failed_ " + gmtOffset +"_" + dstStart).alert();
461 //GetPCTimeZoneString.setText("");
462 return -1;
463 } else {
464 //GetPCTimeZoneString.setText(timezoneStringComboBox.getItemText(index));
465 //timezoneString.setText(timezoneStringArray[1][index]);
466 return index;
467 }
468}
469function toCharArray(str) {
470 var charArray = new Array(0);
471 for(var i=0; i<str.length; i++)
472 charArray[i]=str.charAt(i);
473 return charArray;
474}
475
476/* We know the day of month but not the week. We can find day of the month for few years
477 * and guess which week of the month it would be */
478function getChangeWeek( hourStart, hourEnd, year, StandardGMToffset) {
479 var i;
480 var min = 32 , max = 0, dom = 0;
481
482 for(i = year; i < year + 20 ; i++) {
483 dom =(getDstStartTime(hourStart,hourEnd,i,StandardGMToffset)).getDate();
484 if(dom > max) {
485 max = dom;
486 }
487 if(dom < min) {
488 min = dom;
489 }
490 }
491
492 if(max == min) {
493 return -1;
494 }
495
496 /* Some regions have fixed day for start of dst settings. e.g 1 April
497 * We handle it as special case */
498 if(max - min != 6) {
499 return -2;
500 }
501
502 //new XDialog("Error","max " + max + "min " + min + " dom " + dom).alert();
503 return getAbsValue((((max + 6)/7)));
504
505}
506
507function getAbsValue(i) {
508
509 return i.toString().split(".")[0];
510}
511
512
513function getHelp(helpPage) {
514 if(GetCookie('locale')=='')
515 htmlFilename = "help_en.html";
516 else
517 htmlFilename = "help_" + GetCookie('locale')+".html";
518 var host = window.location.protocol + "//" + window.location.host + "/";
519 var url = host + htmlFilename + "#" + helpPage;
520
521 var helpWindow = window.open(url, 'newwindow');
522 helpWindow.focus();
523
524}
525function getMainHelp() {
526 getHelp("");
527}
528function showAlert(msgLanguageID) {
529 ShowDlg("alertMB",350,150);
530 document.getElementById("lAlertMessage").innerHTML = jQuery.i18n.prop(msgLanguageID);
531 document.getElementById("lAlert").innerHTML = jQuery.i18n.prop("lAlert");
532 LocalElementById("btnModalOk");
533}
534
535
536function UniEncode(string) {
537 if (undefined == string) {
538 return "";
539 }
540 var code = "";
541 for (var i = 0; i < string.length; ++i) {
542 var charCode = string.charCodeAt(i).toString(16);
543 var paddingLen = 4 - charCode.length;
544 for (var j = 0; j < paddingLen; ++j) {
545 charCode = "0" + charCode;
546 }
547
548 code += charCode;
549 }
550 return code;
551}
552
553function GetSmsTime() {
554 var date = new Date();
555 var fullYear = new String(date.getFullYear());
556 var year = fullYear.substr(2, fullYear.length - 1);
557 var month = date.getMonth() + 1;
558 var day = date.getDate();
559 var hour = date.getHours();
560 var mimute = date.getMinutes();
561 var second = date.getSeconds();
562 var timeZone = 0 - date.getTimezoneOffset() / 60;
563 var timeZoneStr = "";
564 if (timeZone > 0) {
565 timeZoneStr = "%2B" + timeZone;
566 } else {
567 timeZoneStr = "-" + timeZone;
568 }
569 var smsTime = year + "," + month + "," + day + "," + hour + "," + mimute + "," + second + "," + timeZoneStr;
570 return smsTime;
571}
572
573
574function UniDecode(encodeString) {
575 if (undefined == encodeString) {
576 return "";
577 }
578 var deCodeStr = "";
579
580 var strLen = encodeString.length / 4;
581 for (var idx = 0; idx < strLen; ++idx) {
582 deCodeStr += String.fromCharCode(parseInt(encodeString.substr(idx * 4, 4), 16));
583 }
584 return deCodeStr;
585}
586
587function showMsgBox(title, message) {
588 ShowDlg("alertMB", 350, 150);
589 document.getElementById("lAlertMessage").innerHTML = message;
590 document.getElementById("lAlert").innerHTML = title;
591 document.getElementById("btnModalOk").value = jQuery.i18n.prop("btnModalOk");
592}
593
594function GetBrowserType() {
595 var usrAgent = navigator.userAgent;
596 if (navigator.userAgent.indexOf("MSIE") > 0) {
597 var b_version = navigator.appVersion
598 var version = b_version.split(";");
599 var trim_Version = version[1].replace(/[ ]/g, "");
600 if (trim_Version == "MSIE6.0") {
601 return "IE6";
602 } else if(trim_Version == "MSIE7.0") {
603 return "IE7";
604 } else if (trim_Version == "MSIE8.0") {
605 return "IE8";
606 } else if (trim_Version == "MSIE9.0") {
607 return "IE9";
608 }
609 }
610 if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
611 return "Firefox";
612 }
613 if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
614 return "Safari"; //google
615 }
616 if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {
617 return "Camino";
618 }
619 if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {
620 return "Gecko";
621 }
622}
623
624function IsGSM7Code(str) {
625 var len = 0;
626 for( var i = 0; i < str.length; i++) {
627 var chr = str.charCodeAt(i);
628 if(((chr>=0x20&&chr<=0x7f)||0x20AC==chr||0x20AC==chr||0x0c==chr||0x0a==chr||0x0d==chr||0xa1==chr||0xa3==chr||0xa5==chr||0xa7==chr
629 ||0xbf==chr||0xc4==chr||0xc5==chr||0xc6==chr||0xc7==chr||0xc9==chr||0xd1==chr||0xd6==chr||0xd8==chr||0xdc==chr||0xdf==chr
630 ||0xe0==chr||0xe4==chr||0xe5==chr||0xe6==chr||0xe8==chr||0xe9==chr||0xec==chr||0xf11==chr||0xf2==chr||0xf6==chr||0xf8==chr||0xf9==chr||0xfc==chr
631 ||0x3c6==chr||0x3a9==chr||0x3a8==chr||0x3a3==chr||0x3a0==chr||0x39e==chr||0x39b==chr||0x398==chr||0x394==chr||0x393==chr)
632 && 0x60 != chr) {
633 ++len;
634 }
635 }
636 return len == str.length;
637}
638
639function EditHrefs(s_html) {
640 var s_str = new String(s_html);
641s_str = s_str.replace(/\bhttp\:\/\/www(\.[\w+\.\:\/\_]+)/gi,
642 "http\:\/\/&not;&cedil;$1");
643s_str = s_str.replace(/\b(http\:\/\/\w+\.[\w+\.\:\/\_]+)/gi,
644 "<a target=\"_blank\" href=\"$1\">$1<\/a>");
645s_str = s_str.replace(/\b(www\.[\w+\.\:\/\_]+)/gi,
646 "<a target=\"_blank\" href=\"http://$1\">$1</a>");
647s_str = s_str.replace(/\bhttp\:\/\/&not;&cedil; (\.[\w+\.\:\/\_]+)/gi,
648 "<a target=\"_blank\" href=\"http\:\/\/www$1\">http\:\/\/www$1</a>");
649 s_str = s_str.replace(/\b(\w+@[\w+\.?]*)/gi,
650 "<a href=\"mailto\:$1\">$1</a>");
651 return s_str;
652}
653
654function RemoveHrefs(str) {
655 str = str.replace(/<a.*?>/ig,"");
656 str = str.replace(/<\/a>/ig,"");
657 return str;
658}
659
660
661
662function GetIpAddr(elementId){
663 var ipAddr="";
664 for(var idx = 1; idx < 5; ++idx){
665 var selectorId = "#" + elementId + idx;
666 ipAddr = ipAddr + $(selectorId).val() + ".";
667 }
668 return ipAddr.substr(0,ipAddr.length-1);
669}
670
671
672function SetIpAddr(elementId, ipAddr){
673 var IpAddrArr = ipAddr.split(".");
674 for(var idx = 1; idx < 5; ++idx){
675 var selectorId = "#" + elementId + idx;
676 $(selectorId).val(IpAddrArr[idx-1]);
677 }
678}
679
680//time format: hh:mm:ss
681function GetTimeFromElement(elementId){
682 var strTime="";
683 for(var idx = 1; idx < 4; ++idx){
684 var selectorId = "#" + elementId + idx;
685 strTime = strTime + $(selectorId).val() + ":";
686 }
687 return strTime.substr(0,strTime.length-1);
688}
689
690//time format: hh:mm:ss
691function SetTimeToElement(elementId,time){
692 var timeArr = time.split(":");
693 for(var idx = 1; idx < 4; ++idx){
694 var selectorId = "#" + elementId + idx;
695 $(selectorId).val(timeArr[idx-1]);
696 }
697}
698
699
700//date format: yyyy-mm-dd
701function SetDateToElement(elementId,date){
702 var timeArr = date.split("-");
703 for(var idx = 1; idx < 4; ++idx){
704 var selectorId = "#" + elementId + idx;
705 $(selectorId).val(timeArr[idx-1]);
706 }
707}
708
709//date format: yyyy-mm-dd
710function GetDateFromElement(elementId){
711 var strDate = "";
712 for(var idx = 1; idx < 4; ++idx){
713 var selectorId = "#" + elementId + idx;
714 strDate = strDate + $(selectorId).val() + "-";
715 }
716 return strDate.substr(0,strDate.length-1);
717}
718
719//time format: hh:mm
720function GetTimeFromElementEx(elementId) {
721 var strTime = "";
722 for (var idx = 1; idx < 3; ++idx) {
723 var selectorId = "#" + elementId + idx;
724 strTime = strTime + $(selectorId).val() + ":";
725 }
726 return strTime.substr(0, strTime.length - 1);
727}
728
729//time format: hh:mm
730function SetTimeToElementEx(elementId, timectrl) {
731 var timeArr = timectrl.split(":");
732 for (var idx = 1; idx < 3; ++idx) {
733 var selectorId = "#" + elementId + idx;
734 $(selectorId).val(timeArr[idx - 1]);
735 }
736}
737
738function GetPortFromElement(elementId){
739 var strPort="";
740 for(var idx = 1; idx < 3; ++idx){
741 var selectorId = "#" + elementId + idx;
742 strPort = strPort + $(selectorId).val() + ":";
743 }
744 return strPort.substr(0,strPort.length-1);
745}
746
747//port format: xxxx:yyyy
748function SetPortToElement(elementId,port){
749 var portArr = port.split(":");
750 for(var idx = 1; idx < 3; ++idx){
751 var selectorId = "#" + elementId + idx;
752 $(selectorId).val(portArr[idx-1]);
753 }
754}
755
756function FormatSeconds(longTime) {
757
758 var time = parseFloat(longTime);
759 var d=0;
760 var h=0;
761 var m=0;
762 var s=0;
763 if (time != null && time != ""){
764 if (time < 60) {
765 s = time;
766
767 } else if (time > 60 && time < 3600) {
768 m = parseInt(time / 60);
769 s = parseInt(time % 60);
770
771 } else if (time >= 3600 && time < 86400) {
772 h = parseInt(time / 3600);
773 m = parseInt(time % 3600 / 60);
774 s = parseInt(time % 3600 % 60 % 60);
775
776 } else if (time >= 86400) {
777 d = parseInt(time / 86400);
778 h = parseInt(time % 86400 / 3600);
779 m = parseInt(time % 86400 % 3600 / 60)
780 s = parseInt(time % 86400 % 3600 % 60 % 60);
781
782 }
783 }
784
785 time = d+" - "+fix(h,2)+":"+fix(m,2)+":"+fix(s,2)+("(Days - hh:mm:ss)");
786 return time;
787 }
788
789function fix(num, length) {
790 return ('' + num).length < length ? ((new Array(length + 1)).join('0') + num).slice(-length) : '' + num;
791}
792
793