aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Wittamore <philip@wittamore.com>2025-12-21 12:05:53 +0100
committerPhilip Wittamore <philip@wittamore.com>2025-12-21 12:05:53 +0100
commit2444adfe7afba6bed2608bfcd6cccc79eccf39f3 (patch)
tree88a6ca97f124ec5a412172922a99a2a10d03ac09
parent5637b6bc9e9ca99779fd6483318f33a6fe38152d (diff)
downloadscripts-2444adfe7afba6bed2608bfcd6cccc79eccf39f3.tar.gz
scripts-2444adfe7afba6bed2608bfcd6cccc79eccf39f3.tar.bz2
scripts-2444adfe7afba6bed2608bfcd6cccc79eccf39f3.zip
-rwxr-xr-x[-rw-r--r--]README.md0
-rwxr-xr-x[-rw-r--r--]getfeeds.php36
-rwxr-xr-x[-rw-r--r--]search.php0
-rwxr-xr-xwifi_connect73
4 files changed, 99 insertions, 10 deletions
diff --git a/README.md b/README.md
index becd979..becd979 100644..100755
--- a/README.md
+++ b/README.md
diff --git a/getfeeds.php b/getfeeds.php
index ca52b9b..a632c5f 100644..100755
--- a/getfeeds.php
+++ b/getfeeds.php
@@ -20,11 +20,16 @@ if (file_exists("$root/$hs")) {
copy("$root/$hs", "$root/gophermap");
$dt = new DateTime("now", new DateTimeZone('Europe/Paris'));
file_put_contents("$root/gophermap", "last update: ".$dt->format('Y-m-d H:i:s')."\n\n", FILE_APPEND);
+}else{
+ echo "$root/$hs not found, aborting";
+ exit;
}
// iterate through feed directories
+// each directory contains the feed url and title
+// and receives the constructed gophermap
foreach ($dir as $subdir) {
- # get feed settings from directory
+ # if config files missing go to next directory
if (!file_exists("$subdir/$fs")) continue;
if (!file_exists("$subdir/$ts")) continue;
@@ -43,6 +48,7 @@ foreach ($dir as $subdir) {
// simplepie can't recuperate a gopher url
// so we use curl in this case
$gopher = 0;
+ $rssstring = "";
if (str_starts_with($feedurl, "gopher")) {
exec("curl $feedurl", $rssdata, $retval);
if (!empty($rssdata)) {
@@ -64,18 +70,20 @@ foreach ($dir as $subdir) {
// extract each feed item
$x=0;
+ $youtube=false;
foreach ($feed->get_items(0, 30) as $item) {
$itemlink = $item->get_permalink();
$itemtitle = $item->get_title();
$itemdate = $item->get_date("Y-m-d");
- if (empty($itemtitle)) $itemtitle="No itemtitle found";
+ if (empty($itemtitle)) $itemtitle="No item title found";
// build item link
if ($gopher==1) {
$host = parse_url($itemlink, PHP_URL_HOST);
$port = parse_url($itemlink, PHP_URL_PORT);
+ if ((int)$port < 70) $port="70";
$path = parse_url($itemlink, PHP_URL_PATH);
if (pathinfo($path, PATHINFO_EXTENSION)) {
$itemlist .= "0".$itemdate." ".$itemtitle."\t".substr($path,2)."\t".$host."\t".$port."\n";
@@ -83,23 +91,28 @@ foreach ($dir as $subdir) {
$itemlist .= "1".$itemdate." ".$itemtitle."\t".substr($path,2)."\t".$host."\t".$port."\n";
}
}else{
+ //
+ if (str_contains($itemlink,"youtu")) {
// convert rss youtube url to youtu.be url
- $itemlink = str_replace("www.youtube.com/watch?v=", "youtu.be/", $itemlink);
- $itemlist .= "h".$itemdate." ".$itemtitle."\tURL:".$itemlink."\n";
+ $youtube=true;
+ $itemlink = str_replace("www.youtube.com/watch?v=", "youtu.be/", $itemlink);
+ }
+ $itemlist .= "U".$itemdate." ".$itemtitle."\tURL:".$itemlink."\n";
}
$x++;
}
// build list of feed items
if ($x==0) {
- $itemlist .= "! Error - No items found\n\n";
- $itemlist .= "DEBUG\n";
- $itemlist .= "curl $feedurl\n";
- $itemlist .= "result:\n";
- $itemlist .= $rssstring;
- $itemlist .= "\nEOF\n";
+ // gopher error tag
+ if ( str_starts_with($rssstring,"3")) {
+ $itemlist .= "$rssstring\t/errors.txt\tspike.nagatha.fr\t70\n";
+ }else{
+ $itemlist .= $rssstring;
+ }
}
file_put_contents("$subdir/gophermap", $itemlist);
+ file_put_contents("$subdir/gophermap", str_repeat("\n ", 30), FILE_APPEND);
// build list of feeds
$feedname = "1".$feeditemtitle."\t".basename($subdir)."\n";
@@ -112,6 +125,9 @@ foreach ($dir as $subdir) {
unset($itemlist);
}
+// add empty lines to gophermap
+file_put_contents("$root/gophermap", str_repeat("\n ", 30), FILE_APPEND);
+
?>
diff --git a/search.php b/search.php
index dc09366..dc09366 100644..100755
--- a/search.php
+++ b/search.php
diff --git a/wifi_connect b/wifi_connect
new file mode 100755
index 0000000..a92a07d
--- /dev/null
+++ b/wifi_connect
@@ -0,0 +1,73 @@
+#!/usr/bin/env bash
+
+# wpa_supplicant script to discover and add access points
+# or connect to known access points
+
+set -e
+
+W_IF="wlan0" # change with your right interface
+WPA_CONF="/etc/wpa_supplicant/wpa_supplicant.conf"
+
+# bogus call of doas to force auth so as to not be bothered by fzf blocking
+# the prompt later on.
+# assumes that you're not being prompt for passwd at every single call :)
+doas echo -n
+
+# with a little help from my friends
+get_essid ()
+{
+ ESSID=$(doas iw ${W_IF} scan | rg "\tSSID" | \
+ sed -e 's/^.*SSID: //g' | sort | uniq | fzf )
+}
+
+known_essid ()
+{
+ ID=$(doas wpa_cli list_networks | rg -F "${ESSID}")
+}
+
+connect_essid ()
+{
+ echo "${ESSID} found, connecting..."
+ echo
+ doas wpa_cli enable_network "${ID}"
+ # uncomment following if using with wpa-conf
+ #echo
+ #doas dhclient -v ${W_IF}
+}
+
+add_essid ()
+{
+ while true; do
+ echo "ESSID PASSWORD: "
+ read -r ESSID_PASSWD
+ while true; do
+ echo "Is \"${ESSID_PASSWD}\" correct? (y/n)"
+ read -r ANSWER_PASSWD
+ if [ "${ANSWER_PASSWD}" = "y" ]; then
+ ENTRY="$(wpa_passphrase "$ESSID" "$ESSID_PASSWD")"
+ echo "$ENTRY" | doas tee -a $WPA_CONF
+ break
+ fi
+ done
+ break
+ done
+ echo "${ESSID} added, connecting..."
+}
+
+get_essid
+if known_essid; then
+ connect_essid
+ exit
+else
+ while true; do
+ echo "Add this access point? (y/n)"
+ read -r ANSWER_ADD
+ if [ "${ANSWER_ADD}" = "y" ]; then
+ add_essid
+ wpa_cli reconfigure
+ known_essid
+ connect_essid
+ exit
+ fi
+ done
+fi