Skip to content

Commit e35be47

Browse files
Added service start, stop, and restart enpoints for DNS Resolver (unbound), updated pkg-plist and Makefile
1 parent ad01a95 commit e35be47

6 files changed

Lines changed: 145 additions & 0 deletions

File tree

pfSense-pkg-API/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@ do-install:
190190
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/unbound
191191
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/services/unbound/index.php \
192192
${STAGEDIR}${PREFIX}/www/api/v1/services/unbound
193+
# Unbound start
194+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/unbound/start
195+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/services/unbound/start/index.php \
196+
${STAGEDIR}${PREFIX}/www/api/v1/services/unbound/start
197+
# Unbound stop
198+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/unbound/stop
199+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/services/unbound/stop/index.php \
200+
${STAGEDIR}${PREFIX}/www/api/v1/services/unbound/stop
201+
# Unbound restart
202+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/unbound/restart
203+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/services/unbound/restart/index.php \
204+
${STAGEDIR}${PREFIX}/www/api/v1/services/unbound/restart
193205
# Unbound add
194206
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/unbound/add
195207
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/unbound/add/hosts

pfSense-pkg-API/files/etc/inc/api.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ require_once("config.inc");
33
require_once("util.inc");
44
require_once("interfaces.inc");
55
require_once("interfaces_fast.inc");
6+
require_once("service-utils.inc");
67
require_once("filter.inc");
78
require_once("shaper.inc");
89
require_once("auth.inc");
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
// IMPORTS--------------------------------------------------------------------------------------------------------------
4+
require_once("config.inc");
5+
require_once("auth.inc");
6+
require_once("functions.inc");
7+
require_once("api.inc");
8+
9+
// HEADERS--------------------------------------------------------------------------------------------------------------
10+
api_runtime_allowed(); // Check that our configuration allows this API call to run first
11+
header('Content-Type: application/json');
12+
header("Referer: no-referrer");
13+
14+
// VARIABLES------------------------------------------------------------------------------------------------------------
15+
global $config, $api_resp, $client_params;
16+
$read_only_action = true; // Set whether this action requires read only access
17+
$req_privs = array("page-all", "page-services-dnsresolver"); // Array of privs allowed
18+
$http_method = $_SERVER['REQUEST_METHOD']; // Save our HTTP method
19+
$unbound_array = array(); // Init our return array
20+
21+
// RUN TIME-------------------------------------------------------------------------------------------------------------
22+
// Check that client is authenticated and authorized
23+
if (api_authorized($req_privs, $read_only_action)) {
24+
// Check that our HTTP method is POST (UPDATE)
25+
if ($http_method === 'POST') {
26+
$stop_serv = service_control_restart("unbound", []); // Stop our service
27+
// Print our JSON response
28+
$api_resp = array("status" => "ok", "code" => 200, "return" => 0, "message" => "service unbound has been restarted");
29+
http_response_code(200);
30+
echo json_encode($api_resp) . PHP_EOL;
31+
die();
32+
} else {
33+
$api_resp = array("status" => "bad request", "code" => 400, "return" => 2, "message" => "invalid http method");
34+
http_response_code(400);
35+
echo json_encode($api_resp) . PHP_EOL;
36+
die();
37+
}
38+
} else {
39+
http_response_code(401);
40+
echo json_encode($api_resp) . PHP_EOL;
41+
die();
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
// IMPORTS--------------------------------------------------------------------------------------------------------------
4+
require_once("config.inc");
5+
require_once("auth.inc");
6+
require_once("functions.inc");
7+
require_once("api.inc");
8+
9+
// HEADERS--------------------------------------------------------------------------------------------------------------
10+
api_runtime_allowed(); // Check that our configuration allows this API call to run first
11+
header('Content-Type: application/json');
12+
header("Referer: no-referrer");
13+
14+
// VARIABLES------------------------------------------------------------------------------------------------------------
15+
global $config, $api_resp, $client_params;
16+
$read_only_action = true; // Set whether this action requires read only access
17+
$req_privs = array("page-all", "page-services-dnsresolver"); // Array of privs allowed
18+
$http_method = $_SERVER['REQUEST_METHOD']; // Save our HTTP method
19+
$unbound_array = array(); // Init our return array
20+
21+
// RUN TIME-------------------------------------------------------------------------------------------------------------
22+
// Check that client is authenticated and authorized
23+
if (api_authorized($req_privs, $read_only_action)) {
24+
// Check that our HTTP method is POST (UPDATE)
25+
if ($http_method === 'POST') {
26+
$stop_serv = service_control_start("unbound", []); // Stop our service
27+
// Print our JSON response
28+
$api_resp = array("status" => "ok", "code" => 200, "return" => 0, "message" => "service unbound has been started");
29+
http_response_code(200);
30+
echo json_encode($api_resp) . PHP_EOL;
31+
die();
32+
} else {
33+
$api_resp = array("status" => "bad request", "code" => 400, "return" => 2, "message" => "invalid http method");
34+
http_response_code(400);
35+
echo json_encode($api_resp) . PHP_EOL;
36+
die();
37+
}
38+
} else {
39+
http_response_code(401);
40+
echo json_encode($api_resp) . PHP_EOL;
41+
die();
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
// IMPORTS--------------------------------------------------------------------------------------------------------------
4+
require_once("config.inc");
5+
require_once("auth.inc");
6+
require_once("functions.inc");
7+
require_once("api.inc");
8+
9+
// HEADERS--------------------------------------------------------------------------------------------------------------
10+
api_runtime_allowed(); // Check that our configuration allows this API call to run first
11+
header('Content-Type: application/json');
12+
header("Referer: no-referrer");
13+
14+
// VARIABLES------------------------------------------------------------------------------------------------------------
15+
global $config, $api_resp, $client_params;
16+
$read_only_action = true; // Set whether this action requires read only access
17+
$req_privs = array("page-all", "page-services-dnsresolver"); // Array of privs allowed
18+
$http_method = $_SERVER['REQUEST_METHOD']; // Save our HTTP method
19+
$unbound_array = array(); // Init our return array
20+
21+
// RUN TIME-------------------------------------------------------------------------------------------------------------
22+
// Check that client is authenticated and authorized
23+
if (api_authorized($req_privs, $read_only_action)) {
24+
// Check that our HTTP method is POST (UPDATE)
25+
if ($http_method === 'POST') {
26+
$stop_serv = service_control_stop("unbound", []); // Stop our service
27+
// Print our JSON response
28+
$api_resp = array("status" => "ok", "code" => 200, "return" => 0, "message" => "service unbound has been stopped");
29+
http_response_code(200);
30+
echo json_encode($api_resp) . PHP_EOL;
31+
die();
32+
} else {
33+
$api_resp = array("status" => "bad request", "code" => 400, "return" => 2, "message" => "invalid http method");
34+
http_response_code(400);
35+
echo json_encode($api_resp) . PHP_EOL;
36+
die();
37+
}
38+
} else {
39+
http_response_code(401);
40+
echo json_encode($api_resp) . PHP_EOL;
41+
die();
42+
}

pfSense-pkg-API/pkg-plist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,16 @@
9191
@dir /usr/local/www/api/v1/services/unbound/add
9292
@dir /usr/local/www/api/v1/services/unbound/delete
9393
@dir /usr/local/www/api/v1/services/unbound/modify
94+
@dir /usr/local/www/api/v1/services/unbound/start
95+
@dir /usr/local/www/api/v1/services/unbound/stop
96+
@dir /usr/local/www/api/v1/services/unbound/restart
9497
@dir /usr/local/www/api/v1/services/unbound/add/hosts
9598
@dir /usr/local/www/api/v1/services/unbound/delete/hosts
9699
@dir /usr/local/www/api/v1/services/unbound/modify/hosts
97100
/usr/local/www/api/v1/services/unbound/index.php
101+
/usr/local/www/api/v1/services/unbound/start/index.php
102+
/usr/local/www/api/v1/services/unbound/stop/index.php
103+
/usr/local/www/api/v1/services/unbound/restart/index.php
98104
/usr/local/www/api/v1/services/unbound/add/hosts/index.php
99105
/usr/local/www/api/v1/services/unbound/delete/hosts/index.php
100106
/usr/local/www/api/v1/services/unbound/modify/hosts/index.php

0 commit comments

Comments
 (0)