Skip to content

Commit 27daff6

Browse files
committed
* **API.Utility.GetIP** method fixed when HttpContext.Current is null and the IPHostEntry is used instead
* Under maintenance flag implemented in order to disconnect the JSON-RPC listener when the system is under maintenance. * Add the application setting **API_JSONRPC_MAINTENANCE** in the `Web.config` ```xml <!-- JSONRPC - Maintenance flag [TRUE, FALSE] --> <add key="API_JSONRPC_MAINTENANCE" value="FALSE" /> ```
1 parent cf6902b commit 27daff6

File tree

17 files changed

+49
-13
lines changed

17 files changed

+49
-13
lines changed

rls/API.Library.dll

512 Bytes
Binary file not shown.

rls/API.Library.dll.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
**********************************************************************
2121
-->
2222

23+
<!-- JSONRPC - Maintenance flag [TRUE, FALSE] -->
24+
<add key="API_JSONRPC_MAINTENANCE" value="FALSE" />
2325
<!-- JSONRPC - Success response (case sensitive) -->
2426
<add key="API_JSONRPC_SUCCESS" value="success" />
2527
<!-- JSONRPC - Windows Authentication [ANONYMOUS, WINDOWS, ANY] -->

rls/API.Library.pdb

0 Bytes
Binary file not shown.

src/API.Library/App.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
**********************************************************************
2121
-->
2222

23+
<!-- JSONRPC - Maintenance flag [TRUE, FALSE] -->
24+
<add key="API_JSONRPC_MAINTENANCE" value="FALSE" />
2325
<!-- JSONRPC - Success response (case sensitive) -->
2426
<add key="API_JSONRPC_SUCCESS" value="success" />
2527
<!-- JSONRPC - Windows Authentication [ANONYMOUS, WINDOWS, ANY] -->

src/API.Library/Entities/JSONRPC.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public class JSONRPC : IHttpHandler, IRequiresSessionState
5959
/// </summary>
6060
private dynamic userPrincipal = null;
6161

62+
/// <summary>
63+
/// Maintenance flag
64+
/// </summary>
65+
public static bool maintenance = Convert.ToBoolean(ConfigurationManager.AppSettings["API_JSONRPC_MAINTENANCE"]);
66+
6267
/// <summary>
6368
/// Successfull response (case sensitive)
6469
/// </summary>
@@ -70,7 +75,7 @@ public class JSONRPC : IHttpHandler, IRequiresSessionState
7075
private static string API_JSONRPC_AUTHENTICATION_TYPE = ConfigurationManager.AppSettings["API_JSONRPC_AUTHENTICATION_TYPE"];
7176

7277
/// <summary>
73-
/// Stateless
78+
/// Stateless flag
7479
/// </summary>
7580
private static bool API_JSONRPC_STATELESS = Convert.ToBoolean(ConfigurationManager.AppSettings["API_JSONRPC_STATELESS"]);
7681

@@ -130,6 +135,13 @@ public void ProcessRequest(HttpContext context)
130135
// Set CacheControl to no-cache
131136
context.Response.CacheControl = "no-cache";
132137

138+
// Check for the maintenance flag
139+
if (maintenance)
140+
{
141+
JSONRPC_Error error = new JSONRPC_Error { code = -32001, data = "The system is currently under maintenance. \r\nPlease try again later." };
142+
this.ParseError(ref context, null, error);
143+
}
144+
133145
// Deserialize and parse the JSON request into an Object dynamically
134146
JSONRPC_Request JSONRPC_Request = this.ParseRequest(ref context);
135147

@@ -196,6 +208,9 @@ private void ParseError(ref HttpContext context, object id, JSONRPC_Error error)
196208
case -32000:
197209
error.message = "Invalid version";
198210
break;
211+
case -32001:
212+
error.message = "System maintenance";
213+
break;
199214
case -32002:
200215
error.message = "Invalid authentication";
201216
break;

src/API.Library/Entities/Utility.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ private static string GetIP()
109109

110110
try
111111
{
112+
// check if this is a HTTP request
113+
if (HttpContext.Current == null)
114+
{
115+
// Look for the Network Host information
116+
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
117+
ipAddress = Convert.ToString(ipHostInfo.AddressList.FirstOrDefault(address => address.AddressFamily == AddressFamily.InterNetwork));
118+
119+
Log.Instance.Info("IP Address (IPHostEntry): " + ipAddress);
120+
return ipAddress;
121+
}
122+
112123
// Look for the Server Variable HTTP_X_FORWARDED_FOR
113124
ipAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
114125
if (IPAddress.TryParse(ipAddress, out ip))
@@ -125,12 +136,7 @@ private static string GetIP()
125136
return ipAddress;
126137
}
127138

128-
// Look for the Network Host information
129-
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
130-
ipAddress = Convert.ToString(ipHostInfo.AddressList.FirstOrDefault(address => address.AddressFamily == AddressFamily.InterNetwork));
131-
132-
Log.Instance.Info("IP Address (IPHostEntry): " + ipAddress);
133-
return ipAddress;
139+
throw new Exception("IP Address not found");
134140
}
135141
catch (Exception e)
136142
{

src/API.Library/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("4.0.0.0")]
36-
[assembly: AssemblyFileVersion("4.0.0.0")]
35+
[assembly: AssemblyVersion("4.0.1")]
36+
[assembly: AssemblyFileVersion("4.0.1")]
3737

3838
// Configure log4net using the Web.config file by default
3939
[assembly: log4net.Config.XmlConfigurator(Watch = true)]

test/API.Test/API.Test.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<NuGetPackageImportStamp>
2626
</NuGetPackageImportStamp>
2727
<TargetFrameworkProfile />
28+
<Use64BitIISExpress />
2829
</PropertyGroup>
2930
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
3031
<DebugSymbols>true</DebugSymbols>
@@ -71,9 +72,9 @@
7172
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
7273
</PropertyGroup>
7374
<ItemGroup>
74-
<Reference Include="API.Library, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
75+
<Reference Include="API.Library, Version=4.0.1, Culture=neutral, processorArchitecture=MSIL">
7576
<SpecificVersion>False</SpecificVersion>
76-
<HintPath>..\packages\API.Library.4.0.0\API.Library.dll</HintPath>
77+
<HintPath>..\packages\API.Library.4.0.1\API.Library.dll</HintPath>
7778
</Reference>
7879
<Reference Include="Enyim.Caching, Version=2.16.0.0, Culture=neutral, PublicKeyToken=cec98615db04012e, processorArchitecture=MSIL">
7980
<HintPath>..\packages\EnyimMemcached.2.16.0\lib\net35\Enyim.Caching.dll</HintPath>

test/API.Test/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
//
3232
// You can specify all the values or you can default the Revision and Build Numbers
3333
// by using the '*' as shown below:
34-
[assembly: AssemblyVersion("4.0.0.0")]
35-
[assembly: AssemblyFileVersion("4.0.0.0")]
34+
[assembly: AssemblyVersion("4.0.1")]
35+
[assembly: AssemblyFileVersion("4.0.1")]

test/API.Test/Web.Live.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
**********************************************************************
6666
-->
6767

68+
<!-- JSONRPC - Maintenance flag [TRUE, FALSE] -->
69+
<add key="API_JSONRPC_MAINTENANCE" value="FALSE" />
6870
<!-- JSONRPC - Success response (case sensitive) -->
6971
<add key="API_JSONRPC_SUCCESS" value="success" />
7072
<!-- JSONRPC - Windows Authentication [ANONYMOUS, WINDOWS, ANY] -->

0 commit comments

Comments
 (0)