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.

594 lines
16 KiB

  1. <SCRIPT Language=JavaScript>
  2. //========================================================================
  3. // Module: shares_nfsprop.js
  4. //
  5. // Synopsis: Manage NFS Share Permissions
  6. //
  7. // Copyright (c) Microsoft Corporation. All rights reserved.
  8. //========================================================================
  9. var blnFlag;
  10. var arrStrRights = new Array(5);
  11. var arrStrValues = new Array(5);
  12. arrStrRights[0] = "<%=L_NOACESS_TEXT%>";
  13. arrStrRights[1] = "<%=L_READONLY_TEXT%>";
  14. arrStrRights[2] = "<%=L_READWRITE_TEXT%>";
  15. arrStrRights[3] = "<%=L_READONLY_TEXT%>"+" + "+"<%=L_ROOT_TEXT%>";
  16. arrStrRights[4] = "<%=L_READWRITE_TEXT%>"+" + "+"<%=L_ROOT_TEXT%>";
  17. arrStrValues[0] = "1,17";
  18. arrStrValues[1] = "2,18";
  19. arrStrValues[2] = "4,19";
  20. arrStrValues[3] = "10,20";
  21. arrStrValues[4] = "12,21";
  22. var memberArr = new Array(); // Used to store all Members
  23. var groupArr = new Array(); // Used to store all Groups
  24. var tempArr = new Array(); // Used for temporay swapings
  25. function NFSInit()
  26. { document.frmTask.onkeydown = ClearErr;
  27. //checking for the length of the Permissions ListBox if empty make Remove button disable
  28. if (document.frmTask.lstPermissions.length!=0)
  29. {
  30. //making the first element selected
  31. document.frmTask.lstPermissions.options[0].selected=true;
  32. //Function call to select the particular right selected in the list item
  33. selectAccess( document.frmTask.lstPermissions,document.frmTask.cboRights )
  34. }
  35. document.frmTask.btnRemove.disabled=true;
  36. clgrps_Init();
  37. }
  38. function OnSelectClientGroup()
  39. {
  40. document.frmTask.lstPermissions.selectedIndex = -1;
  41. selectReadOnly();
  42. selectAccess( document.frmTask.lstPermissions,document.frmTask.cboRights );
  43. document.frmTask.cboRights.selectedIndex = 0;
  44. }
  45. function OnSelectNameInput()
  46. {
  47. Deselect();
  48. selectReadOnly();
  49. selectAccess( document.frmTask.lstPermissions,document.frmTask.cboRights );
  50. }
  51. // function to select the read write every time
  52. function selectReadOnly()
  53. {
  54. // making the readwrite selected every time
  55. for ( var i=0; i<document.frmTask.cboRights.length ;i++)
  56. {
  57. if (document.frmTask.cboRights.options[i].text == "<%=L_READONLY_TEXT%>")
  58. {
  59. document.frmTask.cboRights.options[i].selected=true;
  60. return;
  61. }
  62. }
  63. }
  64. // function to retrive Groups form "hidGroups" to groupArr
  65. function clgrps_Init()
  66. {
  67. var strGroups;
  68. var groupArr;
  69. if(document.frmTask.hidGroups.value != "")
  70. {
  71. strGroups = document.frmTask.hidGroups.value;
  72. groupArr = strGroups.split("]");
  73. if (groupArr.length == 0)
  74. {
  75. document.frmTask.btnAdd.disabled = false;
  76. document.frmTask.btnRemove.disabled = true;
  77. return false;
  78. }
  79. document.frmTask.scrollCliGrp.selectedIndex=-1;
  80. clgrps_onChange(document.frmTask.scrollCliGrp.selectedIndex);
  81. return true
  82. }
  83. else
  84. {
  85. document.frmTask.btnAdd.disabled = false;
  86. }
  87. }
  88. //Function to Disable Button
  89. function DisableBtn()
  90. {
  91. // No functionality for this function
  92. }
  93. //Function to deselect
  94. function Deselect()
  95. {
  96. document.frmTask.lstPermissions.selectedIndex = -1;
  97. document.frmTask.scrollCliGrp.selectedIndex = -1;
  98. }
  99. function DeselectPerm(objLst)
  100. {
  101. document.frmTask.objLst.selectedIndex = -1;
  102. }
  103. //To disable Enter and escape key actions when the focus is in TextArea...Hosts file
  104. function HandleKey(input)
  105. {
  106. if(input == "DISABLE")
  107. document.onkeypress = "";
  108. else
  109. document.onkeypress = HandleKeyPress;
  110. }
  111. //Function to get the list of computers & permission in the permission list box
  112. function NFSSetData()
  113. {
  114. var intEnd=document.frmTask.lstPermissions.length;
  115. var strSelectedusers;
  116. strSelectedusers = "";
  117. //Going through the list of permissions and pack up in a string
  118. for ( var i=0; i < intEnd;i++)
  119. {
  120. if (i==0)
  121. strSelectedusers=document.frmTask.lstPermissions.options[i].value + ";" ;
  122. else
  123. strSelectedusers+=document.frmTask.lstPermissions.options[i].value + ";";
  124. }
  125. document.frmTask.hidUserNames.value=strSelectedusers;
  126. // Updating the check box variables for EUCJP
  127. if (document.frmTask.chkEUCJP.checked)
  128. document.frmTask.hidEUCJP.value="CHECKED";
  129. else
  130. document.frmTask.hidEUCJP.value="";
  131. // Update Allow Anon Access
  132. if (document.frmTask.chkAllowAnnon.checked)
  133. document.frmTask.hidchkAllowAnnon.value="NO";
  134. else
  135. document.frmTask.hidchkAllowAnnon.value="";
  136. }
  137. //To check for Invalid Characters
  138. function checkKeyforValidCharacters(strName)
  139. {
  140. var nLength = strName.length;
  141. for(var i=0; i<nLength;i++)
  142. {
  143. charAtPos = strName.charCodeAt(i);
  144. 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 )
  145. {
  146. return false;
  147. }
  148. }
  149. return true;
  150. }
  151. //Function to submit the form
  152. function getUsernames(objText,objListBox)
  153. {
  154. var strUser;
  155. strUserName=Trim(objText.value);
  156. if(document.frmTask.scrollCliGrp.selectedIndex != -1)
  157. {
  158. strUserName= document.frmTask.scrollCliGrp.options[document.frmTask.scrollCliGrp.selectedIndex].value;
  159. var myString = new String(strUserName)
  160. splitString = myString.split(",")
  161. Text=splitString[0]+addSpaces(24-splitString[0].length)+document.frmTask.cboRights.options[document.frmTask.cboRights.selectedIndex].text
  162. value="N"+","+strUserName+",0,"+document.frmTask.cboRights.options[document.frmTask.cboRights.selectedIndex].value
  163. addToListBox(document.frmTask.lstPermissions,"",Text,value);
  164. document.frmTask.btnRemove.disabled = false;
  165. }
  166. else
  167. {
  168. if(strUserName == "")
  169. return;
  170. intErrorNumber = isValidIP(objText)
  171. if(isValidIP(objText)==0)
  172. {
  173. Text=strUserName+addSpaces(24-strUserName.length)+document.frmTask.cboRights.options[document.frmTask.cboRights.selectedIndex].text
  174. value="N"+","+strUserName+",0,"+document.frmTask.cboRights.options[document.frmTask.cboRights.selectedIndex].value
  175. addToListBox(document.frmTask.lstPermissions,"",Text,value)
  176. strUserName=""
  177. document.frmTask.btnRemove.disabled = false;
  178. }
  179. else
  180. {
  181. if(!checkKeyforValidCharacters(strUserName))
  182. {
  183. DisplayErr('<%=Server.HTMLEncode(SA_EscapeQuotes(L_INVALID_COMPUTERNAME_ERRORMESSAGE))%>');
  184. objText.focus()
  185. objText.select()
  186. document.frmTask.onkeypress = ClearErr
  187. return false;
  188. }
  189. else
  190. { Text=strUserName+addSpaces(24-strUserName.length)+document.frmTask.cboRights.options[document.frmTask.cboRights.selectedIndex].text
  191. // SFU
  192. value="N"+","+strUserName+",0,"+document.frmTask.cboRights.options[document.frmTask.cboRights.selectedIndex].value
  193. addToListBox(document.frmTask.lstPermissions,"",Text,value)
  194. strUserName=""
  195. }
  196. document.frmTask.btnRemove.disabled = false;
  197. }
  198. document.frmTask.txtCommName.value=""
  199. }
  200. if (checkDuplicate(objListBox,strUserName))
  201. {
  202. tmp = strUserName.replace("<","&lt;")
  203. tmp = tmp.replace(">","&gt;")
  204. DisplayErr(tmp + " "+"<%=Server.HTMLEncode(SA_EscapeQuotes(L_DUPLICATE_ERRORMESSAGE))%>" );
  205. return;
  206. }
  207. //Changing the status of the value to TRUE
  208. document.frmTask.hidAddBtn.value = "TRUE" ;
  209. //Calling setData to pack up the values
  210. NFSSetData();
  211. //Submit's the Form
  212. //document.frmTask.submit();
  213. }
  214. //function to check the duplicate values in text box
  215. function chkDuplicate(arrNames)
  216. {
  217. var i,j
  218. for( i=0;i<arrNames.length;i++)
  219. {
  220. for(j=0; j<arrNames.length;j++)
  221. {
  222. if (arrNames[i]==arrNames[j] && i!=j )
  223. return false;
  224. }
  225. }
  226. return true;
  227. }
  228. function NFSValidatePermissionSelections()
  229. {
  230. var oPermissions = document.getElementById("lstPermissions");
  231. if ( null != oPermissions)
  232. {
  233. //
  234. // If ALL-MACHINES is the only Permission
  235. if ( oPermissions.length <= 1 )
  236. {
  237. var aPermissionValues = oPermissions.options.value.split(",");
  238. //alert(aPermissionValues);
  239. if ( aPermissionValues.length > 4 )
  240. {
  241. //
  242. // ALL-MACHINES with No-Access (1) is an invalid combination.
  243. if ( parseInt(aPermissionValues[3]) == 1 )
  244. {
  245. DisplayErr("<%=Server.HTMLEncode(SA_EscapeQuotes(L_CANNOTCREATE_EMPTY_SHARE__ERRORMESSAGE))%>");
  246. return false;
  247. }
  248. }
  249. else
  250. {
  251. alert("PANIC#1: Permissions array size invalid: " + aPermissionValues.length);
  252. }
  253. }
  254. else
  255. {
  256. //
  257. // Verify that ALL-MACHINES permission is lower than any of the permissions specified for
  258. // the clients and/or groups.
  259. var aPermissionValues = oPermissions.options[0].value.split(",");
  260. //alert(aPermissionValues);
  261. if ( aPermissionValues.length > 4 )
  262. {
  263. var allMachinesAccess = parseInt(aPermissionValues[3]);
  264. var x;
  265. for(x=1; x<oPermissions.length; ++x)
  266. {
  267. aPermissionValues = oPermissions.options[x].value.split(",");
  268. if ( aPermissionValues.length > 4 )
  269. {
  270. //alert(aPermissionValues.length);
  271. var permissionIndex = (aPermissionValues.length > 5)? 4:3;
  272. if ( allMachinesAccess >= parseInt(aPermissionValues[permissionIndex]))
  273. {
  274. //alert("allMachinesAccess >= aPermissionValues[3] " + allMachinesAccess + ">=" + aPermissionValues[permissionIndex])
  275. //DisplayErr(Server.HTMLEncode(SA_EscapeQuotes(L_ERROR_ALL_MACHINES_MUST_BE_LOWER_THAN))" + oPermissions.options[x].text);
  276. //alert("ALL-MACHINES: " + oPermissions.options[0].value + "\n" + "Current: " + aPermissionValues);
  277. //return false;
  278. }
  279. }
  280. else
  281. {
  282. alert("PANIC#2: Permissions array size invalid: " + aPermissionValues.length);
  283. }
  284. }
  285. }
  286. else
  287. {
  288. alert("PANIC#3: Permissions array size invalid: " + aPermissionValues.length);
  289. }
  290. }
  291. }
  292. return true;
  293. }
  294. // validates user entry
  295. function NFSValidatePage()
  296. {
  297. if ( !NFSValidatePermissionSelections())
  298. {
  299. return false;
  300. }
  301. NFSSetData();
  302. return true;
  303. }
  304. //Function to check the dulicates in the list box
  305. function checkDuplicate(objListBox,strUserName)
  306. {
  307. //checking for the items in the list box
  308. for(var i=0; i<objListBox.length-1;i++)
  309. {
  310. var myString = new String(objListBox.options[i].value)
  311. var strTemp=myString.split(",");
  312. test=strTemp[1].toUpperCase()
  313. test1=strUserName.toUpperCase()
  314. if(strTemp[1].toUpperCase()==strUserName.toUpperCase())
  315. return true;
  316. }
  317. return false;
  318. }
  319. //function to change the rights of the selected user
  320. function changeRights()
  321. {
  322. var strUserName,strCompuId,strClient;
  323. //Getting the selected values
  324. var strNewAccessType=document.frmTask.cboRights.value;
  325. if (document.frmTask.lstPermissions.selectedIndex != -1)
  326. {
  327. var strPermString=document.frmTask.lstPermissions.options.value;
  328. var myString = new String(strPermString)
  329. //Separating the username and accessright
  330. var strTemp= myString.split(",")
  331. //Assigning the username
  332. strClient=strTemp[0];
  333. //Assigning the username
  334. strUserName=strTemp[1];
  335. //Assigning the username
  336. strCompuId=strTemp[2];
  337. //ReAssigning the same to the list box
  338. document.frmTask.lstPermissions.options[document.frmTask.lstPermissions.selectedIndex].value=strClient+","+strUserName+","+strCompuId+","+strNewAccessType;
  339. document.frmTask.lstPermissions.options[document.frmTask.lstPermissions.selectedIndex].text=strUserName+addSpaces(24-strUserName.length)+document.frmTask.cboRights.options[document.frmTask.cboRights.selectedIndex].text;
  340. }
  341. }
  342. //Function to add given number of spaces to the string
  343. function addSpaces(intNumber)
  344. {
  345. var str,intIdx;
  346. str ="";
  347. for (intIdx = 0 ; intIdx < intNumber;intIdx++)
  348. {
  349. str = str +" ";
  350. }
  351. return str;
  352. }
  353. //function to make enable/disable Addbutton
  354. function disableAdd(objText,objButton)
  355. {
  356. var strValue=objText.value;
  357. //Checking for null value
  358. if( Trim(strValue)=="")
  359. objButton.disabled=true;
  360. else
  361. objButton.disabled=false;
  362. }
  363. //Removes the selected item from the list box.
  364. function fnbRemove(arg_Lst,arg_Str)
  365. {
  366. var lidx = 0;
  367. var intEnd = arg_Lst.length;
  368. //getting the Remove button object
  369. var ObjRemove = eval('document.frmTask.btnRemove');
  370. //getting the access Permissions object
  371. var ObjAccess = eval('document.frmTask.cboRights');
  372. if ((intEnd ==1) && (arg_Lst.options[0].selected))
  373. {
  374. ObjRemove.disabled = true;
  375. return ;
  376. }
  377. for (lidx =0;lidx < arg_Lst.length;lidx++)
  378. {
  379. if ( arg_Lst.options[lidx].selected )
  380. {
  381. arg_Lst.options[lidx]=null;
  382. if (lidx == arg_Lst.length)
  383. arg_Lst.options[lidx-1].selected = true;
  384. else
  385. arg_Lst.options[lidx].selected = true;
  386. // checking for the default all machines if so disable the remove button
  387. if (arg_Lst.length==1)
  388. {
  389. // disabling the remove button
  390. ObjRemove.disabled=true;
  391. //Call to load the correct Access rights
  392. selectAccess(arg_Lst,ObjAccess)
  393. }
  394. break;
  395. }
  396. }
  397. }
  398. //Function to make select the same access as the user selectd in the permission ListBox
  399. function selectAccess(objListBox,objComboBox)
  400. {
  401. var i;
  402. var currentlySelectedAccess = objComboBox.selectedIndex;
  403. //
  404. // Clear AccessType's list
  405. while(objComboBox.length)
  406. {
  407. objComboBox.options[0] = null;
  408. }
  409. //
  410. // If ALL_MACHINES is selected
  411. //
  412. if (objListBox.selectedIndex == 0)
  413. {
  414. var x, y, z;
  415. //
  416. // If ALL-MACHINES is the only item in the list then we DO NOT include [No Access] because
  417. // creating a share with only one access group (ALL MACHINES) with permission of [No Access]
  418. // is nonsense. If they only have ALL-MACHINES in the list then they need to pick a valid
  419. // access right.
  420. //
  421. // Otherwise, if there are other clients and/or groups, then we allow ALL-MACHINES to be set
  422. // to [No Access].
  423. x = 0;
  424. y = ((objListBox.length > 1)? 0:1);
  425. z = ((objListBox.length > 1)? 5:4);
  426. for (x=0; x<z; x++, y++)
  427. {
  428. objComboBox.options[x] = new Option(arrStrRights[y],arrStrValues[y],false,false);
  429. }
  430. blnFlag = true;
  431. }
  432. else
  433. {
  434. //if (blnFlag == true)
  435. //{
  436. for (i=1; i<5;i++)
  437. {
  438. objComboBox.options[i-1] = new Option(arrStrRights[i],arrStrValues[i],false,false);
  439. }
  440. blnFlag = false;
  441. //}
  442. }
  443. var strValue=objListBox.options.value;
  444. var arrTemp
  445. var myString = new String(objListBox.options.value)
  446. arrTemp = myString.split(",")
  447. //checking for null and making the one selected as perm list menber
  448. if (arrTemp[3]!="")
  449. {
  450. for(var i=0;i<objComboBox.length;i++)
  451. {
  452. var myString1 = new String(objComboBox.options[i].value)
  453. var strTemp= myString1.split(",");
  454. if( parseInt(strTemp[0])==arrTemp[3] || strTemp[1]==arrTemp[3] )//Checking for the match
  455. {
  456. objComboBox.options[i].selected=true;
  457. return;
  458. }// end of if
  459. }// end of for i
  460. }//if (arrTemp[1]!="")
  461. }// end of function
  462. //Function to clear the error messages
  463. function ClearErr()
  464. {
  465. if (IsIE())
  466. {
  467. document.getElementById("divErrMsg").innerHTML = "";
  468. document.frmTask.onkeypress = null;
  469. }
  470. }
  471. // function to handle the change event of client groups listbox
  472. function clgrps_onChange(idScroll)
  473. {
  474. var strGroups;
  475. var groupArr;
  476. if(document.frmTask.hidGroups.value !="")
  477. {
  478. strGroups = new String(document.frmTask.hidGroups.value)
  479. groupArr=strGroups.split("]");
  480. if (groupArr.length == 0)
  481. {
  482. document.frmTask.btnAdd.disabled = true
  483. }
  484. else
  485. {
  486. document.frmTask.btnAdd.disabled = false
  487. }
  488. }
  489. return true;
  490. }
  491. </SCRIPT>