コード例 #1
0
        private void StartScan(string pathName)
        {
            ServiceController sc = null;

            try
            {
                sc = new ServiceController(ClamConfig.Services.Scan);
            }
            catch (Exception)
            {
                return;
            }

            EnableToolbarButtons(false);
            ScanLogUpdateTimer.Enabled = true;
            LogTabControl.SelectTab("LogScanTabPage");

            // Clear Update Log
            ClearAction();

            // Send our path to scan
            pInfo.AddNotification(ClamConfig.Notification.WHSClamAVScanShare, WHS_Notification_Severity.WHS_INFO, pathName, pathName, "", "", "");
            try
            {
                sc.ExecuteCommand((int)ClamConfig.ServiceCommand.scanShare);
            }
            catch (Exception)
            {
                ThrowError.Throw("Scanning Service is not found on this machine");
                return;
            }
        }
コード例 #2
0
        private void UpdateTabButtonStatus(string TabName)
        {
            switch (TabName)
            {
            // Only enabled clear button for Log files
            case "LogScanTabPage":
            case "LogUpdateTabPage":
                RefreshToolBarButton.Enabled = true;
                ClearToolBarButton.Enabled   = true;
                break;

            // Don't allow clearing of config
            case "ConfigFileTabPage":
                RefreshToolBarButton.Enabled = true;
                ClearToolBarButton.Enabled   = false;
                break;

            // Don't allow update or clearing of version status - not yet implemented.
            case "ClamWinVerTabPage":
                RefreshToolBarButton.Enabled = false;
                ClearToolBarButton.Enabled   = false;
                break;

            default:
                ThrowError.Throw("Error in MainTabUserControl.UpdateTabButtonStatus()");
                break;
            }
        }
コード例 #3
0
        private void ClearAction()
        {
            foreach (Control ctrl in LogTabControl.SelectedTab.Controls)
            {
                if (ctrl is PropertyPageNonEditableTextBoxField)
                {
                    PropertyPageNonEditableTextBoxField ppnedtf = ctrl as PropertyPageNonEditableTextBoxField;
                    ppnedtf.Clear();
                }
            }

            switch (LogTabControl.SelectedTab.Name)
            {
            case "LogScanTabPage":
                ClamAVConfig.ClearClamLogFile(ClamAVConfig.ClamScanLogFile);
                break;

            case "LogUpdateTabPage":
                ClamAVConfig.ClearClamLogFile(ClamAVConfig.ClamUpdateLogFile);
                break;

            case "ConfigFileTabPage":
            case "ClamWinVerTabPage":
            default:
                ThrowError.Throw("Error in MainTabUserControl.ClearAction()");
                break;
            }

            RefreshAction();
        }
