Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
Jeremy Mowery | 81e84cc | 2016-04-19 17:01:48 -0700 | [diff] [blame] | 3 | angular.module('xos.openVPNDashboard', [ |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 4 | 'ngResource', |
| 5 | 'ngCookies', |
| 6 | 'ngLodash', |
| 7 | 'ui.router', |
| 8 | 'xos.helpers' |
| 9 | ]) |
| 10 | .config(($stateProvider) => { |
| 11 | $stateProvider |
Jeremy Mowery | 81e84cc | 2016-04-19 17:01:48 -0700 | [diff] [blame] | 12 | .state('openVPNList', { |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 13 | url: '/', |
Jeremy Mowery | 41d6e88 | 2016-04-19 19:31:11 -0700 | [diff] [blame] | 14 | template: '<vpn-list></vpn-list>' |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 15 | }); |
| 16 | }) |
Jeremy Mowery | c257c41 | 2016-03-01 19:15:40 -0700 | [diff] [blame] | 17 | .config(($compileProvider) => { |
| 18 | $compileProvider.aHrefSanitizationWhitelist( |
| 19 | /^\s*(https?|ftp|mailto|tel|file|blob):/); |
| 20 | }) |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 21 | .service('Vpn', function($http, $q){ |
| 22 | |
Jeremy Mowery | 41d6e88 | 2016-04-19 19:31:11 -0700 | [diff] [blame] | 23 | this.getOpenVpnTenants = () => { |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 24 | let deferred = $q.defer(); |
| 25 | |
Jeremy Mowery | 441c3d6 | 2016-04-23 14:31:10 -0700 | [diff] [blame] | 26 | $http.get('/api/tenant/openvpn/list/') |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 27 | .then((res) => { |
| 28 | deferred.resolve(res.data) |
| 29 | }) |
| 30 | .catch((e) => { |
| 31 | deferred.reject(e); |
| 32 | }); |
| 33 | |
| 34 | return deferred.promise; |
Jeremy Mowery | c770ba0 | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 35 | } |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 36 | }) |
| 37 | .config(function($httpProvider){ |
| 38 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 39 | }) |
Jeremy Mowery | 41d6e88 | 2016-04-19 19:31:11 -0700 | [diff] [blame] | 40 | .directive('vpnList', function(){ |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 41 | return { |
| 42 | restrict: 'E', |
| 43 | scope: {}, |
| 44 | bindToController: true, |
| 45 | controllerAs: 'vm', |
Jeremy Mowery | 81e84cc | 2016-04-19 17:01:48 -0700 | [diff] [blame] | 46 | templateUrl: 'templates/openvpn-list.tpl.html', |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 47 | controller: function(Vpn){ |
Jeremy Mowery | 41d6e88 | 2016-04-19 19:31:11 -0700 | [diff] [blame] | 48 | Vpn.getOpenVpnTenants() |
Jeremy Mowery | e84e3ee | 2016-02-28 22:21:54 -0700 | [diff] [blame] | 49 | .then((vpns) => { |
Jeremy Mowery | 98dd6c8 | 2016-02-25 11:25:53 -0700 | [diff] [blame] | 50 | this.vpns = vpns; |
Jeremy Mowery | 37e4efe | 2016-03-02 00:01:25 -0700 | [diff] [blame] | 51 | for (var i = 0; i < this.vpns.length; i++) { |
Jeremy Mowery | ee13991 | 2016-04-17 19:20:01 -0700 | [diff] [blame] | 52 | var blob = new Blob([this.vpns[i].script_text], {type: 'text/plain'}); |
Jeremy Mowery | 37e4efe | 2016-03-02 00:01:25 -0700 | [diff] [blame] | 53 | this.vpns[i].script_text = (window.URL || window.webkitURL).createObjectURL( blob ); |
| 54 | } |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 55 | }) |
| 56 | .catch((e) => { |
| 57 | throw new Error(e); |
| 58 | }); |
Jeremy Mowery | c770ba0 | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 59 | } |
| 60 | }; |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 61 | }); |