Add modules to repository

This commit is contained in:
Sebastian Kinne
2017-11-16 16:42:22 +11:00
commit d0aa1e38ef
707 changed files with 96750 additions and 0 deletions

239
ModemManager/api/module.php Normal file
View File

@@ -0,0 +1,239 @@
<?php namespace pineapple;
/***
Modem Manager <api/module.php>
Written by Foxtrot <foxtrot@realloc.me>
Distributed under the MIT Licence <https://opensource.org/licenses/MIT>
***/
class ModemManager extends Module
{
public function route()
{
switch ($this->request->action) {
case 'checkDepends':
$this->checkDepends();
break;
case 'installDepends':
$this->installDepends();
break;
case 'removeDepends':
$this->removeDepends();
break;
case 'getUSB':
$this->getUSB();
break;
case 'getTTYs':
$this->getTTYs();
break;
case 'checkConnection':
$this->checkConnection();
break;
case 'setConnection':
$this->setConnection();
break;
case 'unsetConnection':
$this->unsetConnection();
break;
case 'loadConfiguration':
$this->loadConfiguration();
break;
case 'saveConfiguration':
$this->saveConfiguration();
break;
case 'resetConfiguration':
$this->resetConfiguration();
break;
}
}
private function checkDepends()
{
/* Check dependencies */
if(empty($this->checkDependency('comgt'))) {
$this->response = array('installed' => false);
} else {
$this->response = array('installed' => true);
}
}
private function installDepends()
{
/* Install dependencies */
$this->execBackground('opkg update && opkg install comgt wwan uqmi');
$this->response = array("installing" => true);
}
private function removeDepends()
{
/* Remove dependencies */
$this->execBackground('opkg remove comgt wwan uqmi');
$this->response = array('success' => true);
}
private function getUSB()
{
/* Execute 'lsusb' and capture its output in the $lsusb variable.
Then split the output by its newlines. */
exec('lsusb', $lsusb);
$lsusb = implode("\n", $lsusb);
$this->response = array('lsusb' => $lsusb);
}
private function getTTYs()
{
exec('ls /dev/ttyUSB* && ls /dev/cdc-wdm* && ls /dev/ttyACM*', $TTYs);
if (empty($TTYs)) {
$this->response = array('success' => false,
'availableTTYs' => false);
} else {
$TTYs = implode("\n", $TTYs);
$this->response = array('success' => true,
'availableTTYs' => $TTYs);
}
}
private function checkConnection()
{
/* Check the connection of the wan2 interface. */
if(file_exists('/sys/class/net/3g-wan2/carrier')) {
$this->response = array('status' => 'connected');
exec('iptables -t nat -A POSTROUTING -s 172.16.42.0/24 -o 3g-wan2 -j MASQUERADE');
exec('iptables -A FORWARD -s 172.16.42.0/24 -o 3g-wan2 -j ACCEPT');
exec('iptables -A FORWARD -d 172.16.42.0/24 -m state --state ESTABLISHED,RELATED -i 3g-wan2 -j ACCEPT');
} else {
$this->response = array('status' => 'disconnected');
}
}
private function setConnection()
{
/* Set the connection of the wan2 interface. */
$this->execBackground('ifup wan2');
$this->response = array('status' => 'connecting');
}
private function unsetConnection()
{
/* Unset the connection of the wan2 interface. */
$this->execBackground('ifdown wan2');
$this->response = array('status' => 'disconnected');
}
private function loadConfiguration()
{
/* For easier code reading, assign a variable for each bit of information we require from the system.
Read more about UCI at https://wiki.openwrt.org/doc/uci.
For more information about the WiFi Pineapple API, visit https://wiki.wifipineapple.com. */
$interface = $this->uciGet('network.wan2.ifname');
$protocol = $this->uciGet('network.wan2.proto');
$service = $this->uciGet('network.wan2.service');
$vendorid = $this->uciGet('network.wan2.currentVID');
$productid = $this->uciGet('network.wan2.currentPID');
$device = $this->uciGet('network.wan2.device');
$apn = $this->uciGet('network.wan2.apn');
$username = $this->uciGet('network.wan2.username');
$password = $this->uciGet('network.wan2.password');
$dns = $this->uciGet('network.wan2.dns');
$peerdns = $this->uciGet('network.wan2.peerdns');
$pppredial = $this->uciGet('network.wan2.ppp_redial');
$defaultroute = $this->uciGet('network.wan2.defaultroute');
$keepalive = $this->uciGet('network.wan2.keepalive');
$pppdoptions = $this->uciGet('network.wan2.pppd_options');
/* Now send a response inside of an array, with keys being 'interface', 'protocol' etc
and their values being those we obtained from uciGet(). */
$this->response = array('success' => true,
'interface' => $interface,
'protocol' => $protocol,
'service' => $service,
'vendorid' => $vendorid,
'productid' => $productid,
'device' => $device,
'apn' => $apn,
'username' => $username,
'password' => $password,
'dns' => $dns,
'peerdns' => $peerdns,
'pppredial' => $pppredial,
'defaultroute' => $defaultroute,
'keepalive' => $keepalive,
'pppdoptions' => $pppdoptions);
}
private function saveConfiguration()
{
/* In the same way as loadConfiguration(), get the desired information and assign it to a variable.
However this time get the data that was sent with the request from the JS. */
$interface = $this->request->interface;
$protocol = $this->request->protocol;
$service = $this->request->service;
$vendorid = $this->request->vendorid;
$productid = $this->request->productid;
$device = $this->request->device;
$apn = $this->request->apn;
$username = $this->request->username;
$password = $this->request->password;
$dns = $this->request->dns;
$peerdns = $this->request->peerdns;
$pppredial = $this->request->pppredial;
$defaultroute = $this->request->defaultroute;
$keepalive = $this->request->keepalive;
$pppdoptions = $this->request->pppdoptions;
/* Using the APIs uciSet() function, set the UCI properties to
what the JS request gave us. */
$this->uciSet('network.wan2', 'interface');
$this->uciSet('network.wan2.ifname', $interface);
$this->uciSet('network.wan2.proto', $protocol);
$this->uciSet('network.wan2.service', $service);
$this->uciSet('network.wan2.currentVID', $vendorid);
$this->uciSet('network.wan2.currentPID', $productid);
$this->uciSet('network.wan2.device', $device);
$this->uciSet('network.wan2.apn', $apn);
$this->uciSet('network.wan2.peerdns', $peerdns);
$this->uciSet('network.wan2.ppp_redial', $pppredial);
$this->uciSet('network.wan2.defaultroute', $defaultroute);
$this->uciSet('network.wan2.keepalive', $keepalive);
$this->uciSet('network.wan2.pppd_options', $pppdoptions);
if(!empty($username)) {
$this->uciSet('network.wan2.username', $username);
}
if (!empty($password)) {
$this->uciSet('network.wan2.password', $password);
}
if(!empty($dns)) {
$this->uciSet('network.wan2.dns', $dns);
}
unlink("/etc/modules.d/60-usb-serial");
exec("echo 'usbserial vendor=0x$vendorid product=0x$productid maxSize=4096' > /etc/modules.d/60-usb-serial");
$this->response = array('success' => true);
}
private function resetConfiguration()
{
/* Delete the network.wan2 section */
exec('uci del network.wan2');
exec('uci commit');
unlink('/etc/modules.d/60-usb-serial');
$this->response = array('success' => true);
}
}

