From f949738db9de29020a597cb6ed16aa96b307bafa Mon Sep 17 00:00:00 2001 From: high Date: Mon, 5 Sep 2011 14:33:37 -0400 Subject: [PATCH] Added config options for RestApi -IP now changes RestApi listening ip. --- TShockAPI/ConfigFile.cs | 6 ++++++ TShockAPI/Rest/SecureRest.cs | 6 ++++-- TShockAPI/TShock.cs | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index ed142ff0..27cb2b9d 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -193,6 +193,12 @@ namespace TShockAPI [Description("This is used when the API endpoint /status is queried.")] public string ServerNickname = "TShock Server"; + [Description("Enable/Disable the rest api.")] + public bool RestApiEnabled = true; + + [Description("This is the port which the rest api will listen on.")] + public int RestApiPort = 8080; + public static ConfigFile Read(string path) { if (!File.Exists(path)) diff --git a/TShockAPI/Rest/SecureRest.cs b/TShockAPI/Rest/SecureRest.cs index ec7440d2..4d77c9b9 100644 --- a/TShockAPI/Rest/SecureRest.cs +++ b/TShockAPI/Rest/SecureRest.cs @@ -58,11 +58,11 @@ namespace Rests string hash; var rand = new Random(); - var randbytes = new byte[20]; + var randbytes = new byte[32]; do { rand.NextBytes(randbytes); - hash = Tools.HashPassword(randbytes); + hash = randbytes.Aggregate("", (s, b) => s + b.ToString("X2")); } while (Tokens.ContainsKey(hash)); Tokens.Add(hash, user); @@ -71,6 +71,8 @@ namespace Rests return obj; } + + protected override object ExecuteCommand(RestCommand cmd, RestVerbs verbs, IParameterCollection parms) { if (cmd.RequiesToken) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index d4ff9dab..6b1140c3 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -179,6 +179,7 @@ namespace TShockAPI RememberedPos = new RemeberedPosManager(DB); RestApi = new SecureRest(IPAddress.Any, 8080); RestApi.Verify += RestApi_Verify; + RestApi.Port = Config.RestApiPort; RestManager = new RestManager(RestApi); RestManager.RegisterRestfulCommands(); if (Config.EnableGeoIP) @@ -307,6 +308,7 @@ namespace TShockAPI if (IPAddress.TryParse(parms[++i], out ip)) { Netplay.serverListenIP = ip; + RestApi.Ip = ip; Console.Write("Using IP: {0}", ip); } else @@ -384,7 +386,8 @@ namespace TShockAPI AuthToken = 0; } Regions.ReloadAllRegions(); - RestApi.Start(); + if (Config.RestApiEnabled) + RestApi.Start(); }