mirror of
https://github.com/pfsense/pfsense.git
synced 2025-10-26 11:38:35 +00:00
Set some important default values for the new OpenVPN interface screens.
Add functions and interface code to handle local port conflict detection and resolution.
This commit is contained in:
parent
c3d42a86c9
commit
f432e364b2
@ -40,6 +40,7 @@
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/* DISABLE_PHP_LINT_CHECKING */
|
||||
|
||||
require_once('config.inc');
|
||||
require_once('pfsense-utils.inc');
|
||||
@ -56,12 +57,12 @@ function openvpn_vpnid_used($vpnid) {
|
||||
|
||||
if (is_array($config['openvpn']['openvpn-server']))
|
||||
foreach ($config['openvpn']['openvpn-server'] as $id => & $settings)
|
||||
if( $vpnid == $settings['vpnid'] )
|
||||
if ($vpnid == $settings['vpnid'])
|
||||
return true;
|
||||
|
||||
if (is_array($config['openvpn']['openvpn-client']))
|
||||
foreach ($config['openvpn']['openvpn-client'] as $id => & $settings)
|
||||
if( $vpnid == $settings['vpnid'] )
|
||||
if ($vpnid == $settings['vpnid'])
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@ -76,6 +77,33 @@ function openvpn_vpnid_next() {
|
||||
return $vpnid;
|
||||
}
|
||||
|
||||
function openvpn_port_used($prot, $port) {
|
||||
global $config;
|
||||
|
||||
if (is_array($config['openvpn']['openvpn-server']))
|
||||
foreach ($config['openvpn']['openvpn-server'] as $id => & $settings)
|
||||
if ($port == $settings['local_port'] &&
|
||||
$prot == $settings['protocol'])
|
||||
return $settings['vpnid'];
|
||||
|
||||
if (is_array($config['openvpn']['openvpn-client']))
|
||||
foreach ($config['openvpn']['openvpn-client'] as $id => & $settings)
|
||||
if ($port == $settings['local_port'] &&
|
||||
$prot == $settings['protocol'])
|
||||
return $settings['vpnid'];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
function openvpn_port_next($prot) {
|
||||
|
||||
$port = 1194;
|
||||
while(openvpn_port_used($prot, $port))
|
||||
$port++;
|
||||
|
||||
return $port;
|
||||
}
|
||||
|
||||
function openvpn_get_cipherlist() {
|
||||
|
||||
$ciphers = array();
|
||||
|
||||
@ -65,6 +65,11 @@ if ($_GET['act'] == "del") {
|
||||
$savemsg = gettext("Client successfully deleted")."<br/>";
|
||||
}
|
||||
|
||||
if($_GET['act']=="new"){
|
||||
$pconfig['interface'] = "wan";
|
||||
$pconfig['server_port'] = 1194;
|
||||
}
|
||||
|
||||
if($_GET['act']=="edit"){
|
||||
|
||||
if (isset($id) && $a_client[$id]) {
|
||||
@ -101,7 +106,21 @@ if ($_POST) {
|
||||
unset($input_errors);
|
||||
$pconfig = $_POST;
|
||||
|
||||
if (isset($id) && $a_server[$id])
|
||||
$vpnid = $a_server[$id]['vpnid'];
|
||||
else
|
||||
$vpnid = 0;
|
||||
|
||||
/* input validation */
|
||||
if ($pconfig['local_port']) {
|
||||
|
||||
if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port'))
|
||||
$input_errors[] = $result;
|
||||
|
||||
if (openvpn_port_used($pconfig['protocol'], $pconfig['local_port']) != $vpnid)
|
||||
$input_errors[] = "The specified 'Local port' is in use. Please select another value";
|
||||
}
|
||||
|
||||
if ($result = openvpn_validate_host($pconfig['server_addr'], 'Server host or address'))
|
||||
$input_errors[] = $result;
|
||||
|
||||
@ -142,8 +161,8 @@ if ($_POST) {
|
||||
|
||||
$client = array();
|
||||
|
||||
if (isset($id) && $a_client[$id])
|
||||
$client['vpnid'] = $a_client[$id]['vpnid'];
|
||||
if ($vpnid)
|
||||
$client['vpnid'] = $vpnid;
|
||||
else
|
||||
$client['vpnid'] = openvpn_vpnid_next();
|
||||
|
||||
|
||||
@ -65,6 +65,12 @@ if ($_GET['act'] == "del") {
|
||||
$savemsg = gettext("Server successfully deleted")."<br/>";
|
||||
}
|
||||
|
||||
if($_GET['act']=="new"){
|
||||
$pconfig['interface'] = "wan";
|
||||
$pconfig['local_port'] = openvpn_port_next('UDP');
|
||||
$pconfig['pool_enable'] = "yes";
|
||||
}
|
||||
|
||||
if($_GET['act']=="edit"){
|
||||
|
||||
if (isset($id) && $a_server[$id]) {
|
||||
@ -136,6 +142,11 @@ if ($_POST) {
|
||||
unset($input_errors);
|
||||
$pconfig = $_POST;
|
||||
|
||||
if (isset($id) && $a_server[$id])
|
||||
$vpnid = $a_server[$id]['vpnid'];
|
||||
else
|
||||
$vpnid = 0;
|
||||
|
||||
/* input validation */
|
||||
if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port'))
|
||||
$input_errors[] = $result;
|
||||
@ -149,6 +160,9 @@ if ($_POST) {
|
||||
if ($result = openvpn_validate_cidr($pconfig['local_network'], 'Local network'))
|
||||
$input_errors[] = $result;
|
||||
|
||||
if (openvpn_port_used($pconfig['protocol'], $pconfig['local_port']) != $vpnid)
|
||||
$input_errors[] = "The specified 'Local port' is in use. Please select another value";
|
||||
|
||||
if ($pconfig['auth_method'] == 'shared_key')
|
||||
if (!strstr($pconfig['shared_key'], "-----BEGIN OpenVPN Static key V1-----") ||
|
||||
!strstr($pconfig['shared_key'], "-----END OpenVPN Static key V1-----"))
|
||||
@ -205,8 +219,8 @@ if ($_POST) {
|
||||
|
||||
$server = array();
|
||||
|
||||
if (isset($id) && $a_server[$id])
|
||||
$server['vpnid'] = $a_server[$id]['vpnid'];
|
||||
if ($vpnid)
|
||||
$server['vpnid'] = $vpnid;
|
||||
else
|
||||
$server['vpnid'] = openvpn_vpnid_next();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user