home *** CD-ROM | disk | FTP | other *** search
/ Online Praxis 1998 March / Image.iso / CD-ROM / NETSCAPE / CCK / ASE.Z / iasglob.js < prev    next >
Encoding:
Text File  |  1997-08-21  |  15.3 KB  |  561 lines

  1. <!--  to hide script contents from old browsers
  2.  
  3. // the file that includes this must also include settings.js!
  4.  
  5. // iasglob.js
  6.  
  7. //THE FOLLOWING FUNCTION IS LOCATION DEPENDANT
  8.  
  9. function refreshConfigFrame(fileName)
  10. {
  11.     debug("Globals: refreshing config frame");
  12.     if (parent.ias)
  13.     {
  14.         debug("Globals: refreshing config frame : parent");
  15.         parent.ias.refreshIASList();
  16.         if (fileName != null)
  17.             parent.ias.setIASList(fileName);
  18.     } 
  19.     else if (parent.parent.ias)
  20.     {
  21.         debug("Globals: refreshing config frame : parent.parent");
  22.         parent.parent.ias.refreshIASList();
  23.         if (fileName != null)
  24.             parent.parent.ias.setIASList(fileName);
  25.     }
  26.     else
  27.     {
  28.         //diagnostics
  29.             debug("WARNING: Globals:did not find IAS frame");
  30.             debug("parent: " + parent + " ["+parent.name+"]: " + parent.ias);
  31.             debug("parent.parent: " + parent.parent + " ["+parent.parent.name+"]: " + parent.parent.ias);
  32.             debug("this document: " + document.location + document.name + document.ias);
  33.     }
  34. }
  35.  
  36.  
  37.  
  38. ////////////////Interaction functions////////////////
  39. // these functions are for other files to access and load the global data
  40. // we store in the iasglobals frame
  41.  
  42. function getGlobal(fieldName)
  43. {
  44.     
  45.     if (parent.parent.iasglobals)
  46.     {
  47.         //debug ("option 1: parent.parent.iasglobals");
  48.         outValue = parent.parent.iasglobals.document.iasTempVars[fieldName].value;
  49.     }
  50.     else if (parent.iasglobals && parent.iasglobals.document && parent.iasglobals.document.iasTempVars && parent.iasglobals.document.iasTempVars[fieldName])
  51.     {
  52.         //debug ("option 2: parent.iasglobals");
  53.         var outValue = parent.iasglobals.document.iasTempVars[fieldName].value;
  54.     }
  55.  
  56.     if (outValue == null) outValue = "";
  57.     return outValue;
  58. }
  59.  
  60. function setGlobal(fieldName, inValue)
  61. {
  62.     if (inValue == null)
  63.         inValue = "";
  64.  
  65.     if (parent.parent.iasglobals)
  66.     {
  67.         //debug ("SetGobal: option 1: parent.parent.iasglobals");
  68.         parent.parent.iasglobals.document.iasTempVars[fieldName].value = inValue;
  69.     }
  70.     else if (parent.iasglobals)
  71.     {
  72.         //debug ("SetGobal: option 2: parent.iasglobals");
  73.         parent.iasglobals.document.iasTempVars[fieldName].value = inValue;
  74.     }
  75.  
  76. }
  77.  
  78.  
  79. //call this to force a save of the data, and refresh the frames.
  80. function saveAndRefresh()
  81. {
  82.     //flush the current child frame
  83.     if (parent.tabs.tabbody)
  84.         parent.tabs.tabbody.saveData();
  85.     else if (parent.parent.tabs.tabbody)
  86.         parent.tabs.tabbody.saveData();
  87.     
  88.     //save the file
  89.     var fileName = saveNewOrOldFile();
  90.     
  91.     //refresh the popup
  92.     if ((fileName != null) && (fileName != false))
  93.         refreshConfigFrame(fileName);
  94. }
  95.  
  96. //specifies whether the data has been tainted - i.e. whether we should 
  97. // save the data on unload
  98. // usage:     iasDirty(true) sets dirtiness (returns old dirtiness state)
  99. //            iasDirty(false) clears dirtiness (returns old dirtiness state)
  100. //            iasDirty(null) returns current dirtiness state
  101. function iasDirty(inDirt)
  102. {
  103.     var isDirty = getGlobal("GlobalsDirty");
  104.     
  105.     if ((inDirt != null) && (inDirt == true))
  106.         setGlobal("GlobalsDirty", "yes");
  107.     else if ((inDirt != null) && (inDirt == false))
  108.         setGlobal("GlobalsDirty", "no");
  109.         
  110.     if ((isDirty != null) && (isDirty == "yes"))
  111.         return true;
  112.     else
  113.         return false;
  114. }
  115.  
  116.  
  117. /////////////End Interaction functions////////////////
  118.  
  119.  
  120.  
  121. ////////FILE I/O FUNCTIONS/////////
  122.  
  123.  
  124. //get all the data from some file in the Config folder
  125. //fill in the values in our globals form
  126. function readFileData(fileName)
  127. {
  128.     var saved = saveIfDirty();
  129.     
  130.     debug("saved : " + saved);
  131.  
  132.     if (saved == false)
  133.     {
  134.         var siteName = getGlobal("IASFileName");
  135.         if ((siteName == null) || (siteName == "") || (siteName == "null"))
  136.         {
  137.             siteName = "_new_";
  138.         }
  139.         refreshConfigFrame(siteName);
  140.         return false;
  141.     }
  142.     
  143.     
  144.     if ((saved != null) && (saved != "") && (saved != false))
  145.     {
  146.         refreshConfigFrame(fileName);
  147.     }
  148.  
  149.     var tempFlagValue         =     "";
  150.     
  151.     var dicSectionName         =     "Dial-In Configuration";
  152.     var ipSectionName        =    "IP";
  153.     var securitySectionName    =    "Security";                
  154.  
  155.     var configurationSectionName    =    "Configuration";    //this is new - to take up some of the slack
  156.                                                             //from reg.ini
  157.     //old legacy stuff
  158.     //var ipxSectionName        =    "IPX";
  159.     //var netbeuiSectionName    =    "NetBEUI";
  160.     //var windowsSectionName    =    "Windows";
  161.  
  162.     if (fileName == null) fileName = "";
  163.  
  164.     setGlobal("IASFileName", fileName);
  165.     debug("just set Global filename to: " + fileName);
  166.  
  167.  
  168.     tempFlagValue = GetNameValuePair(fileName, dicSectionName, "SiteName");
  169.     setGlobal("SiteName", tempFlagValue);
  170.     tempFlagValue = GetNameValuePair(fileName, dicSectionName, "Description");
  171.     setGlobal("Description", tempFlagValue);
  172.     tempFlagValue = GetNameValuePair(fileName, dicSectionName, "Name");
  173.     setGlobal("Name", tempFlagValue);
  174.     tempFlagValue = GetNameValuePair(fileName, dicSectionName, "Password");
  175.     setGlobal("Password", tempFlagValue);
  176.     tempFlagValue = GetNameValuePair(fileName, dicSectionName, "Phone");
  177.     setGlobal("Phone", tempFlagValue);
  178.     tempFlagValue = GetNameValuePair(fileName, dicSectionName, "ScriptFileName");
  179.     setGlobal("ScriptFileName", tempFlagValue);
  180.  
  181.  
  182.     tempFlagValue = GetNameValuePair(fileName, ipSectionName, "Enabled");
  183.     setGlobal("IPEnabled", tempFlagValue);
  184.     tempFlagValue = GetNameValuePair(fileName, ipSectionName, "IPAddress");
  185.     setGlobal("IPAddress", tempFlagValue);
  186.     tempFlagValue = GetNameValuePair(fileName, ipSectionName, "DomainName");
  187.     setGlobal("DomainName", tempFlagValue);
  188.     tempFlagValue = GetNameValuePair(fileName, ipSectionName, "DNSAddress");
  189.     setGlobal("DNSAddress", tempFlagValue);
  190.     tempFlagValue = GetNameValuePair(fileName, ipSectionName, "DNSAddress2");
  191.     setGlobal("DNSAddress2", tempFlagValue);
  192.     tempFlagValue = GetNameValuePair(fileName, ipSectionName, "RegCGI");
  193.     setGlobal("RegCGI", tempFlagValue);
  194.  
  195.     tempFlagValue = GetNameValuePair(fileName, configurationSectionName, "REG_SCRIPTING");
  196.     setGlobal("REG_SCRIPTING", tempFlagValue);
  197.  
  198.     tempFlagValue = GetNameValuePair(fileName, securitySectionName, "SecurityDevice");
  199.     setGlobal("SecurityDevice", tempFlagValue);
  200.  
  201.     //old legacy stuff
  202.     //tempFlagValue = GetNameValuePair(fileName, ipxSectionName, "Enabled");
  203.     //setGlobal("IPXEnabled", tempFlagValue);    
  204.     //tempFlagValue = GetNameValuePair(fileName, netbeuiSectionName, "Enabled");
  205.     //setGlobal("NetBEUIEnabled", tempFlagValue);
  206.     //tempFlagValue = GetNameValuePair(fileName, windowsSectionName, "Main");
  207.     //setGlobal("Main", tempFlagValue);
  208.     
  209.     //set the flag in ACCTSET.INI to indicate THIS is the new file
  210.     if (fileName == null) fileName = "";
  211.     
  212.     if ((fileName != null) && (fileName != "_new_"))
  213.     SetNameValuePair("ACCTSET.INI", "New Acct Mode", "RegServer", fileName);
  214.  
  215.     //set the dirty bit to clean
  216.     iasDirty(false);
  217.     
  218.     //reload the parent's tabs frame
  219.     //debug("parent.tabs: " + parent.tabs);
  220.     //debug("parent.parent.tabs: " + parent.parent.tabs);
  221.     
  222.     if (parent.tabs && parent.tabs.tabbody && parent.tabs.tabbody.loadData) 
  223.         parent.tabs.tabbody.loadData();
  224.         
  225.  
  226.     return true;
  227. }
  228.  
  229. function writeToFile(fileName)
  230. {
  231.     //alert("in writeToFile");
  232.  
  233.     var tempFlagValue         =     "";
  234.     
  235.     var dicSectionName         =     "Dial-In Configuration";
  236.     var ipSectionName        =    "IP";
  237.     var securitySectionName    =    "Security";                
  238.  
  239.     var configurationSectionName    =    "Configuration";    //this is new - to take over REG.INI stuff
  240.  
  241.     //old legacy stuff
  242.     //var ipxSectionName        =    "IPX";
  243.     //var netbeuiSectionName    =    "NetBEUI";
  244.     //var windowsSectionName    =    "Windows";
  245.  
  246.     
  247.     SetNameValuePair(fileName, dicSectionName, "SiteName", getGlobal("SiteName"));
  248.     SetNameValuePair(fileName, dicSectionName, "Description", getGlobal("Description"));
  249.     SetNameValuePair(fileName, dicSectionName, "Name", getGlobal("Name"));
  250.     SetNameValuePair(fileName, dicSectionName, "Password", getGlobal("Password"));
  251.     SetNameValuePair(fileName, dicSectionName, "Phone", getGlobal("Phone"));
  252.     SetNameValuePair(fileName, dicSectionName, "ScriptFileName", getGlobal("ScriptFileName"));
  253.  
  254.     SetNameValuePair(fileName, ipSectionName, "Enabled", getGlobal("IPEnabled"));
  255.     SetNameValuePair(fileName, ipSectionName, "IPAddress", getGlobal("IPAddress"));
  256.     SetNameValuePair(fileName, ipSectionName, "DomainName", getGlobal("DomainName"));
  257.     SetNameValuePair(fileName, ipSectionName, "DNSAddress", getGlobal("DNSAddress"));
  258.     SetNameValuePair(fileName, ipSectionName, "DNSAddress2", getGlobal("DNSAddress2"));
  259.     SetNameValuePair(fileName, ipSectionName, "RegCGI", getGlobal("RegCGI"));
  260.  
  261.     SetNameValuePair(fileName, configurationSectionName, "REG_SCRIPTING", getGlobal("REG_SCRIPTING"));
  262.     SetNameValuePair(fileName, securitySectionName, "SecurityDevice", getGlobal("SecurityDevice"));
  263.  
  264.     //old legacy stuff
  265.     //SetNameValuePair(fileName, ipxSectionName, "Enabled", getGlobal("IPXEnabled"));
  266.     //SetNameValuePair(fileName, netbeuiSectionName, "Enabled", getGlobal("NetBEUIEnabled"));
  267.     //SetNameValuePair(fileName, windowsSectionName, "Main", getGlobal("Main"));
  268.     //SetNameValuePair(fileName, ipSectionName, "DNSAddress2", getGlobal("DNSAddress2"));
  269.     
  270.     iasDirty(false);    
  271. }
  272.  
  273.  
  274. ////////////FILE NAMING FUNCTIONS/////////////////
  275. //helper function for suggesting fileNames
  276. function isAlphaNumeric(inLetter)
  277. {
  278.  
  279.     //debug("inAlphaNumeric");
  280.     var outValue = false;
  281.     
  282.     if ((inLetter != null) && (inLetter != ""))
  283.     {
  284.  
  285.         if ((!isNaN(parseInt(inLetter))) && (parseInt(inLetter >= 0)) && (parseInt(inLetter <=9)))
  286.             outValue = true;
  287.         else
  288.         {
  289.             var let = inLetter.toLowerCase();
  290.             if ((let <= "z") && ( let >= "a"))
  291.                 outValue = true;
  292.             else if (let == "_")
  293.                 outValue = true;
  294.         }
  295.     }
  296.     return outValue;
  297. }
  298.  
  299. //takes the first eight non-whitespace characters of SiteName, and turns them into a filename
  300. //ending with a .IAS
  301. function suggestIASFileName(sName)
  302. {    
  303.     //debug("suggesting");
  304.     if ((sName == null) || (sName == ""))
  305.         sName     =     getGlobal("SiteName");
  306.  
  307.     var iasName =    "";
  308.     
  309.     if ((sName != null) && (sName != ""))
  310.     {
  311.         var len     =     sName.length;
  312.         var finLen    =    0;
  313.         
  314.         for (var i = 0; i < len; i++)
  315.         {
  316.             if (isAlphaNumeric(sName.charAt(i)))
  317.             {
  318.                 iasName = iasName + sName.charAt(i);
  319.                 finLen++;
  320.             }
  321.             if (finLen >= 8)
  322.                 break;
  323.         }
  324.         iasName = (iasName + ".IAS");             
  325.     }
  326.     return iasName;
  327. }
  328.  
  329.  
  330. function checkIfIASFileExists(inFileName)
  331. {
  332.     var outValue = false;
  333.     
  334.     if ((inFileName != null) && (inFileName != ""))
  335.     {    
  336.         fileList = getFileListFromConfigFolder(".IAS");
  337.         
  338.         if (fileList != null)    
  339.         {
  340.             for (var i=0; i<fileList.length; i++)    
  341.             {
  342.                 if (fileList[i] == inFileName)
  343.                     outValue = true;
  344.             }
  345.         }
  346.     }
  347.     return outValue;
  348. }
  349.  
  350. ////////////////FILE SAVING FUNCTIONS///////////////
  351. function askIASFileNameAndSave()
  352. {
  353.     var sName     =     getGlobal("SiteName");
  354.     var save     =     null;
  355.     
  356.  
  357.     //flush data from currenly open tab into globals
  358.     if (parent.tabs && parent.tabs.tabbody && parent.tabs.tabbody.saveData)
  359.     {
  360.         parent.tabs.tabbody.saveData();
  361.     }
  362.  
  363.     //first check if there is a sitename, if not, prompt for one
  364.     if ((sName == null) || (sName == ""))
  365.     {
  366.         var pName = prompt("Please enter a name for this configuration (this will be shown to the end user):", "");
  367.         if ((pName != null) && (pName != ""))
  368.         {
  369.             setGlobal("SiteName", pName);
  370.             setGlobal("Description", pName);
  371.             sName = pName;
  372.         }
  373.         else
  374.         {
  375.             save = false;
  376.         }    
  377.     }
  378.     
  379.     //now, if there is a sitename, suggest an IAS fileName, prompt for confirmation
  380.     //debug( "about to suggest..." );
  381.     while (save == null)
  382.     {
  383.         //debug( "in that while loop..." );
  384.         if ((sName != null) && (sName != ""))
  385.         {
  386.             var sgName = getGlobal("IASFileName");
  387.         
  388.             if ((sgName == null) || (sgName == "") || (sgName == "_new_"))
  389.                 sgName = suggestIASFileName(null);
  390.             
  391.             var fName = prompt("Enter the file name for this configuration (must end with .IAS)", sgName);
  392.             
  393.             //if they entered an improper suffix, prompt again, and again
  394.             while ((fName != null) && (fName.substring(fName.length-4, fName.length)  != ".IAS"))
  395.             {
  396.                 sgName = suggestIASFileName(fName);
  397.                 fName = prompt("Enter the fileName for this configuration (must end with .IAS)", sgName);
  398.             }
  399.             
  400.             // if the name exists, prompt to replace
  401.             
  402.             if ((fName != null) && (checkIfIASFileExists(fName)))
  403.             {
  404.                 var conf = confirm("The file: " + fName + " already exists.  Replace?");
  405.                 if (conf)
  406.                 { 
  407.                     save = true;
  408.                 }
  409.                 else
  410.                     save = null;
  411.             }
  412.             else if(fName != null)
  413.             {
  414.                 //fileName doesn't exist - we can save
  415.                 save = true;
  416.             }
  417.             else
  418.             {
  419.                 //user canceled - name = null
  420.                 save = false;        
  421.             }
  422.         }
  423.     }    
  424.     
  425.     //now save the file if the user didn't cancel
  426.     if (save == true)
  427.     {
  428.         //save the file
  429.         writeToFile(fName);
  430.         refreshConfigFrame(fName);
  431.         return fName;
  432.     }
  433.     else
  434.     {
  435.         //alert("Could not save this configuration because you did not provide a Name");
  436.         return null;
  437.     }
  438. }
  439.  
  440.  
  441.  
  442. //EVENT HANDLERS
  443.  
  444. function loadData()
  445. {
  446.     if (parent.ias && parent.ias.loadData)
  447.     {
  448.         parent.ias.loadData();
  449.     
  450.         //generate toolbar controls (and load help file if needed)
  451.         if (parent.parent && parent.parent.controls && parent.parent.controls.generateToolBarControls)
  452.             parent.parent.controls.generateToolBarControls();
  453.     }
  454.     else
  455.         setTimeout("loadData()",500);
  456.     //debug("in getdata of iasglob.js");
  457. }
  458.  
  459. //checks validity of entered data to see if we're ready to unload
  460. function checkData()
  461. {
  462.     if (iasDirty(null))
  463.     {
  464.         if (parent.tabs.tabbody.checkData)
  465.         {
  466.             //alert("checkdata exists");
  467.             var checkResult = parent.tabs.tabbody.checkData();
  468.             if (checkResult == false)
  469.                 return checkResult;
  470.         }
  471.         else
  472.             return true;
  473.     }
  474.     else 
  475.         return true;
  476. }
  477.  
  478. //checks to see if globals are dirty - if so, asks if you wanna save
  479. function saveIfDirty()
  480. {
  481.  
  482.     //alert("in SaveifDirty, caller: " + saveIfDirty.caller);
  483.     var fName=null;
  484.         
  485.     if (iasDirty(null))
  486.     {
  487.         if (confirm("You have made changes to this configuration.  Would you like to save them?"))        
  488.             fName= saveNewOrOldFile();
  489.         //alert("fName: " + fName);
  490.         if (fName != false)
  491.             iasDirty(false);
  492.         else
  493.             return false;
  494.     }
  495.     //else
  496.         //debug("Won't save - IAS not dirty");
  497.     if ((fName != null) && (fName != ""))
  498.         return fName;
  499.     else 
  500.         return null;    
  501. }
  502.  
  503.  
  504. // checks if fileName exists, if not asks about saving to a new file, 
  505. // else saves over an old file (no prompting)
  506. function saveNewOrOldFile()
  507. {
  508.  
  509.     //alert("in SavenewOrOldFile");
  510.     //first checkData
  511.     var fileName = checkData();
  512.     if (fileName == false)
  513.         return fileName;
  514.  
  515.  
  516.     //flush data from currenly open tab into globals
  517.     if(parent.tabs && parent.tabs.tabbody && parent.tabs.tabbody.saveData)
  518.     {
  519.         parent.tabs.tabbody.saveData();
  520.     }
  521.  
  522.     iasDirty(false);
  523.  
  524.     fileName = getGlobal("IASFileName");
  525.         
  526.     if ((fileName == null) || (fileName == "") || (fileName == "_new_"))
  527.     {
  528.         //debug("Saving: must ask for FileName");
  529.         var theName = askIASFileNameAndSave();
  530.         fileName = theName;
  531.     }
  532.     else if ((fileName != null) && (fileName != "") && (fileName != "_new_"))
  533.     {
  534.         //debug("Saving: without asking to: " + fileName);
  535.         writeToFile(fileName);
  536.     }
  537.     return fileName;
  538. }
  539.  
  540.  
  541. //this is the onUnLoad event Handler
  542. function saveData()
  543. {
  544.     //alert("in saveData");
  545.     //do a checkdata
  546.     var checkResult = checkData();
  547.     if (checkResult == false)
  548.         return false;
  549.  
  550.     //first make sure any current changes in the open tab are reflected in the globals
  551.     if(parent.tabs && parent.tabs.tabbody && parent.tabs.tabbody.saveData)
  552.     {
  553.         parent.tabs.tabbody.saveData();
  554.     }
  555.     
  556.         saveIfDirty();    //save, if need be
  557.     return true;
  558. }
  559.  
  560. // end hiding contents from old browsers  -->
  561.