Ejemplo n.º 1
0
        /// <summary>
        /// Checking configuration file and preparing it
        /// </summary>
        /// <returns></returns>
        public bool checkConfigureModules()
        {
            try
            {
                Class.registryClass rg = new Class.registryClass();
                string       dir       = rg.getValue("apacheLocation") + "\\conf\\httpd.conf";
                FileStream   fin       = new FileStream(dir, FileMode.Open);
                StreamReader fstr_in   = new StreamReader(fin);

                string data = fstr_in.ReadToEnd();
                fstr_in.Close();
                fin.Close();
                if (data.Contains("#HERE STARTS CONFIGURATION MODULES, DON'T DELETE THIS!"))
                {
                    return(true);
                }
                else
                {
                    if (configureModules())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("BŁĄD: " + e.ToString(), "ERROR");
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Acctive module
        /// </summary>
        /// <param name="moduleName">Module name in httpd.conf</param>
        /// <returns></returns>
        public bool activeModule(string moduleName)
        {
            try{
                Class.registryClass rg = new Class.registryClass();
                string       dir       = rg.getValue("apacheLocation") + "\\conf\\httpd.conf";
                FileStream   fin       = new FileStream(dir, FileMode.Open);
                StreamReader fstr_in   = new StreamReader(fin);
                string       data      = fstr_in.ReadToEnd();
                fstr_in.Close();
                fin.Close();
                int indexofname = data.IndexOf(" " + moduleName + " ");
                if (indexofname > data.IndexOf("#HERE ENDS CONFIGURATION MODULES, DON'T DELETE THIS!") || indexofname < data.IndexOf("#HERE STARTS CONFIGURATION MODULES, DON'T DELETE THIS!"))
                {
                    return(false);
                }
                string       buf      = data.Remove(indexofname - 11, 1);
                FileStream   fout     = new FileStream(dir, FileMode.Create);
                StreamWriter fstr_out = new StreamWriter(fout);
                fstr_out.Write(buf);
                fstr_out.Close();
                fout.Close();

                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show("BŁĄD: " + e.ToString(), "ERROR");
                return(false);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Deactive module in httpd.conf
 /// </summary>
 /// <param name="moduleName">Module name in httpd.conf</param>
 /// <returns></returns>
 public bool deactiveModule(string moduleName)
 {
     try
     {
         Class.registryClass rg = new Class.registryClass();
         string       dir       = rg.getValue("apacheLocation") + "\\conf\\httpd.conf";
         FileStream   fin       = new FileStream(dir, FileMode.Open);
         StreamReader fstr_in   = new StreamReader(fin);
         string       data      = fstr_in.ReadToEnd();
         fstr_in.Close();
         fin.Close();
         int          indexofname = data.IndexOf(" " + moduleName + " ");
         string       buf         = data.Insert(indexofname - 10, "#");
         FileStream   fout        = new FileStream(dir, FileMode.Create);
         StreamWriter fstr_out    = new StreamWriter(fout);
         fstr_out.Write(buf);
         fstr_out.Close();
         fout.Close();
         return(true);
     }
     catch (Exception e)
     {
         MessageBox.Show("BŁĄD: " + e.ToString(), "ERROR");
         return(false);
     }
 }
Ejemplo n.º 4
0
        public string showActualValue(string STRING)
        {
            /// <summary>
            /// Returns searched value from httpd.conf file
            /// </summary>

            try
            {
                Class.registryClass rg = new Class.registryClass();
                string       dir       = rg.getValue("apacheLocation") + "\\conf\\httpd.conf";
                FileStream   fin       = new FileStream(dir, FileMode.Open);
                StreamReader fstr_in   = new StreamReader(fin);
                string       data      = fstr_in.ReadToEnd();
                fstr_in.Close();
                fin.Close();

                string buf = data.Remove(0, data.IndexOf(STRING));
                data = buf.Remove(data.IndexOf("\n"));


                string[] datalines = buf.Split('\n');


                data = datalines[1];

                return(data);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Błąd: " + ex.Message);
            }
            return("0");
        }
Ejemplo n.º 5
0
        public mainConfigurationFiles(MainWindow m)
        {
            this.mw = m;
            InitializeComponent();
            Class.registryClass rg   = new Class.registryClass();
            string apacheLogLocation = rg.getValue("apacheLocation") + "\\conf";

            if (!Directory.Exists(apacheLogLocation))
            {
                MessageBox.Show("Brak plików konfiguracyjnych! Przywróć dane z kopi zapasowej", "ERROR");
            }
            else
            {
                string[] files = Directory.GetFiles(apacheLogLocation, "*.conf");
                foreach (string dir in files)
                {
                    lbFiles.Items.Add(dir.Remove(0, apacheLogLocation.Length + 1));
                }
                apacheLogLocation += "\\extra";
                files              = Directory.GetFiles(apacheLogLocation, "*.conf");
                if (!Directory.Exists(apacheLogLocation))
                {
                    MessageBox.Show("Brak plików konfiguracyjnych! Przywróć dane z kopi zapasowej", "ERROR");
                }
                else
                {
                    foreach (string dir in files)
                    {
                        lbFiles.Items.Add(dir.Remove(0, apacheLogLocation.Length - 5));
                    }
                }
            }
        }
        public disactiveModule(MainWindow m)
        {
            this.mw = m;
            InitializeComponent();
            Class.registryClass rg   = new Class.registryClass();
            string       dir         = rg.getValue("apacheLocation") + "\\conf\\httpd.conf";
            FileStream   fin         = new FileStream(dir, FileMode.Open);
            StreamReader fstr_in     = new StreamReader(fin);
            string       data        = fstr_in.ReadToEnd();
            int          firstmodule = data.IndexOf("LoadModule ");

            data = data.Remove(0, firstmodule - 2);
            string[] datalines = data.Split('\n');
            string   buf;

            foreach (string line in datalines)
            {
                if (line.Contains("LoadModule "))
                {
                    buf = line.Remove(0, line.IndexOf("e ") + 2);
                    buf = buf.Remove(buf.IndexOf(" "));
                    lbmodules.Items.Add(buf);
                }
            }
            fstr_in.Close();
            fin.Close();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adding module to configuration file(default deactive), and copy module file to module location
        /// </summary>
        /// <param name="moduleName"></param>
        /// <param name="moduleLocation"></param>
        /// <returns></returns>
        public string addModule(string moduleName, string moduleLocation)
        {
            try
            {
                Class.registryClass rg = new Class.registryClass();
                string apachelocation  = rg.getValue("apacheLocation");
                string filename        = moduleLocation;
                while (filename.Contains('\\'))
                {
                    filename = filename.Remove(0, filename.IndexOf('\\') + 1);
                }
                filename = "modules/" + filename;
                string apachemodulelocation = apachelocation + "/" + filename;
                if (File.Exists(apachemodulelocation))
                {
                    return("Nie można dodać. Ten plik istnieje.");
                }
                else
                {
                    File.Copy(moduleLocation, apachemodulelocation); // w tym miejscu dokonano skopiowania krok 1
                }

                SortedDictionary <string, string> modules = returnModuleList(0);
                modules.Add(moduleName, filename);       //w tym miejscu dodano do słownika nazwe modułu i lokalizacje

                FileStream   fin     = new FileStream(apachelocation + "/conf/httpd.conf", FileMode.Open);
                StreamReader fstr_in = new StreamReader(fin);
                string       data    = fstr_in.ReadToEnd();
                fstr_in.Close();
                fin.Close();
                int start = data.IndexOf("#HERE STARTS CONFIGURATION MODULES, DON'T DELETE THIS!") + 55;
                int stop  = data.IndexOf("#HERE ENDS CONFIGURATION MODULES, DON'T DELETE THIS!") - start;
                data  = data.Remove(start, stop);
                start = data.IndexOf("#HERE STARTS CONFIGURATION MODULES, DON'T DELETE THIS!") + 55;
                string line = "";
                data = data.Insert(start, "\n");
                foreach (KeyValuePair <string, string> pair in modules)
                {
                    line   = "#LoadModule " + pair.Key + " " + pair.Value + "\n";
                    data   = data.Insert(start, line);
                    start += line.Length;
                }

                FileStream   fout     = new FileStream(apachelocation + "\\conf\\httpd.conf", FileMode.Truncate);
                StreamWriter fstr_out = new StreamWriter(fout);
                fstr_out.Write(data);
                fstr_out.Close();
                fout.Close();
                return("true");
            }
            catch (Exception e)
            { return(e.ToString()); }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Deleting module from configuration file and module file
        /// </summary>
        /// <param name="moduleName">Name of module from httpd.conf</param>
        /// <param name="modulelocation">Location of module from httpd.conf</param>
        /// <returns></returns>
        public bool deleteModule(string moduleName, string modulelocation)
        {
            try
            {
                Class.registryClass rg      = new Class.registryClass();
                string       apachelocation = rg.getValue("apacheLocation");
                string       httpdlocation  = apachelocation + "\\conf\\httpd.conf";
                FileStream   fin            = new FileStream(httpdlocation, FileMode.Open);
                StreamReader fstr_in        = new StreamReader(fin);
                string       data           = fstr_in.ReadToEnd();
                fstr_in.Close();
                fin.Close();
                int    indexofname;
                int    lngth;
                string newdata;
                if (data.Contains("#LoadModule " + moduleName))
                {
                    indexofname = data.IndexOf("#LoadModule " + moduleName);
                    lngth       = data.IndexOf(modulelocation) + modulelocation.Length - indexofname;
                    newdata     = data.Remove(indexofname, lngth + 1);
                }
                else
                {
                    indexofname = data.IndexOf("LoadModule " + moduleName);
                    lngth       = data.IndexOf(modulelocation) + modulelocation.Length - indexofname;
                    newdata     = data.Remove(indexofname, lngth + 1);
                }
                if (modulelocation.Contains('"'))
                {
                    modulelocation = modulelocation.Remove(modulelocation.IndexOf("\""), 1);
                    modulelocation = modulelocation.Remove(modulelocation.IndexOf("\""), 1);
                    File.Delete(modulelocation);
                }
                else
                {
                    modulelocation = modulelocation.Remove(0, modulelocation.IndexOf('/'));
                    File.Delete(apachelocation + "\\modules\\" + modulelocation);
                }

                FileStream   fout     = new FileStream(httpdlocation, FileMode.Truncate);
                StreamWriter fstr_out = new StreamWriter(fout);
                fstr_out.Write(newdata);
                fstr_out.Close();
                fout.Close();
                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show("BŁĄD: " + e.ToString(), "ERROR");
                return(false);
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Adding starting and ending label to httpd.conf
 /// </summary>
 /// <returns></returns>
 public bool configureModules()
 {
     try
     {
         Class.registryClass rg = new Class.registryClass();
         string       dir       = rg.getValue("apacheLocation") + "\\conf\\httpd.conf";
         FileStream   fin       = new FileStream(dir, FileMode.Open);
         StreamReader fstr_in   = new StreamReader(fin);
         string       data      = fstr_in.ReadToEnd();
         fstr_in.Close();
         fin.Close();
         int firstmodule = 0;
         if (data.IndexOf("\nLoadModule") > data.IndexOf("\n#LoadModule"))
         {
             firstmodule = data.IndexOf("\n#LoadModule");
         }
         else
         {
             firstmodule = data.IndexOf("\nLoadModule");
         }
         data = data.Insert(firstmodule - 1, "\n\n\n#HERE STARTS CONFIGURATION MODULES, DON'T DELETE THIS!");
         string[] datalines = data.Split('\n');
         int      secmodule = 0;
         foreach (string line in datalines)
         {
             if (line.Contains("#LoadModule "))
             {
                 secmodule = data.IndexOf(line) + line.Length;
             }
             if (line.Contains("LoadModule "))
             {
                 firstmodule = data.IndexOf(line) + line.Length;
             }
         }
         if (firstmodule < secmodule)
         {
             firstmodule = secmodule;
         }
         data = data.Insert(firstmodule, "\n#HERE ENDS CONFIGURATION MODULES, DON'T DELETE THIS!\n\n");
         FileStream   fout     = new FileStream(dir, FileMode.Truncate);
         StreamWriter fstr_out = new StreamWriter(fout);
         fstr_out.Write(data);
         fout.Close();
         fstr_out.Close();
         return(true);
     }
     catch (Exception e)
     {
         MessageBox.Show("BŁĄD: " + e.ToString(), "ERROR");
         return(false);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Showing, hiding buttons and loading data to listbox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbsource_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            Class.registryClass registry = new Class.registryClass();
            string apacheLogLocation     = registry.getValue("apacheLocation") + "\\logs\\";
            string archiveLocation       = registry.getValue("logLocation");

            if (!Directory.Exists(apacheLogLocation))
            {
                Directory.CreateDirectory(apacheLogLocation);
            }
            if (!Directory.Exists(archiveLocation))
            {
                Directory.CreateDirectory(archiveLocation);
            }
            try
            {
                string[] apacheLogFiles  = Directory.GetFiles(apacheLogLocation, "*.log");
                string[] archiveLogFiles = Directory.GetFiles(archiveLocation, "*.log");
                if (cbsource.SelectedIndex == 1)
                {
                    lbLogs.Items.Clear();
                    foreach (string dir in apacheLogFiles)
                    {
                        lbLogs.Items.Add(dir.Remove(0, apacheLogLocation.Length));
                    }
                    deletearchive.Visibility = Visibility.Hidden;
                    addtoarchive.Visibility  = Visibility.Visible;
                    clearlog.Visibility      = Visibility.Visible;
                }
                if (cbsource.SelectedIndex == 2)
                {
                    lbLogs.Items.Clear();
                    foreach (string dir in archiveLogFiles)
                    {
                        lbLogs.Items.Add(dir.Remove(0, archiveLocation.Length + 1));
                    }
                    addtoarchive.Visibility  = Visibility.Hidden;
                    clearlog.Visibility      = Visibility.Hidden;
                    deletearchive.Visibility = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Rewrite extra\\httpd-vhosts.conf
 /// </summary>
 /// <param name="data"></param>
 /// <returns>Configuration file content</returns>
 public bool vhwrite(string data)
 {
     try
     {
         Class.registryClass rg      = new Class.registryClass();
         string       apachelocation = rg.getValue("apacheLocation");
         string       dir            = apachelocation + "\\conf\\extra\\httpd-vhosts.conf";
         FileStream   fout           = new FileStream(dir, FileMode.Truncate);
         StreamWriter fstr_out       = new StreamWriter(fout);
         fstr_out.Write(data);
         fstr_out.Close();
         fout.Close();
         return(true);
     }
     catch (Exception e)
     {
         MessageBox.Show("BŁĄD: " + e.ToString(), "ERROR");
         return(false);
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Return extra/httpd-vhosts.conf
 /// </summary>
 /// <returns></returns>
 public string vhread()
 {
     try
     {
         Class.registryClass rg      = new Class.registryClass();
         string       apachelocation = rg.getValue("apacheLocation");
         string       dir            = apachelocation + "\\conf\\extra\\httpd-vhosts.conf";
         FileStream   fin            = new FileStream(dir, FileMode.Open);
         StreamReader fstr_in        = new StreamReader(fin);
         string       data           = fstr_in.ReadToEnd();
         fstr_in.Close();
         fin.Close();
         return(data);
     }
     catch (Exception e)
     {
         MessageBox.Show("BŁĄD: " + e.ToString(), "ERROR");
         return(null);
     }
 }
Ejemplo n.º 13
0
        public void changeValue(string STRING, string changedValue)
        {
            /// <summary>
            /// Changing values
            /// </summary>

            Class.registryClass rg = new Class.registryClass();
            string       dir       = rg.getValue("apacheLocation") + "\\conf\\httpd.conf";
            FileStream   fin       = new FileStream(dir, FileMode.Open);
            StreamReader fstr_in   = new StreamReader(fin);
            string       data      = fstr_in.ReadToEnd();

            fstr_in.Close();
            fin.Close();

            string buf = data.Replace(STRING, changedValue);

            FileStream   fout     = new FileStream(dir, FileMode.Create);
            StreamWriter fstr_out = new StreamWriter(fout);

            fstr_out.Write(buf);
            fstr_out.Close();
            fout.Close();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Return dictionary of names and directory of modules
        /// </summary>
        /// <param name="searchrule">Shows: 0 - all modules, 1 - deactive modules, 2 - active modules</param>
        /// <returns>Key - module name, value - module directory</returns>
        public SortedDictionary <string, string> returnModuleList(int searchrule)
        {
            SortedDictionary <string, string> modules = new SortedDictionary <string, string>();

            try
            {
                Class.registryClass rg   = new Class.registryClass();
                string       dir         = rg.getValue("apacheLocation") + "\\conf\\httpd.conf";
                FileStream   fin         = new FileStream(dir, FileMode.Open);
                StreamReader fstr_in     = new StreamReader(fin);
                string       data        = fstr_in.ReadToEnd();
                int          firstmodule = data.IndexOf("LoadModule ");
                data = data.Remove(0, firstmodule - 2);
                string[] datalines = data.Split('\n');
                string   buf;
                bool     check = false;
                switch (searchrule)
                {
                case 0:
                    foreach (string line in datalines)
                    {
                        try
                        {
                            if (line.Contains("#HERE STARTS CONFIGURATION MODULES, DON'T DELETE THIS!"))
                            {
                                check = true;
                            }
                            if (check)
                            {
                                if (line.Contains("LoadModule ") && (!line.Contains("# LoadModule")))
                                {
                                    buf = line.Remove(0, line.IndexOf("e ") + 2);
                                    modules.Add(buf.Remove(buf.IndexOf(" ")), buf.Remove(0, buf.IndexOf(" ") + 1));
                                }
                            }
                            if (line.Contains("#HERE ENDS CONFIGURATION MODULES, DON'T DELETE THIS!"))
                            {
                                break;
                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("Błąd : " + e.Message, "Błąd",
                                            MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    break;

                case 1:
                    foreach (string line in datalines)
                    {
                        try
                        {
                            if (line.Contains("#HERE STARTS CONFIGURATION MODULES, DON'T DELETE THIS!"))
                            {
                                check = true;
                            }
                            if (check)
                            {
                                if (line.Contains("#LoadModule "))
                                {
                                    buf = line.Remove(0, line.IndexOf("e ") + 2);
                                    modules.Add(buf.Remove(buf.IndexOf(" ")), buf.Remove(0, buf.IndexOf(" ") + 1));
                                }
                            }
                            if (line.Contains("#HERE ENDS CONFIGURATION MODULES, DON'T DELETE THIS!"))
                            {
                                break;
                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("Błąd : " + e.Message, "Błąd",
                                            MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    break;

                case 2:
                    foreach (string line in datalines)
                    {
                        try
                        {
                            if (line.Contains("#HERE STARTS CONFIGURATION MODULES, DON'T DELETE THIS!"))
                            {
                                check = true;
                            }
                            if (check)
                            {
                                if (line[0] == 'L' && line.Contains("LoadModule "))
                                {
                                    buf = line.Remove(0, line.IndexOf("e ") + 2);
                                    modules.Add(buf.Remove(buf.IndexOf(" ")), buf.Remove(0, buf.IndexOf(" ") + 1));
                                }
                            }
                            if (line.Contains("#HERE ENDS CONFIGURATION MODULES, DON'T DELETE THIS!"))
                            {
                                break;
                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("Błąd : " + e.Message, "Błąd",
                                            MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    break;
                }
                fstr_in.Close();
                fin.Close();
                return(modules);
            }
            catch (Exception e)
            {
                MessageBox.Show("BŁĄD: " + e.ToString(), "ERROR");
                return(modules);
            }
        }