diff --git a/image/wpa_supplicant.conf.template b/image/wpa_supplicant.conf.template index 79ad31dc..c95b1d8a 100644 --- a/image/wpa_supplicant.conf.template +++ b/image/wpa_supplicant.conf.template @@ -1,5 +1,9 @@ ctrl_interface=DIR=/var/run/wpa_supplicant +{{if .WiFiCountry}} +country={{.WiFiCountry}} +{{end}} + {{if eq .WiFiMode 1}} # WiFi Direct config driver_param=use_p2p_group_interface=1 diff --git a/image/wpa_supplicant_ap.conf.template b/image/wpa_supplicant_ap.conf.template index 28259bca..e1387f98 100644 --- a/image/wpa_supplicant_ap.conf.template +++ b/image/wpa_supplicant_ap.conf.template @@ -1,5 +1,8 @@ ctrl_interface=DIR=/var/run/wpa_supplicant +{{if .WiFiCountry}} +country={{.WiFiCountry}} +{{end}} p2p_disabled=1 ap_scan=2 diff --git a/main/gen_gdl90.go b/main/gen_gdl90.go index 75d86478..08703471 100644 --- a/main/gen_gdl90.go +++ b/main/gen_gdl90.go @@ -1184,6 +1184,7 @@ type settings struct { DeveloperMode bool GLimits string StaticIps []string + WiFiCountry string WiFiSSID string WiFiChannel int WiFiSecurityEnabled bool diff --git a/main/managementinterface.go b/main/managementinterface.go index 1560a6e9..6d971402 100644 --- a/main/managementinterface.go +++ b/main/managementinterface.go @@ -453,6 +453,8 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) { continue } globalSettings.StaticIps = ips + case "WiFiCountry": + setWifiCountry(val.(string)) case "WiFiSSID": setWifiSSID(val.(string)) case "WiFiChannel": diff --git a/main/networksettings.go b/main/networksettings.go index 861953fc..a29a4ab5 100644 --- a/main/networksettings.go +++ b/main/networksettings.go @@ -29,6 +29,7 @@ const ( // NetworkTemplateParams is passed to the template engine to write settings type NetworkTemplateParams struct { WiFiMode int + WiFiCountry string IpAddr string IpPrefix string DhcpRangeStart string @@ -47,6 +48,14 @@ type wifiClientNetwork struct { var hasChanged bool + +func setWifiCountry(countryCode string) { + if countryCode != globalSettings.WiFiCountry { + globalSettings.WiFiCountry = countryCode + hasChanged = true + } +} + func setWifiSSID(ssid string) { if ssid != globalSettings.WiFiSSID { globalSettings.WiFiSSID = ssid @@ -159,6 +168,7 @@ func applyNetworkSettings(force bool, onlyWriteFiles bool) { tplSettings.DhcpRangeStart = dhcpRangeStart tplSettings.DhcpRangeEnd = dhcpRangeEnd tplSettings.WiFiChannel = globalSettings.WiFiChannel + tplSettings.WiFiCountry = globalSettings.WiFiCountry tplSettings.WiFiSSID = globalSettings.WiFiSSID tplSettings.WiFiDirectPin = globalSettings.WiFiDirectPin tplSettings.WiFiClientNetworks = globalSettings.WiFiClientNetworks diff --git a/web/plates/js/settings.js b/web/plates/js/settings.js index 25eb0b22..be5dccd5 100644 --- a/web/plates/js/settings.js +++ b/web/plates/js/settings.js @@ -4,6 +4,259 @@ SettingsCtrl.$inject = ['$rootScope', '$scope', '$state', '$location', '$window' // create our controller function with all necessary logic function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) { + $scope.countryCodes = { + "":"Unspecified", + "AD":"Andorra", + "AE":"United Arab Emirates", + "AF":"Afghanistan", + "AG":"Antigua & Barbuda", + "AI":"Anguilla", + "AL":"Albania", + "AM":"Armenia", + "AO":"Angola", + "AQ":"Antarctica", + "AR":"Argentina", + "AS":"Samoa (American)", + "AT":"Austria", + "AU":"Australia", + "AW":"Aruba", + "AX":"Åland Islands", + "AZ":"Azerbaijan", + "BA":"Bosnia & Herzegovina", + "BB":"Barbados", + "BD":"Bangladesh", + "BE":"Belgium", + "BF":"Burkina Faso", + "BG":"Bulgaria", + "BH":"Bahrain", + "BI":"Burundi", + "BJ":"Benin", + "BL":"St Barthelemy", + "BM":"Bermuda", + "BN":"Brunei", + "BO":"Bolivia", + "BQ":"Caribbean NL", + "BR":"Brazil", + "BS":"Bahamas", + "BT":"Bhutan", + "BV":"Bouvet Island", + "BW":"Botswana", + "BY":"Belarus", + "BZ":"Belize", + "CA":"Canada", + "CC":"Cocos (Keeling) Islands", + "CD":"Congo (Dem. Rep.)", + "CF":"Central African Rep.", + "CG":"Congo (Rep.)", + "CH":"Switzerland", + "CI":"Côte d'Ivoire", + "CK":"Cook Islands", + "CL":"Chile", + "CM":"Cameroon", + "CN":"China", + "CO":"Colombia", + "CR":"Costa Rica", + "CU":"Cuba", + "CV":"Cape Verde", + "CW":"Curaçao", + "CX":"Christmas Island", + "CY":"Cyprus", + "CZ":"Czech Republic", + "DE":"Germany", + "DJ":"Djibouti", + "DK":"Denmark", + "DM":"Dominica", + "DO":"Dominican Republic", + "DZ":"Algeria", + "EC":"Ecuador", + "EE":"Estonia", + "EG":"Egypt", + "EH":"Western Sahara", + "ER":"Eritrea", + "ES":"Spain", + "ET":"Ethiopia", + "FI":"Finland", + "FJ":"Fiji", + "FK":"Falkland Islands", + "FM":"Micronesia", + "FO":"Faroe Islands", + "FR":"France", + "GA":"Gabon", + "GB":"Britain (UK)", + "GD":"Grenada", + "GE":"Georgia", + "GF":"French Guiana", + "GG":"Guernsey", + "GH":"Ghana", + "GI":"Gibraltar", + "GL":"Greenland", + "GM":"Gambia", + "GN":"Guinea", + "GP":"Guadeloupe", + "GQ":"Equatorial Guinea", + "GR":"Greece", + "GS":"South Georgia & the South Sandwich Islands", + "GT":"Guatemala", + "GU":"Guam", + "GW":"Guinea-Bissau", + "GY":"Guyana", + "HK":"Hong Kong", + "HM":"Heard Island & McDonald Islands", + "HN":"Honduras", + "HR":"Croatia", + "HT":"Haiti", + "HU":"Hungary", + "ID":"Indonesia", + "IE":"Ireland", + "IL":"Israel", + "IM":"Isle of Man", + "IN":"India", + "IO":"British Indian Ocean Territory", + "IQ":"Iraq", + "IR":"Iran", + "IS":"Iceland", + "IT":"Italy", + "JE":"Jersey", + "JM":"Jamaica", + "JO":"Jordan", + "JP":"Japan", + "KE":"Kenya", + "KG":"Kyrgyzstan", + "KH":"Cambodia", + "KI":"Kiribati", + "KM":"Comoros", + "KN":"St Kitts & Nevis", + "KP":"Korea (North)", + "KR":"Korea (South)", + "KW":"Kuwait", + "KY":"Cayman Islands", + "KZ":"Kazakhstan", + "LA":"Laos", + "LB":"Lebanon", + "LC":"St Lucia", + "LI":"Liechtenstein", + "LK":"Sri Lanka", + "LR":"Liberia", + "LS":"Lesotho", + "LT":"Lithuania", + "LU":"Luxembourg", + "LV":"Latvia", + "LY":"Libya", + "MA":"Morocco", + "MC":"Monaco", + "MD":"Moldova", + "ME":"Montenegro", + "MF":"St Martin (French)", + "MG":"Madagascar", + "MH":"Marshall Islands", + "MK":"North Macedonia", + "ML":"Mali", + "MM":"Myanmar (Burma)", + "MN":"Mongolia", + "MO":"Macau", + "MP":"Northern Mariana Islands", + "MQ":"Martinique", + "MR":"Mauritania", + "MS":"Montserrat", + "MT":"Malta", + "MU":"Mauritius", + "MV":"Maldives", + "MW":"Malawi", + "MX":"Mexico", + "MY":"Malaysia", + "MZ":"Mozambique", + "NA":"Namibia", + "NC":"New Caledonia", + "NE":"Niger", + "NF":"Norfolk Island", + "NG":"Nigeria", + "NI":"Nicaragua", + "NL":"Netherlands", + "NO":"Norway", + "NP":"Nepal", + "NR":"Nauru", + "NU":"Niue", + "NZ":"New Zealand", + "OM":"Oman", + "PA":"Panama", + "PE":"Peru", + "PF":"French Polynesia", + "PG":"Papua New Guinea", + "PH":"Philippines", + "PK":"Pakistan", + "PL":"Poland", + "PM":"St Pierre & Miquelon", + "PN":"Pitcairn", + "PR":"Puerto Rico", + "PS":"Palestine", + "PT":"Portugal", + "PW":"Palau", + "PY":"Paraguay", + "QA":"Qatar", + "RE":"Réunion", + "RO":"Romania", + "RS":"Serbia", + "RU":"Russia", + "RW":"Rwanda", + "SA":"Saudi Arabia", + "SB":"Solomon Islands", + "SC":"Seychelles", + "SD":"Sudan", + "SE":"Sweden", + "SG":"Singapore", + "SH":"St Helena", + "SI":"Slovenia", + "SJ":"Svalbard & Jan Mayen", + "SK":"Slovakia", + "SL":"Sierra Leone", + "SM":"San Marino", + "SN":"Senegal", + "SO":"Somalia", + "SR":"Suriname", + "SS":"South Sudan", + "ST":"Sao Tome & Principe", + "SV":"El Salvador", + "SX":"St Maarten (Dutch)", + "SY":"Syria", + "SZ":"Eswatini (Swaziland)", + "TC":"Turks & Caicos Is", + "TD":"Chad", + "TF":"French Southern & Antarctic Lands", + "TG":"Togo", + "TH":"Thailand", + "TJ":"Tajikistan", + "TK":"Tokelau", + "TL":"East Timor", + "TM":"Turkmenistan", + "TN":"Tunisia", + "TO":"Tonga", + "TR":"Turkey", + "TT":"Trinidad & Tobago", + "TV":"Tuvalu", + "TW":"Taiwan", + "TZ":"Tanzania", + "UA":"Ukraine", + "UG":"Uganda", + "UM":"US minor outlying islands", + "US":"United States", + "UY":"Uruguay", + "UZ":"Uzbekistan", + "VA":"Vatican City", + "VC":"St Vincent", + "VE":"Venezuela", + "VG":"Virgin Islands (UK)", + "VI":"Virgin Islands (US)", + "VN":"Vietnam", + "VU":"Vanuatu", + "WF":"Wallis & Futuna", + "WS":"Samoa (western)", + "YE":"Yemen", + "YT":"Mayotte", + "ZA":"South Africa", + "ZM":"Zambia", + "ZW":"Zimbabwe" + }; + $scope.$parent.helppage = 'plates/settings-help.html'; @@ -59,15 +312,16 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) { $scope.WatchList = settings.WatchList; $scope.OwnshipModeS = settings.OwnshipModeS; $scope.DeveloperMode = settings.DeveloperMode; - $scope.GLimits = settings.GLimits; - $scope.GDL90MSLAlt_Enabled = settings.GDL90MSLAlt_Enabled; + $scope.GLimits = settings.GLimits; + $scope.GDL90MSLAlt_Enabled = settings.GDL90MSLAlt_Enabled; $scope.EstimateBearinglessDist = settings.EstimateBearinglessDist $scope.StaticIps = settings.StaticIps; - $scope.WiFiSSID = settings.WiFiSSID; - $scope.WiFiPassphrase = settings.WiFiPassphrase; - $scope.WiFiSecurityEnabled = settings.WiFiSecurityEnabled; - $scope.WiFiChannel = settings.WiFiChannel; + $scope.WiFiCountry = settings.WiFiCountry; + $scope.WiFiSSID = settings.WiFiSSID; + $scope.WiFiPassphrase = settings.WiFiPassphrase; + $scope.WiFiSecurityEnabled = settings.WiFiSecurityEnabled; + $scope.WiFiChannel = settings.WiFiChannel; $scope.WiFiIPAddress = settings.WiFiIPAddress; $scope.WiFiMode = settings.WiFiMode.toString(); @@ -76,7 +330,7 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) { $scope.WiFiClientNetworks = settings.WiFiClientNetworks; $scope.WiFiInternetPassThroughEnabled = settings.WiFiInternetPassThroughEnabled; - $scope.Channels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; + $scope.Channels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; $scope.OGNAddrType = settings.OGNAddrType.toString(); $scope.OGNAddr = settings.OGNAddr; @@ -89,6 +343,9 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) { // Update theme $scope.$parent.updateTheme($scope.DarkMode); + + + $scope.CountryCodeList = countryCodes; } function getSettings() { @@ -122,10 +379,10 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) { getSettings(); - // Reset all settings from a button on the page - $scope.resetSettings = function () { - getSettings(); - }; + // Reset all settings from a button on the page + $scope.resetSettings = function () { + getSettings(); + }; $scope.$watchGroup(toggles, function (newValues, oldValues, scope) { var newsettings = {}; @@ -226,27 +483,27 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) { } }; - $scope.updateGLimits = function () { - if ($scope.GLimits !== settings["GLimits"]) { - settings["GLimits"] = $scope.GLimits; - var newsettings = { - "GLimits": settings["GLimits"] - }; - // console.log(angular.toJson(newsettings)); - setSettings(angular.toJson(newsettings)); - } - }; + $scope.updateGLimits = function () { + if ($scope.GLimits !== settings["GLimits"]) { + settings["GLimits"] = $scope.GLimits; + var newsettings = { + "GLimits": settings["GLimits"] + }; + // console.log(angular.toJson(newsettings)); + setSettings(angular.toJson(newsettings)); + } + }; - $scope.postShutdown = function () { - $window.location.href = "/"; - $location.path('/home'); - $http.post(URL_SHUTDOWN). - then(function (response) { - // do nothing - // $scope.$apply(); - }, function (response) { - // do nothing - }); + $scope.postShutdown = function () { + $window.location.href = "/"; + $location.path('/home'); + $http.post(URL_SHUTDOWN). + then(function (response) { + // do nothing + // $scope.$apply(); + }, function (response) { + // do nothing + }); }; $scope.postReboot = function () { @@ -322,69 +579,70 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) { $scope.Ui.turnOff('modalCalibrateDone'); $scope.Ui.turnOn("modalCalibrateFailed"); }); - }; + }; - $scope.addWiFiClientNetwork = function () { - $scope.WiFiClientNetworks.push({ - SSID: '', - Password: '' - }); + $scope.addWiFiClientNetwork = function () { + $scope.WiFiClientNetworks.push({ + SSID: '', + Password: '' + }); $scope.$apply(); - }; + }; - $scope.removeWiFiClientNetwork = function (Network) { - var idx = $scope.WiFiClientNetworks.indexOf(Network); - if (idx >= 0) { - $scope.WiFiClientNetworks.splice(idx, 1); - } + $scope.removeWiFiClientNetwork = function (Network) { + var idx = $scope.WiFiClientNetworks.indexOf(Network); + if (idx >= 0) { + $scope.WiFiClientNetworks.splice(idx, 1); + } $scope.$apply(); - }; + }; - $scope.updateWiFi = function(action) { - $scope.WiFiErrors = { - 'WiFiSSID': '', - 'WiFiPassphrase': '', - 'Errors': false - }; + $scope.updateWiFi = function(action) { + $scope.WiFiErrors = { + 'WiFiSSID': '', + 'WiFiPassphrase': '', + 'Errors': false + }; - if (($scope.WiFiSSID === undefined) || ($scope.WiFiSSID === null) || !isValidSSID($scope.WiFiSSID)) { - $scope.WiFiErrors.WiFiSSID = "Your Network Name(\"SSID\") must be at least 1 character " + - "but not more than 32 characters. It can only contain a-z, A-Z, 0-9, _ or -."; - $scope.WiFiErrors.Errors = true; - } + if (($scope.WiFiSSID === undefined) || ($scope.WiFiSSID === null) || !isValidSSID($scope.WiFiSSID)) { + $scope.WiFiErrors.WiFiSSID = "Your Network Name(\"SSID\") must be at least 1 character " + + "but not more than 32 characters. It can only contain a-z, A-Z, 0-9, _ or -."; + $scope.WiFiErrors.Errors = true; + } - if ($scope.WiFiSecurityEnabled) { - if (!isValidWPA($scope.WiFiPassphrase)) { - $scope.WiFiErrors.WiFiPassphrase = "Your WiFi Password, " + $scope.WiFiPassphrase + - ", contains invalid characters."; - $scope.WiFiErrors.Errors = true; - } - if ($scope.WiFiPassphrase.length < 8 || $scope.WiFiPassphrase.length > 63 ) { - $scope.WiFiErrors.WiFiPassphrase = "Your WiFi Password must be between 8 and 63 characters long."; - $scope.WiFiErrors.Errors = true; - } - } + if ($scope.WiFiSecurityEnabled) { + if (!isValidWPA($scope.WiFiPassphrase)) { + $scope.WiFiErrors.WiFiPassphrase = "Your WiFi Password, " + $scope.WiFiPassphrase + + ", contains invalid characters."; + $scope.WiFiErrors.Errors = true; + } + if ($scope.WiFiPassphrase.length < 8 || $scope.WiFiPassphrase.length > 63 ) { + $scope.WiFiErrors.WiFiPassphrase = "Your WiFi Password must be between 8 and 63 characters long."; + $scope.WiFiErrors.Errors = true; + } + } - if (!$scope.WiFiErrors.Errors) { - var newsettings = { - "WiFiSSID" : $scope.WiFiSSID, - "WiFiSecurityEnabled" : $scope.WiFiSecurityEnabled, - "WiFiPassphrase" : $scope.WiFiPassphrase, - "WiFiChannel" : parseInt($scope.WiFiChannel), + if (!$scope.WiFiErrors.Errors) { + var newsettings = { + "WiFiCountry": $scope.WiFiCountry, + "WiFiSSID" : $scope.WiFiSSID, + "WiFiSecurityEnabled" : $scope.WiFiSecurityEnabled, + "WiFiPassphrase" : $scope.WiFiPassphrase, + "WiFiChannel" : parseInt($scope.WiFiChannel), "WiFiIPAddress" : $scope.WiFiIPAddress, "WiFiMode" : parseInt($scope.WiFiMode), "WiFiDirectPin": $scope.WiFiDirectPin, "WiFiClientNetworks": $scope.WiFiClientNetworks, "WiFiInternetPassThroughEnabled": $scope.WiFiInternetPassThroughEnabled - }; + }; - // console.log(angular.toJson(newsettings)); - setSettings(angular.toJson(newsettings)); - $scope.Ui.turnOn("modalSuccessWiFi"); - } else { - $scope.Ui.turnOn("modalErrorWiFi"); - } - }; + // console.log(angular.toJson(newsettings)); + setSettings(angular.toJson(newsettings)); + $scope.Ui.turnOn("modalSuccessWiFi"); + } else { + $scope.Ui.turnOn("modalErrorWiFi"); + } + }; $scope.wifiModeStr = function() { switch(parseInt($scope.WiFiMode)) { @@ -418,178 +676,178 @@ function isValidWPA(str) { return /^[\u0020-\u007e]{8,63}$/g.test(str); } function isValidPin(str) { return /^([\d]{4}|[\d]{8})$/g.test(str); } angular.module('appControllers') - .directive('hexInput', function() { // directive for ownship hex code validation - return { - require: 'ngModel', - link: function(scope, element, attr, ctrl) { - function hexValidation(value) { - var valid = /^$|^([0-9A-Fa-f]{6},?)*$/.test(value); - ctrl.$setValidity('FAAHex', valid); - if (valid) { - return value; - } else { - return ""; - } - } - ctrl.$parsers.push(hexValidation); - } - }; - }) - .directive('watchlistInput', function() { // directive for ICAO space-separated watch list validation - return { - require: 'ngModel', - link: function(scope, element, attr, ctrl) { - function watchListValidation(value) { - // The list of METAR locations at http://www.aviationweather.gov/docs/metar/stations.txt - // lists only 4-letter/number ICAO codes. - var r = "[A-Za-z0-9]{4}"; - var valid = (new RegExp("^(" + r + "( " + r + ")*|)$", "g")).test(value); - ctrl.$setValidity('ICAOWatchList', valid); - if (valid) { - return value; - } else { - return ""; - } - } - ctrl.$parsers.push(watchListValidation); - } - }; - }) - .directive('ssidInput', function() { // directive for WiFi SSID validation - return { - require: 'ngModel', - link: function(scope, element, attr, ctrl) { - function ssidValidation(value) { - var valid = isValidSSID(value); - ctrl.$setValidity('ssid', valid); - if (valid) { - return value; - } else { - return ""; - } - } - ctrl.$parsers.push(ssidValidation); - } - }; - }) - .directive('wpaInput', function() { // directive for WiFi WPA Passphrase validation - return { - require: 'ngModel', - link: function(scope, element, attr, ctrl) { - function wpaValidation(value) { - var valid = isValidWPA(value); - ctrl.$setValidity('wpaPassphrase', valid); - if (valid) { - return value; - } else { - return ""; - } - } - ctrl.$parsers.push(wpaValidation); - } - }; - }) - .directive('pinInput', function() { - return { - require: 'ngModel', - link: function(scope, element, attr, ctrl) { - function pinValidation(value) { - var valid = isValidPin(value); - ctrl.$setValidity('WiFiDirectPin', valid); - if (valid) { - return value; - } else { - return ""; - } - } - ctrl.$parsers.push(pinValidation); - } - }; + .directive('hexInput', function() { // directive for ownship hex code validation + return { + require: 'ngModel', + link: function(scope, element, attr, ctrl) { + function hexValidation(value) { + var valid = /^$|^([0-9A-Fa-f]{6},?)*$/.test(value); + ctrl.$setValidity('FAAHex', valid); + if (valid) { + return value; + } else { + return ""; + } + } + ctrl.$parsers.push(hexValidation); + } + }; + }) + .directive('watchlistInput', function() { // directive for ICAO space-separated watch list validation + return { + require: 'ngModel', + link: function(scope, element, attr, ctrl) { + function watchListValidation(value) { + // The list of METAR locations at http://www.aviationweather.gov/docs/metar/stations.txt + // lists only 4-letter/number ICAO codes. + var r = "[A-Za-z0-9]{4}"; + var valid = (new RegExp("^(" + r + "( " + r + ")*|)$", "g")).test(value); + ctrl.$setValidity('ICAOWatchList', valid); + if (valid) { + return value; + } else { + return ""; + } + } + ctrl.$parsers.push(watchListValidation); + } + }; + }) + .directive('ssidInput', function() { // directive for WiFi SSID validation + return { + require: 'ngModel', + link: function(scope, element, attr, ctrl) { + function ssidValidation(value) { + var valid = isValidSSID(value); + ctrl.$setValidity('ssid', valid); + if (valid) { + return value; + } else { + return ""; + } + } + ctrl.$parsers.push(ssidValidation); + } + }; + }) + .directive('wpaInput', function() { // directive for WiFi WPA Passphrase validation + return { + require: 'ngModel', + link: function(scope, element, attr, ctrl) { + function wpaValidation(value) { + var valid = isValidWPA(value); + ctrl.$setValidity('wpaPassphrase', valid); + if (valid) { + return value; + } else { + return ""; + } + } + ctrl.$parsers.push(wpaValidation); + } + }; + }) + .directive('pinInput', function() { + return { + require: 'ngModel', + link: function(scope, element, attr, ctrl) { + function pinValidation(value) { + var valid = isValidPin(value); + ctrl.$setValidity('WiFiDirectPin', valid); + if (valid) { + return value; + } else { + return ""; + } + } + ctrl.$parsers.push(pinValidation); + } + }; + }) + .directive('ipListInput', function() { // directive for validation of list of IP addresses + return { + require: 'ngModel', + link: function(scope, element, attr, ctrl) { + function ipListValidation(value) { + var r = "(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"; + var valid = (new RegExp("^(" + r + "( " + r + ")*|)$", "g")).test(value); + ctrl.$setValidity('ipList', valid); + if (valid) { + return value; + } else { + return ""; + } + } + ctrl.$parsers.push(ipListValidation); + } + }; }) - .directive('ipListInput', function() { // directive for validation of list of IP addresses - return { - require: 'ngModel', - link: function(scope, element, attr, ctrl) { - function ipListValidation(value) { - var r = "(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"; - var valid = (new RegExp("^(" + r + "( " + r + ")*|)$", "g")).test(value); - ctrl.$setValidity('ipList', valid); - if (valid) { - return value; - } else { - return ""; - } - } - ctrl.$parsers.push(ipListValidation); - } - }; - }) .directive('ipAddrInput', function() { // directive for validation of a single IP address - return { - require: 'ngModel', - link: function(scope, element, attr, ctrl) { - function ipListValidation(value) { - var r = "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; - var valid = (new RegExp(r, "g")).test(value); - ctrl.$setValidity('ipAddr', valid); - if (valid) { - return value; - } else { - return ""; - } - } - ctrl.$parsers.push(ipListValidation); - } - }; - }) - .directive('gLimitsInput', function() { // directive for validation of list of G Limits - return { - require: 'ngModel', - link: function(scope, element, attr, ctrl) { - function gLimitsValidation(value) { - var r = "[-+]?[0-9]*\.?[0-9]+"; - var valid = (new RegExp("^(" + r + "( " + r + ")*|)$", "g")).test(value); - ctrl.$setValidity('gLimits', valid); - if (valid) { - return value; - } else { - return ""; - } - } - ctrl.$parsers.push(gLimitsValidation); - } - }; - }) - .directive('pilotnameInput', function() { - return { - require: 'ngModel', - link: function(scope, element, attr, ctrl) { - function pilotnameValidation(value) { - var r = "^[0-9a-zA-Z_]*$"; - var valid = new RegExp(r).test(value); - ctrl.$setValidity('pilotname', valid); - if (valid) - return value; - else - return ""; - } - ctrl.$parsers.push(pilotnameValidation); - } - } - }).directive('ognregInput', function() { - return { - require: 'ngModel', - link: function(scope, element, attr, ctrl) { - function ognregValidation(value) { - var r = "^[0-9a-zA-Z_\-]*$"; - var valid = new RegExp(r).test(value); - ctrl.$setValidity('ognreg', valid); - if (valid) - return value; - else - return ""; - } - ctrl.$parsers.push(ognregValidation); - } - } - }); + return { + require: 'ngModel', + link: function(scope, element, attr, ctrl) { + function ipListValidation(value) { + var r = "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; + var valid = (new RegExp(r, "g")).test(value); + ctrl.$setValidity('ipAddr', valid); + if (valid) { + return value; + } else { + return ""; + } + } + ctrl.$parsers.push(ipListValidation); + } + }; + }) + .directive('gLimitsInput', function() { // directive for validation of list of G Limits + return { + require: 'ngModel', + link: function(scope, element, attr, ctrl) { + function gLimitsValidation(value) { + var r = "[-+]?[0-9]*\.?[0-9]+"; + var valid = (new RegExp("^(" + r + "( " + r + ")*|)$", "g")).test(value); + ctrl.$setValidity('gLimits', valid); + if (valid) { + return value; + } else { + return ""; + } + } + ctrl.$parsers.push(gLimitsValidation); + } + }; + }) + .directive('pilotnameInput', function() { + return { + require: 'ngModel', + link: function(scope, element, attr, ctrl) { + function pilotnameValidation(value) { + var r = "^[0-9a-zA-Z_]*$"; + var valid = new RegExp(r).test(value); + ctrl.$setValidity('pilotname', valid); + if (valid) + return value; + else + return ""; + } + ctrl.$parsers.push(pilotnameValidation); + } + } + }).directive('ognregInput', function() { + return { + require: 'ngModel', + link: function(scope, element, attr, ctrl) { + function ognregValidation(value) { + var r = "^[0-9a-zA-Z_\-]*$"; + var valid = new RegExp(r).test(value); + ctrl.$setValidity('ognreg', valid); + if (valid) + return value; + else + return ""; + } + ctrl.$parsers.push(ognregValidation); + } + } + }); diff --git a/web/plates/settings.html b/web/plates/settings.html index 9fed375e..653ec2ff 100644 --- a/web/plates/settings.html +++ b/web/plates/settings.html @@ -228,6 +228,12 @@ +
+ + +