diff --git a/token-validator/htdocs/js/adlin-main.js b/token-validator/htdocs/js/adlin-main.js new file mode 100644 index 0000000..55c6799 --- /dev/null +++ b/token-validator/htdocs/js/adlin-main.js @@ -0,0 +1,159 @@ +angular.module("AdLinApp", ["ngRoute", "ngResource", "ngSanitize"]) + .config(function($routeProvider, $locationProvider) { + $routeProvider + .when("/auth", { + controller: "AuthController", + templateUrl: "views/auth.html" + }) + .when("/domains", { + controller: "DomainsController", + templateUrl: "views/domains.html" + }) + .when("/tunnels", { + controller: "TunnelsController", + templateUrl: "views/tunnels.html" + }) + .when("/", { + templateUrl: "views/home.html" + }); + $locationProvider.html5Mode(true); + }); + +angular.module("AdLinApp") + .factory("Student", function($resource) { + return $resource("/api/students/:studentId", { studentId: '@id' }, { + 'update': {method: 'PUT'}, + }) + }) + .factory("Progression", function($resource) { + return $resource("/api/progress") + }) + .factory("Challenge", function($resource) { + return $resource("/challenge/:challengeId", { challengeId: '@id' }) + }); + +angular.module("AdLinApp") + .run(function($rootScope, $interval, $http) { + $rootScope.checkLoginState = function() { + if (sessionStorage.token === undefined) { + $rootScope.isLogged = false; + return; + } + + var token = sessionStorage.token; + $http({ + method: 'GET', + url: "/api/auth", + headers: { + 'Authorization': "Bearer " + token + } + }).then(function(response) { + $rootScope.isLogged = response.data; + }, function(response) { + $rootScope.isLogged = false; + }); + }; + $rootScope.checkLoginState(); + $interval($rootScope.checkLoginState, 20000); + + $rootScope.disconnectCurrentUser = function() { + sessionStorage.token = undefined; + delete sessionStorage.token; + $rootScope.isLogged = false; + } + }) + + .controller("AuthController", function($scope, $rootScope, $http, $location) { + $scope.auth = { + "username": "", + "password": "", + }; + + $scope.logmein = function() { + $scope.pleaseWait = true; + $http({ + method: 'POST', + url: "/api/auth", + data: $scope.auth + }).then(function(response) { + sessionStorage.token = response.data.id_session + $scope.pleaseWait = false; + $rootScope.checkLoginState(); + $location.url("/"); + }, function(response) { + alert(response.data.errmsg); + $scope.pleaseWait = false; + }); + } + }) + + .controller("TunnelsController", function($scope, $http, $interval) { + $scope.updateTunnelInfo = function() { + $http({ + method: 'GET', + url: "/api/wginfo", + headers: { + 'Authorization': "Bearer " + sessionStorage.token + } + }).then(function(response) { + $scope.wginfo = response.data; + }); + }; + $scope.updateTunnelInfo(); + + $scope.updateTunnelsList = function() { + $http({ + method: 'GET', + url: "/api/wg/", + headers: { + 'Authorization': "Bearer " + sessionStorage.token + } + }).then(function(response) { + $scope.tunnels = response.data; + }, function(response) { + alert(response.data.errmsg); + }); + }; + $scope.updateTunnelsList(); + $interval($scope.updateTunnelsList, 12000); + + $scope.newTunnel = function() { + $scope.pleaseWaitNew = true; + $http({ + method: 'POST', + url: "/api/wg/", + headers: { + 'Authorization': "Bearer " + sessionStorage.token + }, + data: {} + }).then(function(response) { + $scope.updateTunnelsList(); + $scope.pleaseWaitNew = false; + }, function(response) { + alert(response.data.errmsg); + $scope.pleaseWaitNew = false; + }); + } + + $scope.dropTunnel = function(tunnel) { + tunnel.pleaseWaitDrop = true; + $http({ + method: 'DELETE', + url: "/api/wg/" + tunnel.TokenText, + headers: { + 'Authorization': "Bearer " + sessionStorage.token + }, + data: {} + }).then(function(response) { + $scope.updateTunnelsList(); + tunnel.pleaseWaitDrop = false; + }, function(response) { + alert(response.data.errmsg); + tunnel.pleaseWaitDrop = false; + }); + } + }) + + .controller("DomainsController", function($scope, $http, $interval) { + + }) diff --git a/token-validator/htdocs/maatma.html b/token-validator/htdocs/maatma.html new file mode 100644 index 0000000..bbe7261 --- /dev/null +++ b/token-validator/htdocs/maatma.html @@ -0,0 +1,45 @@ + + + + + Maatma: Domains Names, Web Hosting. SSL Certificates, the DIY way + + + + + + + +
+ + + + + + + + + diff --git a/token-validator/htdocs/views/auth.html b/token-validator/htdocs/views/auth.html new file mode 100644 index 0000000..7312923 --- /dev/null +++ b/token-validator/htdocs/views/auth.html @@ -0,0 +1,16 @@ +

