-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: resdb
action: commit
revision:
path_from:
revision_from: 8ff34624691bb86ca9f31598af3e5bf9aa22b8b4:
path_to:
revision_to:

git.thebackupbox.net

resdb

git://git.thebackupbox.net/resdb

commit 8ff34624691bb86ca9f31598af3e5bf9aa22b8b4
Author: epoch <epoch@hack.thebackupbox.net>
Date:   Mon Apr 15 08:03:59 2024 +0000

    I do not want to know how long that was not working.

diff --git a/contrib/whoisd/README b/contrib/whoisd/README

index 228197c6e50398f040f28afe649ed5f20d2c19f3..

index ..e8f0521b53a1fac9db96a61cadcbfe0f2df17326 100644

--- a/contrib/whoisd/README
+++ b/contrib/whoisd/README
@@ -1,8 +1,6 @@
 RTFS

 todo:
-  ipv6
-  more info in responses?
   make it compatible with traceroute -A ?

 add any other features you'd like either in here or the source. You know perl, right?
diff --git a/contrib/whoisd/whoisd-cached.sh b/contrib/whoisd/whoisd-cached.sh

index 248fad629a2a9db512fe32191b0489ffa0bab0bc..

index ..00f0ed28676c6ec5a3fc874aab2a460808db003d 100755

--- a/contrib/whoisd/whoisd-cached.sh
+++ b/contrib/whoisd/whoisd-cached.sh
@@ -1,7 +1,15 @@
-#!/bin/sh
-cd /var/db/resdb
+#!/bin/bash
+if [ "$1" ];then
+  cd "$1"
+else
+  cd /var/db/resdb
+fi
 commit=$(git log -1 | head -n1 | tr -cd 'a-f0-9')
-query=$(head -n1 | tr -cd 'a-zA-Z0-9.:_-')
+query=$(timeout 5 head -n1 | tr -cd 'a-zA-Z0-9.:_/-' | sed 's|/|%2f|g')
 if ! cat "/var/cache/whois/${commit}-${query}" 2>/dev/null;then
- printf "%s\n" "${query}" | /var/db/resdb/contrib/whoisd/whoisd.pl | tee "/var/cache/whois/${commit}-${query}"
+ printf "%s\n" "${query}" \
+   | uriunescape \
+   | /var/db/resdb/contrib/whoisd/whoisd.pl \
+   | cat <(echo "%% cache generated on" "$(date)") - \
+   | tee "/var/cache/whois/${commit}-${query}"
 fi
diff --git a/contrib/whoisd/whoisd.pl b/contrib/whoisd/whoisd.pl

index 7190cca7fd04ac026c52c249ed2dfd3b2221803b..

index ..4c3946a6fd868ae95a325d59a97145f230a615a5 100755

--- a/contrib/whoisd/whoisd.pl
+++ b/contrib/whoisd/whoisd.pl
@@ -4,18 +4,38 @@

 use strict;

+my $dom_prefix="urn:anonet:dom:";
+my $asn_prefix="urn:anonet:asn:";
+my $ip4_prefix="urn:anonet:ip4:";
+my $ip6_prefix="urn:anonet:ip6:";
+my $usr_prefix="urn:anonet:usr:";
+
+my $dom_prefix="dns:";
+my $asn_prefix="asn:";
+my $ip4_prefix="ip4:";
+my $ip6_prefix="ip6:";
+my $usr_prefix="acct:";
+
+my $dom_match="([a-zA-Z][a-zA-Z0-9-]*\.[a-zA-Z0-9-])"; #needs at least one dot. start with a-z, can contain a-z0-9-
+my $asn_match="(?:AS)?([0-9]{1,10})";
+my $ip4_match="([0-9.]+)(:?\/[0-9]+)?"; # lol fuck precision.
+my $ip6_match="([0-9a-f:]+)"; #lol
+my $usr_match="([a-zA-Z]+)";
+
 #maybe chroot this whoisd?
-#my $RESDB = "/services/resdb/resdb";
-my $RESDB = "/var/db/resdb";
+my $RESDB=`pwd`;## make sure to cd to resdb before running this so this gets set right.
+chomp($RESDB);

 my $HACK=0;
 my $QUERY=<stdin>;
-$QUERY =~ s/\r\n//g;
-$QUERY =~ s/\///g;
+$QUERY =~ s/[\r\n]//g;
+#$QUERY =~ s/\///g;#why are we removing /s? because it is gonna be a filename.
 if($QUERY eq '') {
  printf "%% error. no query. wtf?";
  exit 0;
 }
+printf "%% query: '%s'\n", $QUERY;
+
 my $out;
 my $title;
 my $value;