228
ModemManager/js/module.js Normal file
View File

@@ -0,0 +1,228 @@
registerController('USBController', ['$api', '$scope', '$interval', function($api, $scope, $interval) {
$scope.lsusb = "";
$scope.availableTTYs = "";
$scope.installed = false;
$scope.installling = false;
$scope.checkDepends = (function() {
$api.request({
module: 'ModemManager',
action: 'checkDepends'
}, function(response) {
console.log(response);
if(response.installed === true) {
$scope.installed = true;
$scope.installing = false;
$interval.cancel($scope.install_interval);
} else {
$scope.installed = false;
}
});
});
$scope.installDepends = (function() {
$api.request({
module: 'ModemManager',
action: 'installDepends'
}, function(response) {
console.log('INSTALL');
console.log(response);
if(response.installing === true) {
$scope.installing = true;
$scope.install_interval = $interval(function(){
$scope.checkDepends();
}, 1000);
}
});
});
$scope.removeDepends = (function() {
$api.request({
module: 'ModemManager',
action: 'removeDepends'
}, function(response) {
console.log('UNINSTALL');
console.log(response);
if(response.success === true) {
$scope.checkDepends();
}
});
});
$scope.checkDepends();
$scope.$on('$destroy', function() {
$interval.cancel($scope.install_interval);
});
$scope.getUSB = (function(){
$api.request({
module: 'ModemManager',
action: 'getUSB'
}, function(response) {
if (response.lsusb) {
$scope.lsusb = response.lsusb;
}
});
});
$scope.getTTYs = (function() {
$api.request({
module: 'ModemManager',
action: 'getTTYs'
}, function(response) {
if (response.success) {
$scope.availableTTYs = response.availableTTYs;
} else {
$scope.availableTTYs = "No TTYs Found.";
}
});
});
$scope.refresh = (function(){
$scope.lsusb = "";
$scope.availableTTYs = "";
$scope.getUSB();
$scope.getTTYs();
});
$scope.getUSB();
$scope.getTTYs();
}]);
registerController('ConnectionController', ['$api', '$scope', '$timeout', function($api, $scope, $timeout) {
$scope.connected = false;
$scope.connecting = false;
$scope.disconnected = true;
$scope.checkConnection = (function() {
$api.request({
module: 'ModemManager',
action: 'checkConnection'
}, function(response) {
if (response.status == 'connected') {
$scope.connected = true;
$scope.connecting = false;
$scope.disconnected = false;
}
});
});
$scope.setConnection = (function() {
$api.request({
module: 'ModemManager',
action: 'setConnection'
}, function(response) {
if(response.status == 'connecting') {
$scope.connected = false;
$scope.connecting = true;
$scope.disconnected = false;
};
});
});
$scope.unsetConnection = (function() {
$api.request({
module: 'ModemManager',
action: 'unsetConnection'
}, function(response) {
if(response.status == 'disconnected') {
$scope.connecting = false;
$scope.connected = false;
$scope.disconnected = true;
};
});
});
$scope.checkConnection();
setInterval(function() {
$scope.checkConnection();
}, 10000);
}]);
registerController('ModemController', ['$api', '$scope', '$timeout', function($api, $scope, $timeout) {
$scope.savedConfiguration = false;
$scope.resetConfigurationSuccess = false;
$scope.saveConfigurationError = "";
$scope.loadConfigurationError = "";
$scope.resetConfigurationError = "";
$scope.loadConfiguration = (function() {
$api.request({
module: 'ModemManager',
action: 'loadConfiguration'
}, function(response) {
if (response.success === true) {
$scope.interface = response.interface;
$scope.protocol = response.protocol;
$scope.service = response.service;
$scope.vendorid = response.vendorid;
$scope.productid = response.productid;
$scope.device = response.device;
$scope.apn = response.apn;
$scope.username = response.username;
$scope.password = response.password;
$scope.dns = response.dns;
$scope.peerdns = response.peerdns;
$scope.pppredial = response.pppredial;
$scope.defaultroute = response.defaultroute;
$scope.keepalive = response.keepalive;
$scope.pppdoptions = response.pppdoptions;
} else {
$scope.loadConfigurationError = "Failed to load configuration.";
}
});
});
$scope.saveConfiguration = (function() {
$api.request({
module: 'ModemManager',
action: 'saveConfiguration',
interface: $scope.interface,
protocol: $scope.protocol,
service: $scope.service,
vendorid: $scope.vendorid,
productid: $scope.productid,
device: $scope.device,
apn: $scope.apn,
username: $scope.username,
password: $scope.password,
dns: $scope.dns,
peerdns: $scope.peerdns,
pppredial: $scope.pppredial,
defaultroute: $scope.defaultroute,
keepalive: $scope.keepalive,
pppdoptions: $scope.pppdoptions
}, function(response) {
if (response.success === true) {
$scope.savedConfiguration = true;
$timeout(function(){
$scope.savedConfiguration = false;
}, 2000);
} else {
$scope.saveConfigurationError = "Failed to save configuration.";
}
});
});
$scope.resetConfiguration = (function() {
$api.request({
module: 'ModemManager',
action: 'resetConfiguration'
}, function(response) {
if (response.success === true) {
$scope.resetConfigurationSuccess = true;
$scope.loadConfiguration();
$timeout(function(){
$scope.resetConfigurationSuccess = false;
}, 2000);
} else {
$scope.resetConfigurationError = "Failed to open configuration.";
}
});
});
$scope.loadConfiguration();
}]);

