Skip to content

Commit a0fd778

Browse files
Added start, stop, and restart service endpoints for dhcpd and sshd. Updated pkg-plist and Makefile.
1 parent e57ec3a commit a0fd778

11 files changed

Lines changed: 290 additions & 5 deletions

File tree

pfSense-pkg-API/Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,34 @@ do-install:
189189
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services
190190
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/services/index.php \
191191
${STAGEDIR}${PREFIX}/www/api/v1/services
192+
# DHCPD base
193+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/dhcpd
194+
# DHCPD start
195+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/dhcpd/start
196+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/services/dhcpd/start/index.php \
197+
${STAGEDIR}${PREFIX}/www/api/v1/services/dhcpd/start
198+
# DHCPD stop
199+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/dhcpd/stop
200+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/services/dhcpd/stop/index.php \
201+
${STAGEDIR}${PREFIX}/www/api/v1/services/dhcpd/stop
202+
# DHCPD restart
203+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/dhcpd/restart
204+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/services/dhcpd/restart/index.php \
205+
${STAGEDIR}${PREFIX}/www/api/v1/services/dhcpd/restart
206+
# SSHD base
207+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/sshd
208+
# SSHD start
209+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/sshd/start
210+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/services/sshd/start/index.php \
211+
${STAGEDIR}${PREFIX}/www/api/v1/services/sshd/start
212+
# SSHD stop
213+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/sshd/stop
214+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/services/sshd/stop/index.php \
215+
${STAGEDIR}${PREFIX}/www/api/v1/services/sshd/stop
216+
# SSHD restart
217+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/sshd/restart
218+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/services/sshd/restart/index.php \
219+
${STAGEDIR}${PREFIX}/www/api/v1/services/sshd/restart
192220
# Unbound base
193221
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/services/unbound
194222
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/services/unbound/index.php \
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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-dhcp"); // Array of privs allowed
18+
$http_method = $_SERVER['REQUEST_METHOD']; // Save our HTTP method
19+
20+
// RUN TIME-------------------------------------------------------------------------------------------------------------
21+
// Check that client is authenticated and authorized
22+
if (api_authorized($req_privs, $read_only_action)) {
23+
// Check that our HTTP method is POST (UPDATE)
24+
if ($http_method === 'POST') {
25+
$stop_serv = service_control_restart("dhcpd", []); // Restart our service
26+
// Print our JSON response
27+
$api_resp = array("status" => "ok", "code" => 200, "return" => 0, "message" => "service dhcpd has been restarted");
28+
http_response_code(200);
29+
echo json_encode($api_resp) . PHP_EOL;
30+
die();
31+
} else {
32+
$api_resp = array("status" => "bad request", "code" => 400, "return" => 2, "message" => "invalid http method");
33+
http_response_code(400);
34+
echo json_encode($api_resp) . PHP_EOL;
35+
die();
36+
}
37+
} else {
38+
http_response_code(401);
39+
echo json_encode($api_resp) . PHP_EOL;
40+
die();
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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-dhcp"); // Array of privs allowed
18+
$http_method = $_SERVER['REQUEST_METHOD']; // Save our HTTP method
19+
20+
// RUN TIME-------------------------------------------------------------------------------------------------------------
21+
// Check that client is authenticated and authorized
22+
if (api_authorized($req_privs, $read_only_action)) {
23+
// Check that our HTTP method is POST (UPDATE)
24+
if ($http_method === 'POST') {
25+
$stop_serv = service_control_start("dhcpd", []); // Start our service
26+
// Print our JSON response
27+
$api_resp = array("status" => "ok", "code" => 200, "return" => 0, "message" => "service dhcpd has been started");
28+
http_response_code(200);
29+
echo json_encode($api_resp) . PHP_EOL;
30+
die();
31+
} else {
32+
$api_resp = array("status" => "bad request", "code" => 400, "return" => 2, "message" => "invalid http method");
33+
http_response_code(400);
34+
echo json_encode($api_resp) . PHP_EOL;
35+
die();
36+
}
37+
} else {
38+
http_response_code(401);
39+
echo json_encode($api_resp) . PHP_EOL;
40+
die();
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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-dhcp"); // Array of privs allowed
18+
$http_method = $_SERVER['REQUEST_METHOD']; // Save our HTTP method
19+
20+
// RUN TIME-------------------------------------------------------------------------------------------------------------
21+
// Check that client is authenticated and authorized
22+
if (api_authorized($req_privs, $read_only_action)) {
23+
// Check that our HTTP method is POST (UPDATE)
24+
if ($http_method === 'POST') {
25+
$stop_serv = service_control_stop("dhcpd", []); // Stop our service
26+
// Print our JSON response
27+
$api_resp = array("status" => "ok", "code" => 200, "return" => 0, "message" => "service dhcpd has been stopped");
28+
http_response_code(200);
29+
echo json_encode($api_resp) . PHP_EOL;
30+
die();
31+
} else {
32+
$api_resp = array("status" => "bad request", "code" => 400, "return" => 2, "message" => "invalid http method");
33+
http_response_code(400);
34+
echo json_encode($api_resp) . PHP_EOL;
35+
die();
36+
}
37+
} else {
38+
http_response_code(401);
39+
echo json_encode($api_resp) . PHP_EOL;
40+
die();
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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-status-services"); // Array of privs allowed
18+
$http_method = $_SERVER['REQUEST_METHOD']; // Save our HTTP method
19+
20+
// RUN TIME-------------------------------------------------------------------------------------------------------------
21+
// Check that client is authenticated and authorized
22+
if (api_authorized($req_privs, $read_only_action)) {
23+
// Check that our HTTP method is POST (UPDATE)
24+
if ($http_method === 'POST') {
25+
$stop_serv = service_control_restart("sshd", []); // Restart our service
26+
// Print our JSON response
27+
$api_resp = array("status" => "ok", "code" => 200, "return" => 0, "message" => "service sshd has been restarted");
28+
http_response_code(200);
29+
echo json_encode($api_resp) . PHP_EOL;
30+
die();
31+
} else {
32+
$api_resp = array("status" => "bad request", "code" => 400, "return" => 2, "message" => "invalid http method");
33+
http_response_code(400);
34+
echo json_encode($api_resp) . PHP_EOL;
35+
die();
36+
}
37+
} else {
38+
http_response_code(401);
39+
echo json_encode($api_resp) . PHP_EOL;
40+
die();
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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-status-services"); // Array of privs allowed
18+
$http_method = $_SERVER['REQUEST_METHOD']; // Save our HTTP method
19+
20+
// RUN TIME-------------------------------------------------------------------------------------------------------------
21+
// Check that client is authenticated and authorized
22+
if (api_authorized($req_privs, $read_only_action)) {
23+
// Check that our HTTP method is POST (UPDATE)
24+
if ($http_method === 'POST') {
25+
$stop_serv = service_control_start("sshd", []); // Start our service
26+
// Print our JSON response
27+
$api_resp = array("status" => "ok", "code" => 200, "return" => 0, "message" => "service sshd has been started");
28+
http_response_code(200);
29+
echo json_encode($api_resp) . PHP_EOL;
30+
die();
31+
} else {
32+
$api_resp = array("status" => "bad request", "code" => 400, "return" => 2, "message" => "invalid http method");
33+
http_response_code(400);
34+
echo json_encode($api_resp) . PHP_EOL;
35+
die();
36+
}
37+
} else {
38+
http_response_code(401);
39+
echo json_encode($api_resp) . PHP_EOL;
40+
die();
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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-status-services"); // Array of privs allowed
18+
$http_method = $_SERVER['REQUEST_METHOD']; // Save our HTTP method
19+
20+
// RUN TIME-------------------------------------------------------------------------------------------------------------
21+
// Check that client is authenticated and authorized
22+
if (api_authorized($req_privs, $read_only_action)) {
23+
// Check that our HTTP method is POST (UPDATE)
24+
if ($http_method === 'POST') {
25+
$stop_serv = service_control_stop("sshd", []); // Stop our service
26+
// Print our JSON response
27+
$api_resp = array("status" => "ok", "code" => 200, "return" => 0, "message" => "service sshd has been stopped");
28+
http_response_code(200);
29+
echo json_encode($api_resp) . PHP_EOL;
30+
die();
31+
} else {
32+
$api_resp = array("status" => "bad request", "code" => 400, "return" => 2, "message" => "invalid http method");
33+
http_response_code(400);
34+
echo json_encode($api_resp) . PHP_EOL;
35+
die();
36+
}
37+
} else {
38+
http_response_code(401);
39+
echo json_encode($api_resp) . PHP_EOL;
40+
die();
41+
}

pfSense-pkg-API/files/usr/local/www/api/v1/services/unbound/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
$read_only_action = true; // Set whether this action requires read only access
1717
$req_privs = array("page-all", "page-services-dnsresolver"); // Array of privs allowed
1818
$http_method = $_SERVER['REQUEST_METHOD']; // Save our HTTP method
19-
$unbound_array = array(); // Init our return array
2019

2120
// RUN TIME-------------------------------------------------------------------------------------------------------------
2221
// Check that client is authenticated and authorized

pfSense-pkg-API/files/usr/local/www/api/v1/services/unbound/restart/index.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
$read_only_action = true; // Set whether this action requires read only access
1717
$req_privs = array("page-all", "page-services-dnsresolver"); // Array of privs allowed
1818
$http_method = $_SERVER['REQUEST_METHOD']; // Save our HTTP method
19-
$unbound_array = array(); // Init our return array
2019

2120
// RUN TIME-------------------------------------------------------------------------------------------------------------
2221
// Check that client is authenticated and authorized
2322
if (api_authorized($req_privs, $read_only_action)) {
2423
// Check that our HTTP method is POST (UPDATE)
2524
if ($http_method === 'POST') {
26-
$stop_serv = service_control_restart("unbound", []); // Stop our service
25+
$stop_serv = service_control_restart("unbound", []); // Restart our service
2726
// Print our JSON response
2827
$api_resp = array("status" => "ok", "code" => 200, "return" => 0, "message" => "service unbound has been restarted");
2928
http_response_code(200);

pfSense-pkg-API/files/usr/local/www/api/v1/services/unbound/start/index.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
$read_only_action = true; // Set whether this action requires read only access
1717
$req_privs = array("page-all", "page-services-dnsresolver"); // Array of privs allowed
1818
$http_method = $_SERVER['REQUEST_METHOD']; // Save our HTTP method
19-
$unbound_array = array(); // Init our return array
2019

2120
// RUN TIME-------------------------------------------------------------------------------------------------------------
2221
// Check that client is authenticated and authorized
2322
if (api_authorized($req_privs, $read_only_action)) {
2423
// Check that our HTTP method is POST (UPDATE)
2524
if ($http_method === 'POST') {
26-
$stop_serv = service_control_start("unbound", []); // Stop our service
25+
$stop_serv = service_control_start("unbound", []); // Start our service
2726
// Print our JSON response
2827
$api_resp = array("status" => "ok", "code" => 200, "return" => 0, "message" => "service unbound has been started");
2928
http_response_code(200);

0 commit comments

Comments
 (0)