Esempio n. 1
0
        static void Main()
        {
            certificateFileName = (ClientName == "GearHead Connect") ? ghCetrfileName : activeiCertfileName;
            path = (ClientName == "GearHead Connect") ? ghurlPath : activeiurlPath;
            certificatePassword = (ClientName == "GearHead Connect") ? ghcertificatePassword : activeicertificatePassword;

            ErrorTracker errorTracker = new ErrorTracker();
            errorTracker.WriteLog("=================================================");
            errorTracker.WriteLog("Program.Main() method was invoked.");
            errorTracker.WriteLog("=================================================");

            string directoryName = string.Empty;
            errorTracker.WriteLog("Going to Add the certificate....");
            AddCert(loadCertificate(out directoryName, path), directoryName);

            //errorTracker.WriteLog("Downloading Offline pages...");
            //downloadOfflinePage();

            //errorTracker.WriteLog("Downloading NetgearHTMLOffline.zip ...");
            //UnZipFiles();

            errorTracker.WriteLog("Going to invoke the Bootstarp UI....");
            errorTracker = null;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Bootstrap());
        }
Esempio n. 2
0
 private void Form1_Load(object sender, EventArgs e)
 {
     ErrorTracker errorTracker = new ErrorTracker();
     errorTracker.WriteLog("=================================================");
     errorTracker.WriteLog("Bootstrap.Form1_Load() method was invoked.");
     errorTracker.WriteLog("=================================================");
     errorTracker.WriteLog("timer1 was started.....");
     errorTracker = null;
     timer1.Start();
 }
Esempio n. 3
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     ErrorTracker errorTracker = new ErrorTracker();
     errorTracker.WriteLog("=================================================");
     errorTracker.WriteLog("timer1_Tick()  was invoked.");
     errorTracker.WriteLog("=================================================");
     errorTracker.WriteLog("Going to exit the Application.");
     Application.Exit();
     errorTracker.WriteLog("Application Exited.");
     errorTracker = null;
 }
Esempio n. 4
0
        private static string loadCertificate(out string directoryName, string urlPath)
        {
            string fileName = string.Empty;

            try
            {
                ErrorTracker errorTracker = new ErrorTracker();
                errorTracker.WriteLog("=================================================");
                errorTracker.WriteLog("Program.loadCertificate() method was invoked.");
                errorTracker.WriteLog("=================================================");

                directoryName = string.Empty;
                System.Net.WebClient webClient = new System.Net.WebClient();

                fileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                errorTracker.WriteLog("MyDocuments Path :: " + fileName);

                fileName = Path.Combine(fileName, ((ClientName == "GearHead Connect") ? "GearHeadConnect" : "CssConnect"));
                errorTracker.WriteLog("GearHeadConnect Path :: " + fileName);

                errorTracker.WriteLog("Going to create " + ClientName + "directory:: " + fileName);
                Directory.CreateDirectory(fileName);

                errorTracker.WriteLog("Going to AddDirectorySecurity to " + ClientName + " directory:: " + fileName);
                AddDirectorySecurity(fileName, @"Users", FileSystemRights.FullControl, AccessControlType.Allow);

                directoryName = fileName;
                fileName = Path.Combine(directoryName, certificateFileName);

                errorTracker.WriteLog("Dowloading" + certificateFileName + "file (" + urlPath + certificateFileName + ") :: " + fileName);
                webClient.DownloadFile(urlPath + certificateFileName, fileName);
                errorTracker.WriteLog("Dowloading" + certificateFileName + "file (" + urlPath + certificateFileName + ") :: " + fileName + " was Completed");
                errorTracker.WriteLog("==Program.loadCertificate() method invokation was completed.==");
                errorTracker.WriteLog("==============================================================");
                errorTracker = null;
            }
            catch (Exception ex)
            {
                directoryName = fileName;
                ErrorTracker errorTracker = new ErrorTracker();
                errorTracker.WriteErrorLog("Program.cs", "loadCertificate", "", ex.Message, ex.StackTrace, "ERROR");
                if (ex.InnerException != null)
                {
                    errorTracker.WriteErrorLog("Program.cs", "loadCertificate", "", ex.InnerException.Message, ex.InnerException.StackTrace, "ERROR - InnerException");
                }
                errorTracker = null;
            }

            return fileName;
        }