205
ModemManager/module.html Normal file
View File

@@ -0,0 +1,205 @@
<div class="row">
<div class="col-md-7" ng-controller="USBController">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">USB & TTY
<span class="pull-right" data-toggle="modal" data-target="#USBInfo">
&#8505;
</span>
</h3>
</div>
<div class="panel-body">
<div class="center-block" ng-hide="lsusb">
<img class="center-block" src="img/throbber.gif">
</div>
<pre class="scrollable-pre" ng-show="lsusb">{{ lsusb }}</pre>
<div class="center-block" ng-hide="availableTTYs">
<img class="center-block" src="img/throbber.gif">
</div>
<pre class="scrollable-pre" ng-show="availableTTYs">{{ availableTTYs }}</pre>
<div>
<span class="pull-right">
<button type="button" class="btn btn-default" style="padding: 0px 5px;" ng-click="installDepends();" ng-hide="installed">
Install Dependencies
</button>
<button type="button" class="btn btn-default" style="padding: 0px 5px;" ng-click="removeDepends();" ng-show="installed">Remove Dependencies
</button>
<button type="button" class="btn btn-default" style="padding: 0px 5px;" ng-click="refresh();">
Refresh
</button>
<img src="/img/throbber.gif" ng-show="installing">
</span>
</div>
</div>
</div>
</div>
<div class="col-md-5" ng-controller="ConnectionController">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Mobile Connection</h3>
</div>
<div class="panel-body">
<span class="label label-success" ng-show="connected">Connected</span>
<span class="label label-warning" ng-show="connecting">Connecting</span>
<span class="label label-default" ng-show="disconnected">Not Connected</span>
<button class="btn btn-default btn-fixed-width pull-right" style="padding: 0px 5px;" ng-show="!connected" ng-click="setConnection();">Connect</button>
<button class="btn btn-danger btn-fixed-width pull-right" style="padding: 0px 5px;" ng-show="connected" ng-click="unsetConnection();">Disconnect</button>
<div ng-show="connected">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-7">
<div class="panel panel-default" ng-controller="ModemController">
<div class="panel-heading">
<h3 class="panel-title">Modem Configuration
<span class="pull-right" data-toggle="modal" data-target="#ModemInfo">
&#8505;
</span>
</h3>
</div>
<div class="panel-body">
<div class="well well-sm alert-danger" ng-show="loadConfigurationError">{{ loadConfigurationError }}</div>
<div class="well well-sm alert-danger" ng-show="saveConfigurationError">{{ saveConfigurationError }}</div>
<div class="well well-sm alert-danger" ng-show="resetConfigurationError">{{ resetConfigurationError }}</div>
<div class="well well-sm alert-success" ng-show="savedConfiguration">Configuration saved. You may need to reboot for changes to take place.</div>
<div class="well well-sm alert-success" ng-show="resetConfigurationSuccess">Configuration reset.</div>
<div class="form-horizontal">
<div class="form-group">
<label for="interfaceName" class="col-sm-2 control-label">Interface Name</label>
<div class="col-sm-10">
<input type="textbox" class="form-control" id="interfaceName" placeholder="ppp0" ng-model="interface">
</div>
</div>
<div class="form-group">
<label for="protocol" class="col-sm-2 control-label">Protocol</label>
<div class="col-sm-10">
<select class="form-control" ng-model="protocol">
<option value="3g">3G/4G</option>
</select>
</div>
</div>
<div class="form-group">
<label for="service" class="col-sm-2 control-label">Service</label>
<div class="col-sm-10">
<select class="form-control" ng-model="service">
<option value="cdma">CDMA</option>
<option value="evdo">EVDO</option>
<option value="umts">UMTS</option>
<option value="gprs">GPRS</option>
</select>
</div>
</div>
<div class="form-group">
<label for="vendorid" class="col-sm-2 control-label">VID:PID</label>
<div class="col-sm-10">
<div class="input-group">
<input type="text" class="form-control" id="vendorid" placeholder="VID" ng-model="vendorid">
<span class="input-group-addon">:</span>
<input type="text" class="form-control" id="productid" placeholder="PID" ng-model="productid">
</div>
</div>
</div>
<div class="form-group">
<label for="device" class="col-sm-2 control-label">Device</label>
<div class="col-sm-10">
<input type="textbox" class="form-control" id="device" placeholder="/dev/ttyUSB0" ng-model="device">
</div>
</div>
<div class="form-group">
<label for="apn" class="col-sm-2 control-label">APN</label>
<div class="col-sm-10">
<input type="textbox" class="form-control" id="apn" placeholder="apn.vodafone.co.uk" ng-model="apn">
</div>
</div>
<div class="form-group">
<label for="username" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="textbox" class="form-control" id="username" placeholder="Username" ng-model="username">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="password" placeholder="Password" ng-model="password">
</div>
</div>
<div class="form-group">
<label for="DNS" class="col-sm-2 control-label">DNS</label>
<div class="col-sm-10">
<input type="textbox" class="form-control" id="DNS" placeholder="8.8.8.8" ng-model="dns">
</div>
</div>
<div class="form-group">
<label for="pppdOptions" class="col-sm-2 control-label">PPPd Options</label>
<div class="col-sm-10">
<input type="textbox" class="form-control" id="pppdOptions" placeholder="" ng-model="pppdoptions">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Other Options</label>
<div class="col-sm-10">
<label class="checkbox-inline"><input type="checkbox" ng-model="peerdns">Peer DNS</label>
<label class="checkbox-inline"><input type="checkbox" ng-model="pppredial">PPP Redial</label>
<label class="checkbox-inline"><input type="checkbox" ng-model="defaultroute">Default Route</label>
<label class="checkbox-inline"><input type="checkbox" ng-model="keepalive">Keep Alive</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<span class="pull-right">
<button class="btn btn-danger" ng-click="resetConfiguration();">Reset</button>
<button class="btn btn-default" ng-click="saveConfiguration();">Save</button>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="USBInfo" tabindex="-1" role="dialog" aria-labelledby="USBInfoModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">USB & TTY Information</h4>
</div>
<div class="modal-body">
<h3>USB</h3>
<p>The USB information is displayed at the top. It will show the bus, device, <b>VID:PID</b> and its name.
The important information is usually the <b>V</b>endor<b>ID</b> and <b>P</b>roduct<b>ID</b>. This Information
is used to identify the USB device once inserted.</p>
<h3>TTYs</h3>
<p>Modems will produce one or more TTYs in the form of <b>ttyUSBX</b>, where X is a number from 0. These TTYs are used
to communicate with the modem when dialing.</p>
<p>You may not need the information in this section, but it is supplied just incase.</p>
</div>
</div>
</div>
</div>
<div class="modal fade" id="ModemInfo" tabindex="-1" role="dialog" aria-labelledby="ModemInfoModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Modem Information</h4>
</div>
<div class="modal-body">
<p>This help dialog provides enough information to configure your 3G/4G Modem and initiate a connection. For more information
about 3G/4G devices and the WiFi Pineapple, please visit the <a href="https://wiki.wifipineapple.com/legacy/compatible_modems.md">WiFi Pineapple Wiki</a>
and the <a href="https://wiki.openwrt.org/doc/recipes/3gdongle">OpenWRT article on modems</a>.
</p>
</div>
</div>
</div>
</div>

10
ModemManager/module.info Normal file
View File

@@ -0,0 +1,10 @@
{
"author": "Foxtrot",
"description": "3G and 4G Modem Manager",
"devices": [
"nano",
"tetra"
],
"title": "Modem Manager",
"version": "1.1"
}