Added network settings

This commit is contained in:
Martin Schröder 2015-05-20 14:03:01 +02:00 committed by Martin Schröder
parent 9659690a8b
commit 22b6eae674
36 changed files with 176 additions and 77 deletions

View file

@ -3,4 +3,4 @@
npm install
sudo npm install -g grunt-cli
sudo npm install -g mocha
sudo npm install -g bower
sudo npm install -g bower

View file

@ -10,7 +10,7 @@
}
var fake_storage = {};
function JUCILocalStorage(){
this.getItem = function(item){
this.getItem = function(item){
if(supports_html5_storage()) return localStorage.getItem(item);
else return fake_storage[item];
};

View file

@ -31,7 +31,7 @@
deferred.reject();
});
return deferred.promise();
};
};
this.login = function(obj){
var self = this;
var deferred = $.Deferred();

View file

@ -1,5 +1,5 @@
//! Author: Martin K. Schröder <mkschreder.uk@gmail.com>
// service for managing session data
JUCI.app.factory('$tr', function(gettextCatalog) {
return function(str){

View file

@ -166,6 +166,12 @@
"hostname": { dvalue: '', type: String },
"displayname": { dvalue: '', type: String },
"log_size": { dvalue: 200, type: Number }
},
"upgrade": {
"fw_check_url": { dvalue: "", type: String, required: false},
"fw_path_url": { dvalue: "", type: String, required: false},
"fw_find_ext": { dvalue: "", type: String, required: false},
"fw_down_path": { dvalue: "", type: String, required: false}
}
},
"network": {
@ -187,14 +193,6 @@
// "username": { dvalue: "", type: String },
// "password": { dvalue: "", type: String }
//},
"unknown": {
"upgrade": {
"fw_check_url": { dvalue: "", type: String, required: false},
"fw_path_url": { dvalue: "", type: String, required: false},
"fw_find_ext": { dvalue: "", type: String, required: false},
"fw_down_path": { dvalue: "", type: String, required: false}
}
}
};
function UCI(){

View file

@ -1,4 +1,4 @@
$juci.module("core")
.controller("LoginPageCtrl", function($scope){
console.log("LOGIN PAGE: "+$juci.module("core").plugin_root);
console.log("LOGIN PAGE: "+$juci.module("core").plugin_root);
});

View file

@ -21,7 +21,7 @@
"widgets/luci.input.timespan",
"widgets/luci.input.radio",
"widgets/luci.input.ipaddress"
],
],
"pages": {
"overview": {
"view": "pages/overview"

View file

@ -2,6 +2,6 @@
<div class="col-md-2"><button class="btn btn-sm btn-default pull-right" ng-click="onDecrease()"><i class="fa fa-arrow-circle-left "></i></button></div>
<div class="col-md-8">
<div ng-repeat="bar in bars" ng-click="onBarClick(bar)" style="width: 20%; float: left; height: 30px; background-color: #{{bar.color}};"></div>
</div>
</div>
<div class="col-md-2"><button class="btn btn-sm btn-default pull-left" ng-click="onIncrease()"><i class="fa fa-arrow-circle-right"></i></button></div>
</div>

View file

@ -8,7 +8,7 @@
</thead>
<tr ng-repeat="row in data.rows ">
<td ng-repeat="cell in row track by $index" class="{{ cellClass($index) }}" dynamic="cell">
</td>
</tr>
</table>

View file

@ -1,4 +1,5 @@
angular.module("luci").config(function($stateProvider) {
JUCI.app
.config(function($stateProvider) {
var plugin_root = $juci.module("internet").plugin_root;
$stateProvider.state("internet", {
url: "/internet",
@ -7,3 +8,18 @@ angular.module("luci").config(function($stateProvider) {
}
});
});
UCI.$registerConfig("network");
UCI.network.$registerSectionType("interface", {
"is_lan": { dvalue: false, type: Boolean },
"ifname": { dvalue: '', type: String },
"proto": { dvalue: 'dhcp', type: String },
"ipaddr": { dvalue: '127.0.0.1', type: String },
"netmask": { dvalue: '255.0.0.0', type: String },
"type": { dvalue: '', type: String },
"ip6assign": { dvalue: 60, type: Number },
"bridge_instance": { dvalue: false, type: Boolean },
"vendorid": { dvalue: '', type: String },
"hostname": { dvalue: '', type: String },
"ipv6": { dvalue: false, type: Boolean }
});

View file

@ -9,7 +9,7 @@ $juci.module("internet")
}).always(function(){ next(); });
},
function(next){
function(next){
if($uci.firewall.dmzhost == undefined){
$uci.firewall.create({".type": "dmzhost", ".name": "dmzhost"}).done(function(){
next();

View file

@ -0,0 +1,14 @@
<luci-layout-with-sidebar>
<div ng-controller="SettingsNetworkCtrl">
<luci-config-section>
<luci-config-heading>{{ 'Network Settings' | translate }}</luci-config-heading>
<luci-config-info>{{ 'settings.network.info' | translate }}</luci-config-info>
<p translate ng-hide="network">Missing uci config boardpanel.</p>
</luci-config-section>
<luci-config-section ng-show="network">
<div ng-repeat="interface in interfaces">
<uci-network-interface-edit ng-model="interface"></uci-network-interface-edit>
</div>
</luci-config-section>
</div>
</luci-layout-with-sidebar>

View file

@ -0,0 +1,7 @@
JUCI.app
.controller("SettingsNetworkCtrl", function($scope, $uci){
$uci.sync("network").done(function(){
$scope.network = $uci.network;
$scope.interfaces = $uci.network['@interface'].filter(function(i){ return i.type.value != ""; });
});
});

View file

@ -1,12 +1,16 @@
{
"scripts": [
"internet",
"widgets/uci.firewall.nat.rule.edit"
"widgets/uci.firewall.nat.rule.edit",
"widgets/uci.network.interface.edit"
],
"pages": {
"internet/dns": {
"view": "pages/internet.dns"
},
"settings.network": {
"view": "pages/settings.network"
},
"internet/exposed_host": {
"view": "pages/internet.exposed_host"
},

View file

@ -32,4 +32,8 @@ describe("UCI.firewall", function(){
expect(ping_rule).not.to.be.empty();
if(ping_rule[0].hidden.value != 0) throw new Error("Allow-Ping firewall rule should be configured with hidden=0");
});
it("should have network config and settings", function(done){
expect($uci.network).to.be.ok();
expect($uci.network["@all"].to.not.be.empty());
});
});

View file

@ -0,0 +1,35 @@
<div>
<div class="panel panel-default">
<div class="panel-heading">
<div class="btn-group pull-right">
<span class="btn " ng-click="expanded = !expanded">
<i class="fa fa-caret-down fa-2x" ng-show="expanded"></i>
<i class="fa fa-caret-left fa-2x" ng-hide="expanded"></i>
</span>
</div>
<h3 class="panel-title" style="font-size: 1.5em; padding-top: 0.4em; font-weight: bold; font-family: 'vodafont';">
{{interface.hostname.value}} ({{interface.type.value}})
</h3>
<div style="clear: both;"></div>
</div>
<div class="panel-body " ng-show="expanded" >
<luci-config-lines>
<luci-config-line title="{{'Hostname'|translate}}">
<input class="form-control" ng-model="interface.hostname.value" ></input>
</luci-config-line>
<luci-config-line title="{{'IP Type'|translate}}">
<luci-select ng-model="interface.proto.value" ng-items="['static', 'dhcp']" placeholder="Pick type of IP"></luci-select>
</luci-config-line>
<luci-config-line title="{{'IP Address'|translate}}" ng-show="interface.proto.value == 'static'">
<input class="form-control" ng-model="interface.ipaddr.value" ></input>
</luci-config-line>
<luci-config-line title="{{'Netmask'|translate}}" ng-show="interface.proto.value == 'static'">
<input class="form-control" ng-model="interface.netmask.value" ></input>
</luci-config-line>
</luci-config-lines>
</div>
<div class="panel-footer" ng-show="expanded">
<luci-config-apply></luci-config-apply>
</div>
</div>
</div>

View file

@ -0,0 +1,17 @@
JUCI.app
.directive("uciNetworkInterfaceEdit", function($compile, $parse){
var plugin_root = $juci.module("internet").plugin_root;
return {
templateUrl: plugin_root+"/widgets/uci.network.interface.edit.html",
scope: {
interface: "=ngModel"
},
controller: "uciNetworkInterfaceEdit",
replace: true,
require: "^ngModel"
};
}).controller("uciNetworkInterfaceEdit", function($scope, $uci, $rpc, $log){
$scope.$watch("interface", function(interface){
});
});

View file

@ -2,7 +2,7 @@
<div ng-controller="SettingsNetworkCtrl">
<luci-config-section>
<luci-config-heading>{{ 'Network Settings' | translate }}</luci-config-heading>
<p translate ng-hide="boardpanel">Missing uci config boardpanel.</p>
<p translate ng-hide="network">Missing uci config boardpanel.</p>
</luci-config-section>
<luci-config-section ng-show="boardpanel">
<luci-config-info>{{ 'settings.energy.info' | translate }}</luci-config-info>
@ -19,7 +19,7 @@
<luci-config-line title="{{'Power-LED Brightness'|translate}}" no-pull>
<luci-slider ng-model="boardpanel.settings.power_led_br.value" min="0" max="100"></luci-slider>
<!--<switch id="enabled" name="enabled" ng-model="boardpanel.settings.power_led_br.value" class="green"></switch>-->
</luci-config-line>
</luci-config-line>
</luci-config-lines>
<luci-config-apply></luci-config-apply>
</luci-config-section>

View file

@ -1,4 +1,4 @@
$juci.module("settings")
.controller("SettingsNetworkCtrl", function($scope){
});

View file

@ -17,7 +17,7 @@
<div class="col-sm-8">
<input ng-model="modal.old_password" type="password" class="form-control" id="inputEmail3" placeholder="Current Password">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">New Password</label>
<div class="col-sm-8">

View file

@ -14,7 +14,7 @@ $juci.module("settings")
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{4,}).*", "g");
if(strongRegex.test(p)) return 3;
if(mediumRegex.test(p)) return 2;
if(enoughRegex.test(p)) return 1;

View file

@ -1,6 +1,6 @@
<luci-layout-with-sidebar>
<div ng-controller="SettingsUpgradeCtrl">
<luci-config-section>
<luci-config-section>
<luci-config-heading>{{ 'Firmware Upgrade' | translate }}</luci-config-heading>
<luci-config-info>{{ 'settings.upgrade.info' | translate }}</luci-config-info>
<luci-config-lines>
@ -26,10 +26,9 @@
<h3>{{'Online Update'|translate}}</h3>
<p>{{'settings.upgrade.online.info'|translate}}</p>
<luci-config-lines>
<luci-config-line title="">
<strong ng-show="onlineUpgrade">New version available: {{onlineUpgrade}}</strong>
<button ng-hide="onlineUpgrade" class="btn btn-lg btn-default">{{'Check for Update'|translate}}</button>
<button ng-show="onlineUpgrade" class="btn btn-lg btn-default">{{'Upgrade'|translate}}</button>
<luci-config-line title="{{onlineUpgrade}}">
<button ng-hide="onlineUpgrade" class="btn btn-lg btn-default" ng-click="onOnlineCheck()">{{'Check for Update'|translate}}</button>
<button ng-show="onlineUpgrade" class="btn btn-lg btn-default" ng-click="onUpgradeOnline()">{{'Upgrade'|translate}}</button>
</luci-config-line>
</luci-config-lines>
<h3>{{'USB Firmware Upgrade'|translate}}</h3>

View file

@ -116,6 +116,7 @@ $juci.module("settings")
console.log("SID: "+$scope.sessionID);
function upgradeStart(path){
alert("Will try to upgrade from "+path);
$rpc.luci2.system.upgrade_start({"path": path}).done(function(){
alert("Upgrade process has started. The web gui will not be available until the process has finished and the box has restarted!");
}).fail(function(response){
@ -132,22 +133,29 @@ $juci.module("settings")
$scope.onCheckOnline = function(){
$rpc.luci2.system.upgrade_check({type: "online"}).done(function(response){
$scope.onlineUpgrade = response.stdout.replace("\n", "");
if(response.stdout) $scope.onlineUpgrade = response.stdout.replace("\n", "");
if(response.stderr) $scope.$emit("error", "Online upgrade check failed: "+response.stderr);
$scope.$apply();
});
}
}
$scope.onUpgradeOnline = function(){
upgradeStart($scope.onlineUpgrade);
}
$scope.onCheckUSB = function(){
$rpc.luci2.system.upgrade_check({type: "usb"}).done(function(response){
$scope.usbUpgrade = response.stdout.replace("\n", "");
if(response.stdout) $scope.usbUpgrade = response.stdout.replace("\n", "");
if(response.stderr) $scope.$emit("error", "USB upgrade check failed: "+response.stderr);
$scope.$apply();
});
}
$scope.onUpgradeUSB = function(){
upgradeStart($scope.usbUpgrade);
}
$scope.onCheckUSB();
$scope.onCheckOnline();
$scope.onUploadComplete = function(result){
console.log("Upload completed: "+JSON.stringify(result));
}
@ -157,7 +165,7 @@ $juci.module("settings")
var obj = {};
try {
obj = JSON.parse(json);
} catch(e){ alert("The server returned an error!"); }
} catch(e){ alert("The server returned an error ("+JSON.stringify(json)+")"); }
$rpc.luci2.system.upgrade_test().done(function(result){
console.log(JSON.stringify(result));

View file

@ -8,10 +8,7 @@
},
"settings.energy": {
"view": "pages/settings.energy"
},
"settings.network": {
"view": "pages/settings.network"
},
},
"settings.password": {
"view": "pages/settings.password"
},

View file

@ -24,7 +24,7 @@ describe("Settings", function(){
});
it("should be able to check for usb upgrade", function(done){
$rpc.luci2.system.upgrade_check({type: "usb"}).done(function(){
done();
done();
}).fail(function(){
throw new Error("Could not check for online upgrade!");
});

View file

@ -8,7 +8,7 @@
<!--<luci-table
title="{{'DSL Connection'|translate}}"
data="dslConnectionInfo">
</luci-table>-->
</luci-table>-->
<luci-table
title="{{'DSL Mode'|translate}}"
data="dslModeInfo">

View file

@ -57,7 +57,7 @@ $juci.module("status")
}
}
}
}
}
}
reconstruct_floats(dslstats);

View file

@ -10,7 +10,7 @@
<th translate>Group IP</th>
<th translate>Client IP</th>
<th translate>LAN Port</th>
<th translate>WAN Port</th>
<th translate>WAN Port</th>
<th translate>Timeout</th>
</tr>
<tr ng-repeat="row in igmptable">

View file

@ -4,7 +4,7 @@ $juci.module("status")
if(!result.table) {
$scope.$emit("error", gettext("Unable to retreive igmptable from device!"));
return;
}
}
$scope.igmptable = result.igmptable;
});
});