Esempio n. 5
0
        private static void InstallCertificate(string certificatePath, string certificatePassword)
        {
            try
            {
                ErrorTracker errorTracker = new ErrorTracker();
                errorTracker.WriteLog("================================================");
                errorTracker.WriteLog("Program.InstallCertificate() method was invoked.");
                errorTracker.WriteLog("================================================");

                var serviceRuntimeUserCertificateStore = new X509Store(StoreName.TrustedPublisher);
                serviceRuntimeUserCertificateStore.Open(OpenFlags.ReadWrite);
                X509Certificate2 cert;
                try
                {
                    cert = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), certificatePassword, X509KeyStorageFlags.MachineKeySet |
                                     X509KeyStorageFlags.PersistKeySet |
                                     X509KeyStorageFlags.Exportable);
                }
                catch (Exception ex)
                {
                    errorTracker.WriteLog("ERROR :: Failed to load certificate " + certificatePath);
                    errorTracker.WriteLog("ERROR :: Certificate appeared to load successfully but also seems to be null.");
                    errorTracker.WriteErrorLog("Program.cs", "InstallCertificate", "", ex.Message, ex.StackTrace, "ERROR");
                    if (ex.InnerException != null)
                    {
                        errorTracker.WriteErrorLog("Program.cs", "InstallCertificate", "", ex.InnerException.Message, ex.InnerException.StackTrace, "ERROR - InnerException");
                    }
                    throw new DataException("Certificate appeared to load successfully but also seems to be null.", ex);
                }

                serviceRuntimeUserCertificateStore.Add(cert);
                serviceRuntimeUserCertificateStore.Close();

                errorTracker.WriteLog("==Program.InstallCertificate() method invokation was completed.==");
                errorTracker.WriteLog("=================================================================");
                errorTracker = null;
            }
            catch (Exception ex)
            {
                ErrorTracker errorTracker = new ErrorTracker();
                errorTracker.WriteLog("ERROR :: Failed to install {0}.  Check the certificate index entry and verify the certificate file exists. " + certificatePath);
                errorTracker.WriteErrorLog("Program.cs", "InstallCertificate", "", ex.Message, ex.StackTrace, "ERROR");
                if (ex.InnerException != null)
                {
                    errorTracker.WriteErrorLog("Program.cs", "InstallCertificate", "", ex.InnerException.Message, ex.InnerException.StackTrace, "ERROR - InnerException");
                }
                errorTracker = null;
            }
        }
Esempio n. 6
0
        public static void AddCert(string cerFileName, string directoryName)
        {
            try
            {
                ErrorTracker errorTracker = new ErrorTracker();
                errorTracker.WriteLog("=====================================");
                errorTracker.WriteLog("Program.AddCert() method was invoked.");
                errorTracker.WriteLog("=====================================");

                
                
                string certificateLocation = cerFileName;
                errorTracker.WriteLog("certificateLocation :: " + cerFileName);
                errorTracker.WriteLog("Installing the certificate....");
                InstallCertificate(certificateLocation, certificatePassword);
                errorTracker.WriteLog("certificate installation was completed.");

                if (Directory.Exists(directoryName))
                {
                    errorTracker.WriteLog("certificate directory : " + directoryName);
                    File.Delete(Path.Combine(directoryName, certificateFileName));
                    errorTracker.WriteLog("certificate file deleted : " + directoryName);
                }
                errorTracker.WriteLog("==Program.AddCert() method invokation was completed.==");
                errorTracker.WriteLog("======================================================");
                errorTracker = null;
            }
            catch (Exception ex)
            {
                ErrorTracker errorTracker = new ErrorTracker();
                errorTracker.WriteErrorLog("Program.cs", "AddCert", "", ex.Message, ex.StackTrace, "ERROR");
                if (ex.InnerException != null)
                {
                    errorTracker.WriteErrorLog("Program.cs", "AddCert", "", ex.InnerException.Message, ex.InnerException.StackTrace, "ERROR - InnerException");
                }
                errorTracker = null;
            }
        }
