-- Leo's gemini proxy
-- Connecting to m0yng.uk:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini;lang=en
Created 2020-08-26
Modified 2021-02-10
Linux
Hacking
It's an obvious problem to me that I have too many computers, and keeping on top of which have been updated recently is... not simple.
I've finally got around to making a semi solution, using a bash script and some PHP! Is there a better way? Almost certainly! Would it work easily and quickly on even a raspberry pi v1 and zero without stopping them doing the thing I want them to do? Maybe not.
A bash script which runs `apt update` and then `apt list --upgradeable` to count how many packages could be updated.
That file is in `/etc/cron.daily/` so should run every day
A PHP file that gets info from the script and stores it in a `json` file, but also:
Sends a page via DAPNET if there are more than 0 packages
Provides a quick reference `html` page
Also `json`
The page is simple, and looks like this (I could probably format the date time, but meh.)
#!/bin/bash hostname=$(hostname) datetime=$(date --iso-8601=seconds) apt update updatecount=$(apt list --upgradeable | wc -l) # correct for always getting at least one, even if there are none updatecount=$((updatecount - 1)) echo $updatecount curl -X POST -F "hostname=$hostname" -F "datetime=$datetime" -F "updatecount=$updatecount" http://myserver/aptCounter.php
<?php $aptCounterData = json_decode(file_get_contents("aptCounter.json"), true); if (!empty($_POST)) { $newEntry = (object) [ "hostname" => (string) $_POST['hostname'], "datetime" => (string) $_POST['datetime'], "updatecount" => (int) $_POST['updatecount'], ]; $hostname = $newEntry->hostname; $aptCounterData[$newEntry->hostname] = $newEntry; file_put_contents("aptCounter.json", json_encode($aptCounterData)); if ($newEntry->updatecount > 0) { echo $newEntry->updatecount; $url = 'http://www.hampager.de:8080/calls'; $data = array('text' => "M0YNG: $newEntry->hostname has $newEntry->updatecount updates available.", 'callSignNames' => ['m0yng'], 'transmitterGroupNames' => ['UK-ALL'], 'emergency' => 'false'); $auth = base64_encode('m0yng:mypassword'); $options = array( 'http' => array( 'header' => "Content-type: application/json\r\nAuthorization: Basic $auth", 'method' => 'POST', 'content' => json_encode($data), ), ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); var_dump($result); } echo "Done."; exit(); } else if ($_SERVER['QUERY_STRING'] == 'format=json') { header('Content-Type: application/json'); echo json_encode($aptCounterData); } else { usort($aptCounterData, function ($a, $b) {return $a['updatecount'] < $b['updatecount'];}); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="initial-scale=1.0"> <title>aptChecker Counts</title> <style> * { box-sizing: border-box; } body { background-color: #1d1f21; color: #c9cacc; font-family: "Fira Code", monospace; } main, header { max-width: 70rem; padding: 1rem; margin: 0 auto; } table { width: 100%; text-align: left; } table td { padding: 0.5em; } table td:last-of-type { font-weight: bold; } table td.good { color: #8f8; } table td.bad { color: #f88; } </style> </head> <body> <header> <h1>aptChecker Counts</h1> </header> <main> <table> <tr> <th>Hostname</th><th>DateTime</th><th>Update Count</th> </tr> <?php foreach ($aptCounterData as $host) { if (host['updatecount'] > 0) { } $host['goodbad'] = ($host['updatecount'] > 0 ? 'bad' : 'good'); echo "<tr><td>${host['hostname']}</td><td>${host['datetime']}</td><td class='${host['goodbad']}'>${host['updatecount']}</td></tr>"; } ?> </table> </main> </body> </html> <?php } ?>
-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-
๐ค Black Lives Matter
๐๐ค๐ Trans Rights are Human Rights
โค๏ธ๐งก๐๐๐๐ Love is Love
Copyright ยฉ 2024 Christopher M0YNG - It is forbidden to use any part of this site for crypto/NFT/AI related projects.
Page generated 2024-03-24 by Complex 19
-- Response ended
-- Page fetched on Sat May 18 23:12:38 2024