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.

330 lines
8.1 KiB

  1. <script language="JavaScript">
  2. //
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. //
  5. // validates user entry
  6. function GenValidatePage()
  7. {
  8. var objSharename=document.frmTask.txtShareName;
  9. var objSharepath=document.frmTask.txtSharePath;
  10. var strShareName=objSharename.value;
  11. var strSharePath=objSharepath.value;
  12. strShareName = LTrimtext(strShareName); // Removes all leading spaces.
  13. strShareName = RTrimtext(strShareName); // Removes all trailing spaces.
  14. objSharename.value = strShareName;
  15. strSharePath = LTrimtext(strSharePath); // Removes all leading spaces.
  16. strSharePath = RTrimtext(strSharePath); // Removes all trailing spaces.
  17. objSharepath.value = strSharePath;
  18. //
  19. // For SAK 2.2, since now we add client dynamically, AppleTalk is not clients[5] anymore
  20. //
  21. // Check whether Appletalk share is selected
  22. //var chkAppletalkStatus = document.frmTask.clients[5].checked;
  23. //if (chkAppletalkStatus == true)
  24. //{
  25. // if (strShareName.length > 27 )
  26. // {
  27. // DisplayErr('<%=Server.HTMLEncode(SA_EscapeQuotes(L_APPLETALKSHARENAMELIMIT_ERRORMESSAGE))%>');
  28. // objSharename.focus();
  29. // document.frmTask.onkeypress = ClearErr;
  30. // return false;
  31. // }
  32. //}
  33. var strPathLength = strSharePath.length;
  34. //if(strSharePath.indexOf("\\",strPathLength -1) > 0 )
  35. //{
  36. // DisplayErr('<%=Server.HTMLEncode(SA_EscapeQuotes(L_INVALIDPATH_ERRORMESSAGE))%>');
  37. // selectFocus(document.frmTask.txtSharePath);
  38. // document.frmTask.onkeypress = ClearErr;
  39. // return false;
  40. //}
  41. //Blank Sharename Validation
  42. if (Trim(strShareName)=="")
  43. {
  44. DisplayErr('<%=Server.HTMLEncode(SA_EscapeQuotes(L_ENTERNAME_ERRORMESSAGE))%>');
  45. objSharename.focus()
  46. document.frmTask.onkeypress = ClearErr
  47. return false;
  48. }
  49. // Check for '\' in the share name
  50. if(strShareName.indexOf("\\",1)>0)
  51. {
  52. DisplayErr('<%=Server.HTMLEncode(SA_EscapeQuotes(L_INVALIDNAME_ERRORMESSAGE))%>');
  53. objSharename.focus()
  54. document.frmTask.onkeypress = ClearErr;
  55. return false;
  56. }
  57. // Checks For Invalid Key Entry
  58. if(!(checkKeyforValidCharacters(strShareName)))
  59. {
  60. DisplayErr('<%=Server.HTMLEncode(SA_EscapeQuotes(L_INVALIDNAME_ERRORMESSAGE))%>');
  61. objSharename.focus()
  62. document.frmTask.onkeypress = ClearErr
  63. return false;
  64. }
  65. //Blank Sharepath Validation
  66. if (Trim(strSharePath)=="")
  67. {
  68. DisplayErr('<%=Server.HTMLEncode(SA_EscapeQuotes(L_INVALIDPATH_ERRORMESSAGE))%>');
  69. objSharepath.focus()
  70. document.frmTask.onkeypress = ClearErr
  71. return false;
  72. }
  73. // Sharepath Validation
  74. if(!isValidDirName(strSharePath))
  75. {
  76. DisplayErr('<%=Server.HTMLEncode(SA_EscapeQuotes(L_INVALIDPATH_ERRORMESSAGE))%>');
  77. objSharepath.focus();
  78. document.frmTask.onkeypress = ClearErr;
  79. return false;
  80. }
  81. if (strSharePath.length > 260)
  82. {
  83. DisplayErr('<%=Server.HTMLEncode(SA_EscapeQuotes(L_SHAREPATHMAXLIMIT_ERRORMESSAGE))%>');
  84. objSharepath.focus();
  85. document.frmTask.onkeypress = ClearErr;
  86. return false;
  87. }
  88. UpdateHiddenVaribles();
  89. if((document.frmTask.hidSharesChecked.value)=="")
  90. {
  91. DisplayErr('<%=Server.HTMLEncode(SA_EscapeQuotes(L_CHK_ERRORMESSAGE))%>');
  92. document.frmTask.onkeypress = ClearErr
  93. return false;
  94. }
  95. return true;
  96. }
  97. //To check for Invalid Characters
  98. function checkKeyforValidCharacters(strName)
  99. {
  100. alert();
  101. var nLength = strName.length;
  102. for(var i=0; i<nLength;i++)
  103. {
  104. charAtPos = strName.charCodeAt(i);
  105. 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 )
  106. {
  107. return false;
  108. }
  109. }
  110. return true;
  111. }
  112. //function which executes when form loads..
  113. function GenInit()
  114. {
  115. var strTmp
  116. var strFlag
  117. strFlag = document.frmTask.hidErrFlag.value
  118. strTmp = document.frmTask.hidSharesChecked.value
  119. document.frmTask.txtShareName.focus();
  120. document.frmTask.txtShareName.select();
  121. //makeDisable(document.frmTask.txtShareName);
  122. EnableCancel();
  123. // for clearing error message when serverside error occurs
  124. document.frmTask.onkeypress = ClearErr
  125. if (strFlag =="1")
  126. {
  127. document.frmTask.chkCreatePath.focus()
  128. document.frmTask.chkCreatePath.select()
  129. }
  130. //check whether any share types is checked
  131. var objChkShare = document.frmTask.clients;
  132. var blnChkStatus = false;
  133. for(var i=0; i< objChkShare.length;i++)
  134. {
  135. if(objChkShare[i].checked == true)
  136. blnChkStatus = true;
  137. }
  138. if (blnChkStatus == false)
  139. {
  140. document.frmTask.clients[0].checked = true;
  141. if(document.frmTask.clients[2].disabled == false)
  142. document.frmTask.clients[2].checked = true;
  143. }
  144. }
  145. // function to make the Ok button disable
  146. function makeDisable(objSharename)
  147. {
  148. var strSharename=objSharename.value;
  149. if (Trim(strSharename)== "")
  150. DisableOK();
  151. else
  152. EnableOK();
  153. }
  154. //Dummy function for Framework
  155. function GenSetData()
  156. {
  157. }
  158. //to UpdateHiddenVaribles
  159. function UpdateHiddenVaribles()
  160. {
  161. document.frmTask.hidSharename.value = document.frmTask.txtShareName.value;
  162. document.frmTask.hidSharePath.value = document.frmTask.txtSharePath.value;
  163. document.frmTask.hidCreatePathChecked.value = document.frmTask.chkCreatePath.checked;
  164. var strClients
  165. var objCheckBox
  166. strClients = ""
  167. for(var i=0; i < document.frmTask.clients.length; i++)
  168. {
  169. objCheckBox = eval(document.frmTask.clients[i])
  170. if (objCheckBox.checked)
  171. strClients = strClients + " " + objCheckBox.value
  172. }
  173. document.frmTask.hidSharesChecked.value = strClients
  174. }
  175. //function to validate the real directory path format
  176. function isValidDirName(dirPath)
  177. {
  178. reInvalid = /[\/\*\?\"<>\|]/;
  179. if (reInvalid.test(dirPath))
  180. return false;
  181. reColomn2 = /:{2,}/;
  182. reColomn1 = /:{1,}/;
  183. if ( reColomn2.test(dirPath) || ( dirPath.charAt(1) != ':' && reColomn1.test(dirPath) ))
  184. return false;
  185. reEndColomn = /: *$/;
  186. if (reEndColomn.test(dirPath))
  187. return false;
  188. reAllSpaces = /[^ ]/;
  189. if (!reAllSpaces.test(dirPath))
  190. return false;
  191. if (countChars(dirPath,":") != 1)
  192. return false;
  193. if (dirPath.charAt(2) != '\\')
  194. return false;
  195. reEndSlash2 = /\\{2,}/;
  196. if (reEndSlash2.test(dirPath))
  197. return false;
  198. return true;
  199. }
  200. // to count the number of occurences of given character in the text
  201. function countChars(strText,charToCount)
  202. {
  203. var searchFromPos = 0;
  204. var charFoundAt =0;
  205. var count = 0;
  206. while((charFoundAt=strText.indexOf(charToCount,searchFromPos)) >= 0)
  207. {
  208. count++;
  209. searchFromPos = charFoundAt + 1;
  210. }
  211. return count ;
  212. }
  213. //------------------------------------------------------------------------
  214. // Function :LTrimtext
  215. // Description :function to remove left trailing spaces
  216. // input :String
  217. // returns :String
  218. //------------------------------------------------------------------------
  219. function LTrimtext(str)
  220. {
  221. var res="", i, ch, index;
  222. x = str.length;
  223. index = "false";
  224. for (i=0; i < str.length; i++)
  225. {
  226. ch = str.charAt(i);
  227. if (index == "false")
  228. {
  229. if (ch != ' ')
  230. {
  231. index = "true";
  232. res = ch;
  233. }
  234. }
  235. else
  236. {
  237. res = res + ch;
  238. }
  239. }
  240. return res;
  241. }
  242. //------------------------------------------------------------------------
  243. // Function :RTrimtext
  244. // Description :function to remove right trailing spaces
  245. // input :String
  246. // returns :String
  247. //------------------------------------------------------------------------
  248. function RTrimtext(str)
  249. {
  250. var res="", i, ch, index, j, k;
  251. x = str.length;
  252. index = "false";
  253. if(x==0 || x==1)
  254. return str;
  255. for(i=x; i >= 0; i--)
  256. {
  257. ch = str.charAt(i);
  258. if (index == "false")
  259. {
  260. if( (ch == ' ') || (ch == '') )
  261. {
  262. continue;
  263. }
  264. else
  265. {
  266. index = "true";
  267. j = i;
  268. }
  269. }
  270. if (index == "true")
  271. {
  272. for(k=0; k<=j; k++)
  273. {
  274. res = res + str.charAt(k);
  275. }
  276. return res;
  277. }
  278. }
  279. }
  280. </script>