From patchwork Wed Dec 5 18:14:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erik Kapfer X-Patchwork-Id: 1988 Return-Path: Received: from mail01.ipfire.org (mail01.i.ipfire.org [172.28.1.200]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mail01.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web07.i.ipfire.org (Postfix) with ESMTPS id 06B198AB84A for ; Wed, 5 Dec 2018 07:14:24 +0000 (GMT) Received: from mail01.i.ipfire.org (localhost [IPv6:::1]) by mail01.ipfire.org (Postfix) with ESMTP id 9DABF208A796; Wed, 5 Dec 2018 07:14:22 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=201801; t=1543994063; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:list-id:list-unsubscribe:list-subscribe:list-post; bh=YXRmNRcpcpVa/9K4yQN8zqtOMLEJJRUBmjP0ygpTj6k=; b=UXaEk3XR+8iaYMbPq/PhihKSL4IK+tFxHTcjSxAoSZV7vgDzLB1KcHpaiTro+0Q9UQNi4A dObDMKZJaOgcEKEFRdHJ9A9CDy8d6xE/2uyAfzO10yBMcDKoeno50Fu4Uq1Rch30yxgIRz AUYS9jk8X6KQRZWzPjGJ/0FZvNQABLXaNOgO+0bU3E2ZEjIqAdDiYXFAkRXUgUTSrVxgBU tvg2yhHX/2odgExvLwUNCiA6ts0rlhWc28LpN+qVGno2n/9PyuX6rMZHpoOP+7hQ2PVmMj hZVjgV5v8l87/PpvUYfwb57GLKaSGUMJ9zpRxaGDxY+kCNbzOXAcQK4VAZ1Ffg== Received: from ipfire-server.local (i59F5F667.versanet.de [89.245.246.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 387B921AF004; Wed, 5 Dec 2018 07:14:19 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=201801; t=1543994059; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=YXRmNRcpcpVa/9K4yQN8zqtOMLEJJRUBmjP0ygpTj6k=; b=OBmSIsPdWU9GZ467UoLP0w97JKzkXWXn5a4grlIuX+Jd2bBe+XNOlt9i68/nNxGpnqIGt9 rNsl9+i+B5mQ69GRcHVxyI28/Vaq38n2tF/uUOGO1weDkiEsaNI2VAOYUYB22PfzK77/JW MNx+ClDWVWrF4cBK9Iy+uikAKMirfBPUr+heFNgZI5MbJkGFsKeIHlnfT1s6e52v0PJgPi vPE3+eeJNP9QIwIaPE5fNcLBRk8VfmGKZVUuHMK7hoTtna9WvX1FNFNhi0GaZvSg33a4lg vUAF2RvVakxmAIcV2Cs9LGjPQoxuHRYeFkY5jlDPtHoTGhmzL4vl/0AoqZRU+A== From: Erik Kapfer To: development@lists.ipfire.org Subject: [PATCH v2] OpenVPN: Calculate CIDR to DDN notation for RW Date: Wed, 5 Dec 2018 08:14:03 +0100 Message-Id: <20181205071403.22330-1-erik.kapfer@ipfire.org> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20181204073402.27898-1-erik.kapfer@ipfire.org> References: <20181204073402.27898-1-erik.kapfer@ipfire.org> Authentication-Results: mail01.ipfire.org; auth=pass smtp.auth=ummeegge smtp.mailfrom=erik.kapfer@ipfire.org X-Spamd-Result: default: False [-8.53 / 11.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; DKIM_SIGNED(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM(-2.43)[-0.810,0]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:8881, ipnet:89.245.240.0/20, country:DE]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-8.53 X-Rspamd-Server: mail01.i.ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Fixes #11823 Patches enables CIDR and dotted-decimal notation for "OpenVPN subnet:" entries in "Global settings". network-functions.pl has been introduced. Signed-off-by: Erik Kapfer --- html/cgi-bin/ovpnmain.cgi | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/html/cgi-bin/ovpnmain.cgi b/html/cgi-bin/ovpnmain.cgi index 976300fc7..6e57a4991 100644 --- a/html/cgi-bin/ovpnmain.cgi +++ b/html/cgi-bin/ovpnmain.cgi @@ -32,6 +32,7 @@ use strict; use Archive::Zip qw(:ERROR_CODES :CONSTANTS); use Sort::Naturally; require '/var/ipfire/general-functions.pl'; +require '/var/ipfire/network-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; require "${General::swroot}/countries.pl"; @@ -245,6 +246,7 @@ sub pkiconfigcheck sub writeserverconf { my %sovpnsettings = (); my @temp = (); + my @tempovpnsubnet = (); &General::readhash("${General::swroot}/ovpn/settings", \%sovpnsettings); &read_routepushfile; @@ -267,8 +269,16 @@ sub writeserverconf { print CONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; print CONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; print CONF "dh ${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}\n"; - my @tempovpnsubnet = split("\/",$sovpnsettings{'DOVPN_SUBNET'}); - print CONF "server $tempovpnsubnet[0] $tempovpnsubnet[1]\n"; + # ovpn subnet calculate prefix to netmask if needed + if ($sovpnsettings{'DOVPN_SUBNET'} ne '') { + my ($ip,$subnet) = split(/\//,"$vpnsettings{'DOVPN_SUBNET'}"); + if (&Network::check_prefix($subnet)) { + $subnet = &Network::convert_prefix2netmask($subnet); + print CONF "server $ip $subnet\n"; + } else { + print CONF "server $ip $subnet\n"; + } + } #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n"; # Check if we are using mssfix, fragment and set the corretct mtu of 1500.