Add '/blocked_services/services' API
This commit is contained in:
parent
82af43039c
commit
0f2a9f262e
|
@ -1355,6 +1355,19 @@ Internally, all supported services are stored as a map:
|
||||||
service name -> list of rules
|
service name -> list of rules
|
||||||
|
|
||||||
|
|
||||||
|
### API: Get blocked services list of available services
|
||||||
|
|
||||||
|
Request:
|
||||||
|
|
||||||
|
GET /control/blocked_services/services
|
||||||
|
|
||||||
|
Response:
|
||||||
|
|
||||||
|
200 OK
|
||||||
|
|
||||||
|
[ "name1", ... ]
|
||||||
|
|
||||||
|
|
||||||
### API: Get blocked services list
|
### API: Get blocked services list
|
||||||
|
|
||||||
Request:
|
Request:
|
||||||
|
|
|
@ -2,6 +2,21 @@ import { createAction } from 'redux-actions';
|
||||||
import apiClient from '../api/Api';
|
import apiClient from '../api/Api';
|
||||||
import { addErrorToast, addSuccessToast } from './toasts';
|
import { addErrorToast, addSuccessToast } from './toasts';
|
||||||
|
|
||||||
|
export const getBlockedServicesAvailableServicesRequest = createAction('GET_BLOCKED_SERVICES_AVAILABLE_SERVICES_REQUEST');
|
||||||
|
export const getBlockedServicesAvailableServicesFailure = createAction('GET_BLOCKED_SERVICES_AVAILABLE_SERVICES_FAILURE');
|
||||||
|
export const getBlockedServicesAvailableServicesSuccess = createAction('GET_BLOCKED_SERVICES_AVAILABLE_SERVICES_SUCCESS');
|
||||||
|
|
||||||
|
export const getBlockedServicesAvailableServices = () => async (dispatch) => {
|
||||||
|
dispatch(getBlockedServicesAvailableServicesRequest());
|
||||||
|
try {
|
||||||
|
const data = await apiClient.getBlockedServicesAvailableServices();
|
||||||
|
dispatch(getBlockedServicesAvailableServicesSuccess(data));
|
||||||
|
} catch (error) {
|
||||||
|
dispatch(addErrorToast({ error }));
|
||||||
|
dispatch(getBlockedServicesAvailableServicesFailure());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const getBlockedServicesRequest = createAction('GET_BLOCKED_SERVICES_REQUEST');
|
export const getBlockedServicesRequest = createAction('GET_BLOCKED_SERVICES_REQUEST');
|
||||||
export const getBlockedServicesFailure = createAction('GET_BLOCKED_SERVICES_FAILURE');
|
export const getBlockedServicesFailure = createAction('GET_BLOCKED_SERVICES_FAILURE');
|
||||||
export const getBlockedServicesSuccess = createAction('GET_BLOCKED_SERVICES_SUCCESS');
|
export const getBlockedServicesSuccess = createAction('GET_BLOCKED_SERVICES_SUCCESS');
|
||||||
|
|
|
@ -481,10 +481,17 @@ class Api {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blocked services
|
// Blocked services
|
||||||
|
BLOCKED_SERVICES_SERVICES = { path: 'blocked_services/services', method: 'GET' };
|
||||||
|
|
||||||
BLOCKED_SERVICES_LIST = { path: 'blocked_services/list', method: 'GET' };
|
BLOCKED_SERVICES_LIST = { path: 'blocked_services/list', method: 'GET' };
|
||||||
|
|
||||||
BLOCKED_SERVICES_SET = { path: 'blocked_services/set', method: 'POST' };
|
BLOCKED_SERVICES_SET = { path: 'blocked_services/set', method: 'POST' };
|
||||||
|
|
||||||
|
getBlockedServicesAvailableServices() {
|
||||||
|
const { path, method } = this.BLOCKED_SERVICES_SERVICES;
|
||||||
|
return this.makeRequest(path, method);
|
||||||
|
}
|
||||||
|
|
||||||
getBlockedServices() {
|
getBlockedServices() {
|
||||||
const { path, method } = this.BLOCKED_SERVICES_LIST;
|
const { path, method } = this.BLOCKED_SERVICES_LIST;
|
||||||
return this.makeRequest(path, method);
|
return this.makeRequest(path, method);
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
// This file was autogenerated. Please do not change.
|
// This file was autogenerated. Please do not change.
|
||||||
// All changes will be overwrited on commit.
|
// All changes will be overwrited on commit.
|
||||||
export default class BlockedServicesApi {
|
export default class BlockedServicesApi {
|
||||||
|
static async blockedServicesAvailableServices(): Promise<string[] | Error> {
|
||||||
|
return await fetch(`/control/blocked_services/services`, {
|
||||||
|
method: 'GET',
|
||||||
|
}).then(async (res) => {
|
||||||
|
if (res.status === 200) {
|
||||||
|
return res.json();
|
||||||
|
} else {
|
||||||
|
return new Error(String(res.status));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
static async blockedServicesList(): Promise<string[] | Error> {
|
static async blockedServicesList(): Promise<string[] | Error> {
|
||||||
return await fetch(`/control/blocked_services/list`, {
|
return await fetch(`/control/blocked_services/list`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|
|
@ -331,6 +331,21 @@ func (d *DNSFilter) ApplyBlockedServices(setts *Settings, list []string, global
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *DNSFilter) handleBlockedServicesAvailableServices(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var list []string
|
||||||
|
for _, v := range serviceRulesArray {
|
||||||
|
list = append(list, s.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
err := json.NewEncoder(w).Encode(list)
|
||||||
|
if err != nil {
|
||||||
|
aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encode: %s", err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (d *DNSFilter) handleBlockedServicesList(w http.ResponseWriter, r *http.Request) {
|
func (d *DNSFilter) handleBlockedServicesList(w http.ResponseWriter, r *http.Request) {
|
||||||
d.confLock.RLock()
|
d.confLock.RLock()
|
||||||
list := d.Config.BlockedServices
|
list := d.Config.BlockedServices
|
||||||
|
@ -365,6 +380,7 @@ func (d *DNSFilter) handleBlockedServicesSet(w http.ResponseWriter, r *http.Requ
|
||||||
|
|
||||||
// registerBlockedServicesHandlers - register HTTP handlers
|
// registerBlockedServicesHandlers - register HTTP handlers
|
||||||
func (d *DNSFilter) registerBlockedServicesHandlers() {
|
func (d *DNSFilter) registerBlockedServicesHandlers() {
|
||||||
|
d.Config.HTTPRegister(http.MethodGet, "/control/blocked_services/services", d.handleBlockedServicesAvailableServices)
|
||||||
d.Config.HTTPRegister(http.MethodGet, "/control/blocked_services/list", d.handleBlockedServicesList)
|
d.Config.HTTPRegister(http.MethodGet, "/control/blocked_services/list", d.handleBlockedServicesList)
|
||||||
d.Config.HTTPRegister(http.MethodPost, "/control/blocked_services/set", d.handleBlockedServicesSet)
|
d.Config.HTTPRegister(http.MethodPost, "/control/blocked_services/set", d.handleBlockedServicesSet)
|
||||||
}
|
}
|
||||||
|
|
|
@ -874,6 +874,19 @@
|
||||||
'summary': 'Set (dis)allowed clients, blocked hosts, etc.'
|
'summary': 'Set (dis)allowed clients, blocked hosts, etc.'
|
||||||
'tags':
|
'tags':
|
||||||
- 'clients'
|
- 'clients'
|
||||||
|
'/blocked_services/services':
|
||||||
|
'get':
|
||||||
|
'tags':
|
||||||
|
- 'blocked_services'
|
||||||
|
'operationId': 'blockedServicesAvailableServices'
|
||||||
|
'summary': 'Get available services to use for blocking'
|
||||||
|
'responses':
|
||||||
|
'200':
|
||||||
|
'description': 'OK.'
|
||||||
|
'content':
|
||||||
|
'application/json':
|
||||||
|
'schema':
|
||||||
|
'$ref': '#/components/schemas/BlockedServicesArray'
|
||||||
'/blocked_services/list':
|
'/blocked_services/list':
|
||||||
'get':
|
'get':
|
||||||
'tags':
|
'tags':
|
||||||
|
|
Loading…
Reference in New Issue