home *** CD-ROM | disk | FTP | other *** search
/ PC User 2004 November / PCU1104CD1.iso / software / security / files / norton.exe / Setup / ISCommon / APP / LocWiz.dll / HTML / LOCATION-WIZ.JS < prev    next >
Encoding:
JavaScript  |  2003-09-06  |  15.3 KB  |  566 lines

  1. ////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // PRODUCT: Norton Internet Security/Symantec Desktop Firewall
  4. //
  5. // NAME:    Location-Wiz.js (Javascript file for Location-Wiz.htm)
  6. //
  7. // Copyright (c) 2003 by Symantec Corporation. All rights reserved.
  8. //
  9. ////////////////////////////////////////////////////////////////////////////////////////////
  10.  
  11. var IE4 = document.all;
  12.  
  13. var g_SelectedLocationName = "";
  14. var g_bLaunchedFromAlert = true;
  15.  
  16. var g_numberTrusted = 0;
  17. var g_numberTrustable = 0;
  18. var g_iLocationList;
  19.  
  20. ///////////////////////////////////////////////////////
  21. /////////new alert params /////////////////////////////
  22. ///////////////////////////////////////////////////////
  23. //icon:
  24. // 0 = no icon
  25. // 1 = error
  26. // 2 = question
  27. // 3 = alert
  28. // 4 = info
  29. //
  30. //buts:
  31. // 0 = ok
  32. // 1 = ok, cancel
  33. // 2 = abort, retry, cancel
  34. // 3 = yes, no, cancel
  35. // 4 = yes, no
  36. // 5 = retry, cancel
  37. //
  38. //defbut
  39. // 0 = first
  40. // 1 = second
  41. // 2 = third
  42. //
  43. //mods:
  44. // 0 = app modal
  45. // 1 = system modal
  46. function newAlert(mess, title, icon, buts, defbut, mods)
  47. {
  48.     if(IE4)
  49.         makeMsgBox(title, mess, icon, buts, defbut, mods)
  50.     else
  51.         alert(mess);
  52. }
  53.  
  54. function Window_OnLoad()
  55. {
  56.     dialogheight = "400px";
  57.     dialogWidth = "532px";
  58.     returnValue = "";
  59.  
  60.     try
  61.     {
  62.         var RLevelStatus = new ActiveXObject("RLevel.NISStatusInfo");
  63.         
  64.         if (RLevelStatus.IsSystemInHighContrastMode)
  65.             document.body.scroll = "auto";
  66.         else
  67.             document.body.scroll = "no";
  68.     }
  69.     catch(err)
  70.     {  
  71.         // Just bail... we'll continue anyways.
  72.     }
  73.     
  74.     FinishBtn.disabled = false; // enable the finish button beacuse a location will be selected by default
  75.     BackBtn.disabled = true;
  76.  
  77.     Location_PopulateDropDown(DropList_Location, 1);
  78.  
  79.     // if no arguments were passed in, then this is being launched from the NIS main UI,
  80.     // so picking from saved locations is not an option
  81.     // if arguments are passed in, then this is being launched from the new location alert
  82.     (window.dialogArguments != "undefined" && window.dialogArguments.length) ? g_bLaunchedFromAlert = true : g_bLaunchedFromAlert = false;
  83.  
  84.     g_iLocationList = new ActiveXObject("ccFWSettg.LocationList");
  85.     var nNumberLocations =  g_iLocationList.ItemCount;
  86.     if(nNumberLocations >= 64)
  87.     {
  88.         Radio_CreateNewLocation.disabled = true;
  89.         var webWnd = new ActiveXObject("CcWebWnd.ccWebWindow");
  90.         webWnd.SetIcon2("res://nisres.dll/105");
  91.         webWnd.MsgBox(StrID("EnoughWithTheNewLocationsAlready!"), UserManager.ProductName, 0);
  92.  
  93.         // if no arguments were passed in, then this is being launched from the NIS main UI,
  94.         // so picking from saved locations is not an option
  95.         // if arguments are passed in, then this is being launched from the new location alert
  96.         if(!g_bLaunchedFromAlert)
  97.         {
  98.             returnValue = "";
  99.             window.navigate("res://closeme.xyz");
  100.             return;
  101.         }
  102.     }
  103.     else
  104.     {
  105.         GenerateSuggestedLocationName();
  106.  
  107.         g_numberTrustable = HomeNetCore.Detect();
  108.  
  109.         // must manually disable detected networks.  HomeNetCore ought to wait until the code tells it to enable anything before doing so
  110.         for(var i = 0; i < g_numberTrustable; i++)
  111.         {
  112.             HomeNetCore.EnableHN(i, false);
  113.         }
  114.  
  115.         if(g_numberTrustable)
  116.         {
  117.             InitializeTrustableList();
  118.         }
  119.     }
  120.  
  121.     // if no arguments were passed in, then this is being launched from the NIS main UI,
  122.     // so picking from saved locations is not an option
  123.     // if arguments are passed in, then this is being launched from the new location alert
  124.     if(!g_bLaunchedFromAlert)
  125.     {
  126.         FixBtnText(false);  // we need the next button, not the finish button
  127.         Cancel.disabled = false;
  128.  
  129.         PageA.style.display = "none";
  130.         if(g_numberTrustable)
  131.         {
  132.             PageB.style.display = "";
  133.         }
  134.         else
  135.         {
  136.             PageD.style.display = "";
  137.         }
  138.     }
  139.     else
  140.     {
  141.         FixBtnText(true);           // change next button to finish since the "use preexisting location" option is the default
  142.         PageA.style.display = "";
  143.         Cancel.style.display = "none";
  144.     }
  145.  
  146.     window.focus();
  147. }
  148.  
  149. function InitializeTrustableList()
  150. {
  151.     // Setup the list control
  152.     TrustableList.SetTableClass("ListBoxClass");
  153.     TrustableList.OnDblClick = TrustableList_OnDblClick;
  154.     TrustableList.OnSpace   = TrustableList_OnSpace;
  155.     TrustableList.OnClick   = TrustableList_OnClick;
  156.  
  157.     TrustableList.SetColumnCount(2);
  158.     TrustableList.SetColumnWidth(0, "15%");
  159.     TrustableList.SetColumnWidth(1, "85%");
  160.  
  161.     var Checked = "";   // don't select anything by default var Enabled = "checked"
  162.     var checkboxString = "<input type=checkbox " + Checked + ">";
  163.  
  164.     for(var i = 0; i < g_numberTrustable; i++)
  165.     {
  166.  
  167.         var pRow = TrustableList.InsertRow(-1);
  168.  
  169.         TrustableList.SetCellTextPtr(pRow, 0, checkboxString);
  170.  
  171.         var trustableDescription = StrID("Address") + ":  " + HomeNetCore.GetIPAddress(i);
  172.         trustableDescription += "<br>" + StrID("Mask") + ":     " + HomeNetCore.GetMask(i);
  173.  
  174.         var TextToAdd = "<div style='margin-top:6;margin-bottom:6'>" + trustableDescription + "</div>";
  175.         TrustableList.SetCellTextPtr(pRow, 1, TextToAdd);
  176.     }
  177. }
  178.  
  179. function TrustableList_OnSpace()
  180. {
  181.     var nCurSel = TrustableList.GetCurSel();
  182.     var bEnable = false;
  183.  
  184.     if(nCurSel < 0)
  185.     {
  186.         return;
  187.     }
  188.  
  189.     // Swap the state of the check box for this item
  190.     var CheckBox = TrustableList.GetCellPtr(nCurSel, 0).children[0];
  191.     CheckBox.checked = !CheckBox.checked;
  192.  
  193.     var arrayTrusted = GetSelectedTrustable();
  194.     g_numberTrusted = arrayTrusted.length;
  195. }
  196.  
  197. function TrustableList_OnClick()
  198. {
  199.     var arrayTrusted = GetSelectedTrustable();
  200.     g_numberTrusted = arrayTrusted.length;
  201. }
  202.  
  203. function TrustableList_OnDblClick()
  204. {
  205.     var nCurSel = TrustableList.GetCurSel();
  206.     var bEnable = false;
  207.  
  208.     if(nCurSel < 0)
  209.     {
  210.         return;
  211.     }
  212.  
  213.     // Swap the state of the check box for this item
  214.     var CheckBox = TrustableList.GetCellPtr(nCurSel, 0).children[0];
  215.     CheckBox.checked = !CheckBox.checked;
  216.  
  217.     var arrayTrusted = GetSelectedTrustable();
  218.     g_numberTrusted = arrayTrusted.length;
  219. }
  220.  
  221. function GetSelectedTrustable()
  222. {
  223.     var arrayTrusted = new Array();
  224.  
  225.     for(var i = 0; i < TrustableList.GetRowCount(); i++)
  226.     {
  227.         var CheckBox = TrustableList.GetCellPtr(i, 0).children[0];
  228.         var bChecked = CheckBox.checked;
  229.         if(bChecked)
  230.         {
  231.             arrayTrusted[arrayTrusted.length] = i;
  232.         }
  233.     }
  234.     return arrayTrusted;
  235. }
  236.  
  237. function FinishBtn_OnClick()
  238. {
  239.     BackBtn.disabled = true;
  240.     NextBtn.disabled = true;
  241.     FinishBtn.disabled = true;
  242.     Cancel.disabled = true;
  243.  
  244.     if (g_SelectedLocationName == "")
  245.     {
  246.         OnDropListLocationChange(DropList_Location.options[DropList_Location.selectedIndex]);
  247.     }
  248.  
  249.     if(Radio_CreateNewLocation.checked || !g_bLaunchedFromAlert)
  250.     {
  251.         setTimeout("Finish_LongProcessing()", 100);
  252.     }
  253.     else
  254.     {
  255.         setTimeout("Finish_LongProcessing_Location_Existed()", 100);
  256.     }
  257. }
  258.  
  259. function Finish_LongProcessing_Location_Existed()
  260. {
  261.     var iLocation = g_iLocationList.GetItemByName(g_SelectedLocationName);
  262.  
  263.     if(null != iLocation)
  264.     {
  265.         iLocation.AddNetSpec(window.dialogArguments);
  266.  
  267.         g_iLocationList.SaveItem(iLocation);
  268.     }
  269.  
  270.     window.navigate("res://closeme.xyz");
  271. }
  272.  
  273. function Finish_LongProcessing()
  274. {
  275.     var iLocation = new ActiveXObject("ccFWSettg.Location");
  276.  
  277.     if (window.dialogArguments != "")
  278.     {
  279.         iLocation.AddNetSpec(window.dialogArguments);
  280.     }
  281.  
  282.     if(Radio_UseSavedLocation.checked && window.dialogArguments.length)
  283.     {
  284.         iLocation.Name = g_SelectedLocationName;
  285.     }
  286.     else
  287.     {
  288.         iLocation.AutomaticProgramControl = Radio_ProgramControl_On.checked;
  289.         iLocation.Name = newLocationName.value;
  290.     }
  291.  
  292.     var iLocationList = new ActiveXObject("ccFWSettg.LocationList");
  293.     iLocationList.SaveItem(iLocation);
  294.  
  295.     var iFirewallSettings = new ActiveXObject("ccFWSettg.FirewallSettings");
  296.     iFirewallSettings.CreateDefaultSettingsForLocation(iLocation.Name);
  297.  
  298.     // Trusted Zones must be added after the location is created and assigned an ID
  299.     var arrayTrusted = GetSelectedTrustable();
  300.     if(arrayTrusted.length)
  301.     {
  302.         HomeNetCore.FilterByLocation = newLocationName.value;
  303.         for(var i = 0; i < arrayTrusted.length; i++)
  304.         {
  305.             var networkNum = 0;
  306.             networkNum = Number(arrayTrusted[i]);
  307.             HomeNetCore.EnableHN(networkNum, true);
  308.         }
  309.         HomeNetCore.AddItems();
  310.     }
  311.  
  312.     returnValue = "";
  313.     window.navigate("res://closeme.xyz");
  314. }
  315.  
  316. function NextBtn_OnClick()
  317. {
  318.     if(PageE.style.display == "")
  319.     {
  320.         // remove all backslashes, and leading and trailing whitespace
  321.         newLocationName.value = newLocationName.value.replace(/\\/g,"");
  322.         newLocationName.value = newLocationName.value.replace(/^\s*/,"");
  323.         newLocationName.value = newLocationName.value.replace(/\s*$/,"");
  324.  
  325.         // if the result is an empty string, do not continue
  326.         // TODO: There should be a MsgBox warning here, but it's now
  327.         //       too late in the NIS2004 development cycle to add one.
  328.         if (newLocationName.value.length == 0) return;
  329.  
  330.         // if the result already exists, warn with a MsgBox, but do not continue
  331.             var iLocationList = new ActiveXObject("ccFWSettg.LocationList");
  332.             var iLocation = iLocationList.GetItemByName(newLocationName.value);
  333.             if(null != iLocation)
  334.             {
  335.                 var webWnd = new ActiveXObject("CcWebWnd.ccWebWindow");
  336.                 webWnd.SetIcon2("res://nisres.dll/105");
  337.                 webWnd.MsgBox(StrID("LocationDupeEntry"), UserManager.ProductName, 0);
  338.                 return;
  339.             }
  340.  
  341.             SummaryLocationName.innerText = newLocationName.value;
  342.             if(Radio_ProgramControl_On.checked)
  343.             {
  344.                 SummaryLocationProgramControlType.innerText = StrID("Automatic");
  345.             }
  346.             else
  347.             {
  348.                 SummaryLocationProgramControlType.innerText = StrID("AlertMe");
  349.             }
  350.  
  351.             if(g_numberTrusted)
  352.             {
  353.                 SummaryLocationTrustedNumber.innerText =    g_numberTrusted;
  354.             }
  355.             else
  356.             {
  357.                 SummaryLocationTrustedNumber.innerText =    StrID("None");
  358.             }
  359.  
  360.             BackBtn.disabled = false;
  361.             PageE.style.display = "none";
  362.             PageF.style.display = "";
  363.             FixBtnText(true);
  364.             FinishBtn.disabled = false;
  365.         window.focus();
  366.         return;
  367.     }
  368.  
  369.     if(PageD.style.display == "")
  370.     {
  371.         BackBtn.disabled = false;
  372.         PageD.style.display = "none";
  373.         PageE.style.display = "";
  374.         window.focus();
  375.         return;
  376.     }
  377.  
  378.     if(PageC.style.display == "")
  379.     {
  380.         BackBtn.disabled = false;
  381.         PageC.style.display = "none";
  382.         PageD.style.display = "";
  383.         window.focus();
  384.         return;
  385.     }
  386.  
  387.     if(PageB.style.display == "")
  388.     {
  389.         BackBtn.disabled = false;
  390.         PageB.style.display = "none";
  391.         if(Radio_EnableTrustedZones.checked)
  392.         {
  393.             PageC.style.display = "";
  394.         }
  395.         else
  396.         {
  397.             PageD.style.display = "";
  398.         }
  399.         window.focus();
  400.         return;
  401.     }
  402.  
  403.     if(PageA.style.display == "")
  404.     {
  405.         PageA.style.display = "none";
  406.  
  407.         if(g_numberTrustable)
  408.         {
  409.             PageB.style.display = "";
  410.         }
  411.         else
  412.         {
  413.             PageD.style.display = "";
  414.         }
  415.  
  416.         BackBtn.disabled = false;
  417.         window.focus();
  418.         return;
  419.     }
  420. }
  421.  
  422. function BackBtn_OnClick()
  423. {
  424.     if(PageB.style.display == "")
  425.     {
  426.         PageB.style.display = "none"
  427.         PageA.style.display = ""
  428.         BackBtn.disabled = true
  429.         FixBtnText(false)
  430.         return;
  431.     }
  432.  
  433.     if(PageC.style.display == "")
  434.     {
  435.         if(!g_bLaunchedFromAlert)
  436.         {
  437.             BackBtn.disabled = true;
  438.         }
  439.         PageC.style.display = "none"
  440.         PageB.style.display = ""
  441.         return;
  442.     }
  443.  
  444.     if(PageD.style.display == "")
  445.     {
  446.         PageD.style.display = "none"
  447.  
  448.         if(g_numberTrustable)
  449.         {
  450.             PageB.style.display = ""
  451.             if(!g_bLaunchedFromAlert)
  452.             {
  453.                 BackBtn.disabled = true;
  454.             }
  455.         }
  456.         else if(g_bLaunchedFromAlert)
  457.         {
  458.             PageA.style.display = ""
  459.             BackBtn.disabled = true;
  460.             FixBtnText(false)
  461.         }
  462.         return;
  463.     }
  464.  
  465.     if(PageE.style.display == "")
  466.     {
  467.         if(!g_numberTrustable && !g_bLaunchedFromAlert)
  468.         {
  469.             BackBtn.disabled = true;
  470.         }
  471.  
  472.         PageE.style.display = "none"
  473.         PageD.style.display = ""
  474.         EnableButton(NextBtn, true);
  475.         return;
  476.     }
  477.  
  478.     if(PageF.style.display == "")
  479.     {
  480.         PageF.style.display = "none"
  481.         PageE.style.display = ""
  482.         FixBtnText(false)
  483.         return;
  484.     }
  485. }
  486.  
  487. function OnKeyDownHandler()
  488. {
  489.     // Last Control Tab over to the <back, next, close> button.
  490.     var VK_ESCAPE = 0x1B;
  491.  
  492.     if (window.event.keyCode == VK_ESCAPE)
  493.     {
  494.         // Escape key.. We want to exit out of the wizard..
  495. //      window.navigate("res://closeme.xyz");
  496.     }
  497. }
  498.  
  499. function Radio_CreateNewLocation_OnClick()
  500. {
  501.     if(Radio_CreateNewLocation.checked)
  502.     {
  503.         FixBtnText(false);
  504.     }
  505.     else
  506.     {
  507.         FixBtnText(true);
  508.     }
  509.  
  510.     // disable the finish button if the user hasn't selected a location
  511.     if(g_SelectedLocationName.length)
  512.     {
  513.         FinishBtn.disabled = false;
  514.     }
  515.     else
  516.     {
  517.         FinishBtn.disabled = true;
  518.     }
  519. }
  520.  
  521. function OnDropListLocationChange(oSelectedOption)
  522. {
  523.     var sLocation = Location_GetDropDownSelectedItemText(oSelectedOption);
  524.     g_SelectedLocationName = sLocation;
  525.  
  526.     FinishBtn.disabled = false;
  527. }
  528.  
  529. function Cancel_OnClick()
  530. {
  531.     returnValue = "";
  532.     window.navigate("res://closeme.xyz");
  533. }
  534.  
  535. function FixBtnText(bFinish)
  536. {
  537.     if(bFinish == true)
  538.     {
  539.         NextBtn.style.display = "none"
  540.         FinishBtn.style.display = ""
  541.     }
  542.     else
  543.     {
  544.         NextBtn.style.display = ""
  545.         FinishBtn.style.display = "none"
  546.     }
  547. }
  548.  
  549. function GenerateSuggestedLocationName()
  550. {
  551.     var iLocationList = new ActiveXObject("ccFWSettg.LocationList");
  552.     var iLocation = iLocationList.GetItemByName(newLocationName.value);
  553.  
  554.     var locationNameBase = newLocationName.value;
  555.     locationNameBase = locationNameBase.slice(0, locationNameBase.length - 1);  // strip off the "1" from Location1
  556.  
  557.     // look for a location name "locationN" that is not in use
  558.     var nIndex = 2;
  559.     while(null != iLocation)
  560.     {
  561.         iLocation = iLocationList.GetItemByName(locationNameBase + nIndex);
  562.         nIndex++;
  563.     }
  564.     newLocationName.value = locationNameBase + (nIndex -1); // add the number of the first location not in use to the word "Location"
  565. }
  566.