2017-03-15 00:26:01 +00:00
|
|
|
console.log("app.sh startup")
|
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
var app = angular.module("rvpnApp", ["ngRoute", "angular-duration-format"]);
|
|
|
|
|
2017-03-15 00:26:01 +00:00
|
|
|
app.config(function($routeProvider, $locationProvider) {
|
|
|
|
$routeProvider
|
2017-03-20 00:04:47 +00:00
|
|
|
|
|
|
|
.when("/admin/status/", {
|
|
|
|
templateUrl : "admin/partials/status.html"
|
|
|
|
})
|
|
|
|
|
2017-03-16 00:32:05 +00:00
|
|
|
.when("/admin/index.html", {
|
|
|
|
templateUrl : "admin/partials/servers.html"
|
|
|
|
})
|
2017-03-20 00:04:47 +00:00
|
|
|
|
2017-03-16 00:32:05 +00:00
|
|
|
.when("/admin/servers/", {
|
2017-03-15 00:26:01 +00:00
|
|
|
templateUrl : "admin/partials/servers.html"
|
|
|
|
})
|
2017-03-20 00:04:47 +00:00
|
|
|
|
2017-03-16 00:32:05 +00:00
|
|
|
.when("/admin/#domains", {
|
2017-03-15 00:26:01 +00:00
|
|
|
templateUrl : "green.htm"
|
|
|
|
})
|
2017-03-20 00:04:47 +00:00
|
|
|
|
2017-03-15 00:26:01 +00:00
|
|
|
.when("/blue", {
|
|
|
|
templateUrl : "blue.htm"
|
|
|
|
});
|
|
|
|
$locationProvider.html5Mode(true);
|
2017-03-16 00:32:05 +00:00
|
|
|
});
|
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
app.filter('bytes', function() {
|
|
|
|
return function(bytes, precision) {
|
|
|
|
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
|
|
|
|
if (typeof precision === 'undefined') precision = 1;
|
|
|
|
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
|
|
|
|
number = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
|
|
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
|
|
|
|
}
|
|
|
|
});
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
app.filter('hfcduration', function() {
|
|
|
|
return function(duration, precision) {
|
|
|
|
remain = duration
|
|
|
|
duration_day = 24*60*60
|
|
|
|
duration_hour = 60*60
|
|
|
|
duration_minute = 60
|
|
|
|
duration_str = ""
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
days = Math.floor(remain / duration_day)
|
|
|
|
if (days > 0) {
|
|
|
|
remain = remain - (days * duration_day)
|
|
|
|
duration_str = duration_str + days + 'd'
|
|
|
|
}
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
hours = Math.floor(remain / duration_hour)
|
|
|
|
if (hours > 0) {
|
|
|
|
remain = remain - (hours * duration_hour)
|
|
|
|
duration_str = duration_str + hours + 'h'
|
|
|
|
}
|
|
|
|
|
|
|
|
mins = Math.floor(remain / duration_minute)
|
|
|
|
if (mins > 0) {
|
|
|
|
remain = remain - (mins * duration_minute)
|
|
|
|
duration_str = duration_str + mins + 'm'
|
2017-03-16 00:32:05 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
secs = Math.floor(remain)
|
|
|
|
duration_str = duration_str + secs + 's'
|
|
|
|
|
|
|
|
return (duration_str);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-03-23 23:10:49 +00:00
|
|
|
app.controller('statusController', function ($scope, $http) {
|
|
|
|
console.log("statusController");
|
|
|
|
$scope.status_search = "";
|
|
|
|
|
2017-03-26 22:33:40 +00:00
|
|
|
var api = '/api/com.daplie.tunnel/status'
|
2017-03-23 23:10:49 +00:00
|
|
|
|
|
|
|
$scope.updateView = function() {
|
|
|
|
$http.get(api).then(function(response) {
|
|
|
|
console.log(response);
|
|
|
|
data = response.data;
|
|
|
|
if (data.error == 'ok' ){
|
|
|
|
$scope.status = data.result;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.updateView()
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
app.controller('serverController', function ($scope, $http) {
|
|
|
|
$scope.servers = [];
|
|
|
|
$scope.servers_search = "";
|
|
|
|
$scope.servers_trigger_details = [];
|
2017-03-18 19:45:12 +00:00
|
|
|
$scope.filtered
|
2017-03-18 19:28:54 +00:00
|
|
|
|
2017-03-26 22:33:40 +00:00
|
|
|
var api = '/api/com.daplie.tunnel/servers'
|
2017-03-18 19:28:54 +00:00
|
|
|
|
|
|
|
$scope.updateView = function() {
|
|
|
|
$http.get(api).then(function(response) {
|
|
|
|
//console.log(response);
|
|
|
|
data = response.data;
|
|
|
|
if (data.error == 'ok' ){
|
|
|
|
$scope.servers = data.result.servers;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
$scope.triggerDetail = function(id) {
|
2017-03-20 00:04:47 +00:00
|
|
|
//console.log("triggerDetail ", id, $scope.servers_trigger_details[id])
|
2017-03-18 19:28:54 +00:00
|
|
|
if ($scope.servers_trigger_details[id] == true) {
|
|
|
|
$scope.servers_trigger_details[id] = false;
|
|
|
|
} else {
|
|
|
|
$scope.servers_trigger_details[id] = true
|
|
|
|
}
|
|
|
|
};
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
$scope.checkDetail = function(id) {
|
2017-03-20 00:04:47 +00:00
|
|
|
//console.log("checkDetail ", id, $scope.servers_trigger_details[id])
|
2017-03-18 19:28:54 +00:00
|
|
|
if ($scope.servers_trigger_details[id] == true) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
};
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
$scope.updateView()
|
2017-03-16 00:32:05 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|