From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH 7/8] extrahd.cgi: Re-order sanity check logic Date: Fri, 23 Jun 2023 06:01:23 +0200 Message-ID: <20230623040124.3826-7-stefan.schantl@ipfire.org> In-Reply-To: <20230623040124.3826-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3938584007605260437==" List-Id: --===============3938584007605260437== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Signed-off-by: Stefan Schantl --- html/cgi-bin/extrahd.cgi | 49 +++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/html/cgi-bin/extrahd.cgi b/html/cgi-bin/extrahd.cgi index a4d6e2e3a..89ba19921 100644 --- a/html/cgi-bin/extrahd.cgi +++ b/html/cgi-bin/extrahd.cgi @@ -98,28 +98,7 @@ $extrahdsettings{'UUID'} =3D ''; ## Add a new device. # if ($extrahdsettings{'ACTION'} eq $Lang::tr{'add'}) { - # Open device file for reading. - open( FILE, "< $devicefile" ) or die "Unable to read $devicefile"; - my @devices =3D ; - close FILE; - - # Loop through the entries line-by-line. - foreach my $entry (sort @devices) { - # Split the line into pieces and assign nice variables. - my ($uuid, $fs, $path) =3D split( /\;/, $entry ); - - # Check if the path is allready used. - if ( "$extrahdsettings{'PATH'}" eq "$path" ) { - $errormessage =3D "$Lang::tr{'extrahd you cant mount'} $extrahdsettings{'= DEVICE'} $Lang::tr{'extrahd to'} $extrahdsettings{'PATH'}$Lang::tr{'extrahd b= ecause there is already a device mounted'}."; - } - - # Check if the uuid is allready used. - if ("$extrahdsettings{'DEVICE'} eq $uuid") { - $errormessage =3D "$extrahdsettings{'DEVICE'} is allready mounted."; - } - } - - # Check if a valid mount path has been choosen.=20 + # Check if a valid mount path has been choosen. unless(&is_valid_dir("$extrahdsettings{'PATH'}")) { $errormessage =3D "$Lang::tr{'extrahd you cant mount'} $extrahdsettings{'D= EVICE'} $Lang::tr{'extrahd to root'}."; } @@ -129,7 +108,31 @@ if ($extrahdsettings{'ACTION'} eq $Lang::tr{'add'}) { $errormessage =3D "$Lang::tr{'extrahd you cant mount'} $extrahdsettings{'D= EVICE'} $Lang::tr{'extrahd to'} $extrahdsettings{'PATH'}$Lang::tr{'extrahd be= cause there is already a device mounted'}."; } =20 - # Check if there was an error message. + # Check against may previously configured drives. + unless ($errormessage) { + # Open device file for reading. + open( FILE, "< $devicefile" ) or die "Unable to read $devicefile"; + my @devices =3D ; + close FILE; + + # Loop through the entries line-by-line. + foreach my $entry (sort @devices) { + # Split the line into pieces and assign nice variables. + my ($uuid, $fs, $path) =3D split( /\;/, $entry ); + + # Check if the path is allready used. + if ( "$extrahdsettings{'PATH'}" eq "$path" ) { + $errormessage =3D "$Lang::tr{'extrahd you cant mount'} $extrahdsettings{= 'DEVICE'} $Lang::tr{'extrahd to'} $extrahdsettings{'PATH'}$Lang::tr{'extrahd = because there is already a device mounted'}."; + } + + # Check if the uuid is allready used. + if ("$extrahdsettings{'DEVICE'} eq $uuid") { + $errormessage =3D "$extrahdsettings{'DEVICE'} is allready mounted."; + } + } + } + + # Go further if there was no error message. unless($errormessage) { # Re-open the device file for writing. open(FILE, ">> $devicefile" ) or die "Unable to write $devicefile"; --=20 2.39.2 --===============3938584007605260437==--