aboutsummaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorepochqwert <epoch@53flpnlls43fcguy.onion>2015-02-07 04:33:50 -0600
committerepochqwert <epoch@53flpnlls43fcguy.onion>2015-02-07 04:33:50 -0600
commite79f3c775cb1957e09716d7782d91da33fa8f0c8 (patch)
treea5f1690a04305306a54d1999f147b6ca59836c0d /misc
parentaf42bb47f92b772411cd4235c850caa0ac988a10 (diff)
downloadmisc-e79f3c775cb1957e09716d7782d91da33fa8f0c8.tar.gz
misc-e79f3c775cb1957e09716d7782d91da33fa8f0c8.zip
The stuff I use to generate my anonet map. check out paths-to-edges. :>
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/svgmap/cached.sh11
-rwxr-xr-xmisc/svgmap/clear_cache.sh2
-rwxr-xr-xmisc/svgmap/generate.sh60
-rw-r--r--misc/svgmap/paths-to-edges.c132
4 files changed, 205 insertions, 0 deletions
diff --git a/misc/svgmap/cached.sh b/misc/svgmap/cached.sh
new file mode 100755
index 0000000..4c8c28e
--- /dev/null
+++ b/misc/svgmap/cached.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+/usr/pkg/sbin/nc 127.0.0.1 64777 > /var/cache/svgmap/data.new
+if cmp /var/cache/svgmap/data.new \
+ /var/cache/svgmap/data >/dev/null 2>&1;then
+ cat /var/cache/svgmap/output
+else
+ cp /var/cache/svgmap/data.new /var/cache/svgmap/data
+ cat /var/cache/svgmap/data \
+ | /var/www/libexec/svgmap/generate.sh \
+ | tee /var/cache/svgmap/output
+fi
diff --git a/misc/svgmap/clear_cache.sh b/misc/svgmap/clear_cache.sh
new file mode 100755
index 0000000..f95289f
--- /dev/null
+++ b/misc/svgmap/clear_cache.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+rm /var/cache/svgmap/*
diff --git a/misc/svgmap/generate.sh b/misc/svgmap/generate.sh
new file mode 100755
index 0000000..209f83b
--- /dev/null
+++ b/misc/svgmap/generate.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+export PATH=$PATH:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin
+
+echo '<svg id="map" width="500" height="500">'
+
+cat > /var/cache/svgmap/data.tmp
+
+nodes=$(cat /var/cache/svgmap/data.tmp \
+ | /var/www/libexec/svgmap/paths-to-edges \
+ | tr ' ' '\n' \
+ | sort \
+ | uniq )
+
+nn=$(echo $nodes | tr ' ' '\n' | wc -l | tr -d ' ')
+
+scale=200
+xoff=250
+yoff=250
+
+cat /var/cache/svgmap/data.tmp | /var/www/libexec/svgmap/paths-to-edges > /var/cache/svgmap/edges.list
+
+nsin=""
+ncos=""
+lsin=""
+lcos=""
+for i in $(seq 0 $nn);do
+ tmpsin="$(echo | awk "{ print ( ( sin( ( ${i}.0 / ${nn}.0) * 2.0 * atan2(0,-1) ) ) ) }")"
+ tmpcos="$(echo | awk "{ print ( ( cos( ( ${i}.0 / ${nn}.0) * 2.0 * atan2(0,-1) )) ) }")"
+ scale=200
+ nsin="$nsin $(echo | awk "{print $scale * $tmpsin + $xoff}")"
+ ncos="$ncos $(echo | awk "{print $scale * $tmpcos + $yoff}")"
+ scale=180
+ lsin="$lsin $(echo | awk "{print $scale * $tmpsin + $xoff}")"
+ lcos="$lcos $(echo | awk "{print $scale * $tmpcos + $yoff}")"
+done
+
+for i in $nodes;do
+ node1n=$(echo $nodes | tr ' ' '\n' | grep -n '^'$i'$' | cut -d: -f1)
+ x="$(echo $nsin | cut '-d ' -f$node1n)"
+ y="$(echo $ncos | cut '-d ' -f$node1n)"
+ printf '<g class="node_and_links">'
+ printf '<a xlink:href="/cgi-bin/whois.cgi?q=AS%s">' "$i"
+ printf '<circle name="%s" cx="%f" cy="%f" r="20"/>' "$i" "$x" "$y"
+ printf '<text x="%f" y="%f" fill="red" transform="rotate(0 %f,%f)">%s</text>' "$x" "$y" "$x" "$y" "$i"
+ echo "</a>"
+ cat /var/cache/svgmap/edges.list | grep "\b$i\b" | while read edge;do
+ node1=$(echo $edge | cut '-d ' -f1)
+ node2=$(echo $edge | cut '-d ' -f2)
+ node1n=$(echo $nodes | tr ' ' '\n' | grep -n '^'$node1'$' | cut -d: -f1)
+ node2n=$(echo $nodes | tr ' ' '\n' | grep -n '^'$node2'$' | cut -d: -f1)
+ x1="$(echo $lsin | cut '-d ' -f$node1n)"
+ y1="$(echo $lcos | cut '-d ' -f$node1n)"
+ x2="$(echo $lsin | cut '-d ' -f$node2n)"
+ y2="$(echo $lcos | cut '-d ' -f$node2n)"
+ printf '<line x1="%f" y1="%f" x2="%f" y2="%f"/>\n' "$x1" "$y1" "$x2" "$y2"
+ done
+ printf "</g>\n"
+done
+
+echo '</svg>'
diff --git a/misc/svgmap/paths-to-edges.c b/misc/svgmap/paths-to-edges.c
new file mode 100644
index 0000000..526f890
--- /dev/null
+++ b/misc/svgmap/paths-to-edges.c
@@ -0,0 +1,132 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+struct link {
+ char *a;
+ char *b;
+ int count;
+};
+
+struct link ** get_links(char ***data) {
+ int i,j,k=0;
+ for(i=0;data[i];i++) {
+ for(j=0;data[i][j];j++) {
+ k++;//this is overkill because I can't remove dedups that won't need
+ //new space allocated.
+ }
+ }
+ struct link **link=malloc(sizeof(struct link *) * k+1); //???
+ memset(link,0,sizeof(struct link *) * k+1);
+ for(i=0;data[i];i++) {
+ for(j=0;data[i][j+1];j++) {
+ for(k=0;link[k];k++) {
+ if(!strcmp(link[k]->a,data[i][j]) && !strcmp(link[k]->b,data[i][j+1]) ||
+ !strcmp(link[k]->b,data[i][j]) && !strcmp(link[k]->a,data[i][j+1])) {
+ break;
+ }
+ }
+ if(!link[k]) {
+ link[k]=malloc(sizeof(struct link));
+ link[k]->a=strdup(data[i][j]);
+ link[k]->b=strdup(data[i][j+1]);
+ link[k]->count=1;
+ } else {
+ link[k]->count++;
+ }
+ }
+ }
+ return link;
+}
+
+char *recurse_readline(int chars);
+
+char **recurse_readfile(int lines) {
+ char **malloced;
+ char *line=recurse_readline(0);
+ if(feof(stdin)) {
+ malloced=malloc(sizeof(char *) * (lines+1));
+ malloced[lines]=0;
+ return malloced;
+ }
+ malloced=recurse_readfile(lines+1);
+ malloced[lines]=line;
+ return malloced;
+}
+
+char *recurse_readline(int chars) {
+ char *malloced;
+ short in=fgetc(stdin);
+ if(in == '\n' || in == -1) {
+ malloced=malloc(chars+2);
+ malloced[chars]='\n';
+ malloced[chars+1]=0;
+ return malloced;
+ }
+ malloced=recurse_readline(chars+1);
+ malloced[chars]=in;
+ return malloced;
+}
+
+//this is the function failing on full-size data.
+char ***lines_to_data(char **lines) {
+ char ***data;
+ int i,j,k,n,m;
+ for(i=0;lines[i];i++);
+ data=malloc(sizeof(char **) * i+1);
+ data[i]=0;
+
+ for(i=0;lines[i];i++) {
+ k=0;
+ for(j=0;lines[i][j];j++) {
+ if(lines[i][j]==' ' || lines[i][j] == '\n' || lines[i][j] == '\0') k++;
+ }
+ data[i]=malloc(sizeof(char *) * k+1);
+ data[i+1]=0;
+ data[i][k]=0;
+ }
+/* in this for loop somewhere. */
+ for(i=0;lines[i];i++) {
+ k=0;
+ n=0;
+ for(j=0;lines[i][j];j++) {
+ if(lines[i][j]==' ' || lines[i][j]=='\n' || lines[i][j]=='\0') {
+ data[i][n]=strndup(lines[i]+k,j-k);
+ data[i][n][j-k]=0;
+ n++;
+ k=j+1;
+ }
+ }
+ }
+ return data;
+}
+
+int main() {
+ int i,j;
+ char **lines;
+ char ***data;
+ struct link **link;
+ lines=recurse_readfile(0);
+/* for(i=0;lines[i];i++) {
+ printf("lines[%d]=\"%s\"\n",i,lines[i]);
+ }*/
+ data=lines_to_data(lines);
+/* for(i=0;data[i];i++) {
+ for(j=0;data[i][j];j++) {
+ printf("data[%d][%d]='%s'\n",i,j,data[i][j]);
+ }
+ printf("\n");
+ }
+*/
+ link=get_links(data);
+ //printf("//graph generated by paths-to-edges to DOT format\n");
+ //printf("graph anonet {\n");
+ for(i=0;link[i];i++) {
+ //printf("%s -> %s (%d)\n",link[i]->a,link[i]->b,link[i]->count);
+ //printf("%s -- %s;\n",link[i]->a,link[i]->b,link[i]->count);
+ printf("%s %s\n",link[i]->a,link[i]->b);
+ }
+ //printf("}\n");
+
+ return 0;
+}