forked from LibreSchool/doraemon
global hosts actions
This commit is contained in:
parent
eccdbb68d4
commit
d425ad55a2
20
root/etc/e-smith/events/actions/doraemon-reboot-all
Executable file
20
root/etc/e-smith/events/actions/doraemon-reboot-all
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
|
package esmith;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use Errno;
|
||||||
|
use esmith::DB::db;
|
||||||
|
use IO::File;
|
||||||
|
use English;
|
||||||
|
|
||||||
|
my $db_hosts = esmith::DB::db->open('hosts') || die("Could not open e-smith db (" . esmith::DB::db->error . ")\n");
|
||||||
|
|
||||||
|
my @items = $db_hosts->get_all('remote');
|
||||||
|
foreach my $item (@items) {
|
||||||
|
my $hostName = $item->key;
|
||||||
|
system("/usr/bin/sudo -u amgmt /usr/bin/ssh -o StrictHostKeyChecking=no amgmt\@$hostName /usr/bin/sudo /sbin/reboot &") == 0
|
||||||
|
or die "Error rebooting $hostName";
|
||||||
|
}
|
||||||
|
|
||||||
|
exit 0;
|
20
root/etc/e-smith/events/actions/doraemon-shutdown-all
Executable file
20
root/etc/e-smith/events/actions/doraemon-shutdown-all
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
|
package esmith;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use Errno;
|
||||||
|
use esmith::DB::db;
|
||||||
|
use IO::File;
|
||||||
|
use English;
|
||||||
|
|
||||||
|
my $db_hosts = esmith::DB::db->open('hosts') || die("Could not open e-smith db (" . esmith::DB::db->error . ")\n");
|
||||||
|
|
||||||
|
my @items = $db_hosts->get_all('remote');
|
||||||
|
foreach my $item (@items) {
|
||||||
|
my $hostName = $item->key;
|
||||||
|
system("/usr/bin/sudo -u amgmt /usr/bin/ssh -o StrictHostKeyChecking=no amgmt\@$hostName /usr/bin/sudo /sbin/poweroff &") == 0
|
||||||
|
or die "Error shutting down $hostName";
|
||||||
|
}
|
||||||
|
|
||||||
|
exit 0;
|
21
root/etc/e-smith/events/actions/doraemon-wake-all
Executable file
21
root/etc/e-smith/events/actions/doraemon-wake-all
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
|
package esmith;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use Errno;
|
||||||
|
use esmith::DB::db;
|
||||||
|
use IO::File;
|
||||||
|
use English;
|
||||||
|
|
||||||
|
my $db_hosts = esmith::DB::db->open('hosts') || die("Could not open e-smith db (" . esmith::DB::db->error . ")\n");
|
||||||
|
|
||||||
|
my @items = $db_hosts->get_all('remote');
|
||||||
|
foreach my $item (@items) {
|
||||||
|
my $hostName = $item->key;
|
||||||
|
my $mac = $item->prop('MacAddress');
|
||||||
|
system("/sbin/ether-wake -i lan0 $mac &") == 0
|
||||||
|
or die "Error waking up $hostName";
|
||||||
|
}
|
||||||
|
|
||||||
|
exit 0;
|
@ -0,0 +1 @@
|
|||||||
|
../actions/doraemon-reboot-all
|
@ -0,0 +1 @@
|
|||||||
|
../actions/doraemon-shutdown-all
|
1
root/etc/e-smith/events/doraemon-wake-all/S50doraemon-wake-all
Symbolic link
1
root/etc/e-smith/events/doraemon-wake-all/S50doraemon-wake-all
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../actions/doraemon-wake-all
|
@ -8,3 +8,6 @@ $L['MacAddress_label'] = 'MAC Address';
|
|||||||
$L['shutdown_label'] = 'Shutdown';
|
$L['shutdown_label'] = 'Shutdown';
|
||||||
$L['reboot_label'] = 'Reboot';
|
$L['reboot_label'] = 'Reboot';
|
||||||
$L['wake_label'] = 'Wake Up';
|
$L['wake_label'] = 'Wake Up';
|
||||||
|
$L['shutdown-all_label'] = 'Shutdown all';
|
||||||
|
$L['reboot-all_label'] = 'Reboot all';
|
||||||
|
$L['wake-all_label'] = 'Wake Up all';
|
||||||
|
@ -8,3 +8,6 @@ $L['MacAddress_label'] = 'MAC Address';
|
|||||||
$L['shutdown_label'] = 'Spegni';
|
$L['shutdown_label'] = 'Spegni';
|
||||||
$L['reboot_label'] = 'Riavvia';
|
$L['reboot_label'] = 'Riavvia';
|
||||||
$L['wake_label'] = 'Accendi';
|
$L['wake_label'] = 'Accendi';
|
||||||
|
$L['shutdown-all_label'] = 'Spegni tutti';
|
||||||
|
$L['reboot-all_label'] = 'Riavvia tutti';
|
||||||
|
$L['wake-all_label'] = 'Accendi tutti';
|
||||||
|
@ -24,6 +24,9 @@ class Hosts extends \Nethgui\Controller\TableController
|
|||||||
->addRowAction(new \NethServer\Module\Doraemon\Hosts\TogglePower('shutdown'))
|
->addRowAction(new \NethServer\Module\Doraemon\Hosts\TogglePower('shutdown'))
|
||||||
->addRowAction(new \NethServer\Module\Doraemon\Hosts\Modify('delete'))
|
->addRowAction(new \NethServer\Module\Doraemon\Hosts\Modify('delete'))
|
||||||
->addTableAction(new \NethServer\Module\Doraemon\Hosts\Modify('create'))
|
->addTableAction(new \NethServer\Module\Doraemon\Hosts\Modify('create'))
|
||||||
|
->addTableAction(new \NethServer\Module\Doraemon\Hosts\TogglePowerAll('wake-all'))
|
||||||
|
->addTableAction(new \NethServer\Module\Doraemon\Hosts\TogglePowerAll('reboot-all'))
|
||||||
|
->addTableAction(new \NethServer\Module\Doraemon\Hosts\TogglePowerAll('shutdown-all'))
|
||||||
->addTableAction(new \Nethgui\Controller\Table\Help('Help'))
|
->addTableAction(new \Nethgui\Controller\Table\Help('Help'))
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
namespace NethServer\Module\Doraemon\Hosts;
|
||||||
|
|
||||||
|
use Nethgui\System\PlatformInterface as Validate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle host power status
|
||||||
|
*
|
||||||
|
* Fires events
|
||||||
|
* - doraemon-wake-all
|
||||||
|
* - doraemon-reboot-all
|
||||||
|
* - doraemon-shutdown-all
|
||||||
|
*/
|
||||||
|
class TogglePowerAll extends \Nethgui\Controller\Table\AbstractAction
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct($identifier = NULL)
|
||||||
|
{
|
||||||
|
if ($identifier !== 'wake-all' && $identifier !== 'reboot-all' && $identifier !== 'shutdown-all') {
|
||||||
|
throw new \InvalidArgumentException(sprintf('%s: module identifier must be one of "wake-all" or "reboot-all" or "shutdown-all".', get_class($this)), 1325579395);
|
||||||
|
}
|
||||||
|
parent::__construct($identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process()
|
||||||
|
{
|
||||||
|
if ( ! $this->getRequest()->isMutation()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->getPlatform()->signalEvent(sprintf('doraemon-%s@post', $this->getIdentifier()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
$view->requireFlag($view::INSET_DIALOG);
|
||||||
|
|
||||||
|
if ($view->getModule()->getIdentifier() == 'shutdown-all') {
|
||||||
|
$headerText = $T('Shutdown all hosts');
|
||||||
|
$panelText = $T('Proceed with all hosts shutdown?');
|
||||||
|
} elseif ($view->getModule()->getIdentifier() == 'reboot-all') {
|
||||||
|
$headerText = $T('Reboot all hosts');
|
||||||
|
$panelText = $T('Proceed with all hosts reboot?');
|
||||||
|
} else {
|
||||||
|
$headerText = $T('Wakeup all hosts');
|
||||||
|
$panelText = $T('Proceed with all hosts wakeup?');
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $view->header()->setAttribute('template', $headerText);
|
||||||
|
// TODO: add a text label here
|
||||||
|
// echo $view->textLabel()->setAttribute('template', $panelText);
|
||||||
|
echo $view->buttonList()
|
||||||
|
->insert($view->button('Yes', $view::BUTTON_SUBMIT))
|
||||||
|
->insert($view->button('No', $view::BUTTON_CANCEL)->setAttribute('value', $view['Cancel']))
|
||||||
|
;
|
Loading…
x
Reference in New Issue
Block a user