From f3d161fa9251b4e80732bb23cf1f39cef5561e05 Mon Sep 17 00:00:00 2001 From: matteo Date: Mon, 1 Feb 2021 01:13:51 +0100 Subject: - warn the user and exit if manahost is run w/o privileges --- lib/ManaTools/Module/Hosts.pm | 59 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/lib/ManaTools/Module/Hosts.pm b/lib/ManaTools/Module/Hosts.pm index 25b779e2..4c353c13 100644 --- a/lib/ManaTools/Module/Hosts.pm +++ b/lib/ManaTools/Module/Hosts.pm @@ -21,6 +21,7 @@ package ManaTools::Module::Hosts; use Modern::Perl '2011'; +use English; use autodie; use Moose; use POSIX qw(ceil); @@ -94,7 +95,15 @@ sub _SharedUGUIInitialize { sub start { my $self = shift; - $self->_manageHostsDialog(); + my $login = (getpwuid $>); + if ($login ne 'root') + { + $self->_warningMissingPrivileges(); + } + else + { + $self->_manageHostsDialog(); + } }; #============================================================= @@ -385,6 +394,54 @@ sub setupTable { } } +sub _warningMissingPrivileges{ + my $self = shift; + + my $appTitle = yui::YUI::app()->applicationTitle(); + my $appIcon = yui::YUI::app()->applicationIcon(); + ## set new title to get it in dialog + my $newTitle = $self->loc->N("Need administrator privileges"); + + my $factory = yui::YUI::widgetFactory; + my $optional = yui::YUI::optionalWidgetFactory; + +## TODO remove title and icon when using Shared::Module::GUI::Dialog + ## set new title to get it in dialog + yui::YUI::app()->setApplicationTitle($self->name()); + ## set icon if not already set by external launcher + yui::YUI::app()->setApplicationIcon($self->icon()); + + $self->dialog($factory->createMainDialog()); + my $layout = $factory->createVBox($self->dialog); + + my $hbox_header = $factory->createHBox($layout); + my $labelAppDescription = $factory->createLabel($hbox_header,$newTitle); + $labelAppDescription->setWeight($yui::YD_HORIZ,0); + my $hbox_foot = $factory->createHBox($layout); + my $okButton = $factory->createPushButton($hbox_foot,$self->loc->N("&OK")); + + # main loop + while(1) { + my $event = $self->dialog->waitForEvent(); + my $eventType = $event->eventType(); + + #event type checking + if ($eventType == $yui::YEvent::CancelEvent) { + last; + } + elsif ($eventType == $yui::YEvent::WidgetEvent) { + my $widget = $event->widget(); + if ($widget == $okButton) { + last; + } + } + } + $self->dialog->destroy() ; + + #restore old application title + yui::YUI::app()->setApplicationTitle($appTitle); +} + sub _manageHostsDialog { my $self = shift; -- cgit v1.2.1