[Mageia-dev] [soft-commits] [6416] Initial commit of Admin Panel.

Guillaume Rousse guillomovitch at gmail.com
Tue Nov 6 13:16:20 CET 2012


Le 06/11/2012 12:09, root at mageia.org a écrit :
> Revision
>     6416
> Author
>     tuxta
> Date
>     2012-11-06 12:09:51 +0100 (Tue, 06 Nov 2012)
>
>
>       Log Message
>
> Initial commit of Admin Panel.
> Has basic functionality that you might expect from the core program, escalates priviledges, loads categories and modules dynamically from configuration file, launches modules and returns to the panel once the module has completed. Works within ncurses, gtk and qt environments using the native widget set.
>
>
>       Added Paths
>
>   * AdminPanel/trunk/
>   * AdminPanel/trunk/Auth.pm <#AdminPaneltrunkAuthpm>
>   * AdminPanel/trunk/Category.pm <#AdminPaneltrunkCategorypm>
>   * AdminPanel/trunk/ConfigReader.pm <#AdminPaneltrunkConfigReaderpm>
>   * AdminPanel/trunk/MainDisplay.pm <#AdminPaneltrunkMainDisplaypm>
>   * AdminPanel/trunk/Module.pm <#AdminPaneltrunkModulepm>
>   * AdminPanel/trunk/SettingsReader.pm <#AdminPaneltrunkSettingsReaderpm>
>   * AdminPanel/trunk/apanel.pl <#AdminPaneltrunkapanelpl>
>   * AdminPanel/trunk/categories.conf <#AdminPaneltrunkcategoriesconf>
>   * AdminPanel/trunk/extras/
>   * AdminPanel/trunk/extras/README <#AdminPaneltrunkextrasREADME>
>   * AdminPanel/trunk/extras/org.freedesktop.policykit.pkexec.policy
>     <#AdminPaneltrunkextrasorgfreedesktoppolicykitpkexecpolicy>
>   * AdminPanel/trunk/images/
>   * AdminPanel/trunk/images/logo_mageia.png
>     <#AdminPaneltrunkimageslogo_mageiapng>
>   * AdminPanel/trunk/images/mageia.png <#AdminPaneltrunkimagesmageiapng>
>   * AdminPanel/trunk/images/quit.png <#AdminPaneltrunkimagesquitpng>
>   * AdminPanel/trunk/modules/
>   * AdminPanel/trunk/modules/test.cpp <#AdminPaneltrunkmodulestestcpp>
>   * AdminPanel/trunk/settings.conf <#AdminPaneltrunksettingsconf>
>
> Added: AdminPanel/trunk/Auth.pm
> ===================================================================
> --- AdminPanel/trunk/Auth.pm	                        (rev 0)
> +++ AdminPanel/trunk/Auth.pm	2012-11-06 11:09:51 UTC (rev 6416)
> @@ -0,0 +1,50 @@
> +#    Copyright 2012 Matteo Pasotti
> +#
> +#    This file is part of mcc2
> +#
> +#    mcc2 is free software: you can redistribute it and/or modify
> +#    it under the terms of the GNU General Public License as published by
> +#    the Free Software Foundation, either version 2 of the License, or
> +#    (at your option) any later version.
> +#
> +#    mcc2 is distributed in the hope that it will be useful,
> +#    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#    GNU General Public License for more details.
> +#
> +#    You should have received a copy of the GNU General Public License
> +#    along with mcc2.  If not, see <http://www.gnu.org/licenses/>.
I'm not convinced of the interest of repeating license and copyright 
information in every single file, whereas a single top-level README file 
would be enough.

> +
> +package Auth;
I'm convinced tough than using a shared top-level namespace, for 
instance AdminPanel or Mageia::AdminPanel, would be a better idea to 
express the idea than this module is a part of a software, than a loose 
comment such as "This file is part of mcc2".
package Mageia::AdminPanel::Auth;

> +
> +require Exporter;
> + at ISA = qw(Exporter);
You'd rather use a modern perl idiom:
use base qw(Exporter)

or

use parent qw(Exporter);

> + at EXPORT = qw(require_root_capability
> +	     ask_for_authentication);
> +
> +use strict;
> +use warnings;
> +use diagnostics;
Those pragmas should come first, before package variables

> +use Data::Dumper;
Unused anywere. Don't load debug-related modules in production coed.

> +sub require_root_capability {
> +	return 0 if(!$>);
> +	return 1;
> +}
Perl best practice: use english name for magic variables, for readability:

use English qw(-no_match_vars );
return 0 if (!$EUID);

And your condition could be expressed in a single statement:
sub require_root_capability {
     return $EUID == 0;
}

> +
> +sub ask_for_authentication {
> +	my @args = @ARGV;
> +	my $command = wrap_command($0);
> +	unshift(@args, $command->[2]);
> +	exec { $command->[0] } $command->[1], @args or die ("command %s missing", $command->[0]);
> +	die "You must be root to run this program" if $>;
> +}
You're duplicating the condition from previous function here.
die "You must be root to run this program" if
     !require_root_capability();

Morevoer, you'd better test before executing the command:
die "You must be root to run this program" if
     !require_root_capability();
exec { $command->[0] } $command->[1], @args
     or die ("command %s missing", $command->[0]);

> +sub wrap_command {
> +	my $currenv = "env";
> +	my $wrapper = "pkexec";
> +	my $app = $0;
> +	my $command = [$wrapper, $currenv, $app];
> +	($command);
> +}
Perl best practice: use explicit return statement, for better readability:
return ($command);

Using temporary variables for constant isn't very useful here, the whole 
function would probably be more readable this way:

sub wrap_command {
     my ($app) = @_;
     return (['pkexec', 'env', $app]);
}

I don't understand the need for list contexte here, tough.

BTW, your indentation isn't consistent between various files.
-- 
BOFH excuse #445:

Browser's cookie is corrupted -- someone's been nibbling on it.


More information about the Mageia-dev mailing list