@@ -37,7 +57,7 @@ if($QUERY eq "!!\n") {
 sub get_user_from_ASN {
  my $AS=$_[0];
  my $user;
- chdir("$RESDB/db/as") || die "%% error";
+ chdir($RESDB . "/db/as") || die "%% error";
  if(chdir($AS) || die "%% ASN not found.") {
   open(FILE,"owner") || die "%% ASN's owner not found.";
   $user=<FILE>;
@@ -51,11 +71,14 @@ sub get_user_from_ASN {
 sub get_user_from_IPv4 {
  my @parts;
  my $user;
- chdir("$RESDB/db/ip") || die "%% error";
- @parts=split(/\./,$_[0]);
+ my $ip4=$_[0];
+ printf "%% ip: %s\n", $ip4;
+ $ip4 =~ s/\/([0-9]+)$//g;
+ chdir($RESDB . "/db/ip") || die "%% error";
+ @parts=split(/\./,$ip4);
  for($i=0;$i<scalar(@parts)-1;$i++) {
   if(!chdir(sprintf("%02X",$parts[$i]))) {
-   printf "%-20s %s\n", "error" . ":", "IP not found." unless $HACK;
+   printf "%-20s %s\n", "error" . ":", "IP not found. ( " . $ip4 . " )" unless $HACK;
    exit;
   }
  }
@@ -69,7 +92,8 @@ sub get_user_from_domain {
  my @parts;
  my $user;
  my $i;
- @parts=split(/\./,$_[0]);
+ my $dom=$_[0];
+ @parts=split(/\./,$dom);
  chdir("$RESDB/db/dom") || die "%% error";
  for($i=scalar(@parts)-1;$i>scalar(@parts)-3;$i--) {
   if(!$parts[$i]) {
@@ -77,7 +101,7 @@ sub get_user_from_domain {
    exit
   }
   if(!chdir($parts[$i])) {
-   printf "%-20s %s", "warning" . ":", "domain not found.";
+   printf "%-20s %s", "warning" . ":", "domain not found." . "( " . $dom . " )";
    exit;
   }
  }
@@ -93,6 +117,7 @@ sub get_user_from_IPv6 {
  #print "$d";
  $d =~ s/[^0-9a-f]//gi;
  $d =~ tr/a-z/A-Z/;
+ $d =~ s/\/[0-9]+$//g;
  foreach(split(//,$d)) {
   $d=$_;
   chdir($d);
@@ -104,31 +129,32 @@ sub get_user_from_IPv6 {
 }

 sub ASN_lookup {
- if($QUERY =~ m/^AS(.+?)$/i) {
+ if($QUERY =~ m/^AS([0-9]+?)$/i or $QUERY =~ m/^$asn_prefix([0-9]+?)$/i) {
   printf "%% AS section for %s\n", $QUERY;
   my $AS=$1;
-  chdir("$RESDB/db/as") || die "%% error";
-  if(chdir($AS) || die "%% error") {
-   foreach(split(/\n/,`grep '' -r .`)) {
-    $out = $_;
-    $out =~ s/^\.\///g;
-    $out =~ m/^(.+?):(.+?)$/;
-    ($title, $value) = ($1, $2);
-    printf "%-20s %s\n", $title . ":", $value;
-    if($title eq "owner") {
-     $QUERY = $value;
+  if(chdir("$RESDB/db/as")) { # no ASNs in this database
+   if(chdir($AS) || die "%% error") {
+    foreach(split(/\n/,`grep '' -r .`)) {
+     $out = $_;
+     $out =~ s/^\.\///g;
+     $out =~ m/^(.+?):(.+?)$/;
+     ($title, $value) = ($1, $2);
+     printf "%-20s %s\n", $title . ":", $value;
+     if($title eq "owner") {
+      $QUERY = $value;
+     }
     }
+   } else {
+    printf "AS not found.";
    }
-  } else {
-   printf "AS not found.";
-  }
+  } # no ASNs in this database
  }
 }


 # IPv4 addresses #this checks all dirs in the ip dir. so, 1., 2., and 21. (15)
 sub IPv4_lookup {
- if($QUERY =~ m/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/) {
+ if($QUERY =~ m/^$ip4_match$/) {
   printf "%% IP section for %s\n", $QUERY unless $HACK;
   chdir("$RESDB/db/ip") || die "%% error";
   @parts=split(/\./,$QUERY);
@@ -184,7 +210,7 @@ sub domain_lookup {

 #IPv6 addresses
 sub IPv6_lookup {
- if($QUERY =~ m/:/) {#close enough?
+ if($QUERY =~ m/([0-9a-f]{4}:[0-9a-f]{4})*:([0-9a-f]{4}:[0-9a-f]{4})*/i) {#close enough?
   $QUERY =~ s/://g;
   $QUERY =~ s/[^a-fA-F0-9]//g;
   $QUERY = uc($QUERY);
@@ -220,60 +246,78 @@ sub user_based_lookups {
  } else {
   printf "%-20s missing db/usr file.\n", "warning" . ":" unless $HACK;
  }
- chdir("$RESDB/db/as") || die "%% error";
  my @asn;
- foreach(split(/\n/,`grep '^$QUERY\$' */owner | cut -d/ -f1`)) {
-  $out = $_;
-  $out =~ s/\n//g;
-  printf "%-20s AS%s\n", "origin" . ":", $out if $HACK;
-  printf "%-20s AS%s\n", "origin" . ":", $out unless $HACK;
-  @asn[scalar(@asn)]=$out;
+ if(chdir("$RESDB/db/as")) {
+  foreach(split(/\n/,`grep '^$QUERY\$' */owner | cut -d/ -f1`)) {
+   $out = $_;
+   $out =~ s/\n//g;
+   printf "%-20s %s\n", "origin" . ":", $asn_prefix . $out if $HACK;
+   printf "%-20s %s\n", "origin" . ":", $asn_prefix . $out unless $HACK;
+   @asn[scalar(@asn)]=$out;
+  }
  }
- chdir("$RESDB/db/ip") || die "%% error";
- my $merp;
- foreach(split(/\n/,`grep '^$QUERY\$' */*/*/owner | cut -d/ -f1-3 | xargs printf '%s/cidr\n' | xargs cat | uniq`)) {
-  chomp $_;
-  printf "%-20s %s\n", "cidr" . ":", $_;
+ if(chdir("$RESDB/db/ip")) {
+  my $merp;
+  foreach(split(/\n/,`grep '^$QUERY\$' */*/*/owner | cut -d/ -f1-3 | xargs printf '%s/cidr\n' | xargs cat | uniq`)) {
+   chomp $_;
+   printf "%-20s %s\n", "cidr" . ":", $ip4_prefix . $_;
+  }
  }

- chdir("$RESDB/db/ip6") || die "%% error";
- foreach(split(/\n/,`grep '^$QUERY\$' -r * | cut -d/ -f1-16 | xargs printf '%s/cidr\n' | xargs cat | uniq`)) {
-  chomp $_;
-  printf "%-20s %s\n", "cidr" . ":", $_;
+ if(chdir("$RESDB/db/ip6")) {
+  foreach(split(/\n/,`grep '^$QUERY\$' -r * | cut -d/ -f1-16 | xargs printf '%s/cidr\n' | xargs cat | uniq`)) {
+   chomp $_;
+   printf "%-20s %s\n", "cidr" . ":", $ip6_prefix . $_;
+  }
  }

  foreach(split(/\n/,`grep -i -e "^$QUERY\$" "$RESDB/db/dom"/*/*/owner`)) {
   $out = $_;
   $out =~ s/.*\/db\/dom\/(.+?)\/(.+?)\/owner.*/\2\.\1/;
   if ($out ne "") { #fix this comparison.
-   printf "%-20s %s\n", "domain" . ":", $out;
+   printf "%-20s %s\n", "domain" . ":", $dom_prefix . $out;
   }
  }

  foreach(@asn) {
-  $QUERY="AS$_"; #meh. fix to pass it instead of global.
+  $QUERY=$asn_prefix . $_; #meh. fix to pass it instead of global.
   ASN_lookup();
  }
  #printf "%-20s %s\n", "notice:","$QUERY did not claim any domains yet";
 }

-if($QUERY =~ m/^AS(.+?)$/i) {
+printf "%%%% %s", `git log -1 | head -n1`;
+
+#printf "wtf?1\n";
+
+if($QUERY =~ m/^$asn_match$/ or $QUERY =~ m/^$asn_prefix([0-9]+)$/) {
+#printf "wtf?2\n";
+ printf "%% query looks like an ASN\n";
  $user=get_user_from_ASN($1);
+#printf "wtf?3\n";
 }
-elsif($QUERY =~ m/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/) {
- $user=get_user_from_IPv4($QUERY);
+elsif($QUERY =~ m/^$ip4_match$/ or $QUERY =~ m/^$ip4_prefix:$ip4_match$/) {
+ printf "%% query looks like an IPv4 address\n";
+ $user=get_user_from_IPv4($1);
 }
-elsif($QUERY =~ m/\./) {
- $user=get_user_from_domain($QUERY);
+elsif($QUERY =~ m/^([a-z][a-z0-9-]+\.[a-z0-9-]+)$/ or $QUERY =~ m/^$dom_prefix(.*)$/) {
+ printf "%% query looks like a domain\n";
+ $user=get_user_from_domain($1);
 }
-elsif($QUERY =~ m/:/) {
- $user=get_user_from_IPv6($QUERY);
+elsif($QUERY =~ m/^([0-9a-f:]+)$/i or $QUERY =~ m/$ip6_prefix(.*)$/) {
+ printf "%% query looks like an IPv6 address\n";
+ $user=get_user_from_IPv6($1);
+#printf "wtf?9\n";
 }
 else {
+#printf "wtf?10\n";
+ printf "%% query didn't look like any specific. assuming a username\n";
  $user=$QUERY;
+#printf "wtf?11\n";
 }
 $user =~ s/[\r\n]//g;
-printf "%%%% %s", `git log -1 | head -n1`;
+
+#printf "wtf?12\n";
 printf "%%%% found user: %s for the query.\n", $user;

 #k. we got user... now to find stuff belonging to that user.

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 11:37:19 2024