summaryrefslogtreecommitdiffstats
path: root/modules-available/rebootcontrol
diff options
context:
space:
mode:
authorSimon Rettberg2021-05-06 10:26:09 +0200
committerSimon Rettberg2021-05-11 14:51:13 +0200
commit8dc2b92d667f1401ab9f1315a36add61658f899c (patch)
tree452c5fe040055884cf9d9ee834415db84999a9a1 /modules-available/rebootcontrol
parent[session] Add simple session overview table (diff)
downloadslx-admin-8dc2b92d667f1401ab9f1315a36add61658f899c.tar.gz
slx-admin-8dc2b92d667f1401ab9f1315a36add61658f899c.tar.xz
slx-admin-8dc2b92d667f1401ab9f1315a36add61658f899c.zip
Moderize Database handling
* Auto-convert to utf8mb4_unicode_520_ci * Use foreach instead of while to loop over results * Drop useless statement caching * Keep emulated prepares, as we sometimes loop over nested queries
Diffstat (limited to 'modules-available/rebootcontrol')
-rw-r--r--modules-available/rebootcontrol/hooks/cron.inc.php8
-rw-r--r--modules-available/rebootcontrol/inc/rebootcontrol.inc.php6
-rw-r--r--modules-available/rebootcontrol/inc/rebootutils.inc.php4
-rw-r--r--modules-available/rebootcontrol/inc/scheduler.inc.php4
-rw-r--r--modules-available/rebootcontrol/pages/jumphost.inc.php4
-rw-r--r--modules-available/rebootcontrol/pages/subnet.inc.php6
6 files changed, 16 insertions, 16 deletions
diff --git a/modules-available/rebootcontrol/hooks/cron.inc.php b/modules-available/rebootcontrol/hooks/cron.inc.php
index 8f5c73a0..73de020d 100644
--- a/modules-available/rebootcontrol/hooks/cron.inc.php
+++ b/modules-available/rebootcontrol/hooks/cron.inc.php
@@ -5,7 +5,7 @@
*/
if (in_array((int)date('G'), [6, 7, 9, 12, 15]) && in_array(date('i'), ['00', '01', '02', '03'])) {
$res = Database::simpleQuery('SELECT hostid, host, port, username, sshkey, script FROM reboot_jumphost');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
RebootControl::wakeViaJumpHost($row, '255.255.255.255', [['macaddr' => '00:11:22:33:44:55']]);
}
}
@@ -171,7 +171,7 @@ if ($res->rowCount() === 0)
return;
Stuff::$subnets = [];
-while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+foreach ($res as $row) {
if (!isset(Stuff::$subnets[$row['subnetid']])) {
Stuff::$subnets[$row['subnetid']] = [];
}
@@ -194,7 +194,7 @@ $res = Database::simpleQuery("SELECT subnetid FROM reboot_subnet
WHERE subnetid IN (:active) AND nextdirectcheck < UNIX_TIMESTAMP() AND fixed = 0
ORDER BY nextdirectcheck ASC LIMIT 10", ['active' => array_keys(Stuff::$subnets)]);
cron_log('Direct checks: ' . $res->rowCount() . ' (' . implode(', ', array_keys(Stuff::$subnets)) . ')');
-while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+foreach ($res as $row) {
$dst = (int)$row['subnetid'];
cron_log('Direct check for subnetid ' . $dst);
$result = testServerToClient($dst);
@@ -239,7 +239,7 @@ if (count($combos) > 0) {
ORDER BY sxs.nextcheck ASC
LIMIT 10", ['combos' => $combos]);
cron_log('C2C checks: ' . $res->rowCount());
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$src = (int)$row['srcid'];
$dst = (int)$row['dstid'];
$result = testClientToClient($src, $dst);
diff --git a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php
index da1dd69a..71801f1a 100644
--- a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php
+++ b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php
@@ -167,7 +167,7 @@ class RebootControl
if (!empty($invalid)) {
$res = Database::simpleQuery('SELECT machineuuid, clientip, locationid FROM machine WHERE machineuuid IN (:uuids)',
['uuids' => array_keys($invalid)]);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (isset($invalid[$row['machineuuid']])) {
$valid[] = $row + $invalid[$row['machineuuid']];
} else {
@@ -300,7 +300,7 @@ class RebootControl
// Need all subnets...
$subnets = [];
$res = Database::simpleQuery('SELECT subnetid, start, end, isdirect FROM reboot_subnet');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row += [
'jumphosts' => [],
'direct' => [],
@@ -317,7 +317,7 @@ class RebootControl
LEFT JOIN reboot_subnet s ON (INET_ATON(jh.host) BETWEEN s.start AND s.end)
LEFT JOIN reboot_subnet_x_subnet sxs ON (sxs.srcid = s.subnetid AND sxs.reachable <> 0)
GROUP BY jh.hostid');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['subnets1'] === null && $row['subnets2'] === null)
continue;
$nets = explode(',', $row['subnets1'] . ',' . $row['subnets2']);
diff --git a/modules-available/rebootcontrol/inc/rebootutils.inc.php b/modules-available/rebootcontrol/inc/rebootutils.inc.php
index 99235e8a..f6843150 100644
--- a/modules-available/rebootcontrol/inc/rebootutils.inc.php
+++ b/modules-available/rebootcontrol/inc/rebootutils.inc.php
@@ -18,9 +18,9 @@ class RebootUtils
$res = Database::simpleQuery("SELECT $columns FROM machine
WHERE machineuuid IN (:list)", compact('list'));
if (!$assoc)
- return $res->fetchAll(PDO::FETCH_ASSOC);
+ return $res->fetchAll();
$ret = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$ret[$row['machineuuid']] = $row;
}
return $ret;
diff --git a/modules-available/rebootcontrol/inc/scheduler.inc.php b/modules-available/rebootcontrol/inc/scheduler.inc.php
index 292529fa..7da4b46b 100644
--- a/modules-available/rebootcontrol/inc/scheduler.inc.php
+++ b/modules-available/rebootcontrol/inc/scheduler.inc.php
@@ -117,7 +117,7 @@ class Scheduler
$res = Database::simpleQuery("SELECT s.locationid, s.action, s.nextexecution, s.options
FROM reboot_scheduler s
WHERE s.nextexecution < :now AND s.nextexecution > 0", ['now' => $now]);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
// Calculate next_execution for the event and update DB.
$options = json_decode($row['options'], true);
// Determine proper opening times by waling up tree
@@ -269,7 +269,7 @@ class Scheduler
LEFT JOIN reboot_scheduler rs USING (locationid)
WHERE l.locationid IN (:list)", ['list' => $childIdList]);
$locationData = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$locationData[$row['locationid']] = $row;
}
// Handle all child locations
diff --git a/modules-available/rebootcontrol/pages/jumphost.inc.php b/modules-available/rebootcontrol/pages/jumphost.inc.php
index bf0a67e2..90508e91 100644
--- a/modules-available/rebootcontrol/pages/jumphost.inc.php
+++ b/modules-available/rebootcontrol/pages/jumphost.inc.php
@@ -135,7 +135,7 @@ class SubPage
LEFT JOIN reboot_jumphost_x_subnet jxs USING (hostid)
GROUP BY hostid
ORDER BY hostid');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$hosts[] = $row;
}
$data = [
@@ -188,7 +188,7 @@ class SubPage
ORDER BY start ASC',
['id' => $id]);
$list = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['cidr'] = IpUtil::rangeToCidr($row['start'], $row['end']);
if ($row['hostid'] !== null) {
$row['checked'] = 'checked';
diff --git a/modules-available/rebootcontrol/pages/subnet.inc.php b/modules-available/rebootcontrol/pages/subnet.inc.php
index d165a59d..c1631cbd 100644
--- a/modules-available/rebootcontrol/pages/subnet.inc.php
+++ b/modules-available/rebootcontrol/pages/subnet.inc.php
@@ -115,7 +115,7 @@ class SubPage
GROUP BY subnetid, start, end
ORDER BY start ASC, end DESC');
$deadline = strtotime('-60 days');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['cidr'] = IpUtil::rangeToCidr($row['start'], $row['end']);
$row['lastseen_s'] = Util::prettyTime($row['lastseen']);
if ($row['lastseen'] && $row['lastseen'] < $deadline) {
@@ -149,7 +149,7 @@ class SubPage
ORDER BY h.host ASC', ['id' => $id]);
// Mark those assigned to the current subnet
$jh = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['checked'] = $row['subnetid'] === null ? '' : 'checked';
$jh[] = $row;
}
@@ -159,7 +159,7 @@ class SubPage
INNER JOIN reboot_subnet_x_subnet sxs ON (s.subnetid = sxs.srcid AND sxs.dstid = :id AND sxs.reachable = 1)
ORDER BY s.start ASC', ['id' => $id]);
$sn = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$sn[] = ['cidr' => IpUtil::rangeToCidr($row['start'], $row['end'])];
}
$subnet['sourceNets'] = $sn;