diff --git a/Novetus/NovetusCore/Classes/WebProxy.cs b/Novetus/NovetusCore/Classes/WebProxy.cs index 76ef906..a54446d 100644 --- a/Novetus/NovetusCore/Classes/WebProxy.cs +++ b/Novetus/NovetusCore/Classes/WebProxy.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; using Titanium.Web.Proxy; using Titanium.Web.Proxy.EventArguments; using Titanium.Web.Proxy.Http; @@ -21,11 +22,49 @@ public class WebProxy return Server.ProxyRunning; } + public void DoSetup() + { + if (GlobalVars.UserConfiguration.WebProxyInitialSetupRequired) + { + string text = "Would you like to enable the Novetus web proxy?\n\n" + + "A web proxy redirects web traffic to a different location and in some cases can act as a gateway to different sites. Novetus uses the web proxy for additional client features and asset redirection.\n\n" + + "When enabling the web proxy, Novetus will locally create a certificate upon startup that ensures the proxy's functionality. Novetus will not send any user data to anyone, as everything involving the web proxy is entirely local to this computer.\n" + + "If you have any issue connecting to other web sites, including Roblox, closing Novetus or typing 'proxy off' into Novetus' console will fix it in most instances.\n\n" + + "Upon pressing 'Yes', Windows will ask you for permission to install the certificate.\n\n" + + "You can change this option at any time by typing 'proxy disable' or 'proxy on' in the Novetus console. This message will appear only once.\n"; + + DialogResult result = MessageBox.Show(text, "Novetus - Web Proxy Opt-In", MessageBoxButtons.YesNo); + + switch (result) + { + case DialogResult.Yes: + GlobalVars.UserConfiguration.WebProxyEnabled = true; + Start(); + break; + case DialogResult.No: + default: + break; + } + + GlobalVars.UserConfiguration.WebProxyInitialSetupRequired = false; + FileManagement.Config(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName, true); + } + else + { + if (GlobalVars.UserConfiguration.WebProxyEnabled) + { + Start(); + } + } + } + public void Start() { try { //load ext + Server.CertificateManager.RootCertificateIssuerName = "Novetus"; + Server.CertificateManager.RootCertificateName = "Novetus Web Proxy"; Server.BeforeRequest += new AsyncEventHandler(OnRequest); UpdateEndPoint(true); Util.ConsolePrint("Web Proxy started on port " + GlobalVars.WebProxyPort, 3); diff --git a/Novetus/NovetusCore/StorageAndFunctions/FileManagement.cs b/Novetus/NovetusCore/StorageAndFunctions/FileManagement.cs index a383314..024a61f 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/FileManagement.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/FileManagement.cs @@ -89,6 +89,8 @@ public class FileFormat NewGUI = false; URIQuickConfigure = true; BootstrapperShowUI = true; + WebProxyInitialSetupRequired = true; + WebProxyEnabled = false; } public string SelectedClient { get; set; } @@ -120,6 +122,8 @@ public class FileFormat public bool NewGUI { get; set; } public bool URIQuickConfigure { get; set; } public bool BootstrapperShowUI { get; set; } + public bool WebProxyInitialSetupRequired { get; set; } + public bool WebProxyEnabled { get; set; } } #endregion @@ -831,6 +835,8 @@ public class FileManagement ini.IniWriteValue(section, "NewGUI", GlobalVars.UserConfiguration.NewGUI.ToString()); ini.IniWriteValue(section, "URIQuickConfigure", GlobalVars.UserConfiguration.URIQuickConfigure.ToString()); ini.IniWriteValue(section, "BootstrapperShowUI", GlobalVars.UserConfiguration.BootstrapperShowUI.ToString()); + ini.IniWriteValue(section, "WebProxyInitialSetupRequired", GlobalVars.UserConfiguration.WebProxyInitialSetupRequired.ToString()); + ini.IniWriteValue(section, "WebProxyEnabled", GlobalVars.UserConfiguration.WebProxyEnabled.ToString()); ConfigUseOldValIfExists(ini, section, "ItemMakerDisableHelpMessage", "AssetSDKDisableHelpMessage", GlobalVars.UserConfiguration.DisabledAssetSDKHelp.ToString(), write); ConfigUseOldValIfExists(ini, section, "AssetLocalizerSaveBackups", "AssetSDKFixerSaveBackups", GlobalVars.UserConfiguration.AssetSDKFixerSaveBackups.ToString(), write); @@ -850,7 +856,8 @@ public class FileManagement disablehelpmessage, discord, mappath, mapsnip, graphics, reshade, qualitylevel, style, savebackups, altIP, disReshadeDel, showNotifs, SB_Name, SB_Address, priority, - firstServerLaunch, newgui, quickconfigure, bootstrapper; + firstServerLaunch, newgui, quickconfigure, bootstrapper, + webproxysetup, webproxy; INIFile ini = new INIFile(cfgpath); @@ -881,6 +888,8 @@ public class FileManagement newgui = ini.IniReadValue(section, "NewGUI", GlobalVars.UserConfiguration.NewGUI.ToString()); quickconfigure = ini.IniReadValue(section, "URIQuickConfigure", GlobalVars.UserConfiguration.URIQuickConfigure.ToString()); bootstrapper = ini.IniReadValue(section, "BootstrapperShowUI", GlobalVars.UserConfiguration.BootstrapperShowUI.ToString()); + webproxysetup = ini.IniReadValue(section, "WebProxyInitialSetupRequired", GlobalVars.UserConfiguration.WebProxyInitialSetupRequired.ToString()); + webproxy = ini.IniReadValue(section, "WebProxyEnabled", GlobalVars.UserConfiguration.WebProxyEnabled.ToString()); disablehelpmessage = ConfigUseOldValIfExists(ini, section, "ItemMakerDisableHelpMessage", "AssetSDKDisableHelpMessage", GlobalVars.UserConfiguration.DisabledAssetSDKHelp.ToString(), write); savebackups = ConfigUseOldValIfExists(ini, section, "AssetLocalizerSaveBackups", "AssetSDKFixerSaveBackups", GlobalVars.UserConfiguration.AssetSDKFixerSaveBackups.ToString(), write); @@ -926,6 +935,8 @@ public class FileManagement GlobalVars.UserConfiguration.NewGUI = ValueBool(newgui, DefaultConfiguration.NewGUI); GlobalVars.UserConfiguration.URIQuickConfigure = ValueBool(quickconfigure, DefaultConfiguration.URIQuickConfigure); GlobalVars.UserConfiguration.BootstrapperShowUI = ValueBool(bootstrapper, DefaultConfiguration.BootstrapperShowUI); + GlobalVars.UserConfiguration.WebProxyInitialSetupRequired = ValueBool(webproxysetup, DefaultConfiguration.WebProxyInitialSetupRequired); + GlobalVars.UserConfiguration.WebProxyEnabled = ValueBool(webproxy, DefaultConfiguration.WebProxyEnabled); string oldMapath = Path.GetDirectoryName(GlobalVars.UserConfiguration.MapPath); //update the map path if the file doesn't exist and write to config. @@ -1325,6 +1336,9 @@ public class FileManagement public static void ResetConfigValues() #endif { + bool WebProxySetupComplete = GlobalVars.UserConfiguration.WebProxyInitialSetupRequired; + bool WebProxy = GlobalVars.UserConfiguration.WebProxyEnabled; + GlobalVars.UserConfiguration = new FileFormat.Config(); GlobalVars.UserConfiguration.SelectedClient = GlobalVars.ProgramInformation.DefaultClient; GlobalVars.UserConfiguration.Map = GlobalVars.ProgramInformation.DefaultMap; @@ -1333,6 +1347,8 @@ public class FileManagement #if LAUNCHER GlobalVars.UserConfiguration.LauncherStyle = style; #endif + GlobalVars.UserConfiguration.WebProxyInitialSetupRequired = WebProxySetupComplete; + GlobalVars.UserConfiguration.WebProxyEnabled = WebProxy; NovetusFuncs.GeneratePlayerID(); ResetCustomizationValues(); } diff --git a/Novetus/NovetusCore/StorageAndFunctions/Util.cs b/Novetus/NovetusCore/StorageAndFunctions/Util.cs index 42911a7..73bb7cf 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/Util.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/Util.cs @@ -678,42 +678,6 @@ public static class Util return (p <= 0); } - private static void FormPrint(string text, int type, RichTextBox box, bool noTime = false) - { - if (box == null) - return; - - if (!noTime) - { - box.AppendText("[" + DateTime.Now.ToShortTimeString() + "] - ", Color.White); - } - - switch (type) - { - case 1: - box.AppendText(text, Color.White); - break; - case 2: - box.AppendText(text, Color.Red); - break; - case 3: - box.AppendText(text, Color.Lime); - break; - case 4: - box.AppendText(text, Color.Aqua); - break; - case 5: - box.AppendText(text, Color.Yellow); - break; - case 0: - default: - box.AppendText(text, Color.Black); - break; - } - - box.AppendText(Environment.NewLine, Color.White); - } - public static void ConsolePrint(string text, int type = 1, bool notime = false, bool noLog = false) { if (!notime) @@ -762,6 +726,75 @@ public static class Util #endif } + public static void ConsolePrintMultiLine(string text, int type = 1, bool notime = false, bool noLog = false) + { + try + { + string[] NewlineChars = {Environment.NewLine, "\n"}; + string[] lines = text.Split(NewlineChars, StringSplitOptions.None); + ConsolePrintMultiLine(lines, type, notime, noLog); + } + catch (Exception e) + { +#if URI || LAUNCHER || BASICLAUNCHER + LogExceptions(e); +#endif + } + } + + public static void ConsolePrintMultiLine(ICollection textColection, int type = 1, bool notime = false, bool noLog = false) + { + if (!textColection.Any()) + return; + + if (textColection.Count == 1) + { + ConsolePrint(textColection.First(), type, notime, noLog); + return; + } + + foreach (string text in textColection) + { + ConsolePrint(text, type, notime, noLog); + } + } + + private static void FormPrint(string text, int type, RichTextBox box, bool noTime = false) + { + if (box == null) + return; + + if (!noTime) + { + box.AppendText("[" + DateTime.Now.ToShortTimeString() + "] - ", Color.White); + } + + switch (type) + { + case 1: + box.AppendText(text, Color.White); + break; + case 2: + box.AppendText(text, Color.Red); + break; + case 3: + box.AppendText(text, Color.Lime); + break; + case 4: + box.AppendText(text, Color.Aqua); + break; + case 5: + box.AppendText(text, Color.Yellow); + break; + case 0: + default: + box.AppendText(text, Color.Black); + break; + } + + box.AppendText(Environment.NewLine, Color.White); + } + private static void ConsoleText(string text, ConsoleColor color, bool newLine = false) { Console.ForegroundColor = color; diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs index bab066e..7ca63ac 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs @@ -125,6 +125,8 @@ namespace NovetusLauncher { LocalVars.launcherInitState = false; } + + GlobalVars.Proxy.DoSetup(); } public string GetProductVersion() @@ -626,7 +628,7 @@ namespace NovetusLauncher Util.ConsolePrint("Config Saved.", 3); } - public void ResetConfigValues(bool ShowBox = false) + public void ResetConfigValuesInternal() { //https://stackoverflow.com/questions/9029351/close-all-open-forms-except-the-main-menu-in-c-sharp List
openForms = new List(); @@ -636,11 +638,19 @@ namespace NovetusLauncher foreach (Form f in openForms) { + if (f.GetType() == typeof(NovetusConsole)) + continue; + if (f.Name != Parent.Name) f.Close(); } FileManagement.ResetConfigValues(FormStyle); + } + + public void ResetConfigValues(bool ShowBox = false) + { + ResetConfigValuesInternal(); WriteConfigValues(); ReadConfigValues(); if (ShowBox) diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylish.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylish.cs index 6d0dcee..412afbc 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylish.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylish.cs @@ -156,19 +156,7 @@ namespace NovetusLauncher public void ResetConfigValues(bool ShowBox = false) { - //https://stackoverflow.com/questions/9029351/close-all-open-forms-except-the-main-menu-in-c-sharp - List openForms = new List(); - - foreach (Form f in Application.OpenForms) - openForms.Add(f); - - foreach (Form f in openForms) - { - if (f.Name != Name) - f.Close(); - } - - FileManagement.ResetConfigValues(Settings.Style.Stylish); + launcherFormStylishInterface1.launcherForm.ResetConfigValuesInternal(); WriteConfigValues(); ReadConfigValues(); if (ShowBox) diff --git a/Novetus/NovetusLauncher/Forms/NovetusConsole.cs b/Novetus/NovetusLauncher/Forms/NovetusConsole.cs index bad4b05..57096aa 100644 --- a/Novetus/NovetusLauncher/Forms/NovetusConsole.cs +++ b/Novetus/NovetusLauncher/Forms/NovetusConsole.cs @@ -364,20 +364,71 @@ namespace NovetusLauncher if (vals[1].Equals("on", StringComparison.InvariantCultureIgnoreCase)) { + if (GlobalVars.Proxy.HasStarted()) + { + Util.ConsolePrint("The web proxy is already on and running.", 2); + return; + } + + if (GlobalVars.UserConfiguration.WebProxyInitialSetupRequired) + { + // this is wierd and really dumb if we are just using console mode..... + GlobalVars.Proxy.DoSetup(); + } + else + { + if (!GlobalVars.UserConfiguration.WebProxyEnabled) + { + GlobalVars.UserConfiguration.WebProxyEnabled = true; + } + } + GlobalVars.Proxy.Start(); } else if (vals[1].Equals("off", StringComparison.InvariantCultureIgnoreCase)) { + if (!GlobalVars.Proxy.HasStarted()) + { + Util.ConsolePrint("The web proxy is already turned off.", 2); + return; + } + + if (!GlobalVars.UserConfiguration.WebProxyEnabled) + { + Util.ConsolePrint("The web proxy is disabled. Please turn it on in order to use this command.", 2); + return; + } + GlobalVars.Proxy.Stop(); } + else if (vals[1].Equals("disable", StringComparison.InvariantCultureIgnoreCase)) + { + if (!GlobalVars.Proxy.HasStarted() && !GlobalVars.UserConfiguration.WebProxyEnabled) + { + Util.ConsolePrint("The web proxy is already disabled.", 2); + return; + } + + if (GlobalVars.UserConfiguration.WebProxyEnabled) + { + GlobalVars.UserConfiguration.WebProxyEnabled = false; + } + + if (GlobalVars.Proxy.HasStarted()) + { + GlobalVars.Proxy.Stop(); + } + + Util.ConsolePrint("The web proxy has been disabled. To re-enable it, use the 'proxy on' command.", 2); + } else { - Util.ConsolePrint("Please specify 'on' or 'off'.", 2); + Util.ConsolePrint("Please specify 'on', 'off', or 'disable'.", 2); } } catch (Exception) { - Util.ConsolePrint("Please specify 'on' or 'off'.", 2); + Util.ConsolePrint("Please specify 'on' or 'off', or 'disable'.", 2); } break; default: diff --git a/Novetus/NovetusURI/Forms/QuickConfigure.cs b/Novetus/NovetusURI/Forms/QuickConfigure.cs index d85a862..76ba01e 100644 --- a/Novetus/NovetusURI/Forms/QuickConfigure.cs +++ b/Novetus/NovetusURI/Forms/QuickConfigure.cs @@ -22,6 +22,7 @@ namespace NovetusURI { ReadConfigValues(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName); CenterToScreen(); + GlobalVars.Proxy.DoSetup(); } void Button3Click(object sender, EventArgs e)