Updated with frontend and added new features

This commit is contained in:
root 2012-07-21 05:55:30 -07:00
parent 41b83c3553
commit 1166c879f5
33 changed files with 243 additions and 52 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ design
db db
config.php config.php
scanner/pamela.log scanner/pamela.log
mac_log.csv
mac_log.csv.complete

31
admin.php Executable file
View File

@ -0,0 +1,31 @@
<?php
if ($_POST) {
$text = preg_replace("/\s{2}/i","\n",$_POST['text']);
file_put_contents("mac_log.csv",$text);
header ("Location: ".$_SERVER['PHP_SELF']."?saved=true");
exit;
}
$text = htmlspecialchars(file_get_contents("mac_log.csv"));
if($_GET['saved'] == "true") {
$message = "Saved successfully.";
}
?><html>
<head>
<style type="text/css">
textarea { height: 600px; width: 400px; }
</style>
</head>
<body>
<span class="message">
<?php echo $message; ?>
</span>
<form method="POST">
<textarea name="text"><?php echo $text; ?></textarea>
<input type="submit" value="Save">
</form>
</body>
</html>

77
associate.php Executable file
View File

@ -0,0 +1,77 @@
<?php
$message = "";
if(isset($_POST['submit'])) {
$mac = csv_filter($_POST['macaddress']);
$name = csv_filter($_POST['name']);
if($mac != "" && $name != null) {
if(is_mac($mac)) {
file_put_contents("mac_log.csv","$mac,$name\n",FILE_APPEND);
$message = "Registered, thanks! It might take a few minutes for your name to show up.";
}
else {
$message = "The MAC address doesn't look right. MAC addresses look like this: 00:1a:2b:3c:4d:5e";
}
}
else {
$message = "Please enter a MAC address and name.";
}
}
function csv_filter($value) {
return preg_replace('/[^a-z0-9:]/i','',$value);
}
function is_mac($mac) {
if(preg_match('/^([0-9a-f]{2}([:-]|$)){6}$/i',$mac) > 0){
return true;}
else { return false; }
}
$arp_found = false;
function arp_lookup($ip) {
global $arp_found;
$arp = shell_exec("/usr/sbin/arp -a | grep $ip");
preg_match('/at ([0-9a-f]{2}[: ]){6}/i',$arp,$matches);
if(sizeof($matches) > 0) {
$mac = split(" ",$matches[0]);
$arp_found = true;
return $mac[1];
}
else {
$arp_found = false;
return "";
}
}
include('header-inc.php');
?>
<span class="message">
<?php echo $message; ?>
</span>
<div id="content">
<h2>Register Your Device</h2>
<div class="caption">
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<h3>Your computer or mobile device's MAC address can be found under your network info!</h3>
<table>
<tr><td><label for="name">Your Name:</label></td><td><input type="text" id="name" name="name" /></td></tr>
<tr><td><label for="macaddress">MAC Address:</label></td><td><input type="text" id="macaddress" name="macaddress" value="<?php echo arp_lookup($_SERVER['REMOTE_ADDR']); ?>" />
<span id="autodetect"><?php if($arp_found) { echo "(Autodetected MAC from IP address ".$_SERVER['REMOTE_ADDR'].")"; } ?></span>
</td></tr>
</table>
<input type="submit" id="submit" name="submit" value="Register" />
</form>
</div>
</div>
</div>
</body>
</html>

39
header-inc.php Executable file
View File

