private void pictureBoxAdd_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.CheckPathExists = true;
            openFile.CheckFileExists = true;
            openFile.Filter          = "Assemblies (*.dll)|*.dll";
            openFile.Title           = "Please select plugin assembly";
            openFile.Multiselect     = true;
            if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string pluginDirectory = Cyberarms.IntrusionDetection.Shared.IddsConfig.Instance.PluginsDirectory;
                string chosenDirectory = openFile.FileNames[0].Substring(0, openFile.FileNames[0].LastIndexOf('\\'));
                if (openFile.FileNames.Length <= 0)
                {
                    GenericErrorDialog error = new GenericErrorDialog("No file was selected!", "Please choose at least one assembly to load.", false);
                    error.ShowDialog();
                    return;
                }
                if (chosenDirectory == pluginDirectory)
                {
                    GenericErrorDialog error = new GenericErrorDialog("Invalid directory", "Please choose a directory other than the plugin directory. These assemblies are already loaded.", false);
                    error.ShowDialog();
                    return;
                }
                if (!Directory.Exists(pluginDirectory))
                {
                    try {
                        Directory.CreateDirectory(pluginDirectory);
                    } catch (Exception ex) {
                        GenericErrorDialog error = new GenericErrorDialog("Plugin directory not found!", ex.Message, false);
                        error.ShowDialog();
                        return;
                    }
                }
                foreach (string fileName in openFile.FileNames)
                {
                    string assemblyName = fileName.Remove(0, fileName.LastIndexOf('\\') + 1);
                    if (!File.Exists(pluginDirectory + assemblyName) ||
                        MessageBox.Show("This assembly already exists. Do you want to overwrite the existing?", "Overwrite existing?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                    {
                        try {
                            File.Copy(fileName, pluginDirectory + assemblyName, true);
                        } catch (Exception ex) {
                            GenericErrorDialog error = new GenericErrorDialog("Assembly cannot be copied.", ex.Message, false);
                            error.ShowDialog();
                        }
                    }
                }
                Cyberarms.IntrusionDetection.Shared.SecurityAgents.Instance.InitializeAgents();
                OnPluginsChanged();
            }
        }
Example #2
0
        public void InitAdmin()
        {
            if (IsInitialized)
            {
                return;
            }
            InitAgentSettings();
            //SecurityAgent agentX = new SecurityAgent("FTP Security Agent", 1563, 18, 230, global::Cyberarms.IntrusionDetection.Admin.Properties.Resources.Paladin_Icon_32);

            //Dashboard.AddAgent(agentX);

            labelMenuHome_Click(labelMenuHome, EventArgs.Empty);

            //CurrentMenu = labelMenuHome;
            paintPanelTopBorder();

            // Invalidate(false);
            try {
                serviceController = new System.ServiceProcess.ServiceController("Cyberarms Intrusion Detection Service");
                IsServiceRunning  = serviceController.Status != System.ServiceProcess.ServiceControllerStatus.Running;
            } catch (Exception ex) {
                GenericErrorDialog errdlg = new GenericErrorDialog("Error starting application", "The service is not installed or installed correctly. Please uninstall Cyberarms IDDS and reinstall to fix the problem!", false);
                errdlg.ShowDialog();
                EventLog.WriteEntry("Cyberarms.IntrusionDetection.Admin", ex.Message);
            }
            logReader          = new Timer();
            logReader.Interval = 1000;
            logReader.Tick    += new EventHandler(logReader_Tick);
            logReader.Enabled  = true;
            logReader.Start();

            timerRefreshServiceStatus          = new Timer();
            timerRefreshServiceStatus.Interval = 1000;
            timerRefreshServiceStatus.Tick    += new EventHandler(serviceReader_Tick);
            timerRefreshServiceStatus.Enabled  = true;
            timerRefreshServiceStatus.Start();

            eventLogCyberarms        = new EventLog("Cyberarms");
            eventLogCyberarms.Source = "Cyberarms Intrusion Detection";

            ShowMenu(labelMenuHome);
            Dashboard.BringToFront();
        }