Accès à votre compte

+ +
+
+ + +
+
+ + +
+ +
diff --git a/token-validator/htdocs/views/home.html b/token-validator/htdocs/views/home.html new file mode 100644 index 0000000..131932f --- /dev/null +++ b/token-validator/htdocs/views/home.html @@ -0,0 +1,43 @@ +
+

+ Bienvenue {{ isLogged.login }} chez Maatma ! +

+

L'hébergement vraiment pas cher (mais DIY) !

+ +
+ +

+ Connectez-vous ! +

+ +

+ Qu'allons-nous faire aujourd'hui ? +

+
+ +
+
+ ... +
+
Card title
+

This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.

+

Last updated 3 mins ago

+
+
+
+ ... +
+
Card title
+

This card has supporting text below as a natural lead-in to additional content.

+

Last updated 3 mins ago

+
+
+
+ ... +
+
Card title
+

This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.

+

Last updated 3 mins ago

+
+
+
diff --git a/token-validator/htdocs/views/tunnels.html b/token-validator/htdocs/views/tunnels.html new file mode 100644 index 0000000..e7bc99a --- /dev/null +++ b/token-validator/htdocs/views/tunnels.html @@ -0,0 +1,48 @@ +

+ Tunnels +

+ + + + + + + + + + + + + + + + + + + + + + + +
TokenDernière utilisationClef publique
{{ tunnel.TokenText }}{{ tunnel.Time | date:"medium" }}{{ tunnel.PubKey }}(none) + +
+ +
+ +
+

Paramètres du tunnel

+ +
diff --git a/token-validator/static.go b/token-validator/static.go index 9c5e72f..4e345d4 100644 --- a/token-validator/static.go +++ b/token-validator/static.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "path" + "strings" "github.com/julienschmidt/httprouter" ) @@ -12,21 +13,6 @@ import ( //go:generate go fmt bindata.go func init() { - Router().GET("/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - if data, err := Asset("htdocs/index.html"); err != nil { - fmt.Fprintf(w, "{\"errmsg\":%q}", err) - } else { - w.Write(data) - } - }) - Router().GET("/dashboard/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - if data, err := Asset("htdocs/dashboard.html"); err != nil { - fmt.Fprintf(w, "{\"errmsg\":%q}", err) - } else { - w.Write(data) - } - }) - Router().GET("/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { w.Header().Set("Content-Type", "text/css") if data, err := Asset(path.Join("htdocs", r.URL.Path)); err != nil { @@ -65,4 +51,95 @@ func init() { w.Write(data) } }) + + Router().GET("/dashboard/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + if data, err := Asset("htdocs/dashboard.html"); err != nil { + fmt.Fprintf(w, "{\"errmsg\":%q}", err) + } else { + w.Write(data) + } + }) + Router().GET("/dashboard/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + w.Header().Set("Content-Type", "text/css") + if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/dashboard"))); err != nil { + http.NotFound(w, r) + } else { + w.Write(data) + } + }) + Router().GET("/dashboard/js/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + w.Header().Set("Content-Type", "text/javascript") + if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/dashboard"))); err != nil { + http.NotFound(w, r) + } else { + w.Write(data) + } + }) + + Router().GET("/maatma/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + if data, err := Asset("htdocs/maatma.html"); err != nil { + fmt.Fprintf(w, "{\"errmsg\":%q}", err) + } else { + w.Write(data) + } + }) + Router().GET("/maatma/auth", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + if data, err := Asset("htdocs/maatma.html"); err != nil { + fmt.Fprintf(w, "{\"errmsg\":%q}", err) + } else { + w.Write(data) + } + }) + Router().GET("/maatma/domains", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + if data, err := Asset("htdocs/maatma.html"); err != nil { + fmt.Fprintf(w, "{\"errmsg\":%q}", err) + } else { + w.Write(data) + } + }) + Router().GET("/maatma/tunnels", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + if data, err := Asset("htdocs/maatma.html"); err != nil { + fmt.Fprintf(w, "{\"errmsg\":%q}", err) + } else { + w.Write(data) + } + }) + Router().GET("/maatma/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + w.Header().Set("Content-Type", "text/css") + if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/maatma"))); err != nil { + http.NotFound(w, r) + } else { + w.Write(data) + } + }) + Router().GET("/maatma/fonts/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/maatma"))); err != nil { + http.NotFound(w, r) + } else { + w.Write(data) + } + }) + Router().GET("/maatma/img/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/maatma"))); err != nil { + http.NotFound(w, r) + } else { + w.Write(data) + } + }) + Router().GET("/maatma/js/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + w.Header().Set("Content-Type", "text/javascript") + if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/maatma"))); err != nil { + http.NotFound(w, r) + } else { + w.Write(data) + } + }) + Router().GET("/maatma/views/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + w.Header().Set("Content-Type", "text/html") + if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/maatma"))); err != nil { + http.NotFound(w, r) + } else { + w.Write(data) + } + }) }