@ -0,0 +1,39 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<?php if(isset($auto_reload)) { ?>
<script type="text/javascript">
function reload() {
window.location.reload()
}
function pageLoad() {
setInterval ( "reload()", 30000 );
}
</script>
<?php } ?>
<style type="text/css">
#autodetect { display: block; color: #666; }
.macaddr { color: #666; }
</style>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css" />
</head>
<body <?php if(isset($auto_reload)){ ?>onLoad="pageLoad()"<?php } ?>>
<div id="header">
<div id="header_middle">
<img src="/static/images/logo.png" />
<div id="header_buttons">
<h2>Local Network</h2>
<p>See if there are people at the space!<br/>
If the feed is broken, please contact <a href="#">someone</a>.</p>
<p>Nobody here? Check the <a href="#">Website</a>.</p>
</div>
</div>
<div id="header_menu">
<a href="/">See Who's Here</a>
<a href="/associate.php">Register your device!</a>
</div>
</div>
<div id="content">

View File

@ -1,45 +1,30 @@
<?php <?php
/* $auto_reload = true;
Copyright 2010 Pieter Iserbyt include('header-inc.php');
This file is part of Pamela.
Pamela is free software: you can redistribute it and/or modify $result = http_parse_message(http_get("http://localhost/pamela/data.php"));
it under the terms of the GNU General Public License as published by $result = preg_replace("/\s/","",$result->body); // get rid of linebreaks
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pamela is distributed in the hope that it will be useful, $decode = json_decode($result);
but WITHOUT ANY WARRANTY; without even the implied warranty of $decode = preg_replace("/^([0-9a-f]{2}([:]|$)){6}$/i",'{$0}',$decode);
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the sort($decode,SORT_STRING | SORT_FLAG_CASE);
GNU General Public License for more details.
You should have received a copy of the GNU General Public License $array = preg_grep("/^(?!\.)/",$decode);
along with Pamela. If not, see <http://www.gnu.org/licenses/>.
*/
require_once("config.php"); echo "<h2>Who's here right now?</h2>";
?><html xmlns="http://www.w3.org/1999/xhtml"> echo "<ul>";
<head> foreach($array as $entry) {
<title>Pamela</title> if(substr($entry,0,1) == "{") {
<script src="js/jquery-1.3.2.js" type="text/javascript"></script> echo "<li class='macaddr'>".$entry."</li>";
<script src="js/pamela-conf.php" type="text/javascript"></script> }
<script src="js/pamela-buttons.js" type="text/javascript"></script> else{
<script src="js/pamela-nodes.js" type="text/javascript"></script> echo "<li>".$entry."</li>";
<script src="js/pamela-matrices.js" type="text/javascript"></script> }
<script src="js/pamela.js" type="text/javascript"></script> }
<style type="text/css"> echo "</ul>";
* {
margin:0;
padding:0;
}
body { ?>
background-color: <?php echo PAM_BGCOLOR; ?>; </div>
} </body>
</style>
</head>
<body>
<canvas id="pamela"></canvas>
</body>
</html> </html>

View File

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 549 B

After

Width:  |  Height:  |  Size: 549 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 673 B

After

Width:  |  Height:  |  Size: 673 B

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

45
pamela/index.php Executable file
View File

@ -0,0 +1,45 @@
<?php
/*
Copyright 2010 Pieter Iserbyt
This file is part of Pamela.
Pamela is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pamela is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Pamela. If not, see <http://www.gnu.org/licenses/>.
*/
require_once("config.php");
?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Pamela</title>
<script src="js/jquery-1.3.2.js" type="text/javascript"></script>
<script src="js/pamela-conf.php" type="text/javascript"></script>
<script src="js/pamela-buttons.js" type="text/javascript"></script>
<script src="js/pamela-nodes.js" type="text/javascript"></script>
<script src="js/pamela-matrices.js" type="text/javascript"></script>
<script src="js/pamela.js" type="text/javascript"></script>
<style type="text/css">
* {
margin:0;
padding:0;
}
body {
background-color: <?php echo PAM_BGCOLOR; ?>;
}
</style>
</head>
<body>
<canvas id="pamela"></canvas>
</body>
</html>

View File

@ -26,11 +26,11 @@ PAM_CRON="/etc/cron.d/pamela"
PAM_SCRIPT="${PAM_DIR}/$(basename $0)" PAM_SCRIPT="${PAM_DIR}/$(basename $0)"
REGISTER='' REGISTER=''
SIMULATE='' SIMULATE=''
IF='eth0' IF='p2p1'
OUT='http://yourserver.com/pamela/upload.php' OUT='http://yourserver.com/upload.php'
USER='' USER=''
PASSWORD='' PASSWORD=''
TRANSLATE='' TRANSLATE='/var/www/html/mac_log.csv'
POST='' POST=''
TIMEOUT=200 TIMEOUT=200
@ -137,34 +137,44 @@ function translate {
return 0 return 0
fi fi
# translate denotes a url # clean old translations
# save the output of the url to a file and use it as a file rm $TRANSLATE.complete
TRANSLATE_URL=${TRANSLATE}
TRANSLATE=$(mktemp)
wget --timeout="${TIMEOUT}" --no-check-certificate --quiet -O "${TRANSLATE}" "${TRANSLATE_URL}" # Then we fall back to names obtained via zeroconf (aka avahi, aka bonjour)
#avahi-browse -a -t|grep :.*:.*:.*:|sed -e 's/.*IPv. \(.*\) \[\(.*\)].*/\2,\1[\2]/g' > $TRANSLATE.bon
POST=$(echo ${POST} | awk -v names="${TRANSLATE}" 'BEGIN { # Finally we fall back to the name from arp-scan (maker of the network chipset)
# Yes I know we already ran arp-scan once...I'm too lazy to do it right
# And yes I'm using regex instead of learning how awk works.
#arp-scan -I eth0 -R --localnet|sed -e 's/\(.*\)\t\(.*\)\t\(.*\)/\2,\3[\2]/g'|grep :.*:.*:> $TRANSLATE.arp
# Combine names from 3 sources to one
# Note that the code below uses the last name to appear in the file
# So order them accordingly
#cat $TRANSLATE.bon $TRANSLATE.arp
cat $TRANSLATE >> $TRANSLATE.complete
POST=$(echo ${POST} | awk -v names="${TRANSLATE}.complete" 'BEGIN {
RS="\n" RS="\n"
FS="," FS=","
while ((getline nl < names) > 0) { while ((getline nl < names) > 0) {
split(nl, n); split(nl, n);
nms[n[1]] = n[2] nms[n[1]] = n[2]
} }
close(names) close(names)
RS="," RS=","
first=1 first=1
while ((getline i)> 0) { while ((getline i)> 0) {
sub(/\n$/,"",i) sub(/\n$/,"",i)
#print "input:", i, "translates to", (i in nms?nms[i]:i) # if (i in nms){ print "input:", i, "translates to", nms[i] }
if (!first) if (!first)
printf(",") printf(",")
printf (i in nms?nms[i]:i) printf (i in nms?nms[i]:i)
first=0 first=0
} }
}')
rm ${TRANSLATE} }')
} }
function upload { function upload {
@ -191,3 +201,5 @@ scan
translate translate
upload upload
git commit mac_log.csv -m "Save updates user database"

0
static/images/logo.png Normal file
View File

0
style.css Normal file
View File