public bool UpdateData(bool SetPHP = false) { if (!Directory.Exists(this.ApacheInstallation)) { Globals.AddToLog("Directory " + this.ApacheInstallation + " not exist."); return(false); } this.PHPmodule = null; if (SetPHP) { String PHPpath = Path.GetDirectoryName(Globals.Servers.PHP.Exe); if (string.IsNullOrEmpty(Globals.Servers.WebServer.CGIlinker) && !Directory.Exists(PHPpath)) { Globals.AddToLog("Couldn't start Apache with PHP."); return(false); } else { this.PHPmodule = Globals.Servers.WebServer.CGIlinker; } } this.Write(); return(true); }
private Process ServiceStart(String Exe, String Arguments = null) { var p = new Process(); int pID = -1; ThreadStart ths = new ThreadStart(() => { p.StartInfo.WorkingDirectory = Path.GetDirectoryName(Exe); p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.OutputDataReceived += new DataReceivedEventHandler((s, e) => { Globals.Processes.stdOut = e.Data; }); p.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { Globals.Processes.stdErr = e.Data; }); p.StartInfo.FileName = Exe; if (Arguments != null) { p.StartInfo.Arguments = Arguments; } p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; try { p.Start(); if (!this.ProcessesPIDs.Contains(p.Id)) { this.ProcessesPIDs.Add(p.Id); p.BeginOutputReadLine(); p.BeginErrorReadLine(); } pID = p.Id; p.WaitForExit(); } catch (InvalidOperationException ex) { Globals.AddToLog("Error: " + ex.Message); } catch (Exception ex) { Globals.AddToLog("Error: " + ex.Message); } }); Thread th = new Thread(ths); th.IsBackground = true; th.Start(); while (pID < 0 && th.IsAlive) { Thread.Sleep(50); } return(p); }
public bool PHPStart(String Exe, String Args) { this.PHP = this.ServiceStart(Exe, Args); if (this.PHP.Id >= 0) { this.PHPID = this.PHP.Id; return(true); } else { Globals.AddToLog("Unable to start the PHP CGI Server."); return(false); } }
public bool WebServerStart(String Exe) { String WSDir = Globals.AppFolder + @"bin\WebServer\" + Globals.ActiveWebServerVersion + @"\"; String ExeFile = Exe; String Opts = null; switch (Globals.Servers.WebServer.Type) { case WebServers.WSType.Apache: if (Globals.RewriteConfigFiles == "1") { //ApacheConfigFile ApacheFile = new ApacheConfigFile(WSDir); ApacheConfigFile ApacheFile = new ApacheConfigFile(Directory.GetParent(Path.GetDirectoryName(ExeFile)).ToString() + @"\"); ApacheFile.MakeItCompatible(Globals.Servers.WebServer.Version()); ApacheFile.UpdateData(this.InternalPHP); } break; case WebServers.WSType.nginx: if (Globals.RewriteConfigFiles == "1") { nginxConfigFile nginxFile = new nginxConfigFile(WSDir); nginxFile.UpdateData(this.ExternalPHP); } break; case WebServers.WSType.lighttpd: if (Globals.RewriteConfigFiles == "1") { lighttpdConfigFile lighttpdeFile = new lighttpdConfigFile(WSDir); lighttpdeFile.UpdateData(this.ExternalPHP); } Opts = "-Df " + WSDir + @"\conf\lighttpd.conf"; break; } this.WebServer = this.ServiceStart(ExeFile, Opts); if (this.WebServer.Id >= 0) { this.WebServerID = this.WebServer.Id; return(true); } else { Globals.AddToLog("Unable to start the Web Server."); return(false); } }
public Boolean DownloadUpdate() { this.DeleteFile(Globals.AppFolder + "tmp.zip"); try { this.client = new WebClient(); this.client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted); this.client.DownloadFileAsync(new Uri(this.URL), Globals.AppFolder + "tmp.zip"); return(true); } catch (Exception e) { Globals.AddToLog(e.Message); this.DeleteFile(Globals.AppFolder + "tmp.zip"); return(false); } }
public Boolean CreateConfigFile() { String dbFile = Globals.AppFolder + @"config.db"; SQLiteDatabase Target = new SQLiteDatabase(dbFile); String[] SQLs = new String[] { "CREATE TABLE General (param TEXT, value TEXT);", "INSERT INTO General VALUES('WebServerStart',0);", "INSERT INTO General VALUES('MySQLStart',0);", "INSERT INTO General VALUES('PHPStart',0);", "INSERT INTO General VALUES('DataBasePass','WebDevelopmentServer1');", "INSERT INTO General VALUES('StartOnLaunch',0);", "INSERT INTO General VALUES('StartInSystray',0);", "INSERT INTO General VALUES('RewriteConfigFiles',1);", "INSERT INTO General VALUES('ActiveWebServerVersion','null');", "INSERT INTO General VALUES('ActivePHPVersion','null');", "INSERT INTO General VALUES('ActiveMySQLVersion','null');", "INSERT INTO General VALUES('LastServersDBMod','01/01/2000 00:00:00');", "CREATE TABLE ActiveModules (Module TEXT, ServerType TEXT);", "CREATE TABLE Aliases (AliasID INTEGER PRIMARY KEY, AliasFolder TEXT, AliasName TEXT, VHostID NUMERIC);", "CREATE TABLE ConfigModules (ServerType TEXT, IfModule TEXT, IfModuleActive NUMERIC, Module TEXT);", "CREATE TABLE CustomSettings (ServerType TEXT, Id INTEGER PRIMARY KEY, Param TEXT);", "CREATE TABLE Directories (DirectoryID INTEGER PRIMARY KEY, VHostID NUMERIC, Others TEXT, AllowOverride NUMERIC, MultiViews NUMERIC, Indexes NUMERIC, Includes NUMERIC, SymLinks NUMERIC, DirectoryName TEXT);", "CREATE TABLE PHPModules (Module TEXT, Value TEXT);", "CREATE TABLE PHPSettings (Active NUMERIC, Param TEXT, Value TEXT);", "CREATE TABLE VirtualHosts (DocumentRoot TEXT, IP TEXT, Others TEXT, Port NUMERIC, ServerAlias TEXT, ServerName TEXT, VHostID INTEGER PRIMARY KEY);" }; try { SQLiteConnection.CreateFile(dbFile); Target.ExecuteNonQueryBulk(SQLs); Globals.AddToLog("This is the first time you run this program.\r\nIt's highly recommended that you run the Configuration Wizard before you start using it."); return(true); } catch (Exception) { Globals.Error.Show("Error: Unable to create the database file at:\r\n\r\n" + Directory.GetParent(dbFile)); return(false); } }
private void DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { this.client = null; this.DeleteFile(Globals.AppFolder + "tmp"); if (e.Error != null) { Globals.Error.Show(e.Error.Message); } else { Decompress.ExtractZip(Globals.AppFolder, "tmp.zip", true); Globals.LastServersDBMod = this.LastModified.ToString(); Config.SaveSetting("LastServersDBMod", Globals.LastServersDBMod); LoadDataBase(Globals.AppFolder + @"servers.db", ref Globals.dbServ); Globals.AddToLog("Servers database successfully updated."); } string[] fileList = Directory.GetFiles(Globals.AppFolder + "tmp\\"); string file2; foreach (string file in fileList) { file2 = Path.GetFileName(file); if (System.IO.File.Exists(Globals.AppFolder + file2)) { File.Delete(Globals.AppFolder + file2); } File.Move(Globals.AppFolder + "tmp\\" + file2, Globals.AppFolder + file2); } this.DeleteFile(Globals.AppFolder + "tmp.zip"); this.DeleteFile(Globals.AppFolder + "tmp"); }
public bool DataBaseStart(String Exe) { if (Globals.DataBasePassChange) { this.thePass.ChangeRootPasswordFile(); this.DataBase = this.ServiceStart(Exe, "--explicit_defaults_for_timestamp --init-file=\"\\mysqlWSD\""); } else { this.DataBase = this.ServiceStart(Exe, "--explicit_defaults_for_timestamp"); } if (this.DataBase.Id >= 0) { this.DataBaseID = this.DataBase.Id; return(true); } else { Globals.AddToLog("Unable to start the DataBase Server."); return(false); } }
public bool WebServerLoadsPHP(WebServers.WSType SrvType) { Globals.Processes.ExternalPHP = false; Globals.Processes.InternalPHP = false; int[] PHPver = new int[3]; try { PHPver = Globals.Servers.PHP.Version(); } catch (Exception) { return(false); } switch (SrvType) { case WebServers.WSType.Apache: int[] WSver = Globals.Servers.WebServer.Version(); String PHPDir = Path.GetDirectoryName(Globals.Servers.PHP.Exe); // SAPI. String LinkerFile = "php" + PHPver[0] + "apache" + WSver[0] + "_" + WSver[1] + "-php" + PHPver[0] + "." + PHPver[1] + "." + ((Globals.Servers.WebServer.Is32Bits) ? "win32" : "win64") + "*.dll"; String[] AvailableLinkers = Directory.GetFiles(Globals.AppFolder + @"extras\", LinkerFile); if (AvailableLinkers.Length > 0) { Globals.Servers.WebServer.CGIlinker = AvailableLinkers[0]; Globals.Processes.InternalPHP = true; } else // FastCGI. { LinkerFile = "mod_fcgid.so.apache" + ((WSver[1] >= 4) ? WSver[0].ToString() + "_" + WSver[1].ToString() : WSver[0].ToString()) + "." + ((Globals.Servers.WebServer.Is32Bits) ? "win32" : "win64") + "*"; AvailableLinkers = Directory.GetFiles(Globals.AppFolder + @"extras\", LinkerFile); if (AvailableLinkers.Length > 0) { Globals.Servers.WebServer.CGIlinker = AvailableLinkers[0]; Globals.Processes.InternalPHP = true; } else // CGI. { Globals.AddToLog("It is not possible to connect Apache " + WSver[0] + "." + WSver[1] + " version with PHP " + PHPver[0] + "." + PHPver[1] + "."); Globals.Servers.WebServer.CGIlinker = Path.GetFullPath(Path.GetDirectoryName(Globals.Servers.WebServer.Exe) + @"\..\modules\mod_cgi.so"); if (File.Exists(Globals.Servers.WebServer.CGIlinker)) { Globals.AddToLog("Trying with CGI module (Use this only for development and testing purposes)."); Globals.Processes.InternalPHP = true; } } } break; case WebServers.WSType.nginx: if (PHPver[0] == 5) // FastCGI. { Globals.Processes.ExternalPHP = true; } break; case WebServers.WSType.lighttpd: if (PHPver[0] < 5) // CGI. { Globals.Processes.InternalPHP = true; } else // FastCGI. { Globals.Processes.ExternalPHP = true; } break; default: Globals.Processes.ExternalPHP = true; break; } return(Globals.Processes.InternalPHP); }
public void Write() { if (File.Exists(ApacheInstallation + @"conf\httpd.conf")) { File.Delete(ApacheInstallation + @"conf\httpd.conf"); } try { StreamWriter WriteFile = new StreamWriter(ApacheInstallation + @"conf\httpd.conf"); String[] Available = Globals.Servers.LoadAvailableModules("Apache"); String[] NotAvailable = Globals.Servers.WebServer.ActiveModules.Except(Available).ToArray(); if (NotAvailable.Length > 0) { Globals.AddToLog("Module not found in this WebServer: " + string.Join(", ", NotAvailable)); Globals.Servers.WebServer.ActiveModules = Globals.Servers.WebServer.ActiveModules.Except(NotAvailable).ToList <String>(); } if (!Globals.Servers.WebServer.ActiveModules.Contains("mod_alias.so")) { Globals.Servers.WebServer.ActiveModules.Add("mod_alias.so"); } if (Globals.Servers.WebServer.Type == WebServers.WSType.Apache && !Globals.Servers.WebServer.ActiveModules.Contains("mod_authz_core.so")) { int[] ver = Globals.Servers.WebServer.Version(); if (ver[0] >= 2 && ver[1] >= 4) { Globals.Servers.WebServer.ActiveModules.Add("mod_authz_core.so"); } } foreach (String Mod in Globals.Servers.WebServer.ActiveModules) { WriteFile.WriteLine("LoadModule " + Mod.Replace(".so", "_module").Replace("mod_", "") + " " + "modules/" + Mod); } if (!string.IsNullOrEmpty(this.PHPmodule) && File.Exists(this.PHPmodule)) { // SAPI: if (this.PHPmodule.Contains(".dll")) { String PHPpath = Path.GetDirectoryName(Globals.Servers.PHP.Exe); String FileName = Path.GetFileName(Globals.Servers.WebServer.CGIlinker); File.Copy(Globals.Servers.WebServer.CGIlinker, PHPpath + @"\" + FileName, true); this.PHPmodule = PHPpath + @"\" + FileName; if (this.PHPmodule.Contains("php7apache")) { WriteFile.WriteLine("LoadModule php7_module \"" + this.PHPmodule + "\""); } else if (this.PHPmodule.Contains("php5apache")) { WriteFile.WriteLine("LoadModule php5_module \"" + this.PHPmodule + "\""); } else if (this.PHPmodule.Contains("php4apache")) { WriteFile.WriteLine("LoadModule php4_module \"" + this.PHPmodule + "\""); } WriteFile.WriteLine("PHPIniDir \"" + Globals.AppFolder.Replace("\\", "/") + "bin/PHP/" + Globals.ActivePHPVersion + "\""); WriteFile.WriteLine("AddHandler application/x-httpd-php .php"); } // FastCGI: else if (this.PHPmodule.Contains("fcgid.so")) { File.Copy(Globals.Servers.WebServer.CGIlinker, ApacheInstallation + @"\modules\mod_fcgid.so", true); this.PHPmodule = ApacheInstallation.Replace("\\", "/") + "modules/mod_fcgid.so"; WriteFile.WriteLine("LoadModule fcgid_module modules/mod_fcgid.so"); WriteFile.WriteLine("<IfModule fcgid_module>"); WriteFile.WriteLine("\tFcgidInitialEnv PHPRC \"" + Globals.AppFolder.Replace("\\", "/") + "bin/PHP/" + Globals.ActivePHPVersion + "/php\""); WriteFile.WriteLine("\tAddHandler fcgid-script .php"); WriteFile.WriteLine("\tFcgidWrapper \"" + Globals.AppFolder.Replace("\\", "/") + "bin/PHP/" + Globals.ActivePHPVersion + "/php-cgi.exe\" .php"); WriteFile.WriteLine("</IfModule>"); } // CGI: else if (this.PHPmodule.Contains("cgi.so")) { if (!Globals.Servers.WebServer.ActiveModules.Any("mod_cgi.so".Contains)) { WriteFile.WriteLine("LoadModule cgi_module modules/mod_cgi.so"); } if (!Globals.Servers.WebServer.ActiveModules.Any("mod_cgi.so".Contains)) { WriteFile.WriteLine("LoadModule actions_module modules/mod_actions.so"); } WriteFile.WriteLine("SetEnv PHPRC \"" + Path.GetDirectoryName(Globals.Servers.PHP.Exe) + "\""); WriteFile.WriteLine("ScriptAlias /php/ \"" + Path.GetDirectoryName(Globals.Servers.PHP.Exe) + "/\""); WriteFile.WriteLine("Action application/x-httpd-php \"/php/php.exe\""); WriteFile.WriteLine("AddHandler application/x-httpd-php .php"); } } DataTable DBSettings = Globals.dbConn.GetDataTable("SELECT * FROM ConfigModules WHERE IfModuleActive > 0 AND ServerType LIKE 'Apache'"); if (DBSettings.Rows.Count > 0) { WriteFile.WriteLine(""); String text; foreach (DataRow row in DBSettings.Rows) { text = "<IfModule "; if (row["IfModuleActive"].ToString() == "2") { text += "!"; } text += row["Module"].ToString().Replace(".so", "_module").Replace("mod_", "") + ">\r\n"; text += row["IfModule"] + "\r\n"; text += "</IfModule>"; WriteFile.WriteLine(text + "\r\n"); } WriteFile.WriteLine(""); } DBSettings = Globals.dbConn.GetDataTable("SELECT * FROM CustomSettings WHERE ServerType LIKE 'Apache'"); if (DBSettings.Rows.Count > 0) { foreach (DataRow row in DBSettings.Rows) { WriteFile.WriteLine(row["Param"] + "\r\n"); } WriteFile.WriteLine(""); } String VServ; String tab; List <String> Ports = new List <String>(); foreach (VirtualHost vh in Globals.VHosts) { if (vh.VHostID != 1) { tab = "\t"; } else { tab = ""; } VServ = ""; if (!Ports.Contains(vh.Port)) { VServ += "Listen " + vh.Port + "\r\n"; Ports.Add(vh.Port); } if (vh.VHostID != 1 && vh.Port.Length > 0) { VServ += "NameVirtualHost \"" + vh.IP + ":" + vh.Port + "\"\r\n"; VServ += "<VirtualHost " + vh.IP + ":" + vh.Port + ">" + "\r\n"; } if (vh.ServerName != null && vh.ServerName != "") { VServ += tab + "ServerName \"" + vh.ServerName + "\"" + "\r\n"; } if (vh.VHostID != 1 && vh.ServerAlias != null && vh.ServerAlias != "") { VServ += tab + "ServerAlias \"" + vh.ServerAlias + "\"" + "\r\n"; } if (vh.DocumentRoot != null && vh.DocumentRoot != "") { VServ += tab + "DocumentRoot \"" + vh.DocumentRoot.Replace("\\", "/") + "\"" + "\r\n"; } if (vh.Others != null && vh.Others != "") { VServ += vh.Others + "\r\n"; } foreach (Aliases alias in vh.Alias) { VServ += tab + "Alias \"" + alias.AliasName + "\" \"" + alias.AliasFolder.Replace("\\", "/") + "\"" + "\r\n"; } foreach (Directories dir in vh.Directory) { VServ += tab + "<Directory \"" + dir.DirectoryName.Replace("\\", "/") + "\">" + "\r\n"; VServ += tab + tab + "AllowOverride " + ((dir.AllowOverride) ? "All" : "None") + "\r\n"; VServ += tab + tab + "Options " + ((!dir.SymLinks) ? "-" : "+") + "FollowSymLinks " + ((!dir.Includes) ? "-" : "+") + "Includes " + ((!dir.Indexes) ? "-" : "+") + "Indexes " + ((!dir.MultiViews) ? "-" : "+") + "MultiViews\r\n"; if (dir.Others.Length > 0) { VServ += tab + tab + dir.Others.Trim() + "\r\n"; } VServ += tab + "</Directory>\r\n"; } if (vh.VHostID != 1 && vh.Port.Length > 0) { VServ += "</VirtualHost>\r\n"; } WriteFile.WriteLine(VServ); } WriteFile.Close(); } catch (Exception ex) { Globals.Error.Show(ex.Message); } }
private void Main_Load(object sender, EventArgs e) { CheckForIllegalCrossThreadCalls = false; // Need to modify manually inside the AssemblyInfo.cs file (AssemblyFileVersion). this.Text = String.Format("Web Development Server {0}", Application.ProductVersion); // Add the link to GitHub in the About tab. LinkLabel.Link link = new LinkLabel.Link(); link.LinkData = "https://github.com/mongui"; tGithub.Links.Add(link); Globals.list = this.LogList; Globals.AddToLog("Thanks for using Web Development Server v." + Application.ProductVersion + "."); Globals.AddToLog("------------------------------------------------------------------------------"); #if DEBUG Globals.AppFolder = @"c:\tests\"; #else this.NetworkStatus(); Globals.AppFolder = AppDomain.CurrentDomain.BaseDirectory; #endif // Check if the databases are available. DataBaseFiles dbFiles = new DataBaseFiles(); if (!dbFiles.LoadDataBase(Globals.AppFolder + @"config.db", ref Globals.dbConn)) { if (!dbFiles.CreateConfigFile()) { this.Close(); return; } dbFiles.LoadDataBase(Globals.AppFolder + @"config.db", ref Globals.dbConn); } if (Config.LoadSettings() < 0) { this.Close(); return; } if (Globals.DataBasePass.Length < 8) { Globals.DataBasePass = "******"; Config.SaveSetting("DataBasePass", Globals.DataBasePass); DataBaseConfig DBConfig = new DataBaseConfig(); DBConfig.SetDefaultConfig(Globals.DataBasePass); } Boolean isDownloading = false; #if !DEBUG if (!File.Exists(Globals.AppFolder + @"servers.db") || dbFiles.CheckLastModified()) { isDownloading = dbFiles.DownloadUpdate(); } #endif if (!isDownloading && !dbFiles.LoadDataBase(Globals.AppFolder + @"servers.db", ref Globals.dbServ)) { this.Close(); return; } if (!Directory.Exists(Globals.AppFolder + @"bin")) { Directory.CreateDirectory(Globals.AppFolder + @"bin"); } if (!Directory.Exists(Globals.AppFolder + @"bin\WebServer")) { Directory.CreateDirectory(Globals.AppFolder + @"bin\WebServer"); } if (!Directory.Exists(Globals.AppFolder + @"bin\PHP")) { Directory.CreateDirectory(Globals.AppFolder + @"bin\PHP"); } if (!Directory.Exists(Globals.AppFolder + @"bin\MySQL")) { Directory.CreateDirectory(Globals.AppFolder + @"bin\MySQL"); } this.LoadCombos(); this.LoadCheckboxes(); this.ChecksActive(); this.LoadServerData(true, true, true); if (Globals.Processes.ProcessesPIDs.Count == 0) { this.NotifyIcon.Icon = WDS.Properties.Resources.ServerRed; } // Start in the systray and start servers if the options are checked. if (Globals.StartInSystray == "1") { this.WindowState = FormWindowState.Minimized; } if (Globals.StartOnLaunch == "1") { this.bstart_Click(null, null); } // Check if there is any non-wanted service running. Services Svc = new Services(); String SvcName = Svc.DoesServiceExist("Apache"); if (Svc.StopService(SvcName)) { Globals.AddToLog("Found an Apache service running. Shutting down the webserver..."); } SvcName = Svc.DoesServiceExist("MySQL"); if (Svc.StopService(SvcName)) { Globals.AddToLog("Found an MySQLd service running. Shutting down the database manager..."); } }