From patchwork Sat Jan 18 09:03:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 2704 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 480BmL3pZcz3xYC for ; Sat, 18 Jan 2020 09:03:14 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 480BmJ64drz2Pt; Sat, 18 Jan 2020 09:03:12 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 480BmJ3CLHz2ySy; Sat, 18 Jan 2020 09:03:12 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 480BmG2YPlz2yCW for ; Sat, 18 Jan 2020 09:03:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 480BmD6SkFz2MV; Sat, 18 Jan 2020 09:03:08 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909ed25519; t=1579338189; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=6QAkdAujW4p10KEmEVZB+xRbRQ+gyhVSH6gDe4684j0=; b=fG/Oc5V5W7U17L3nw3scNXu+UykvnT9EGhh0UZYC1U9srkrH8U+q7J/U1e7CY0SYa8GnJD pkdkc0wi9gl4PlDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909rsa; t=1579338189; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=6QAkdAujW4p10KEmEVZB+xRbRQ+gyhVSH6gDe4684j0=; b=IOPzb0QwIUIPnJHjm8iqA7aVGhxqefEvuB6hwMhZf/4pzzISvZT5Ryp/Rilsvimr7AC8Df 2iLw9Nc49RgCr30+wTsu3Q+BFsy9H9IGZ3jcxNXhcCbbQjcM+7MP8acV2G5PE5aos7tiDv WRhwf00IzFYD5Shkrhg3dx/E93gzLBDtgshHMDJH2utLNekInRqcI+hfBlimWZnXf3Fjhd PzU1FR3WyKvdD2jVi4uT9DqyYmmXiJQ99zas6vcXsvYY6pTbua33Y3mYbwQeoDH/81WLg8 ymv23WCW3Calbphv9k0Tf17sr2nAHkpGgnGVESlkq9j/S1yQ4OpiJeIrm5ScGg== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH] convert-dns-settings: Import all possible PPP dialin profiles. Date: Sat, 18 Jan 2020 10:03:06 +0100 Message-Id: <20200118090306.2991-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.auth=stevee smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 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" * Avoid from adding the same imported DNS server multiple times. Signed-off-by: Stefan Schantl --- src/scripts/convert-dns-settings | 44 ++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/scripts/convert-dns-settings b/src/scripts/convert-dns-settings index 04a5344f7..e9d4de86b 100755 --- a/src/scripts/convert-dns-settings +++ b/src/scripts/convert-dns-settings @@ -22,25 +22,49 @@ main() { # Do not convert anything if we already have some servers set if [ ! -s "/var/ipfire/dns/servers" ]; then - local DNS0 DNS1 DNS2 + # Array to store all found DNS servers. + SERVERS=() + + # Try to get the DNS servers from ethernet settings file. + local DNS1 DNS2 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) + # Add the grabbed DNS servers to the servers array. + SERVERS+=($DNS1 $DNS2) + + # Check if the ppp settings file is not empty. if [ -s "/var/ipfire/ppp/settings" ]; then - eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) + # Loop though all profile files. + for file in /var/ipfire/ppp/settings*; do + local DNS1 DNS2 + eval $(/usr/local/bin/readhash $file) + + # Add the DNS servers to the array of SERVERS. + for var in DNS1 DNS2; do + local server="${!var}" + + # Check if the current server is allready part + # of the array. + for element in "${SERVERS[@]}"; do + [[ $element == $server ]] && continue + done + + SERVERS+=($server) + done + + # Remove DNS1 and DNS2 settings from profile file. + sed -i "/^DNS[12]?=/d" $file + done - # Remove DNS, DNS1 and DNS2 - sed -i "/^DNS[12]?=/d" /var/ipfire/ppp/settings elif [ -s "/var/ipfire/dns/settings" ]; then eval $(/usr/local/bin/readhash /var/ipfire/dns/settings) fi - local var + local server local i=3 - for var in DNS0 DNS1 DNS2; do - if [ -n "${!var}" ]; then - echo "${i},${!var},,enabled," - (( i++ )) - fi + for server in "${SERVERS[@]}"; do + echo "${i},${server},,enabled," + (( i++ )) done > /var/ipfire/dns/servers # Empty the old settings file