Skip to content

Commit

Permalink
added setting to bind the API on any IP instead of just the local IP
Browse files Browse the repository at this point in the history
  • Loading branch information
msarilar committed Feb 26, 2020
1 parent 0c8e582 commit 12f5fdb
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 4 deletions.
7 changes: 5 additions & 2 deletions EDEngineer.Server/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ let start (token,
shopppingLists:Func<IDictionary<string, List<Tuple<Blueprint, int>>>>,
changeShoppingList:Action<string, Blueprint, int>,
jsonSettingsGetter:Func<string, JsonSerializerSettings>,
logDirectory:string) =
logDirectory:string,
accessApiFromOtherComputers:bool) =

let corsConfig = {
defaultCORSConfig with
Expand Down Expand Up @@ -361,8 +362,10 @@ let start (token,
>=> addHeader "Access-Control-Allow-Origin" "*"
>=> cors corsConfig

let bindingIp = if accessApiFromOtherComputers then System.Net.IPAddress.Any else System.Net.IPAddress.Loopback

startWebServer {
defaultConfig with
cancellationToken = token
bindings = [ HttpBinding.createSimple HTTP "127.0.0.1" port ] } app
bindings = [ HttpBinding.create HTTP bindingIp port ] } app
state
3 changes: 3 additions & 0 deletions EDEngineer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
<setting name="ClearAggregation" serializeAs="String">
<value>False</value>
</setting>
<setting name="AccessApiFromOtherComputers" serializeAs="String">
<value>False</value>
</setting>
</EDEngineer.Properties.Settings>
</userSettings>
</configuration>
12 changes: 12 additions & 0 deletions EDEngineer/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions EDEngineer/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,8 @@
<Setting Name="ClearAggregation" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="AccessApiFromOtherComputers" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
9 changes: 9 additions & 0 deletions EDEngineer/Resources/Data/localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -5550,6 +5550,15 @@
"ru": "Экспорт/Импорт настроек",
"pl": "Eksportuj/Importuj Ustawienia",
"cs": "Exportuj/importuj nastavení"
},
"Access API from other computers? (tick only if you know what you're doing)": {
"es": null,
"pt": null,
"de": null,
"fr": null,
"ru": null,
"pl": null,
"cs": null
}
}
}
3 changes: 2 additions & 1 deletion EDEngineer/Utils/System/ServerBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ private void Start(ushort? autoRunPort = null)
() => viewModel.Commanders.ToDictionary(kv => kv.Key, kv => kv.Value.ShoppingList.Composition),
(c, b, i) => viewModel.Commanders[c].ShoppingListChange(b, i),
c => viewModel.Commanders[c].JsonSettings,
viewModel.LogDirectory);
viewModel.LogDirectory,
SettingsManager.AccessApiFromOtherComputers);
}, cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default)
.ContinueWith(t =>
{
Expand Down
10 changes: 10 additions & 0 deletions EDEngineer/Utils/System/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ public static bool AutoRunServer
}
}

public static bool AccessApiFromOtherComputers
{
get => Properties.Settings.Default.AccessApiFromOtherComputers;
set
{
Properties.Settings.Default.AccessApiFromOtherComputers = value;
Properties.Settings.Default.Save();
}
}

public static int CargoTabIndex
{
get => Properties.Settings.Default.CargoTabIndex;
Expand Down
13 changes: 12 additions & 1 deletion EDEngineer/Utils/UI/ServerPortPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ public static bool ShowDialog(ushort current, out ushort port)
Dock = DockStyle.Top
};

var accessApiFromOtherComputersBox = new CheckBox
{
Checked = SettingsManager.AccessApiFromOtherComputers,
Height = 50,
Text = translator.Translate(
"Access API from other computers? (tick only if you know what you're doing)"),
Dock = DockStyle.Top
};

var textBox = new NumericUpDown
{
TextAlign = HorizontalAlignment.Center,
Expand Down Expand Up @@ -69,13 +78,14 @@ public static bool ShowDialog(ushort current, out ushort port)
{
FormBorderStyle = FormBorderStyle.FixedToolWindow,
Width = 400,
Height = textBox.Height + autoRunBox.Height + buttonsPanel.Height + 30,
Height = textBox.Height + autoRunBox.Height + accessApiFromOtherComputersBox.Height + buttonsPanel.Height + 30,
Text = translator.Translate("Select the port for the local API server"),
TopMost = true,
AcceptButton = buttonOk,
CancelButton = buttonCancel
};

f.Controls.Add(accessApiFromOtherComputersBox);
f.Controls.Add(autoRunBox);
f.Controls.Add(textBox);
f.Controls.Add(buttonsPanel);
Expand All @@ -85,6 +95,7 @@ public static bool ShowDialog(ushort current, out ushort port)
if (ushort.TryParse(textBox.Text, out port))
{
SettingsManager.AutoRunServer = autoRunBox.Checked;
SettingsManager.AccessApiFromOtherComputers = accessApiFromOtherComputersBox.Checked;
return true;
}
}
Expand Down

0 comments on commit 12f5fdb

Please sign in to comment.