コード例 #4
0
ファイル: ClamConfig.cs プロジェクト: tsew/whsclamav
        public void WriteClamConfigKey(string key, string value)
        {
            // Read config file up until key into string buffer
            StringBuilder tempConfig = new StringBuilder();
            string        line;
            bool          needWrite = false;

            // If config file does not exist return
            if (!File.Exists(_ClamConfigFile))
            {
                return;
            }

            try
            {
                using (TextReader configFile = new StreamReader(_ClamConfigFile))
                {
                    while ((line = configFile.ReadLine()) != null)
                    {
                        // If found return first instance
                        if (line.StartsWith(key))
                        {
                            // Check to see if new key is same as old - if so skip write
                            string writeKey = key + " = " + value;
                            if (!line.Equals(writeKey))
                            {
                                tempConfig.AppendLine(writeKey);
                                needWrite = true;
                            }
                        }
                        else
                        {
                            tempConfig.AppendLine(line);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ThrowError.Throw(ex.Message);
            }

            if (!needWrite)
            {
                return;
            }

            try
            {
                using (TextWriter newConfigFile = new StreamWriter(_ClamConfigFile))
                {
                    newConfigFile.Write(tempConfig.ToString());
                }
            }
            catch (Exception ex)
            {
                ThrowError.Throw(ex.Message);
            }
        }
コード例 #5
0
        private void ProxySaveButton_Click(object sender, EventArgs e)
        {
            ClamConfig config = new ClamConfig();

            // Check if config file exists
            if (!File.Exists(config.ClamConfigFile))
            {
                ThrowError.Throw("ClamAV Config File does not exist\nHave you installed ClamAV?");
                return;
            }

            // Check Fields
            if (String.IsNullOrEmpty(ProxyServerTextBox.Text.Trim()) && !String.IsNullOrEmpty(ProxyUserTextBox.Text.Trim()))
            {
                ProxyServerTextBox.BackColor = Color.Red;
                return;
            }

            if (String.IsNullOrEmpty(ProxyUserTextBox.Text.Trim()) && !String.IsNullOrEmpty(ProxyPasswordTextBox.Text.Trim()))
            {
                ProxyUserTextBox.BackColor = Color.Red;
                return;
            }

            if (!String.IsNullOrEmpty(ProxyPortTextBox.Text))
            {
                try
                {
                    Int32 port = Int32.Parse(ProxyPortTextBox.Text);
                    if (port < 0 || port > 65535)
                    {
                        ProxyPortTextBox.BackColor = Color.Red;
                        return;
                    }
                }
                catch (Exception)
                {
                    ProxyPortTextBox.BackColor = Color.Red;
                    return;
                }
            }

            // All okay so clear all errors
            ProxyServerTextBox.BackColor   = Color.White;
            ProxyPortTextBox.BackColor     = Color.White;
            ProxyUserTextBox.BackColor     = Color.White;
            ProxyPasswordTextBox.BackColor = Color.White;

            // Save Fields
            config.WriteClamConfigKey("host", ProxyServerTextBox.Text.ToString().Trim());
            config.WriteClamConfigKey("port", ProxyPortTextBox.Text.ToString().Trim());
            config.WriteClamConfigKey("user", ProxyUserTextBox.Text.ToString().Trim());
            config.WriteClamConfigKey("password", ProxyPasswordTextBox.Text.ToString().Trim());

            //Disable Save Button
            ProxySaveButton.Enabled = false;
        }
コード例 #6
0
        private void userDefinedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Fetch custom drive paths
            // foreach (string path in Paths)
            // StartScan(pathToScan)
            // suppress log clearing between paths

            ThrowError.Throw("Not yet implemented");
        }
コード例 #7
0
        private void DoInstall()
        {
            DownloadButton.Text    = "Installing";
            DownloadButton.Enabled = false;

            // NOTB - no ask toolbaar
            string command = ClamConfig.ClamAVInstallFile;
            string args    = "/sp- /silent /norestart /NOTB";

            System.Diagnostics.Process installer = new System.Diagnostics.Process();
            installer.StartInfo.FileName  = command;
            installer.StartInfo.Arguments = args;
            installer.Start();

            UpdateInstallLabel("Waiting to Kill Process FreshClam   ");

            // Thread.Sleep(3000);

            while (ClamConfig.WaitForProcess(installer.ProcessName))
            {
                ClamConfig.FindAndKillProcess("freshclam");
            }

            installer.WaitForExit();

            UpdateInstallLabel("Waiting to Kill Process ClamTray   ");

            while (ClamConfig.WaitForProcess("ClamTray"))
            {
                ClamConfig.FindAndKillProcess("ClamTray");
            }

            // Remove automatic start of ClamAV
            ClamConfig.RemoveRegistryKeys();

            // Set Quarantine option
            // Also remove warning for update
            try
            {
                ClamConfig clamConfig = new ClamConfig();
                clamConfig.WriteClamConfigKey("moveinfected", "1");
                clamConfig.WriteClamConfigKey("warnoutofdate", "0");
            }
            catch (Exception ex)
            {
                ThrowError.Throw(ex.Message);
            }

            CheckStatus();
        }
コード例 #8
0
        private void UpdateToolBarButton_Click(object sender, EventArgs e)
        {
            ServiceController sc = null;

            try
            {
                sc = new ServiceController(ClamConfig.Services.Update);
            }
            catch (Exception)
            {
                return;
            }

            try
            {
                if (sc.Status != ServiceControllerStatus.Running)
                {
                    ThrowError.Throw("Update Service is not running: Service is " + sc.Status.ToString());
                    return;
                }
            }
            catch (Exception)
            {
                ThrowError.Throw("Update Service is not found on this machine");
                return;
            }


            // First disable update button
            EnableToolbarButtons(false);

            // Start showing updated log
            UpdateLogUpdateTimer.Enabled = true;
            LogTabControl.SelectTab("LogUpdateTabPage");

            ClearAction();

            try
            {
                sc.ExecuteCommand((int)ClamConfig.ServiceCommand.update);
            }
            catch (Exception)
            {
                ThrowError.Throw("Scanning Service is not found on this machine");
                return;
            }
        }
コード例 #9
0
 /// <summary>
 /// Set the Proxy Host and Port
 /// </summary>
 public static void SetProxyHost()
 {
     // Check to see if port is defined
     if (!String.IsNullOrEmpty(ClamWinConfig.ReadClamConfigKey("port")))
     {
         if (!String.IsNullOrEmpty(ClamWinConfig.ReadClamConfigKey("host")))
         {
             try
             {
                 myProxy = new WebProxy(ClamWinConfig.ReadClamConfigKey("host"), Int32.Parse(ClamWinConfig.ReadClamConfigKey("port")));
             }
             catch (Exception ex)
             {
                 ThrowError.Throw(ex.Message, "Proxy Definition Error");
             }
         }
     }
 }
コード例 #10
0
        private void ScanMemoryToolBarButton_Click(object sender, EventArgs e)
        {
            ServiceController sc = null;

            try
            {
                sc = new ServiceController(ClamConfig.Services.Scan);
            }
            catch (Exception)
            {
                return;
            }

            try
            {
                if (sc.Status != ServiceControllerStatus.Running)
                {
                    ThrowError.Throw("Scanning Service is not running: Service is " + sc.Status.ToString());
                    return;
                }
            }
            catch (Exception)
            {
                ThrowError.Throw("Scanning Service is not found on this machine");
                return;
            }

            EnableToolbarButtons(false);
            ScanLogUpdateTimer.Enabled = true;
            LogTabControl.SelectTab("LogScanTabPage");

            // Clear Update Log
            ClearAction();
            try
            {
                sc.ExecuteCommand((int)ClamConfig.ServiceCommand.scanMemory);
            }
            catch (Exception)
            {
                ThrowError.Throw("Scanning Service is not found on this machine");
                return;
            }
        }
コード例 #11
0
        private void UpdateTabContents(string TabName)
        {
            switch (TabName)
            {
            // Only enable updating for version log
            case "LogScanTabPage":
            case "LogUpdateTabPage":
            case "ConfigFileTabPage":
                break;

            // Don't allow update or clearing of version status - not yet implemented.
            case "ClamWinVerTabPage":
                RefreshVersionInformation();
                break;

            default:
                ThrowError.Throw("Error in MainTabUserControl.UpdateTabContents()");
                break;
            }
        }
コード例 #12
0
        private static void KillServiceThreads(string serviceName)
        {
            ServiceController sc = null;

            try
            {
                sc = new ServiceController(serviceName);
            }
            catch (Exception)
            {
                return;
            }
            try
            {
                sc.ExecuteCommand((int)ClamConfig.ServiceCommand.kill);
            }
            catch (Exception)
            {
                ThrowError.Throw("Service " + serviceName + " is not found on this machine");
                return;
            }
        }
コード例 #13
0
        private void RefreshAction()
        {
            switch (LogTabControl.SelectedTab.Name)
            {
            case "LogScanTabPage":
                LoadScanLog();
                break;

            case "LogUpdateTabPage":
                LoadUpdateLog();
                break;

            case "ConfigFileTabPage":
                LoadConfig();
                break;

            case "ClamWinVerTabPage":
            default:
                ThrowError.Throw("Error in MainTabUserControl.RefreshAction()");
                break;
            }
        }