Skip to content

Commit a315916

Browse files
- Added functions to check authentication server configuration
- Added API call to add LDAP authentication server - Added API call to delete LDAP authentication server - Added API call to delete RADIUS authentication server - Added API call to delete any authentication server - Update pkg-plist and Makefile
1 parent bc7cfa7 commit a315916

9 files changed

Lines changed: 471 additions & 22 deletions

File tree

pfSense-pkg-API/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,30 @@ do-install:
7575
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/users/authservers
7676
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/users/authservers/index.php \
7777
${STAGEDIR}${PREFIX}/www/api/v1/users/authservers
78+
# Authservers delete
79+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/users/authservers/delete
80+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/users/authservers/delete/index.php \
81+
${STAGEDIR}${PREFIX}/www/api/v1/users/authservers/delete
7882
# Authservers ldap
7983
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/users/authservers/ldap
8084
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/users/authservers/ldap/index.php \
8185
${STAGEDIR}${PREFIX}/www/api/v1/users/authservers/ldap
86+
# Authservers ldap add
87+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/users/authservers/ldap/add
88+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/users/authservers/ldap/add/index.php \
89+
${STAGEDIR}${PREFIX}/www/api/v1/users/authservers/ldap/add
90+
# Authservers ldap delete
91+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/users/authservers/ldap/delete
92+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/users/authservers/ldap/delete/index.php \
93+
${STAGEDIR}${PREFIX}/www/api/v1/users/authservers/ldap/delete
8294
# Authservers radius
8395
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/users/authservers/radius
8496
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/users/authservers/radius/index.php \
8597
${STAGEDIR}${PREFIX}/www/api/v1/users/authservers/radius
98+
# Authservers radius delete
99+
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/users/authservers/radius/delete
100+
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/api/v1/users/authservers/radius/delete/index.php \
101+
${STAGEDIR}${PREFIX}/www/api/v1/users/authservers/radius/delete
86102
# SYSTEM API ENDPOINTS----------------------------------------
87103
${MKDIR} ${STAGEDIR}${PREFIX}/www/api/v1/system/
88104
# Version base

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ function get_pfsense_version() {
401401
$ver_lc = str_replace(PHP_EOL, "", fread($ver_lc_file, filesize($ver_lc_path))); // Save bt data
402402
$ver_data["lastcommit"] = $ver_lc; // Save to array
403403
}
404+
$ver_data["program"] = floatval(str_replace(".", "", explode("-", $ver)[0]).".".$ver_patch);
404405
return $ver_data;
405406
}
406407

@@ -1196,3 +1197,15 @@ function enable_carp($enable) {
11961197
set_single_sysctl('net.inet.carp.allow', '1');
11971198
}
11981199
}
1200+
1201+
// Checks if an authentication server exists by name
1202+
function is_authentication_server($name) {
1203+
global $config;
1204+
foreach ($config["system"]["authserver"] as $as) {
1205+
$reserved_names = [$as["name"], "Local_Database", "local", "LOCAL", "Local"];
1206+
if (in_array($name, $reserved_names)) {
1207+
return true;
1208+
}
1209+
}
1210+
return false;
1211+
}

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

Lines changed: 379 additions & 22 deletions
Large diffs are not rendered by default.

pfSense-pkg-API/files/usr/local/www/api/v1/api_return_codes.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ API RETURN CODES
117117
182: certificate description required
118118
183: certificate id required
119119
184: certificate id in use
120+
189: authentication server already exists
121+
190: ldap hostname or ip required
122+
191: invalid ldap hostname or ip
123+
192: ldap port required
124+
193: ldap port out of range
125+
194: ldap url type required
126+
195: invalid ldap url type
127+
196: invalid ldap protocol version
128+
197: ldap search scope required
129+
198: invalid ldap search scope
130+
199: ldap bind dn required
131+
200: ldap bind password required
132+
201: ldap user naming attribute required
133+
202: ldap group naming attribute required
134+
203: ldap group member attribute required
120135

121136

122137

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
# Copyright 2020 - Jared Hendrickson
3+
# IMPORTS
4+
require_once("apicalls.inc");
5+
6+
# RUN API CALL
7+
$resp = api_users_authservers_delete();
8+
http_response_code($resp["code"]);
9+
echo json_encode($resp) . PHP_EOL;
10+
exit();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
# Copyright 2020 - Jared Hendrickson
3+
# IMPORTS
4+
require_once("apicalls.inc");
5+
6+
# RUN API CALL
7+
$resp = api_users_authservers_ldap_add();
8+
http_response_code($resp["code"]);
9+
echo json_encode($resp) . PHP_EOL;
10+
exit();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
# Copyright 2020 - Jared Hendrickson
3+
# IMPORTS
4+
require_once("apicalls.inc");
5+
6+
# RUN API CALL
7+
$resp = api_users_authservers_ldap_delete();
8+
http_response_code($resp["code"]);
9+
echo json_encode($resp) . PHP_EOL;
10+
exit();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
# Copyright 2020 - Jared Hendrickson
3+
# IMPORTS
4+
require_once("apicalls.inc");
5+
6+
# RUN API CALL
7+
$resp = api_users_authservers_radius_delete();
8+
http_response_code($resp["code"]);
9+
echo json_encode($resp) . PHP_EOL;
10+
exit();

pfSense-pkg-API/pkg-plist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
@dir /usr/local/www/api/v1/users/add/groups
1919
@dir /usr/local/www/api/v1/users/delete/groups
2020
@dir /usr/local/www/api/v1/users/authservers
21+
@dir /usr/local/www/api/v1/users/authservers/delete
2122
@dir /usr/local/www/api/v1/users/authservers/ldap
23+
@dir /usr/local/www/api/v1/users/authservers/ldap/add
24+
@dir /usr/local/www/api/v1/users/authservers/ldap/delete
2225
@dir /usr/local/www/api/v1/users/authservers/radius
26+
@dir /usr/local/www/api/v1/users/authservers/radius/delete
2327
/usr/local/www/api/v1/users/index.php
2428
/usr/local/www/api/v1/users/add/index.php
2529
/usr/local/www/api/v1/users/delete/index.php
@@ -29,8 +33,12 @@
2933
/usr/local/www/api/v1/users/add/groups/index.php
3034
/usr/local/www/api/v1/users/delete/groups/index.php
3135
/usr/local/www/api/v1/users/authservers/index.php
36+
/usr/local/www/api/v1/users/authservers/delete/index.php
3237
/usr/local/www/api/v1/users/authservers/ldap/index.php
38+
/usr/local/www/api/v1/users/authservers/ldap/add/index.php
39+
/usr/local/www/api/v1/users/authservers/ldap/delete/index.php
3340
/usr/local/www/api/v1/users/authservers/radius/index.php
41+
/usr/local/www/api/v1/users/authservers/radius/delete/index.php
3442

3543
@dir /usr/local/www/api/v1/system/version
3644
/usr/local/www/api/v1/system/version/index.php

0 commit comments

Comments
 (0)