aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatteo <matteo.pasotti@gmail.com>2021-02-01 01:13:51 +0100
committermatteo <matteo.pasotti@gmail.com>2021-02-01 01:13:51 +0100
commitf3d161fa9251b4e80732bb23cf1f39cef5561e05 (patch)
tree160c22f2d49c083eaeba9aabec9d8032d90d6c6e
parentbbec00251ebfa754c600df2942879741233f4e06 (diff)
downloadmanatools-f3d161fa9251b4e80732bb23cf1f39cef5561e05.tar
manatools-f3d161fa9251b4e80732bb23cf1f39cef5561e05.tar.gz
manatools-f3d161fa9251b4e80732bb23cf1f39cef5561e05.tar.bz2
manatools-f3d161fa9251b4e80732bb23cf1f39cef5561e05.tar.xz
manatools-f3d161fa9251b4e80732bb23cf1f39cef5561e05.zip
- warn the user and exit if manahost is run w/o privileges
-rw-r--r--lib/ManaTools/Module/Hosts.pm59
1 files changed, 58 insertions, 1 deletions
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;