diff --git a/img/ccc.png b/img/ccc.png index 542ac8c..90b164e 100644 Binary files a/img/ccc.png and b/img/ccc.png differ diff --git a/img/dl-col.png b/img/dl-col.png new file mode 100644 index 0000000..b194874 Binary files /dev/null and b/img/dl-col.png differ diff --git a/img/dl.png b/img/dl.png new file mode 100644 index 0000000..875e4de Binary files /dev/null and b/img/dl.png differ diff --git a/js/pamela-buttons.js b/js/pamela-buttons.js index d5d09d8..7e95c1f 100644 --- a/js/pamela-buttons.js +++ b/js/pamela-buttons.js @@ -80,6 +80,37 @@ FullScreenButton.prototype.execute = function() { //TODO: do somth }; +// Class DownloadScriptButton + +jQuery.extend(DownloadScriptButton.prototype, IFaceButton.prototype); +function DownloadScriptButton(x, y) { + + this.width = 64; + this.height = 64; + + this.isHover = false; + + this.dlCol = new Image(); + this.dlCol.src = "img/dl-col.png"; + this.dl = new Image(); + this.dl.src = "img/dl.png"; +}; + +DownloadScriptButton.prototype.draw = function() { + if (this.isHover) { + context.fillStyle = 'rgb(192,192,192)'; + context.font = "18pt sans-serif"; + context.fillText("Download pamela scanner script", this.x, this.y - 10); + context.drawImage(this.dlCol, this.x, this.y); + } else { + context.drawImage(this.dl, this.x, this.y); + } +}; + +DownloadScriptButton.prototype.execute = function() { + location.href = 'pamela-scanner.sh'; +}; + // Class IFace buttons function IFaceButtons() { this.buttons = []; @@ -91,11 +122,11 @@ IFaceButtons.prototype.add = function(button) { }; IFaceButtons.prototype.reposition = function() { - var x = width - 64; + var x = 20; var y = height - 64; for (var i = 0; i < this.buttons.length; i++) { this.buttons[i].moveTo(x, y); - x -= 64; + x += 64; } }; @@ -104,3 +135,17 @@ IFaceButtons.prototype.draw = function() { this.buttons[i].draw(); }; +IFaceButtons.prototype.mousemove = function(event) { + for (var i =0; i < this.buttons.length; i++) { + var b = this.buttons[i]; + b.isHover = b.isHovered(event.offsetX, event.offsetY); + } +}; + +IFaceButtons.prototype.mouseclick = function(event) { + for (var i =0; i < this.buttons.length; i++) { + var b = this.buttons[i]; + if (b.isHovered(event.offsetX, event.offsetY)) + b.execute(); + } +}; diff --git a/js/pamela-nodes.js b/js/pamela-nodes.js index 19b44a9..d837840 100644 --- a/js/pamela-nodes.js +++ b/js/pamela-nodes.js @@ -156,7 +156,7 @@ NorbertNode.prototype.draw = function() { s *= 2; //var x = Math.floor(this.projection.x - (186 / s)); //var y = Math.floor(this.projection.y - (50 / s)); - var x = Math.floor(this.projection.x - (250 / s)); + var x = Math.floor(this.projection.x - (192 / s)); var y = Math.floor(this.projection.y - (180 / s)); context.drawImage(this.norbert, x, y); }; diff --git a/js/pamela.js b/js/pamela.js index 1231fa7..22d14a3 100644 --- a/js/pamela.js +++ b/js/pamela.js @@ -36,8 +36,8 @@ function Pamela(canvas) { }; this.buttons = new IFaceButtons(); - this.fullScreenButton = new FullScreenButton(); - this.buttons.add(this.fullScreenButton); + this.downloadScriptButton = new DownloadScriptButton(); + this.buttons.add(this.downloadScriptButton); this.resize(); this.m = new Matrix(); @@ -114,20 +114,13 @@ Pamela.prototype.start = function() { }; Pamela.prototype.mousemove = function(event) { - this.fullScreenButton.isHover = this.fullScreenButton.isHovered(event.offsetX, event.offsetY); + this.buttons.mousemove(event); this.mouse.x = event.offsetX; this.mouse.y = event.offsetY; }; Pamela.prototype.mouseclick = function(event) { - if (this.fullScreenButton.isHovered(event.offsetX, event.offsetY)) - this.fullScreenButton.execute(); -}; - -Pamela.prototype.mousein = function(event) { -}; - -Pamela.prototype.mouseout = function(event) { + this.buttons.mouseclick(event); }; Pamela.prototype.fire = function() { @@ -199,7 +192,7 @@ Pamela.prototype.resize = function() { Pamela.prototype.updateEntries = function() { var self = this; - $.getJSON("js/input.php", function(data) { + $.getJSON("macs.php", function(data) { self.updateNodes(data); }); self.entriesTimer = setTimeout(function() { self.updateEntries(); }, 60000); diff --git a/macs.php b/macs.php index 7d0e70c..f81f2a2 100644 --- a/macs.php +++ b/macs.php @@ -38,13 +38,13 @@ class Macs { private function readFile($filename) { $mcs = file_get_contents($filename); - $this->macs = array_merge($this->macs, explode('|', $mcs)); + $this->macs = array_merge($this->macs, explode(',', $mcs)); } private function readFiles($directory) { $macFiles = scandir($directory); foreach ($macFiles as $macFile) { - if (preg_match("/\.macs$/", $macFile) != 1) + if (preg_match("/.+\.macs$/", $macFile) != 1) continue; $filename = "$directory/$macFile"; @@ -64,6 +64,11 @@ class Macs { } private function createJson() { + if (count($this->macs) < 1) { + echo '[]'; + return; + } + echo '["'; echo implode('", "', $this->macs); echo '"]'; diff --git a/pamela-scanner.sh b/pamela-scanner.sh index d419bf8..4aedeee 100755 --- a/pamela-scanner.sh +++ b/pamela-scanner.sh @@ -21,39 +21,66 @@ LICENSE -IF='eth0' -OUT='js/input.php' +function usage { + +echo 'Usage: pamela-scanner [OPTIONS] + + -i INTERFACE Interface to arp-scan + -o URL The url of the pamela upload script (including /upload.php) + -s TIME The time to sleep between scans in seconds. + -h Shows help + +Pamela is an arp-scanner, it uploads the mac addresses in your local lan on a webserver +where you get a visual representation of the mac addresses present. Multiple people +on multiple lans can run pamela together against the same server, where all results +are agregated. In short, pamela gives you an overview of how big the shared network is.' +exit 1 + +} + +IF='wlan0' +OUT='http://localhost/sb/pamela/upload.php' SLEEP='60' -TEMP=$(getopt -o i:o:s:-n "pamela arp scanner" -- "$@") +TEMP=$(getopt -o 'hi:o:s:-n' "pamela arp scanner" -- "$@") if [ $? != 0 ] ; then echo "Could not parse parameters..." >&2 ; exit 1 ; fi -eval set "$TEMP" -- +eval set "$TEMP" while true do + shift; + [ -z "$1" ] && break; case "$1" in -i) IF="$2"; shift;; -o) OUT="$2"; shift;; -s) SLEEP="$2"; shift;; - --) break;; + -h|'-?') usage; break;; + *) echo "Unknown param: [$1]"; usage; exit 1; esac - shift done +sudo -n true || { echo "Must be root to run pamela-scanner"; exit 1; } + +if [ -z "$(sudo which arp-scan)" ] +then + echo "Could not find arp-scan, which is required for pamela to scan the mac addresses" +fi + while true do echo $(date)" scanning..." - O=""; - O="$O"' ' - O="$O"' [ ' - O="$O"$(arp-scan -R -i 10 --interface "$IF" --localnet | awk '{ print "\""$2"\", " }' | grep :.*: | sort | uniq) - O="$O"' ] ' - echo "$O" - echo "$O" > "$OUT" + NETMASK="$(ip -4 addr show "$IF" | egrep -o "brd [0-9\.]*" | egrep -o "[0-9\.]*")" + MACS="" + for M in $(sudo arp-scan -R -i 10 --interface "$IF" --localnet | awk '{ print $2 }' | grep :.*: | sort | uniq) + do + [ -n "$MACS" ] && MACS="$MACS,$M" || MACS="$M"; + done + POST="sn=$NETMASK&macs=$MACS" + RESULT=$(wget "$OUT" -O - --quiet --post-data "$POST" || echo "wget error: $?") + if [ -n "$RESULT" ] + then + echo Error uploading results: + echo "$RESULT" + fi echo $(date)" sleeping..." sleep "$SLEEP" done diff --git a/lib/upload.php b/upload.php similarity index 97% rename from lib/upload.php rename to upload.php index bcd7b25..2502a0e 100644 --- a/lib/upload.php +++ b/upload.php @@ -19,8 +19,8 @@ */ header("Content-type: text/plain"); -require_once("../config.php"); -require_once("util.php"); +require_once("config.php"); +require_once("lib/util.php"); function echoln($str) { echo("$str\n");