Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

697 lines
17 KiB

  1. <meta http-equiv="Content-Type" content="text/html; charset=<%=GetCharSet()%>">
  2. <script language=javascript>
  3. //------------------------------------------------------------------------
  4. //
  5. // inc_wsa.js: Resuable JavaScript functions
  6. // used accross all the pages
  7. //
  8. // Copyright (c) Microsoft Corporation. All rights reserved.
  9. //
  10. // Date Description
  11. // 18/09/2000 Created date
  12. //------------------------------------------------------------------------
  13. // Local variables
  14. var flag="false";
  15. //------------------------------------------------------------------------
  16. // Function to clear the error messages (if any on screen) whenever required
  17. //------------------------------------------------------------------------
  18. function ClearErr()
  19. {
  20. // checking for the browser type
  21. if (IsIE())
  22. {
  23. document.all("divErrMsg").innerHTML = "";
  24. // removing the event handling
  25. document.frmTask.onkeypress = null ;
  26. }
  27. }
  28. //------------------------------------------------------------------------
  29. // Function: To check if given input is INTEGER or not
  30. // input: Text value, text length
  31. // returns: True if the field is integer else false
  32. //------------------------------------------------------------------------
  33. function isInteger(strText)
  34. {
  35. var blnResult = true;
  36. var strChar;
  37. // checking for null string
  38. if (strText.length==0)
  39. {
  40. blnResult=false;
  41. }
  42. for(var i=0;i < strText.length;i++)
  43. {
  44. strChar=strText.substring(i,i+1);
  45. if(strChar < "0" || strChar > "9")
  46. {
  47. blnResult = false;
  48. }
  49. }
  50. return blnResult;
  51. }
  52. //------------------------------------------------------------------------
  53. // Function: To count the number of occurences of given character in the text
  54. // input: strText-sourceString
  55. // : charToCount-character to be checked
  56. // returns: The count of no of character
  57. //------------------------------------------------------------------------
  58. function countChars(strText,charToCount)
  59. {
  60. var intStartingPosition = 0;
  61. var intFoundPosition =0;
  62. var intCount = 0;
  63. // checking for the null character
  64. if (charToCount=="")
  65. {
  66. return intCount;
  67. }
  68. while((intFoundPosition=strText.indexOf(charToCount,intStartingPosition)) >= 0)
  69. {
  70. intCount++;
  71. intStartingPosition = intFoundPosition + 1;
  72. }
  73. return intCount ;
  74. }
  75. //------------------------------------------------------------------------
  76. // Function: Check to see if all characters in string are spaces
  77. // input: strText-sourceString
  78. // returns:
  79. // 0 - not all spaces
  80. // 1 - all spaces
  81. //------------------------------------------------------------------------
  82. function IsAllSpaces(strText)
  83. {
  84. var bIsAllSpaces;
  85. if (countChars(strText," ") == strText.length)
  86. {
  87. bIsAllSpaces = 1;
  88. }
  89. else
  90. {
  91. bIsAllSpaces = 0;
  92. }
  93. return bIsAllSpaces ;
  94. }
  95. //------------------------------------------------------------------------
  96. // Function: isValidIP
  97. // Description: to validate the IP address
  98. // input: IP address text object
  99. // returns:0 if it is valid
  100. // 1 Empty
  101. // 2 Invalid Format, number of dots is not 3
  102. // 3 non-integers present in the value
  103. // 4 start ip > 223
  104. // 5 Should not start with 127
  105. // 6 out of bound
  106. // 7 All zeros
  107. // 8 Should not be 0
  108. // support functions:
  109. // IsAllSpaces
  110. // countChars
  111. // isInteger
  112. //------------------------------------------------------------------------
  113. function isValidIP(objIP)
  114. {
  115. var strIPtext = objIP.value;
  116. if ((strIPtext.length == 0) || IsAllSpaces(strIPtext))
  117. {
  118. // IP Empty
  119. return 1;
  120. }
  121. if ( countChars(strIPtext,".") != 3)
  122. {
  123. // Invalid Format, number of dots is not 3
  124. return 2;
  125. }
  126. var arrIP = strIPtext.split(".");
  127. for(var i = 0; i < 4; i++)
  128. {
  129. if ( (arrIP[i].length < 1 ) || (arrIP[i].length > 3 ) )
  130. {
  131. // Invalid Format, continuous dots or more than 3 digits given between dots
  132. return 2;
  133. }
  134. if ( !isInteger(arrIP[i]) )
  135. {
  136. // non-integers present in the value
  137. return 3;
  138. }
  139. arrIP[i] = parseInt(arrIP[i]);
  140. if(i == 0)
  141. {
  142. // start IP value
  143. if(arrIP[i] == 0)
  144. {
  145. // start IP value must not be 0
  146. return 8;
  147. }
  148. if(arrIP[i] > 223)
  149. {
  150. // start IP must not be > 223
  151. return 4;
  152. }
  153. if(arrIP[i] == 127)
  154. {
  155. // start IP must not be 127 - Loopback ip
  156. return 5;
  157. }
  158. }
  159. else
  160. {
  161. // the 2nd, 3rd and 4th IP values between the dots
  162. // these must not be more than 255
  163. if (arrIP[i] > 255)
  164. {
  165. // IP out of bound
  166. return 6;
  167. }
  168. }
  169. }
  170. objIP.value = arrIP.join(".");
  171. if(objIP.value == "0.0.0.0")
  172. {
  173. // IP all zeros
  174. return 7;
  175. }
  176. return 0;
  177. } // end of isValidIP
  178. //------------------------------------------------------------------------
  179. // Function :checkkeyforIPAddress
  180. // Description :function to allow only dots and numbers
  181. // input :Object -TextBox Object
  182. // returns :none
  183. //------------------------------------------------------------------------
  184. function checkKeyforIPAddress(obj)
  185. {
  186. // Clear any previous error messages
  187. ClearErr();
  188. if (!(window.event.keyCode >=48 && window.event.keyCode <=57 || window.event.keyCode == 46))
  189. {
  190. window.event.keyCode = 0;
  191. obj.focus();
  192. }
  193. }
  194. //------------------------------------------------------------------------
  195. // Function :checkkeyforNumbers
  196. // Description :function to allow only numbers
  197. // input :Object -TextBox Object
  198. // returns :none
  199. //------------------------------------------------------------------------
  200. function checkKeyforNumbers(obj)
  201. {
  202. // Clear any previous error messages
  203. ClearErr();
  204. if(window.event.keyCode == 13 || window.event.keyCode == 27)
  205. return;
  206. if (!(window.event.keyCode >=48 && window.event.keyCode <=57 ))
  207. {
  208. window.event.keyCode = 0;
  209. obj.focus();
  210. }
  211. }
  212. //------------------------------------------------------------------------
  213. // Function :checkKeyforNumbersDecimal
  214. // Description :function to allow only numbers
  215. // input :Object -TextBox Object
  216. // returns :none
  217. //------------------------------------------------------------------------
  218. function checkKeyforNumbersDecimal(obj)
  219. {
  220. // Clear any previous error messages
  221. ClearErr();
  222. if(window.event.keyCode == 13 || window.event.keyCode == 27)
  223. return;
  224. if (!((window.event.keyCode >=48 && window.event.keyCode <=57)))
  225. {
  226. window.event.keyCode = 0;
  227. obj.focus();
  228. }
  229. }
  230. //------------------------------------------------------------------------
  231. // Function :checkKeyforCharacters
  232. // Description :function to allow only numbers
  233. // input :Object -TextBox Object
  234. // returns :none
  235. //------------------------------------------------------------------------
  236. function checkKeyforCharacters(obj)
  237. {
  238. // Clear any previous error messages
  239. ClearErr();
  240. if (!((window.event.keyCode >=65 && window.event.keyCode <=92)||
  241. (window.event.keyCode >=97 && window.event.keyCode <=123)||
  242. (window.event.keyCode >=48 && window.event.keyCode <=57)||
  243. (window.event.keyCode == 45)||
  244. (window.event.keyCode == 95)))
  245. {
  246. window.event.keyCode = 0;
  247. obj.focus();
  248. }
  249. }
  250. //------------------------------------------------------------------------
  251. // Function :headerscheckKeyforCharacters
  252. // Description :function to allow only numbers
  253. // input :Object -TextBox Object
  254. // returns :none
  255. //------------------------------------------------------------------------
  256. function headerscheckKeyforCharacters(obj)
  257. {
  258. ClearErr();
  259. if(window.event.keyCode == 59 || window.event.keyCode ==47 ||
  260. window.event.keyCode == 63 || window.event.keyCode == 58 ||
  261. window.event.keyCode==64 || window.event.keyCode == 38 ||
  262. window.event.keyCode == 61 || window.event.keyCode == 36 ||
  263. window.event.keyCode == 43 ||window.event.keyCode == 44)
  264. {
  265. window.event.keyCode = 0;
  266. obj.focus();
  267. }
  268. }
  269. //------------------------------------------------------------------------
  270. // Function :isvalidchar
  271. // Description :Function to check whether the input is valid or not
  272. // input :Invalid char list
  273. // The input string
  274. // returns :true if it doesnt contain the invalid chars; else false
  275. //------------------------------------------------------------------------
  276. // Checks For Invalid Key Entry
  277. function isvalidchar(strInvalidChars,strInput)
  278. {
  279. var reInvalid = eval(strInvalidChars);
  280. if(reInvalid.test(strInput))
  281. {
  282. return false;
  283. }
  284. else
  285. {
  286. return true;
  287. }
  288. }
  289. //------------------------------------------------------------------------
  290. // Function :checkkeyforNumbers
  291. // Description :Function to check only numbers
  292. // ------------------------------------------------------------------------
  293. function checkkeyforNumbers(obj)
  294. {
  295. ClearErr();
  296. if(window.event.keyCode == 13 || window.event.keyCode == 27)
  297. return;
  298. if (!(window.event.keyCode >=48 && window.event.keyCode <=57))
  299. {
  300. window.event.keyCode = 0;
  301. obj.focus();
  302. }
  303. }
  304. //------------------------------------------------------------------------
  305. // Function :checkfordefPortValue
  306. // Description :Function to set the default port value
  307. // -----------------------------------------------------------------------
  308. function checkfordefPortValue(obj)
  309. {
  310. var portValue = obj.value;
  311. if (portValue == "")
  312. obj.value = 80;
  313. }
  314. //------------------------------------------------------------------------
  315. // Function :checkUserLimit
  316. // Description :Function to check the limit entered
  317. // ------------------------------------------------------------------------
  318. function checkUserLimit(obj,str)
  319. {
  320. var intNoofUsers=obj.value;
  321. if(str=="siteid")
  322. {
  323. if (intNoofUsers > 999)
  324. {
  325. obj.value="";
  326. obj.focus();
  327. }
  328. }
  329. // Check whether port value greater than 65535
  330. else if(str=="port")
  331. {
  332. if (intNoofUsers > 65535)
  333. {
  334. obj.value=80;
  335. obj.focus();
  336. }
  337. }
  338. // Check whether no of connections greater than 2000000000
  339. if(str=="con")
  340. {
  341. if (intNoofUsers > 2000000000)
  342. {
  343. obj.value="";
  344. obj.focus();
  345. }
  346. }
  347. // Check whether filesize greater than 4000 in Weblog and FTPlog settings
  348. if(str=="filesize")
  349. {
  350. if (intNoofUsers > 4000)
  351. {
  352. obj.value="";
  353. obj.focus();
  354. }
  355. }
  356. // Check for script timeout
  357. if(str=="scripttimeout")
  358. {
  359. if (intNoofUsers > 2147483647)
  360. {
  361. obj.value="1";
  362. obj.focus();
  363. }
  364. }
  365. // Check for maximum ftp connections
  366. if(str=="conftp")
  367. {
  368. if (intNoofUsers > 4294967295)
  369. {
  370. obj.value="";
  371. obj.focus();
  372. }
  373. }
  374. // Check for connection timeout
  375. if(str=="contimeout")
  376. {
  377. if (intNoofUsers > 2000000)
  378. {
  379. obj.value="";
  380. obj.focus();
  381. }
  382. }
  383. } // End of the function
  384. //------------------------------------------------------------------------------------
  385. // Function :GenerateAdmin
  386. // Description :Function to generate directory path concatenated with site identifier
  387. // -----------------------------------------------------------------------------------
  388. function GenerateAdmin()
  389. {
  390. var strID = document.frmTask.txtSiteID.value;
  391. strID = LTrimtext(strID); // Removes all leading spaces.
  392. strID = RTrimtext(strID); // Removes all trailing spaces.
  393. document.frmTask.txtSiteID.value = strID;
  394. if(strID.length > 0)
  395. {
  396. document.frmTask.txtSiteAdmin.value = strID + "_Admin";
  397. document.frmTask.txtDir.value = document.frmTask.hdnWebRootDir.value + "\\" + strID;
  398. }
  399. else
  400. {
  401. document.frmTask.txtSiteAdmin.value = "";
  402. document.frmTask.txtDir.value = "";
  403. }
  404. }
  405. //------------------------------------------------------------------------
  406. // Function :checkKeyforSpecialCharacters
  407. // Description :function to allow Characters
  408. // input :Object -TextBox Object
  409. // returns :none
  410. //------------------------------------------------------------------------
  411. function checkKeyforSpecialCharacters(obj)
  412. {
  413. // Clear any previous error messages
  414. ClearErr();
  415. if (window.event.keyCode == 47 || window.event.keyCode == 42 || window.event.keyCode == 63 || window.event.keyCode == 34 || window.event.keyCode == 60 || window.event.keyCode == 62 || window.event.keyCode == 124)
  416. {
  417. window.event.keyCode = 0;
  418. obj.focus();
  419. }
  420. }
  421. //------------------------------------------------------------------------
  422. // Function :IsAllDots
  423. // Description :function to check for dots
  424. // input :String
  425. // returns :Boolean
  426. //------------------------------------------------------------------------
  427. function IsAllDots(strText)
  428. {
  429. var bIsAllSpaces;
  430. if (countChars(strText,".") == strText.length)
  431. {
  432. bIsAllSpaces = 1;
  433. }
  434. else
  435. {
  436. bIsAllSpaces = 0;
  437. }
  438. return bIsAllSpaces ;
  439. }
  440. //------------------------------------------------------------------------
  441. // Function :LTrimtext
  442. // Description :function to remove left trailing spaces
  443. // input :String
  444. // returns :String
  445. //------------------------------------------------------------------------
  446. function LTrimtext(str)
  447. {
  448. var res="", i, ch, index;
  449. x = str.length;
  450. index = "false";
  451. for (i=0; i < str.length; i++)
  452. {
  453. ch = str.charAt(i);
  454. if (index == "false")
  455. {
  456. if (ch != ' ')
  457. {
  458. index = "true";
  459. res = ch;
  460. }
  461. }
  462. else
  463. {
  464. res = res + ch;
  465. }
  466. }
  467. return res;
  468. }
  469. //------------------------------------------------------------------------
  470. // Function :RTrimtext
  471. // Description :function to remove right trailing spaces
  472. // input :String
  473. // returns :String
  474. //------------------------------------------------------------------------
  475. function RTrimtext(str)
  476. {
  477. var res="", i, ch, index, j, k;
  478. x = str.length;
  479. index = "false";
  480. if(x==0 || x==1)
  481. return str;
  482. for(i=x; i >= 0; i--)
  483. {
  484. ch = str.charAt(i);
  485. if (index == "false")
  486. {
  487. if( (ch == ' ') || (ch == '') )
  488. {
  489. continue;
  490. }
  491. else
  492. {
  493. index = "true";
  494. j = i;
  495. }
  496. }
  497. if (index == "true")
  498. {
  499. for(k=0; k<=j; k++)
  500. {
  501. res = res + str.charAt(k);
  502. }
  503. return res;
  504. }
  505. }
  506. }
  507. //------------------------------------------------------------------------
  508. // Function :charCount
  509. // Description :Function returns length of string
  510. // input :String
  511. // returns :Integer
  512. //------------------------------------------------------------------------
  513. function charCount(strID)
  514. {
  515. var Len = strID.length;
  516. Len--;
  517. while (Len > 0)
  518. {
  519. var x = strID.charCodeAt(Len);
  520. if(x!= 32)
  521. {
  522. return Len;
  523. }
  524. Len--;
  525. }
  526. }
  527. //Check whether enterKey is pressed
  528. function GenerateDir()
  529. {
  530. var strID = document.frmTask.txtSiteID.value;
  531. var Keyc = window.event.keyCode;
  532. if (Keyc == 13)
  533. {
  534. if(document.frmTask.txtSiteID.value=="")
  535. {
  536. DisplayErr("<%=Server.HTMLEncode(L_ID_NOTEMPTY_ERROR_MESSAGE)%>");
  537. document.frmTask.txtSiteID.focus();
  538. return false;
  539. }
  540. else
  541. {
  542. GenerateAdmin();
  543. return true;
  544. }
  545. }
  546. }
  547. function checkKeyforValidCharacters(strID,identifier)
  548. {
  549. var i;
  550. var colonvalue;
  551. var charAtPos;
  552. var len = strID.length;
  553. if(len > 0)
  554. {
  555. colonvalue = 0;
  556. for(i=0; i < len;i++)
  557. {
  558. charAtPos = strID.charCodeAt(i);
  559. if (identifier == "id")
  560. {
  561. if(charAtPos ==47 || charAtPos == 92 || charAtPos ==58 || charAtPos == 42 || charAtPos == 63 || charAtPos == 34 || charAtPos == 60 || charAtPos == 62 || charAtPos == 124 || charAtPos == 91 || charAtPos == 93 || charAtPos == 59 || charAtPos == 43 || charAtPos == 61 || charAtPos == 44)
  562. {
  563. DisplayErr("<%= Server.HTMLEncode(L_SITE_IDENTIFIER_EMPTY_TEXT) %>");
  564. //document.frmTask.txtSiteID.value = "";
  565. document.frmTask.txtSiteID.focus();
  566. return false;
  567. }
  568. }
  569. if(identifier == "dir")
  570. {
  571. if(charAtPos ==58)
  572. {
  573. colonvalue = colonvalue + 1;
  574. if (colonvalue > 1)
  575. {
  576. DisplayErr("<%= Server.HTMLEncode(L_INVALID_DIR_ERRORMESSAGE) %>");
  577. document.frmTask.txtDir.value = strID;
  578. document.frmTask.txtDir.focus();
  579. return false;
  580. }
  581. }
  582. if(charAtPos ==47 || charAtPos == 42 || charAtPos == 63 || charAtPos == 34 || charAtPos == 60 || charAtPos == 62 || charAtPos == 124 || charAtPos == 91 || charAtPos == 93 || charAtPos == 59 || charAtPos == 43 || charAtPos == 61 || charAtPos == 44)
  583. {
  584. DisplayErr("<%= Server.HTMLEncode(L_INVALID_DIR_ERRORMESSAGE)%>");
  585. document.frmTask.txtDir.value = strID;
  586. document.frmTask.txtDir.focus();
  587. return false;
  588. }
  589. }
  590. }
  591. return true;
  592. }
  593. }
  594. </script>