mirror of
https://github.com/hak5/nano-tetra-modules.git
synced 2025-10-29 16:58:09 +00:00
Add modules to repository
This commit is contained in:
45
MACInfo/api/module.php
Normal file
45
MACInfo/api/module.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php namespace pineapple;
|
||||
|
||||
|
||||
/* The class name must be the name of your module, without spaces. */
|
||||
/* It must also extend the "Module" class. This gives your module access to API functions */
|
||||
class MACInfo extends Module
|
||||
{
|
||||
public function route()
|
||||
{
|
||||
switch ($this->request->action) {
|
||||
case 'getMACInfo':
|
||||
$this->getMACInfo($this->request->moduleMAC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function getMACInfo($mac)
|
||||
{
|
||||
if($this->IsValidMAC($mac)){
|
||||
$url = "http://macvendors.co/api/" . $mac . "/JSON";
|
||||
$retJSON = file_get_contents($url);
|
||||
if($retJSON != false){
|
||||
$mInfo = json_decode($retJSON);
|
||||
if(isset($mInfo) && isset($mInfo->result) && $mInfo->result->error != ""){
|
||||
$this->response = array("success" => false, "error" => $mInfo->result->error);
|
||||
}
|
||||
else{
|
||||
$this->response = array("success" => true,
|
||||
"company" => $mInfo->result->company,
|
||||
"macprefix" => $mInfo->result->mac_prefix,
|
||||
"address" => $mInfo->result->address,
|
||||
"country" => $mInfo->result->country,
|
||||
"type" => $mInfo->result->type
|
||||
);
|
||||
}
|
||||
}
|
||||
else{ $this->response = array("success" => false, "error" => "Error reading contents from: " . $url); }
|
||||
}
|
||||
else{ $this->response = array("success" => false, "error" => "Invalid MAC Address format"); }
|
||||
}
|
||||
private function IsValidMAC($mac) {
|
||||
$pregResult = preg_match('/([a-fA-F0-9]{2}[:|\-]?){6}/', $mac);
|
||||
return ($pregResult != 0 && $pregResult != NULL);
|
||||
}
|
||||
}
|
||||
34
MACInfo/js/module.js
Normal file
34
MACInfo/js/module.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/* This is our AngularJS controller, called "MACInfo". */
|
||||
registerController('MACInfo', ['$api', '$scope', function($api, $scope) {
|
||||
$scope.company = "";
|
||||
$scope.macprefix = "";
|
||||
$scope.address = "";
|
||||
$scope.country = "";
|
||||
$scope.type = "";
|
||||
$scope.error = "";
|
||||
$scope.isLookupSuccess = false;
|
||||
$scope.isLookupFailure = false;
|
||||
$scope.moduleMAC = "";
|
||||
$scope.getMACInfo = (function() {
|
||||
$api.request({
|
||||
module:"MACInfo",
|
||||
action:"getMACInfo",
|
||||
moduleMAC: $scope.moduleMAC
|
||||
}, function(response){
|
||||
if(response.success == true){
|
||||
$scope.isLookupSuccess = true;
|
||||
$scope.isLookupFailure = false;
|
||||
$scope.company = response.company;
|
||||
$scope.macprefix = response.macprefix;
|
||||
$scope.address = response.address;
|
||||
$scope.country = response.country;
|
||||
$scope.type = response.type;
|
||||
}
|
||||
else{
|
||||
$scope.isLookupSuccess = false;
|
||||
$scope.isLookupFailure = true;
|
||||
$scope.error = response.error;
|
||||
}
|
||||
});
|
||||
});
|
||||
}]);
|
||||
42
MACInfo/module.html
Normal file
42
MACInfo/module.html
Normal file
@@ -0,0 +1,42 @@
|
||||
<div class="row" ng-controller="MACInfo"> <!-- This special argument wires the HTML to your controller (in module.js) -->
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">MAC Information</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">MAC Address</label>
|
||||
<div class="col-sm-7">
|
||||
<input type="text" class="form-control" ng-model="moduleMAC" placeholder="MAC Address" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-7 col-md-offset-2">
|
||||
<button class="btn btn-success" ng-click="getMACInfo();">Lookup Information</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<table ng-show="isLookupSuccess" class="table table-condensed">
|
||||
<tr>
|
||||
<th class="text-right">Company</th><td>{{company}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right">MAC Prefix</th><td>{{macprefix}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right">Address</th><td>{{address}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right">Country</th><td>{{country}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-right">Type</th><td>{{type}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="well well-sm alert-danger" ng-show="isLookupFailure">{{error}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
10
MACInfo/module.info
Normal file
10
MACInfo/module.info
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"author": "DJEngineer",
|
||||
"description": "Lookup information on MAC Addresses",
|
||||
"devices": [
|
||||
"nano",
|
||||
"tetra"
|
||||
],
|
||||
"title": "MAC Info",
|
||||
"version": "1.1"
|
||||
}
|
||||
Reference in New Issue
Block a user