2020-04-28 06:58:26 +00:00
|
|
|
console.log("app.sh startup");
|
2017-03-15 00:26:01 +00:00
|
|
|
|
2017-03-18 19:28:54 +00:00
|
|
|
var app = angular.module("rvpnApp", ["ngRoute", "angular-duration-format"]);
|
|
|
|
|
2020-04-28 06:58:26 +00:00
|
|
|
app.config(function ($routeProvider, $locationProvider) {
|
2017-03-15 00:26:01 +00:00
|
|
|
$routeProvider
|
2017-03-20 00:04:47 +00:00
|
|
|
|
2020-04-28 06:58:26 +00:00
|
|
|
.when("/admin/status/", {
|
|
|
|
templateUrl: "admin/partials/status.html"
|
|
|
|
})
|
|
|
|
|
|
|
|
.when("/admin/index.html", {
|
|
|
|
templateUrl: "admin/partials/servers.html"
|
|
|
|
})
|
|
|
|
|
|
|
|
.when("/admin/servers/", {
|
|
|
|
templateUrl: "admin/partials/servers.html"
|
|
|
|
})
|
|
|
|
|
|
|
|
.when("/admin/#domains", {
|
|
|
|
templateUrl: "green.htm"
|
|
|
|
})
|
|
|
|
|
|
|
|
.when("/blue", {
|
|
|
|
templateUrl: "blue.htm"
|
|
|
|
});
|
2017-03-15 00:26:01 +00:00
|
|
|
$locationProvider.html5Mode(true);
|
2017-03-16 00:32:05 +00:00
|
|
|
});
|
|
|
|
|
2020-04-28 06:58:26 +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-18 19:28:54 +00:00
|
|
|
});
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2020-04-28 06:58:26 +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
|
|
|
|
2020-04-28 06:58:26 +00:00
|
|
|
days = Math.floor(remain / duration_day);
|
2017-03-18 19:28:54 +00:00
|
|
|
if (days > 0) {
|
2020-04-28 06:58:26 +00:00
|
|
|
remain = remain - days * duration_day;
|
|
|
|
duration_str = duration_str + days + "d";
|
2017-03-18 19:28:54 +00:00
|
|
|
}
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2020-04-28 06:58:26 +00:00
|
|
|
hours = Math.floor(remain / duration_hour);
|
2017-03-18 19:28:54 +00:00
|
|
|
if (hours > 0) {
|
2020-04-28 06:58:26 +00:00
|
|
|
remain = remain - hours * duration_hour;
|
|
|
|
duration_str = duration_str + hours + "h";
|
2017-03-18 19:28:54 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 06:58:26 +00:00
|
|
|
mins = Math.floor(remain / duration_minute);
|
2017-03-18 19:28:54 +00:00
|
|
|
if (mins > 0) {
|
2020-04-28 06:58:26 +00:00
|
|
|
remain = remain - mins * duration_minute;
|
|
|
|
duration_str = duration_str + mins + "m";
|
2017-03-16 00:32:05 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 06:58:26 +00:00
|
|
|
secs = Math.floor(remain);
|
|
|
|
duration_str = duration_str + secs + "s";
|
|
|
|
|
|
|
|
return duration_str;
|
|
|
|
};
|
2017-03-18 19:28:54 +00:00
|
|
|
});
|
|
|
|
|
2020-04-28 06:58:26 +00:00
|
|
|
app.controller("statusController", function ($scope, $http) {
|
2017-03-23 23:10:49 +00:00
|
|
|
console.log("statusController");
|
|
|
|
$scope.status_search = "";
|
|
|
|
|
2020-04-28 06:58:26 +00:00
|
|
|
var api = "/api/org.rootprojects.tunnel/status";
|
|
|
|
|
|
|
|
$scope.updateView = function () {
|
|
|
|
$http.get(api).then(function (response) {
|
2017-03-23 23:10:49 +00:00
|
|
|
console.log(response);
|
|
|
|
data = response.data;
|
2020-04-28 06:58:26 +00:00
|
|
|
if (data.error == "ok") {
|
2017-03-23 23:10:49 +00:00
|
|
|
$scope.status = data.result;
|
|
|
|
}
|
|
|
|
});
|
2020-04-28 06:58:26 +00:00
|
|
|
};
|
2017-03-23 23:10:49 +00:00
|
|
|
|
2020-04-28 06:58:26 +00:00
|
|
|
$scope.updateView();
|
2017-03-23 23:10:49 +00:00
|
|
|
});
|
|
|
|
|
2020-04-28 06:58:26 +00:00
|
|
|
app.controller("serverController", function ($scope, $http) {
|
2017-03-18 19:28:54 +00:00
|
|
|
$scope.servers = [];
|
|
|
|
$scope.servers_search = "";
|
|
|
|
$scope.servers_trigger_details = [];
|
2020-04-28 06:58:26 +00:00
|
|
|
$scope.filtered;
|
2017-03-18 19:28:54 +00:00
|
|
|
|
2020-04-28 06:58:26 +00:00
|
|
|
var api = "/api/org.rootprojects.tunnel/servers";
|
|
|
|
|
|
|
|
$scope.updateView = function () {
|
|
|
|
$http.get(api).then(function (response) {
|
2017-03-18 19:28:54 +00:00
|
|
|
//console.log(response);
|
|
|
|
data = response.data;
|
2020-04-28 06:58:26 +00:00
|
|
|
if (data.error == "ok") {
|
2017-03-18 19:28:54 +00:00
|
|
|
$scope.servers = data.result.servers;
|
|
|
|
}
|
|
|
|
});
|
2020-04-28 06:58:26 +00:00
|
|
|
};
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2020-04-28 06:58:26 +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 {
|
2020-04-28 06:58:26 +00:00
|
|
|
$scope.servers_trigger_details[id] = true;
|
2017-03-18 19:28:54 +00:00
|
|
|
}
|
|
|
|
};
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2020-04-28 06:58:26 +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 {
|
2020-04-28 06:58:26 +00:00
|
|
|
return true;
|
2017-03-18 19:28:54 +00:00
|
|
|
}
|
|
|
|
};
|
2017-03-16 00:32:05 +00:00
|
|
|
|
2020-04-28 06:58:26 +00:00
|
|
|
$scope.updateView();
|
2017-03-16 00:32:05 +00:00
|
|
|
});
|