From 2786dfea1ce80bfecb3173baa0b554f787d6060e Mon Sep 17 00:00:00 2001 From: Paolo Asperti Date: Sun, 8 Oct 2017 19:41:59 +0200 Subject: [PATCH 1/6] FIX: small language typos --- root/etc/e-smith/events/actions/doraemon-reboot | 6 +++--- root/etc/e-smith/events/actions/doraemon-shutdown | 6 +++--- root/etc/e-smith/events/actions/doraemon-wake | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/root/etc/e-smith/events/actions/doraemon-reboot b/root/etc/e-smith/events/actions/doraemon-reboot index 5f02685..bd69800 100755 --- a/root/etc/e-smith/events/actions/doraemon-reboot +++ b/root/etc/e-smith/events/actions/doraemon-reboot @@ -10,9 +10,9 @@ use English; my $db_hosts = esmith::DB::db->open('hosts') || die("Could not open e-smith db (" . esmith::DB::db->error . ")\n"); -my $event = $ARGV [0]; +my $event = $ARGV[0]; -defined $ARGV[1] || die "No host specied"; +defined $ARGV[1] || die "No host specified"; my $host = $ARGV[1]; reboot_host($host); @@ -26,7 +26,7 @@ sub reboot_host # Reboot the host #------------------------------------------------------------ - my $h = $db_hosts->get($hostName) or die "No host record for user $hostName"; + my $h = $db_hosts->get($hostName) or die "No host record for $hostName"; 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"; diff --git a/root/etc/e-smith/events/actions/doraemon-shutdown b/root/etc/e-smith/events/actions/doraemon-shutdown index 04d61c7..d298c1d 100755 --- a/root/etc/e-smith/events/actions/doraemon-shutdown +++ b/root/etc/e-smith/events/actions/doraemon-shutdown @@ -10,9 +10,9 @@ use English; my $db_hosts = esmith::DB::db->open('hosts') || die("Could not open e-smith db (" . esmith::DB::db->error . ")\n"); -my $event = $ARGV [0]; +my $event = $ARGV[0]; -defined $ARGV[1] || die "No host specied"; +defined $ARGV[1] || die "No host specified"; my $host = $ARGV[1]; shutdown_host($host); @@ -26,7 +26,7 @@ sub shutdown_host # Shutdown the host #------------------------------------------------------------ - my $h = $db_hosts->get($hostName) or die "No host record for user $hostName"; + my $h = $db_hosts->get($hostName) or die "No host record for $hostName"; 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"; diff --git a/root/etc/e-smith/events/actions/doraemon-wake b/root/etc/e-smith/events/actions/doraemon-wake index bb43cb6..1e47960 100755 --- a/root/etc/e-smith/events/actions/doraemon-wake +++ b/root/etc/e-smith/events/actions/doraemon-wake @@ -10,9 +10,9 @@ use English; my $db_hosts = esmith::DB::db->open('hosts') || die("Could not open e-smith db (" . esmith::DB::db->error . ")\n"); -my $event = $ARGV [0]; +my $event = $ARGV[0]; -defined $ARGV[1] || die "No host specied"; +defined $ARGV[1] || die "No host specified"; my $host = $ARGV[1]; wake_host($host); @@ -26,7 +26,7 @@ sub wake_host # Wake up the host #------------------------------------------------------------ - my $h = $db_hosts->get($hostName) or die "No host record for user $hostName"; + my $h = $db_hosts->get($hostName) or die "No host record for $hostName"; my $client = $h[0]; my $mac = $client->prop('MacAddress'); system("/sbin/ether-wake -i lan0 $mac") == 0 From 671e8286f4646e0168e11ff5cb1bc7616707bb88 Mon Sep 17 00:00:00 2001 From: Paolo Asperti Date: Sun, 8 Oct 2017 19:42:51 +0200 Subject: [PATCH 2/6] FIX: bug in WOL --- root/etc/e-smith/events/actions/doraemon-wake | 2 +- root/etc/e-smith/events/actions/doraemon-wake-all | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/root/etc/e-smith/events/actions/doraemon-wake b/root/etc/e-smith/events/actions/doraemon-wake index 1e47960..88b45fc 100755 --- a/root/etc/e-smith/events/actions/doraemon-wake +++ b/root/etc/e-smith/events/actions/doraemon-wake @@ -29,7 +29,7 @@ sub wake_host my $h = $db_hosts->get($hostName) or die "No host record for $hostName"; my $client = $h[0]; my $mac = $client->prop('MacAddress'); - system("/sbin/ether-wake -i lan0 $mac") == 0 + system("/sbin/ether-wake -b -i lan0 $mac") == 0 or die "Error waking up $hostName"; } diff --git a/root/etc/e-smith/events/actions/doraemon-wake-all b/root/etc/e-smith/events/actions/doraemon-wake-all index 274d231..73a34bb 100755 --- a/root/etc/e-smith/events/actions/doraemon-wake-all +++ b/root/etc/e-smith/events/actions/doraemon-wake-all @@ -14,7 +14,7 @@ my @items = $db_hosts->get_all('local'); foreach my $item (@items) { my $hostName = $item->key; my $mac = $item->prop('MacAddress'); - system("/sbin/ether-wake -i lan0 $mac &") == 0 + system("/sbin/ether-wake -b -i lan0 $mac &") == 0 or die "Error waking up $hostName"; } From e42fdd96c0c2260a98c3388208a2bc846b1754d0 Mon Sep 17 00:00:00 2001 From: Paolo Asperti Date: Sun, 8 Oct 2017 19:43:37 +0200 Subject: [PATCH 3/6] FEATURE: git ignore rpm files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c0abd76..7fadd8a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.sh *.tar.* +*.rpm From 9589d3b63a579527bced0fcb5201f67d8fb2c6fc Mon Sep 17 00:00:00 2001 From: Paolo Asperti Date: Sun, 8 Oct 2017 19:44:15 +0200 Subject: [PATCH 4/6] RELEASE: new bugfix release --- doraemon.spec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doraemon.spec b/doraemon.spec index be489a9..7408209 100644 --- a/doraemon.spec +++ b/doraemon.spec @@ -1,6 +1,6 @@ Summary: Helps client to join domain and maintain itself Name: doraemon -Version: 2.0.1 +Version: 2.0.2 Release: 1.ns6 URL: https://github.com/bglug-it/doraemon/ License: GPLv2+ @@ -145,6 +145,10 @@ rm -rf %{buildroot} %changelog +* Sun Oct 8 2017 Paolo Asperti - 2.0.2-1 +- FIX: bug in WOL +- FIX: small language typos + * Wed Nov 9 2016 Paolo Asperti - 2.0.1-1 - PHP porting - Added a basic UI From 4b0ecef735b1d10c0bcb88adb30135a8ba34688e Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Fri, 16 Mar 2018 00:24:51 +0100 Subject: [PATCH 5/6] Fixing doraemon-wake script exiting with error everywhere. --- root/etc/e-smith/events/actions/doraemon-wake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/etc/e-smith/events/actions/doraemon-wake b/root/etc/e-smith/events/actions/doraemon-wake index 88b45fc..e6eae53 100755 --- a/root/etc/e-smith/events/actions/doraemon-wake +++ b/root/etc/e-smith/events/actions/doraemon-wake @@ -26,7 +26,7 @@ sub wake_host # Wake up the host #------------------------------------------------------------ - my $h = $db_hosts->get($hostName) or die "No host record for $hostName"; + my @h = $db_hosts->get($hostName) or die "No host record for $hostName"; my $client = $h[0]; my $mac = $client->prop('MacAddress'); system("/sbin/ether-wake -b -i lan0 $mac") == 0 From 5b16daa4afdbcedb386ec8a9a55ead2e3c302053 Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Sun, 17 Jun 2018 02:06:07 +0200 Subject: [PATCH 6/6] Important fix for whatsmyhostname: now it parses correctly the variables passed. Up version. --- doraemon.spec | 6 +++- root/usr/share/doraemon/index.php | 48 ++++++++++++++++++------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/doraemon.spec b/doraemon.spec index 7408209..bdfdb72 100644 --- a/doraemon.spec +++ b/doraemon.spec @@ -1,6 +1,6 @@ Summary: Helps client to join domain and maintain itself Name: doraemon -Version: 2.0.2 +Version: 2.0.3 Release: 1.ns6 URL: https://github.com/bglug-it/doraemon/ License: GPLv2+ @@ -145,6 +145,10 @@ rm -rf %{buildroot} %changelog +* Sun Jun 17 2018 Emiliano Vavassori - 2.0.3-1 +- FIX: whatsmyhostname correctly parse role variable +- Minor aesthetic syntax fixes + * Sun Oct 8 2017 Paolo Asperti - 2.0.2-1 - FIX: bug in WOL - FIX: small language typos diff --git a/root/usr/share/doraemon/index.php b/root/usr/share/doraemon/index.php index 842a624..d6707a5 100644 --- a/root/usr/share/doraemon/index.php +++ b/root/usr/share/doraemon/index.php @@ -53,7 +53,8 @@ function getClient($mac=false) { global $hosts_db; if (!$mac) { $mac = getClientMac(); - if (!$mac) return false; + if (!$mac) + return false; } $hosts = $hosts_db->getAllByProp('MacAddress',$mac); if (count($hosts)>0) { @@ -68,7 +69,8 @@ function getClientMac($ip=false) { $ip = $_SERVER['REMOTE_ADDR']; } $result = pingHost($ip,1); - if (!$result) return false; + if (!$result) + return false; $macAddr=false; $arptable=`arp -n $ip`; $lines=explode("\n", $arptable); @@ -82,11 +84,10 @@ function getClientMac($ip=false) { } function newHostname($mac, $base, $role) { - global $config_db; - global $hosts_db; + global $config_db, $hosts_db; if(!preg_match('/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/', $mac)) { echo "invalid mac address"; - return; + return false; } if ($client=getClient($mac)) { @@ -122,8 +123,6 @@ function pingHost($host, $timeout=1) { return (0 == $retvar); } - - function ROUTE_domain() { global $config_db; $theFile = $config_db->getProp(CONFIG_KEY,'DomainFile'); @@ -139,6 +138,7 @@ function ROUTE_mgmtkey() { function ROUTE_epoptes_srv() { global $hosts_db; $hosts = $hosts_db->getAllByProp('Role','docenti'); + ksort($hosts); if (count($hosts) == 0) { echo 'none'; } else { @@ -160,8 +160,7 @@ function ROUTE_ansible_host() { } function ROUTE_hosts() { - global $hosts_db; - global $get_params; + global $hosts_db, $get_params; if (isset($get_params['role'])) { $items = $hosts_db->getAllByProp('Role', $get_params['role']); } else { @@ -204,10 +203,12 @@ function ROUTE_vaultpass() { exec('/usr/bin/sudo /bin/cat ' . $theFile, $oArr, $exitCode); $content = trim(implode("\n", $oArr)); if (false === $content) { - echo 'no file'; return; + echo 'no file'; + return false; } if (!$client = getClient()) { - echo 'no client'; return; + echo 'no client'; + return false; } $key = md5($client['name'], true); $padlenght = 16 - (strlen($content) % 16); @@ -217,26 +218,33 @@ function ROUTE_vaultpass() { } function ROUTE_whatsmyhostname() { - global $config_db; + global $config_db, $get_params; + if (isset($get_params['role'])) { + $role = $get_params['role']; + } else { + $role = $config_db->getProp(CONFIG_KEY,'DefaultRole'); + } + if (isset($get_params['base'])) { + $base = $get_params['base']; + } else { + $base = $config_db->getProp(CONFIG_KEY,'NamingBase'); + } $mac = getClientMac(); if (!$mac) { echo 'no-mac-address'; return false; } - $base = $config_db->getProp(CONFIG_KEY,'NamingBase'); - $role = $config_db->getProp(CONFIG_KEY,'DefaultRole'); newHostname($mac, $base, $role); } function ROUTE_mac2hostname() { - global $config_db; - global $get_params; - $mac = getClientMac(); - if (!$mac) { + global $config_db, $get_params; + if (isset($get_params['mac'])) { + $mac = $get_params['mac']; + } else { echo 'Usage: GET /mac2hostname?mac=XX_XX_XX_XX_XX_XX[&base=YYY][&role=ZZZ]'; - return; + return false; } - if (isset($get_params['role'])) { $role = $get_params['role']; } else {