View file

@ -28,7 +28,7 @@ $juci.module("wifi")
setTimeout(function(){
$scope.showProgress = 0;
$scope.$apply();
}, 2000);
}, 2000);
}
function wpsFail(){
$scope.pairState = 'fail';

View file

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.6)
PROJECT(luciexpress-plugin C)
ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations -Iinclude)
ADD_DEFINITIONS(-Os -Wall -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wmissing-field-initializers -Wextra -Wformat=2 -Wno-format-nonliteral -Wpointer-arith -Wno-missing-braces --std=gnu99 -g3 -Wmissing-declarations -Iinclude)
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")

View file

@ -1039,7 +1039,7 @@ rpc_luci2_upgrade_test(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
const char fwpath[255];
char fwpath[255];
strcpy(fwpath, "/tmp/firmware.bin");
struct uci_package *p;
@ -1067,7 +1067,7 @@ rpc_luci2_upgrade_test(struct ubus_context *ctx, struct ubus_object *obj,
if (ptr.o && ptr.o->type == UCI_TYPE_STRING)
{
strncpy(fwpath, sizeof(fwpath), ptr.o->v.string);
strncpy(fwpath, ptr.o->v.string, sizeof(fwpath));
}
uci_unload(cursor, p);
@ -1082,7 +1082,7 @@ rpc_luci2_upgrade_start(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
const char fwpath[255];
char fwpath[255];
strcpy(fwpath, "/tmp/firmware.bin");
//const char *keep = "";
@ -1092,47 +1092,47 @@ rpc_luci2_upgrade_start(struct ubus_context *ctx, struct ubus_object *obj,
blobmsg_parse(rpc_upgrade_policy, __RPC_UPGRADE_MAX, tb, blob_data(msg), blob_len(msg));
if (tb[RPC_UPGRADE_PATH] && strlen(blobmsg_data(tb[RPC_UPGRADE_PATH]))) {
fwpath = strncpy(fwpath, sizeof(fwpath), blobmsg_data(tb[RPC_UPGRADE_PATH]));
strncpy(fwpath, blobmsg_data(tb[RPC_UPGRADE_PATH]), sizeof(fwpath));
found = true;
}
/* if (tb[RPC_UPGRADE_KEEP] && !blobmsg_data(tb[RPC_UPGRADE_KEEP]))*/
/* keep = "-n";*/
struct uci_package *p;
struct uci_element *e;
struct uci_section *s;
struct uci_package *p = 0;
struct uci_element *e = 0;
struct uci_section *s = 0;
struct uci_ptr ptr = { .package = "system" };
if (!found)
if (!found){
uci_load(cursor, ptr.package, &p);
if (p)
{
uci_foreach_element(&p->sections, e)
if (p)
{
s = uci_to_section(e);
uci_foreach_element(&p->sections, e)
{
s = uci_to_section(e);
if (strcmp(s->type, "upgrade"))
continue;
if (strcmp(s->type, "upgrade"))
continue;
ptr.o = NULL;
ptr.option = "fw_upload_path";
ptr.section = e->name;
uci_lookup_ptr(cursor, &ptr, NULL, true);
break;
ptr.o = NULL;
ptr.option = "fw_upload_path";
ptr.section = e->name;
uci_lookup_ptr(cursor, &ptr, NULL, true);
break;
}
if (ptr.o && ptr.o->type == UCI_TYPE_STRING)
{
strncpy(fwpath, ptr.o->v.string, sizeof(fwpath));
}
uci_unload(cursor, p);
}
if (ptr.o && ptr.o->type == UCI_TYPE_STRING)
{
strncpy(fwpath, sizeof(fwpath), ptr.o->v.string);
}
return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req);
}
}
const char *cmd[] = { "sysupgrade", "/tmp/firmware.bin", NULL };
const char *cmd[3] = { "sysupgrade", fwpath, NULL };
return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req);
return 0;

View file

@ -24,7 +24,7 @@ for(var i = 0; i < process.argv.length; i++){
case "--user": PARAMS.username = process.argv[++i]; break;
case "--host": PARAMS.host = process.argv[++i]; break;
};
}
}
if(!PARAMS.username || !PARAMS.password ){
console.error("Please specify --user <rpcuser> and --pass <rpcpassword> arguments!");

View file

@ -5,7 +5,7 @@ describe("JUCI", function(){
it("should have questd installed on router", function(){
expect($rpc.router).to.be.an(Object);
expect($rpc.router.info).to.be.a(Function);
});
});
it("should have juci installed on the router", function(){
// TODO: rename luci2 stuff to juci
expect($rpc.luci2).to.be.an(Object);

View file

@ -56,7 +56,7 @@ void dslstats_load(struct dsl_stats *self){
if(id < DSLSTATS_BEARER_COUNT){
bearer = &self->bearers[id];
DSLDEBUG("Switching bearer: %d\n", id);
}
}
}
}
// it is possible to add more stats like this though

View file

@ -42,7 +42,7 @@ typedef struct dsl_bearer {
UpDown max_rate;
UpDown rate;
UpDown msgc;
UpDown msgc;
UpDown b,m,t,r,s,l,d;
UpDown delay;
UpDown inp;