Esempio n. 7
0
        //Loading offline html pages
        //private static void downloadOfflinePage()
        //{
        //    try
        //    {
        //        ErrorTracker errorTracker = new ErrorTracker();
        //        errorTracker.WriteLog("=================================================");
        //        errorTracker.WriteLog("Program.downloadOfflinePage() method was invoked.");
        //        errorTracker.WriteLog("=================================================");
        //        System.Net.WebClient webClient = new System.Net.WebClient();
        //        string fileName = string.Empty;
        //        fileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        //        errorTracker.WriteLog("MyDocuments Path :: " + fileName);

        //        fileName = fileName + "\\GearHeadConnect";
        //        errorTracker.WriteLog("GearHeadConnect Path :: " + fileName);

        //        errorTracker.WriteLog("Going to create GearHeadConnect directory:: " + fileName);
        //        Directory.CreateDirectory(fileName);

        //        errorTracker.WriteLog("Going to AddDirectorySecurity to GearHeadConnect directory:: " + fileName);
        //        AddDirectorySecurity(fileName, @"Users", FileSystemRights.FullControl, AccessControlType.Allow);

        //        fileName = fileName + "\\noconnection.htm";
        //        errorTracker.WriteLog("Dowloading noconnection.htm file (" + urlPath + "offline/noconnection.htm) :: " + fileName);
        //        webClient.DownloadFile(urlPath + "offline/noconnection.htm", fileName);
        //        errorTracker.WriteLog("Dowloading noconnection.htm file (" + urlPath + "offline/noconnection.htm) :: " + fileName + " was Completed");


        //        fileName = string.Empty;
        //        fileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        //        fileName = fileName + "\\GearHeadConnect";
        //        fileName = fileName + "\\error.png";
        //        errorTracker.WriteLog("Dowloading error.png file (" + urlPath + "offline/error.png) :: " + fileName);
        //        webClient.DownloadFile(urlPath + "offline/error.png", fileName);
        //        errorTracker.WriteLog("Dowloading error.png file (" + urlPath + "offline/error.png) :: " + fileName + " was Completed");

        //        fileName = string.Empty;
        //        fileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        //        fileName = fileName + "\\GearHeadConnect";
        //        fileName = fileName + "\\generalerror.htm";
        //        errorTracker.WriteLog("Dowloading generalerror.htm file (" + urlPath + "offline/generalerror.htm) :: " + fileName);
        //        webClient.DownloadFile(urlPath + "offline/generalerror.htm", fileName);
        //        errorTracker.WriteLog("Dowloading generalerror.htm file (" + urlPath + "offline/generalerror.htm) :: " + fileName + " was Completed");

        //        fileName = string.Empty;
        //        fileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        //        fileName = fileName + "\\GearHeadConnect";
        //        fileName = fileName + "\\innerscreenbg.png";
        //        errorTracker.WriteLog("Dowloading innerscreenbg.png file (" + urlPath + "offline/innerscreenbg.png) :: " + fileName);
        //        webClient.DownloadFile(urlPath + "offline/innerscreenbg.png", fileName);
        //        errorTracker.WriteLog("Dowloading innerscreenbg.png file (" + urlPath + "offline/innerscreenbg.png) :: " + fileName + " was Completed");

        //        errorTracker.WriteLog("==Program.downloadOfflinePage() method invokation was completed.==");
        //        errorTracker.WriteLog("==================================================================");
        //    }
        //    catch (Exception ex)
        //    {
        //        ErrorTracker errorTracker = new ErrorTracker();
        //        errorTracker.WriteErrorLog("Program.cs", "downloadOfflinePage", "", ex.Message, ex.StackTrace, "ERROR");
        //        if (ex.InnerException != null)
        //        {
        //            errorTracker.WriteErrorLog("Program.cs", "downloadOfflinePage", "", ex.InnerException.Message, ex.InnerException.StackTrace, "ERROR - InnerException");
        //        }
        //        errorTracker = null;
        //    }
        //}

        // Adds an ACL entry on the specified directory for the specified account. 
        public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
        {
            try
            {
                ErrorTracker errorTracker = new ErrorTracker();
                errorTracker.WriteLog("=================================================");
                errorTracker.WriteLog("Program.AddDirectorySecurity() method was invoked.");
                errorTracker.WriteLog("=================================================");

                // Create a new DirectoryInfo object.
                errorTracker.WriteLog("Create a new DirectoryInfo object");
                DirectoryInfo dInfo = new DirectoryInfo(FileName);

                // Get a DirectorySecurity object that represents the  
                // current security settings.
                errorTracker.WriteLog("Get a DirectorySecurity object that represents the current security settings.");
                DirectorySecurity dSecurity = dInfo.GetAccessControl();

                // Add the FileSystemAccessRule to the security settings. 
                errorTracker.WriteLog("Add the FileSystemAccessRule to the security settings.");
                //dSecurity.AddAccessRule(new FileSystemAccessRule(Account, Rights, ControlType));
                CanonicalizeDacl(dSecurity);

                // Set the new access settings.
                errorTracker.WriteLog("Set the new access settings.");
                dInfo.SetAccessControl(dSecurity);

                errorTracker.WriteLog("==Program.AddDirectorySecurity() method invokation was completed.==");
                errorTracker.WriteLog("===================================================================");
                errorTracker = null;
            }
            catch (Exception ex)
            {
                ErrorTracker errorTracker = new ErrorTracker();
                errorTracker.WriteErrorLog("Program.cs", "AddDirectorySecurity", "", ex.Message, ex.StackTrace, "ERROR");
                if (ex.InnerException != null)
                {
                    errorTracker.WriteErrorLog("Program.cs", "AddDirectorySecurity", "", ex.InnerException.Message, ex.InnerException.StackTrace, "ERROR - InnerException");
                }
                errorTracker = null;
            }
        }