@@ -129,47 +129,110 @@ private async Task ListenForCommandsAsync()
129129 }
130130 }
131131
132- private Response ProcessCommand ( Command command )
132+ private Response ProcessCommand ( Command command )
133+ {
134+ Console . WriteLine ( $ "Processing command: { command . Action } ") ;
135+ try
136+ {
137+ switch ( command . Action . ToLower ( ) )
138+ {
139+ case "getappid" :
140+ return GetAppId ( command . Parameters [ "appPath" ] ) ;
141+ case "getfilternames" :
142+ return GetFilterNames ( ) ;
143+ case "getconnections" :
144+ return GetConnections ( command . Parameters [ "appId" ] ) ;
145+
146+ case "getfilterobject" :
147+ return GetFilterObject ( command . Parameters [ "filterName" ] ) ;
148+ case "getfilterips" :
149+ return GetFilterIpAddresses ( command . Parameters [ "filterName" ] ) ;
150+ case "addiptofilter" :
151+ return AddIpToFilter ( command . Parameters [ "filterName" ] , command . Parameters [ "ipAddress" ] ) ;
152+
153+ case "removeipfromfilter" :
154+ return RemoveIpFromFilter ( command . Parameters [ "filterName" ] , command . Parameters [ "ipAddress" ] ) ;
155+
156+ case "setconnectionlimit" :
157+ return SetConnectionLimit ( int . Parse ( command . Parameters [ "limit" ] ) ) ;
158+
159+ case "enableconnectionlimit" :
160+ return EnableConnectionLimit ( bool . Parse ( command . Parameters [ "enabled" ] ) ) ;
161+
162+ case "endprogram" :
163+ return EndProgram ( ) ;
164+
165+ default :
166+ return new Response { Success = false , Message = "Unknown command" } ;
167+ }
168+ }
169+ catch ( Exception ex )
170+ {
171+ return new Response { Success = false , Message = ex . Message } ;
172+ }
173+ }
174+
175+ private Response GetFilterNames ( )
133176 {
134- Console . WriteLine ( $ "Processing command: { command . Action } ") ;
135177 try
136- {
137- switch ( command . Action . ToLower ( ) )
138- {
139- case "getappid" :
140- return GetAppId ( command . Parameters [ "appPath" ] ) ;
141-
142- case "getconnections" :
143- return GetConnections ( command . Parameters [ "appId" ] ) ;
144-
145- case "getfilterobject" :
146- return GetFilterObject ( command . Parameters [ "filterName" ] ) ;
147-
148- case "addiptofilter" :
149- return AddIpToFilter ( command . Parameters [ "filterName" ] , command . Parameters [ "ipAddress" ] ) ;
150-
151- case "removeipfromfilter" :
152- return RemoveIpFromFilter ( command . Parameters [ "filterName" ] , command . Parameters [ "ipAddress" ] ) ;
178+ {
179+ var filters = _client . Filters ;
180+ var filterNames = filters . Select ( f => f . Name ) . ToList ( ) ;
153181
154- case "setconnectionlimit" :
155- return SetConnectionLimit ( int . Parse ( command . Parameters [ "limit" ] ) ) ;
182+ return new Response
183+ {
184+ Success = true ,
185+ Data = filterNames ,
186+ Message = $ "Found { filterNames . Count } filter(s)"
187+ } ;
188+ }
189+ catch ( Exception ex )
190+ {
191+ return new Response { Success = false , Message = ex . Message } ;
192+ }
193+ }
156194
157- case "enableconnectionlimit" :
158- return EnableConnectionLimit ( bool . Parse ( command . Parameters [ "enabled" ] ) ) ;
195+ private Response GetFilterIpAddresses ( string filterName )
196+ {
197+ try
198+ {
199+ var filters = _client . Filters ;
200+ var filter = _client . Filters . FirstOrDefault ( f => f . Name == filterName ) ;
159201
160- case "endprogram" :
161- return EndProgram ( ) ;
202+ if ( filter != null )
203+ {
204+ var remoteAddressFilter = filter . Functions
205+ . OfType < FFRemoteAddressInRange > ( )
206+ . FirstOrDefault ( ) ;
207+
208+ if ( remoteAddressFilter == null )
209+ {
210+ return new Response { Success = false , Message = "No existing 'Remote address in range' function found." } ;
211+ }
212+
213+ var ipAddresses = remoteAddressFilter . Values
214+ . Select ( range => new
215+ {
216+ Start = range . Range . Start . ToString ( ) ,
217+ End = range . Range . End . ToString ( )
218+ } )
219+ . ToList ( ) ;
220+
221+ return new Response
222+ {
223+ Success = true ,
224+ Data = ipAddresses ,
225+ Message = $ "Found { ipAddresses . Count } IP address range(s)"
226+ } ;
227+ }
162228
163- default :
164- return new Response { Success = false , Message = "Unknown command" } ;
165- }
166- }
167- catch ( Exception ex )
168- {
169- return new Response { Success = false , Message = ex . Message } ;
170- }
229+ return new Response { Success = false , Message = "Filter not found" } ;
230+ }
231+ catch ( Exception ex )
232+ {
233+ return new Response { Success = false , Message = ex . Message } ;
234+ }
171235 }
172-
173236 private Response GetAppId ( string appPath )
174237 {
175238 try
0 commit comments