Phone number blocking

This commit is contained in:
Martin Schröder 2015-05-14 10:16:34 +02:00 committed by Martin Schröder
parent 55048d20ed
commit 19bd9539c6
14 changed files with 293 additions and 70 deletions

View file

@ -115,10 +115,11 @@ JUCI.app.config(function ($stateProvider, $locationProvider, $compileProvider, $
return deferred.promise;
}
},*/
onEnter: function($window, $rootScope){
onEnter: function($uci, $rootScope){
$rootScope.errors.splice(0, $rootScope.errors.length);
document.title = $tr(k+".title")+" - "+$tr(gettext("application.name"));
},
$uci.$revert();
document.title = $tr(k.replace(/\//g, ".")+".title")+" - "+$tr(gettext("application.name"));
}
});
}
});

View file

@ -31,9 +31,8 @@
// an empty json object. Otherwise we have no way to differentiate success
// from failure of a request. This has to be done on the host side.
if(result.result[0] != 0){ // || result.result[1] == undefined) {
console.log("RPC succeeded, but returned error: "+JSON.stringify(result));
deferred.reject((function(){
switch(result.result[0]){
function _errstr(error){
switch(error){
case 0: return gettext("Parse error");
case 1: return gettext("Invalid request");
case 2: return gettext("Invalid parameters");
@ -44,7 +43,9 @@
case 7: return gettext("Timed out");
default: return gettext("RPC error #")+result.result[0]+": "+result.result[1];
}
})());
}
console.log("RPC succeeded ("+namespace+"."+method+"), but returned error: "+JSON.stringify(result)+": "+_errstr(result.result[0]));
deferred.reject(_errstr(result.result[0]));
} else {
deferred.resolve(result.result[1]);
}

View file

@ -83,7 +83,7 @@
}
},
"easybox": {
"easybox-settings": {
"settings": {
"usb_port": { dvalue: true, type: Boolean },
"status_led": { dvalue: true, type: Boolean },
"power_led": { dvalue: true, type: Boolean },
@ -92,7 +92,7 @@
"wpsbutton": { dvalue: true, type: Boolean },
"wpsdevicepin": { dvalue: true, type: Boolean }
},
"easybox-services": {
"services": {
"internet": { dvalue: "", type: String },
"voice": { dvalue: "", type: String },
"iptv": { dvalue: "", type: String }
@ -152,57 +152,6 @@
"log_size": { dvalue: 200, type: Number }
}
},
"voice_client": {
"brcm_line": {
"extension": { dvalue: '', type: String },
"sip_account": { dvalue: '', type: String },
"noise": { dvalue: false, type: Boolean },
"vad": { dvalue: false, type: Boolean },
"txgain": { dvalue: false, type: Boolean },
"rxgain": { dvalue: false, type: Boolean },
"echo_cancel": { dvalue: true, type: Boolean },
"callwaiting": { dvalue: false, type: Boolean },
"clir": { dvalue: false, type: Boolean },
"name": { dvalue: '', type: String },
"instance": { dvalue: '', type: String }
},
"sip_service_provider": {
"name": { dvalue: "Account 1", type: String },
"codec0": { dvalue: "alaw", type: String },
"codec1": { dvalue: "ulaw", type: String },
"codec2": { dvalue: "g729", type: String },
"codec3": { dvalue: "g726", type: String },
"autoframing": { dvalue: false, type: Boolean },
"cfim_on": { dvalue: "*21*", type: String },
"cfim_off": { dvalue: "#21#", type: String },
"cfbs_on": { dvalue: "*61*", type: String },
"cfbs_off": { dvalue: "#61#", type: String },
"call_return": { dvalue: "*69", type: String },
"redial": { dvalue: "*66", type: String },
"is_fax": { dvalue: false, type: Boolean },
"transport": { dvalue: "udp", type: String },
"priority_ulaw": { dvalue: 0, type: Number },
"priority_alaw": { dvalue: 0, type: Number },
"priority_g729": { dvalue: 0, type: Number },
"priority_g723": { dvalue: 0, type: Number },
"priority_g726": { dvalue: 0, type: Number },
"enabled": { dvalue: true, type: Boolean },
"target": { dvalue: "direct", type: String },
"call_lines": { dvalue: "BRCM/4", type: String },
"mailbox": { dvalue: "-", type: String },
"call_filter": { dvalue: "-", type: String },
"domain": { dvalue: "217.27.161.62", type: String },
"user": { dvalue: "0854601910", type: String },
"authuser": { dvalue: "0854601910", type: String },
"displayname": { dvalue: "TEST", type: String },
"ptime_ulaw": { dvalue: 20, type: Number },
"ptime_g726": { dvalue: 20, type: Number },
"ptime_g729": { dvalue: 20, type: Number },
"ptime_alaw": { dvalue: 20, type: Number },
"host": { dvalue: "217.27.161.62", type: String },
"outboundproxy": { dvalue: "217.27.161.62", type: String }
}
},
"wireless": {
"wifi-status": {
"wlan": { dvalue: true, type: Boolean },
@ -528,6 +477,15 @@
});
}
UCIConfig.prototype.$registerSectionType = function(name, descriptor){
var config = this[".name"];
var conf_type = section_types[config];
if(typeof conf_type === "undefined") conf_type = section_types[config] = {};
conf_type[name] = descriptor;
this["@"+name] = [];
console.log("Registered new section type "+config+"."+name);
}
UCIConfig.prototype.$deleteSection = function(section){
var self = this;
var deferred = $.Deferred();
@ -590,7 +548,7 @@
var reqlist = [];
self["@all"].map(function(section){
var changed = section.$getChangedValues();
console.log(JSON.stringify(changed) +": "+Object.keys(changed).length);
//console.log(JSON.stringify(changed) +": "+Object.keys(changed).length);
if(Object.keys(changed).length){
reqlist.push({
"config": self[".name"],
@ -625,6 +583,11 @@
return deferred.promise();
}
UCI.prototype.$registerConfig = function(name){
if(!(name in section_types)) section_types[name] = {};
if(!(name in this)) this[name] = new UCI.Config(this, name);
}
UCI.prototype.sync = function(configs){
var deferred = $.Deferred();
var self = this;
@ -661,6 +624,32 @@
return deferred.promise();
}
UCI.prototype.$revert = function(){
var revert_list = [];
var deferred = $.Deferred();
var errors = [];
var self = this;
Object.keys(self).map(function(k){
if(self[k].constructor == UCI.Config){
if(self[k][".need_commit"]) revert_list.push(self[k][".name"]);
}
});
async.eachSeries(revert_list, function(item, next){
$rpc.uci.revert({"config": item[".name"], "ubus_rpc_session": $rpc.$sid()}).done(function(){
console.log("Reverted config "+item[".name"]);
next();
}).fail(function(){
errors.push("Failed to revert config "+item[".name"]);
next();
});
}, function(){
if(errors.length) deferred.reject(errors);
else deferred.resolve();
});
return deferred.promise();
}
UCI.prototype.save = function(){
var deferred = $.Deferred();
var self = this;

View file

@ -1,10 +1,61 @@
<luci-layout-with-sidebar>
<div ng-controller="PhoneNumberBlockingPageCtrl">
<luci-config-heading>{{ 'Number Blocking' | translate }}</luci-config-heading>
<luci-config-info>{{ 'phone.number_blocking.info' | translate }}</luci-config-info>
<luci-config-section>
<luci-config-heading>{{ 'Number Blocking' | translate }}</luci-config-heading>
<luci-config-info>{{ 'phone.number_blocking.info' | translate }}</luci-config-info>
<h2 translate>Outgoing Calls</h2>
<luci-config-lines>
TODO
<luci-config-line title="Outgoing Number Blocking">
<switch ng-model="filter.block_outgoing.value"></switch>
</luci-config-line>
<luci-config-lines>
<luci-config-lines ng-show="filter.block_outgoing.value">
<hr/>
<luci-config-line title="Do not allow connections to these numbers">
<div class="row" ng-repeat="rule in outgoingRules">
<div class="form-group form-inline">
<input type="text" class="form-control" ng-model="rule.extension.value" ng-blur="onSave()"/>
<button class="btn btn-default" ng-click="onDeleteOutgoingRule(rule)"><i class="fa fa-trash"></i></button>
</div>
</div>
<div class="row">
<div class="form-group form-inline">
<button class="btn btn-default pull-right" ng-click="onAddOutgoingRule()"><i class="fa fa-plus"></i></button>
</div>
</div>
</luci-config-line>
<hr/>
<i translate>You can also block ranges of numbers.For example: "0160#" blocks all numbers starting with "0160".</i>
<luci-config-line title="Block connections to all foreign numbers">
<switch ng-model="filter.block_foreign.value"></switch>
</luci-config-line>
<luci-config-line title="Block connections to all special rate numbers">
<switch ng-model="filter.block_special_rate.value"></switch>
</luci-config-line>
<luci-config-lines>
</luci-config-section>
<luci-config-section>
<h2 translate>Incoming Calls</h2>
<luci-config-lines>
<luci-config-line title="Incoming Number Blocking">
<switch ng-model="filter.block_incoming.value"></switch>
</luci-config-line>
<luci-config-lines>
<luci-config-lines ng-show="filter.block_incoming.value">
<luci-config-line title="Do not allow connections from these numbers">
<div class="row" ng-repeat="rule in incomingRules">
<div class="form-group form-inline">
<input type="text" class="form-control" ng-model="rule.extension.value" ng-blur="onSave()"/>
<button class="btn btn-default" ng-click="onDeleteIncomingRule(rule)"><i class="fa fa-trash"></i></button>
</div>
</div>
<div class="row">
<div class="form-group form-inline">
<button class="btn btn-default pull-right" ng-click="onAddIncomingRule()"><i class="fa fa-plus"></i></button>
</div>
</div>
</luci-config-line>
<luci-config-lines>
</luci-config-section>
<luci-config-apply></luci-config-apply>

View file

@ -21,6 +21,64 @@
*/
$juci.module("phone")
.controller("PhoneNumberBlockingPageCtrl", function($scope){
.controller("PhoneNumberBlockingPageCtrl", function($scope, $uci){
function updateRuleLists(){
$scope.outgoingRules = $uci.voice_client["@call_filter_rule_outgoing"].filter(function(x){
return x.owner.value == "call_filter0";
});
$scope.incomingRules = $uci.voice_client["@call_filter_rule_incoming"].filter(function(x){
return x.owner.value == "call_filter0";
});
setTimeout(function(){ $scope.$apply(); }, 0);
}
$uci.sync("voice_client").done(function(){
if(!$uci.voice_client.call_filter0){
async.series([
function(next){
$uci.voice_client.create({".type": "call_filter", ".name": "call_filter0"}).always(function(){ next(); });
},
function(next){
$uci.voice_client.create({".type": "call_filter_rule_incoming", ".name": "call_filter_rule_incoming0"}).always(function(){ next(); });
},
function(next){
$uci.voice_client.create({".type": "call_filter_rule_outgoing", ".name": "call_filter_rule_outgoing0"}).always(function(){ next(); });
},
function(next){
$uci.voice_client.create({".type": "call_filter_rule_outgoing", ".name": "call_filter_rule_outgoing1"}).always(function(){ next(); });
},
function(next){
$uci.save().always(function(){ next(); });
}
]);
}
$scope.filter = $uci.voice_client.call_filter0;
updateRuleLists();
});
$scope.onAddOutgoingRule = function(){
$uci.voice_client.create({".type": "call_filter_rule_outgoing", "owner": "call_filter0"}).always(function(){
updateRuleLists();
});
}
$scope.onAddIncomingRule = function(){
$uci.voice_client.create({".type": "call_filter_rule_incoming", "owner": "call_filter0"}).always(function(){
updateRuleLists();
});
}
$scope.onDeleteOutgoingRule = function(rule){
rule.$delete().done(function(){
updateRuleLists();
});
}
$scope.onDeleteIncomingRule = function(rule){
rule.$delete().done(function(){
updateRuleLists();
});
}
/*
$scope.onSave = function(){
$uci.save();
}
*/
});

View file

@ -24,6 +24,6 @@ $juci.module("phone")
.controller("PhoneRingingScheduleCtrl", function($scope, $uci){
$uci.sync(["phone"]).done(function(){
// TODO add config for phone
$scope.settings = $uci.phone.settings;
if($uci.phone) $scope.settings = $uci.phone.settings;
});
});

View file

@ -20,7 +20,7 @@
* 02110-1301 USA
*/
angular.module("luci").config(function($stateProvider) {
JUCI.app.config(function($stateProvider) {
var plugin_root = $juci.module("phone").plugin_root;
$stateProvider.state("phone", {
url: "/phone",
@ -28,4 +28,73 @@ angular.module("luci").config(function($stateProvider) {
$juci.redirect("phone-call-log");
},
});
// add the uci classes for voice client
UCI.$registerConfig("voice_client");
UCI.voice_client.$registerSectionType("brcm_line", {
"extension": { dvalue: '', type: String },
"sip_account": { dvalue: '', type: String },
"noise": { dvalue: false, type: Boolean },
"vad": { dvalue: false, type: Boolean },
"txgain": { dvalue: false, type: Boolean },
"rxgain": { dvalue: false, type: Boolean },
"echo_cancel": { dvalue: true, type: Boolean },
"callwaiting": { dvalue: false, type: Boolean },
"clir": { dvalue: false, type: Boolean },
"name": { dvalue: '', type: String },
"instance": { dvalue: '', type: String }
});
UCI.voice_client.$registerSectionType("sip_service_provider", {
"name": { dvalue: "", type: String },
"codec0": { dvalue: "alaw", type: String },
"codec1": { dvalue: "ulaw", type: String },
"codec2": { dvalue: "g729", type: String },
"codec3": { dvalue: "g726", type: String },
"autoframing": { dvalue: false, type: Boolean },
"cfim_on": { dvalue: "*21*", type: String },
"cfim_off": { dvalue: "#21#", type: String },
"cfbs_on": { dvalue: "*61*", type: String },
"cfbs_off": { dvalue: "#61#", type: String },
"call_return": { dvalue: "*69", type: String },
"redial": { dvalue: "*66", type: String },
"is_fax": { dvalue: false, type: Boolean },
"transport": { dvalue: "udp", type: String },
"priority_ulaw": { dvalue: 0, type: Number },
"priority_alaw": { dvalue: 0, type: Number },
"priority_g729": { dvalue: 0, type: Number },
"priority_g723": { dvalue: 0, type: Number },
"priority_g726": { dvalue: 0, type: Number },
"enabled": { dvalue: true, type: Boolean },
"target": { dvalue: "direct", type: String },
"call_lines": { dvalue: "BRCM/4", type: String },
"mailbox": { dvalue: "", type: String },
"call_filter": { dvalue: "", type: String },
"domain": { dvalue: "", type: String },
"user": { dvalue: "", type: String },
"authuser": { dvalue: "", type: String },
"displayname": { dvalue: "", type: String },
"ptime_ulaw": { dvalue: 20, type: Number },
"ptime_g726": { dvalue: 20, type: Number },
"ptime_g729": { dvalue: 20, type: Number },
"ptime_alaw": { dvalue: 20, type: Number },
"host": { dvalue: "", type: String },
"outboundproxy": { dvalue: "", type: String }
});
UCI.voice_client.$registerSectionType("call_filter", {
"name": { dvalue: "", type: String },
"block_outgoing": { dvalue: true, type: Boolean },
"block_incoming": { dvalue: true, type: Boolean },
"block_foreign": { dvalue: true, type: Boolean }, // outgoing foreign
"block_special_rate": { dvalue: false, type: Boolean } // outgoing special rate
});
UCI.voice_client.$registerSectionType("call_filter_rule_outgoing", {
"owner": { dvalue: "", type: String },
"enabled": { dvalue: true, type: Boolean },
"extension": { dvalue: "", type: String }
});
UCI.voice_client.$registerSectionType("call_filter_rule_incoming", {
"owner": { dvalue: "", type: String },
"enabled": { dvalue: true, type: Boolean },
"extension": { dvalue: "", type: String }
});
});

View file

@ -1,6 +1,7 @@
{
"scripts": [
"phone"
"phone",
"widgets/uci.voice_client.call_filter"
],
"pages": {
"phone/number_blocking": {

View file

@ -0,0 +1,11 @@
JUCI.app.directive("uciVoiceClientCallFilterEdit", function(){
var plugin_root = JUCI.module("phone").plugin_root;
return {
restrict: "E",
templateUrl: plugin_root+"/widgets/uci.voice_client.call_filter.html",
controller: "uciVoiceClientCallFilterEdit"
}
})
.controller("uciVoiceClientCallFilterEdit", function($scope, $uci){
});

View file

@ -1,5 +1,23 @@
<luci-layout-with-sidebar>
<div ng-controller="StatusEventsPageCtrl">
Events
<luci-config-section>
<luci-config-heading>{{ 'Event Log' | translate }}</luci-config-heading>
<luci-config-info>{{ 'status.eventlog.info' | translate }}</luci-config-info>
<luci-config-lines>
<luci-config-line title="Categories to Show">
<div class="row" ng-class="{'field-error': schedule.days.error}" >
<div class="col-xs-4" ng-repeat="type in allLogTypes">
<label >
<input type="checkbox" checklist-model="selectedLogTypes" checklist-value="type.value"> {{type.label}}
</label>
</div>
</div>
</luci-config-line>
<luci-config-line title="Events to Show">
<luci-select ng-model="selectedShownType" ng-items="allEventTypes" placeholder="Select events to show"></luci-select>
</luci-config-line>
</luci-config-lines>
<luci-config-heading>{{'Log' | translate}}</luci-config-heading>
</luci-config-section>
</div>
</luci-layout-with-sidebar>

View file

@ -1,4 +1,20 @@
$juci.module("status")
.controller("StatusEventsPageCtrl", function($scope){
$scope.selectedShowType = "all";
$scope.selectedLogTypes = [];
$scope.allLogTypes = [
{ label: "System", value: "system" },
{ label: "WAN", value: "wan" },
{ label: "LAN", value: "lan" },
{ label: "Voice", value: "voice" },
{ label: "Data", value: "data" },
{ label: "IPTV", value: "iptv" },
{ label: "USB", value: "usb" },
{ label: "Firewall", value: "firewall" }
];
$scope.allEventTypes = [
{ label: "Only Errors & Warnings", value: "errwarn" },
{ label: "All Events", value: "all" }
];
});

View file

@ -7,6 +7,13 @@ $juci.module("wifi")
$uci.sync(["wireless", "easybox"]).done(function(){
if($uci.easybox == undefined) $scope.$emit("error", "Easybox config is not present on this system!");
else $scope.easybox = $uci.easybox;
if(!$uci.easybox.settings){
$uci.easybox.create({".type": "settings", ".name": "settings"}).done(function(section){
$uci.save();
}).fail(function(){
$scope.$emit("error", "Could not create required section easybox.settings in config!");
});
}
$scope.wireless = $uci.wireless;
$scope.$apply();
}).fail(function(err){

View file

@ -164,7 +164,8 @@
"uci": [
"dropbear",
"easybox",
"hosts"
"hosts",
"voice_client"
]
}
},