add additional config settings to modify
This commit is contained in:
parent
b2a1fd7bd1
commit
81e84baa35
10
metrics.go
10
metrics.go
|
|
@ -19,6 +19,11 @@ type OneMetric struct {
|
||||||
DeveuiJS template.JS
|
DeveuiJS template.JS
|
||||||
Alias string
|
Alias string
|
||||||
Readonly bool
|
Readonly bool
|
||||||
|
Smsalarmactive string
|
||||||
|
Smsnumber string
|
||||||
|
Emailalarmactive string
|
||||||
|
Email string
|
||||||
|
Greenzone string
|
||||||
Timestamp string
|
Timestamp string
|
||||||
PosTimestamp string
|
PosTimestamp string
|
||||||
Lat string
|
Lat string
|
||||||
|
|
@ -458,6 +463,11 @@ func getLastMetrics(deveui string) OneMetric {
|
||||||
res.LonJS = template.JS(res.Lon)
|
res.LonJS = template.JS(res.Lon)
|
||||||
|
|
||||||
res.Alias = getDevAlias(deveui)
|
res.Alias = getDevAlias(deveui)
|
||||||
|
res.Smsalarmactive = getDevSmsalarmactive(deveui)
|
||||||
|
res.Smsnumber = getDevSmsnumber(deveui)
|
||||||
|
res.Emailalarmactive = getDevEmailalarmactive(deveui)
|
||||||
|
res.Email = getDevEmail(deveui)
|
||||||
|
res.Greenzone = getDevGreenzone(deveui)
|
||||||
res.Readonly = false
|
res.Readonly = false
|
||||||
res.ActiveUntil = getActiveUntil(deveui)
|
res.ActiveUntil = getActiveUntil(deveui)
|
||||||
res.DaysUntilDeactivated = CalcDaysUntil(res.ActiveUntil)
|
res.DaysUntilDeactivated = CalcDaysUntil(res.ActiveUntil)
|
||||||
|
|
|
||||||
123
persistence.go
123
persistence.go
|
|
@ -54,6 +54,11 @@ func ping(c redis.Conn) error {
|
||||||
type Dev struct {
|
type Dev struct {
|
||||||
Deveui string
|
Deveui string
|
||||||
Alias string
|
Alias string
|
||||||
|
SmsAlarmactive string
|
||||||
|
Smsnumber string
|
||||||
|
EmailAlarmactive string
|
||||||
|
Email string
|
||||||
|
Greenzone string
|
||||||
ActiveUntil string // Abo bezahlt bis TT.MM.YYYY
|
ActiveUntil string // Abo bezahlt bis TT.MM.YYYY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,7 +109,13 @@ func updateTrackerSettings(trackerSettings Dev) error {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
// SET object
|
// SET object
|
||||||
_, err := conn.Do("HMSET", devPrefix+trackerSettings.Deveui, "alias", trackerSettings.Alias)
|
_, err := conn.Do("HMSET", devPrefix+trackerSettings.Deveui, "alias", trackerSettings.Alias,
|
||||||
|
"smsalarmactive", trackerSettings.SmsAlarmactive,
|
||||||
|
"smsnumber", trackerSettings.Smsnumber,
|
||||||
|
"emailalarmactive", trackerSettings.EmailAlarmactive,
|
||||||
|
"email", trackerSettings.Email,
|
||||||
|
"greenzone", trackerSettings.Greenzone)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -171,6 +182,116 @@ func getDevAlias(deveui string) string {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDevSmsalarmactive(deveui string) string {
|
||||||
|
res := "0"
|
||||||
|
|
||||||
|
if deveui == "" {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := globalPool.Get()
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
logit("getDevSmslarmactive: Deveui: " + deveui)
|
||||||
|
smsalarmactive, err := redis.String(conn.Do("HGET", devPrefix+deveui, "smsalarmactive"))
|
||||||
|
if err == nil {
|
||||||
|
logit("getDevSmsalarmactive: smsalarmactive: " + smsalarmactive)
|
||||||
|
res = smsalarmactive
|
||||||
|
} else {
|
||||||
|
log.Print(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDevSmsnumber(deveui string) string {
|
||||||
|
res := "+4179XXXXXXX"
|
||||||
|
|
||||||
|
if deveui == "" {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := globalPool.Get()
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
logit("getDevSmsnumber: Deveui: " + deveui)
|
||||||
|
smsnumber, err := redis.String(conn.Do("HGET", devPrefix+deveui, "smsnumber"))
|
||||||
|
if err == nil {
|
||||||
|
logit("getDevSmsnumber: smsnumber: " + smsnumber)
|
||||||
|
res = smsnumber
|
||||||
|
} else {
|
||||||
|
log.Print(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDevEmailalarmactive(deveui string) string {
|
||||||
|
res := "0"
|
||||||
|
|
||||||
|
if deveui == "" {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := globalPool.Get()
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
logit("getDevEmailarmactive: Deveui: " + deveui)
|
||||||
|
emailalarmactive, err := redis.String(conn.Do("HGET", devPrefix+deveui, "emailalarmactive"))
|
||||||
|
if err == nil {
|
||||||
|
logit("getDevEmailarmactive: emailalarmactive: " + emailalarmactive)
|
||||||
|
res = emailalarmactive
|
||||||
|
} else {
|
||||||
|
log.Print(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDevEmail(deveui string) string {
|
||||||
|
res := ""
|
||||||
|
|
||||||
|
if deveui == "" {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := globalPool.Get()
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
logit("getDevEmail: Deveui: " + deveui)
|
||||||
|
email, err := redis.String(conn.Do("HGET", devPrefix+deveui, "email"))
|
||||||
|
if err == nil {
|
||||||
|
logit("getDevEmail: email: " + email)
|
||||||
|
res = email
|
||||||
|
} else {
|
||||||
|
log.Print(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDevGreenzone(deveui string) string {
|
||||||
|
res := ""
|
||||||
|
|
||||||
|
if deveui == "" {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := globalPool.Get()
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
logit("getDevGreenzone: Deveui: " + deveui)
|
||||||
|
greenzone, err := redis.String(conn.Do("HGET", devPrefix+deveui, "greenzone"))
|
||||||
|
if err == nil {
|
||||||
|
logit("getDevGreenzone: greenzone: " + greenzone)
|
||||||
|
res = greenzone
|
||||||
|
} else {
|
||||||
|
log.Print(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func getActiveUntil(deveui string) string {
|
func getActiveUntil(deveui string) string {
|
||||||
res := ""
|
res := ""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,48 @@
|
||||||
<p id="alias_errormsg" class="help is-danger"></p>
|
<p id="alias_errormsg" class="help is-danger"></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<div class="control checkboxes">
|
||||||
|
<label for="smscheckbox" class="checkbox"><input id="smscheckbox" type="checkbox" /><span> SMS Alarmierung aktiv</span></label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label class="label">Alarmnummer (SMS)</label>
|
||||||
|
<div class="control has-icons-right">
|
||||||
|
<input id="smsnumber" class="input" type="text" maxlength="16"> <span id="smsnumber_exclamation" class="icon is-small is-right">
|
||||||
|
<i class="fas fa-exclamation-triangle"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p id="smsnumber_errormsg" class="help is-danger"></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<div class="control checkboxes">
|
||||||
|
<label for="emailcheckbox" class="checkbox"><input id="emailcheckbox" type="checkbox" /><span> E-Mail Alarmierung aktiv</span></label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label class="label">Alarm E-Mail (SMS)</label>
|
||||||
|
<div class="control has-icons-right">
|
||||||
|
<input id="email" class="input" type="text" maxlength="50"> <span id="email_exclamation" class="icon is-small is-right">
|
||||||
|
<i class="fas fa-exclamation-triangle"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p id="email_errormsg" class="help is-danger"></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label class="label">Koordination Grüne Zone</label>
|
||||||
|
<div class="control has-icons-right">
|
||||||
|
<input id="greenzone" class="input" type="text" maxlength="50"> <span id="greenzone_exclamation" class="icon is-small is-right">
|
||||||
|
<i class="fas fa-exclamation-triangle"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p id="greenzone_errormsg" class="help is-danger"></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="is-size-7">
|
<div class="is-size-7">
|
||||||
Device ID: <span id="deveui"></span>
|
Device ID: <span id="deveui"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -102,6 +144,11 @@ Sie erhalten eine E-Mail, sobald die Zahlung erfolgreich abgeschlossen ist.
|
||||||
{{range .LastMetrics}}
|
{{range .LastMetrics}}
|
||||||
<div class="column tracker is-full notification is-light">
|
<div class="column tracker is-full notification is-light">
|
||||||
<p class="is-size-2 is-size-5-mobile has-text-centered has-text-weight-bold" ><span class="alias" id="alias_{{.Deveui}}">{{.Alias}}</span>{{ if not .Readonly }}<a class="show-modal" class="block-link"><span style="float:right;" class="icon is-size-4 is-size-5-mobile"><i class="fa fa-cog"></i></span></a>{{ end }}</p>
|
<p class="is-size-2 is-size-5-mobile has-text-centered has-text-weight-bold" ><span class="alias" id="alias_{{.Deveui}}">{{.Alias}}</span>{{ if not .Readonly }}<a class="show-modal" class="block-link"><span style="float:right;" class="icon is-size-4 is-size-5-mobile"><i class="fa fa-cog"></i></span></a>{{ end }}</p>
|
||||||
|
<p id="smsalarmactive_{{.Deveui}}" hidden>{{.Smsalarmactive}}</p>
|
||||||
|
<p id="smsnumber_{{.Deveui}}" hidden>{{.Smsnumber}}</p>
|
||||||
|
<p id="emailalarmactive_{{.Deveui}}" hidden>{{.Emailalarmactive}}</p>
|
||||||
|
<p id="email_{{.Deveui}}" hidden>{{.Email}}</p>
|
||||||
|
<p id="greenzone_{{.Deveui}}" hidden>{{.Greenzone}}</p>
|
||||||
<p id="lastmeasurement_{{.Deveui}}" class="has-text-centered">letzte übermittelte Messung: {{.Timestamp}}</p>
|
<p id="lastmeasurement_{{.Deveui}}" class="has-text-centered">letzte übermittelte Messung: {{.Timestamp}}</p>
|
||||||
<p id="batpercent_{{.Deveui}}" class="has-text-centered">{{.BatteryPercentHTML}}</p>
|
<p id="batpercent_{{.Deveui}}" class="has-text-centered">{{.BatteryPercentHTML}}</p>
|
||||||
<div id="{{.Deveui}}" class="columns mt-3">
|
<div id="{{.Deveui}}" class="columns mt-3">
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,14 @@ var stripe_pk = "";
|
||||||
function validate(what, text) {
|
function validate(what, text) {
|
||||||
if (what == 'alias') {
|
if (what == 'alias') {
|
||||||
var re = /^[a-zA-Z0-9 ]{1,25}$/;
|
var re = /^[a-zA-Z0-9 ]{1,25}$/;
|
||||||
|
} else if (what == 'smsnumber') {
|
||||||
|
var re = /^\+[0-9]{11,11}$/;
|
||||||
|
} else if (what == 'email') {
|
||||||
|
var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||||
|
} else if (what == 'greenzone') {
|
||||||
|
var re = /^$|^[0-9]+\.[0-9]+,[0-9]+\.[0-9],[0-9]+\.[0-9],[0-9]+\.[0-9]$/;
|
||||||
}
|
}
|
||||||
|
|
||||||
return re.test(text);
|
return re.test(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,11 +53,37 @@ $(document).ready(function () {
|
||||||
abos_to_buy = {};
|
abos_to_buy = {};
|
||||||
$(".show-modal").click(function () {
|
$(".show-modal").click(function () {
|
||||||
$("#alias_exclamation").hide();
|
$("#alias_exclamation").hide();
|
||||||
|
$("#smsnumber_exclamation").hide();
|
||||||
|
$("#email_exclamation").hide();
|
||||||
|
$("#greenzone_exclamation").hide();
|
||||||
|
|
||||||
var alias = $(this).prev().html();
|
var alias = $(this).prev().html();
|
||||||
|
|
||||||
var deveui = $(this).prev().attr('id').replace("alias_", "");
|
var deveui = $(this).prev().attr('id').replace("alias_", "");
|
||||||
$('#deveui').html(deveui);
|
$('#deveui').html(deveui);
|
||||||
|
var smsalarmactive = $('#smsalarmactive_'+deveui).html();
|
||||||
|
var smsnumber = $('#smsnumber_'+deveui).html();
|
||||||
|
var emailalarmactive = $('#emailalarmactive_'+deveui).html();
|
||||||
|
var email = $('#email_'+deveui).html();
|
||||||
|
var greenzone = $('#greenzone_'+deveui).html();
|
||||||
|
|
||||||
$("#alias").val(alias);
|
$("#alias").val(alias);
|
||||||
|
|
||||||
|
if (smsalarmactive == "1") {
|
||||||
|
$('#smscheckbox').prop('checked', true);
|
||||||
|
} else {
|
||||||
|
$('#smscheckbox').prop('checked', false);
|
||||||
|
}
|
||||||
|
$("#smsnumber").val(smsnumber);
|
||||||
|
|
||||||
|
if (emailalarmactive == "1") {
|
||||||
|
$('#emailcheckbox').prop('checked', true);
|
||||||
|
} else {
|
||||||
|
$('#emailcheckbox').prop('checked', false);
|
||||||
|
}
|
||||||
|
$("#email").val(email);
|
||||||
|
$("#greenzone").val(greenzone);
|
||||||
|
|
||||||
$("#modal").addClass("is-active");
|
$("#modal").addClass("is-active");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -140,6 +173,15 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#modal-save").click(function () {
|
$("#modal-save").click(function () {
|
||||||
|
var smsalarmactive = "0";
|
||||||
|
if ($('#smscheckbox').prop('checked')) {
|
||||||
|
smsalarmactive = "1";
|
||||||
|
}
|
||||||
|
var emailalarmactive = "0";
|
||||||
|
if ($('#emailcheckbox').prop('checked')) {
|
||||||
|
emailalarmactive = "1";
|
||||||
|
}
|
||||||
|
|
||||||
// Validation Code
|
// Validation Code
|
||||||
var is_valid = true;
|
var is_valid = true;
|
||||||
if (!validate('alias', $('#alias').val())) {
|
if (!validate('alias', $('#alias').val())) {
|
||||||
|
|
@ -153,6 +195,39 @@ $(document).ready(function () {
|
||||||
$("#alias_exclamation").hide();
|
$("#alias_exclamation").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!validate('smsnumber',$('#smsnumber').val())) {
|
||||||
|
$('#smsnumber_errormsg').html('Beispiel einer gültigen SMS Nummer: +41761234567');
|
||||||
|
$("#smsnumber").addClass("is-danger");
|
||||||
|
$("#smsnumber_exclamation").show();
|
||||||
|
is_valid = false;
|
||||||
|
} else {
|
||||||
|
$('#smsnumber_errormsg').html('');
|
||||||
|
$("#smsnumber").removeClass("is-danger");
|
||||||
|
$("#smsnumber_exclamation").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!validate('email',$('#email').val())) {
|
||||||
|
$('#email_errormsg').html('Beispiel einer gültigen E-Mail Adresse: max.mustermann@example.com');
|
||||||
|
$("#email").addClass("is-danger");
|
||||||
|
$("#email_exclamation").show();
|
||||||
|
is_valid = false;
|
||||||
|
} else {
|
||||||
|
$('#email_errormsg').html('');
|
||||||
|
$("#email").removeClass("is-danger");
|
||||||
|
$("#email_exclamation").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!validate('greenzone',$('#greenzone').val())) {
|
||||||
|
$('#greenzone_errormsg').html('Eingabe: lat_min,lon_min,lat_max,lon_max oder aber leeres Feld');
|
||||||
|
$("#greenzone").addClass("is-danger");
|
||||||
|
$("#greenzone_exclamation").show();
|
||||||
|
is_valid = false;
|
||||||
|
} else {
|
||||||
|
$('#greenzone_errormsg').html('');
|
||||||
|
$("#greenzone").removeClass("is-danger");
|
||||||
|
$("#greenzone_exclamation").hide();
|
||||||
|
}
|
||||||
|
|
||||||
if (!(is_valid)) {
|
if (!(is_valid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -163,11 +238,30 @@ $(document).ready(function () {
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data: {
|
data: {
|
||||||
deveui: $('#deveui').html(),
|
deveui: $('#deveui').html(),
|
||||||
alias: $('#alias').val()
|
alias: $('#alias').val(),
|
||||||
|
smsnumber: $("#smsnumber").val(),
|
||||||
|
smsalarmactive: smsalarmactive,
|
||||||
|
email: $("#email").val(),
|
||||||
|
emailalarmactive: emailalarmactive,
|
||||||
|
greenzone: $("#greenzone").val()
|
||||||
|
|
||||||
},
|
},
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if (response.rc == 0) {
|
if (response.rc == 0) {
|
||||||
$('#alias_' + $('#deveui').html()).html($('#alias').val());
|
$('#alias_'+$('#deveui').html()).html($('#alias').val());
|
||||||
|
var smsalarmactive = "0";
|
||||||
|
if ($('#smscheckbox').prop('checked')) {
|
||||||
|
smsalarmactive = "1";
|
||||||
|
}
|
||||||
|
$('#smsalarmactive_'+$('#deveui').html()).html(smsalarmactive);
|
||||||
|
$('#smsnumber_'+$('#deveui').html()).html($('#smsnumber').val());
|
||||||
|
var emailalarmactive = "0";
|
||||||
|
if ($('#emailcheckbox').prop('checked')) {
|
||||||
|
emailalarmactive = "1";
|
||||||
|
}
|
||||||
|
$('#emailalarmactive_'+$('#deveui').html()).html(emailalarmactive);
|
||||||
|
$('#email_'+$('#deveui').html()).html($('#email').val());
|
||||||
|
$('#greenzone_'+$('#deveui').html()).html($('#greenzone').val());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function (xhr) {
|
error: function (xhr) {
|
||||||
|
|
|
||||||
83
tracker.go
83
tracker.go
|
|
@ -55,9 +55,92 @@ func save_tracker_settingsHandler(response http.ResponseWriter, request *http.Re
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
smsalarmactive, ok3 := request.URL.Query()["smsalarmactive"]
|
||||||
|
|
||||||
|
if !ok3 || len(smsalarmactive[0]) < 1 {
|
||||||
|
log.Println("Url Param 'smsalarmactive' is missing")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 4, \"msg\": \"smsalarmactive must be specified in URL\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mysmsalarmactive := smsalarmactive[0]
|
||||||
|
|
||||||
|
if !((mysmsalarmactive == "0") || (mysmsalarmactive == "1")) {
|
||||||
|
log.Println("Url Param 'smsalarmactive' is not valid")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 10, \"msg\": \"smsalarmactive is not valid\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
smsnumber, ok4 := request.URL.Query()["smsnumber"]
|
||||||
|
|
||||||
|
if !ok4 || len(smsnumber[0]) < 1 {
|
||||||
|
log.Println("Url Param 'smsnumber' is missing")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 5, \"msg\": \"smsnumber must be specified in URL\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mysmsnumber := smsnumber[0]
|
||||||
|
|
||||||
|
match1, _ := regexp.MatchString(`^\+[0-9]{11,11}$`, mysmsnumber)
|
||||||
|
if !(match1) {
|
||||||
|
log.Println("Url Param 'smsnumber' is not valid")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 11, \"msg\": \"smsnumber is not valid, must be in in format +41791234567\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
emailalarmactive, ok5 := request.URL.Query()["emailalarmactive"]
|
||||||
|
|
||||||
|
if !ok5 || len(emailalarmactive[0]) < 1 {
|
||||||
|
log.Println("Url Param 'emailalarmactive' is missing")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 12, \"msg\": \"emailalarmactive must be specified in URL\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
myemailalarmactive := emailalarmactive[0]
|
||||||
|
|
||||||
|
if !((myemailalarmactive == "0") || (myemailalarmactive == "1")) {
|
||||||
|
log.Println("Url Param 'emailalarmactive' is not valid")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 13, \"msg\": \"emailalarmactive is not valid\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
email, ok6 := request.URL.Query()["email"]
|
||||||
|
|
||||||
|
if !ok6 {
|
||||||
|
log.Println("Url Param 'email' is missing")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 14, \"msg\": \"email must be specified in URL\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
myemail := email[0]
|
||||||
|
|
||||||
|
match2, _ := regexp.MatchString(`^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$`, myemail)
|
||||||
|
if !(match2) {
|
||||||
|
log.Println("Url Param 'email' is not valid")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 15, \"msg\": \"email is not valid, must be in in format max.mustermann@example.com\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
greenzone, ok7 := request.URL.Query()["greenzone"]
|
||||||
|
|
||||||
|
if !ok7 {
|
||||||
|
log.Println("Url Param 'greenzone' is missing")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 16, \"msg\": \"greenzone must be specified in URL\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mygreenzone := greenzone[0]
|
||||||
|
|
||||||
|
match3, _ := regexp.MatchString(`^$|^[0-9]+\.[0-9]+,[0-9]+\.[0-9],[0-9]+\.[0-9],[0-9]+\.[0-9]$`, mygreenzone)
|
||||||
|
if !(match3) {
|
||||||
|
log.Println("Url Param 'email' is not valid")
|
||||||
|
fmt.Fprintf(response, "{ \"rc\": 17, \"msg\": \"email is not valid, must be in in format max.mustermann@example.com\" }")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var mydev Dev
|
var mydev Dev
|
||||||
mydev.Deveui = mydeveui
|
mydev.Deveui = mydeveui
|
||||||
mydev.Alias = myalias
|
mydev.Alias = myalias
|
||||||
|
mydev.SmsAlarmactive = mysmsalarmactive
|
||||||
|
mydev.Smsnumber = mysmsnumber
|
||||||
|
mydev.EmailAlarmactive = myemailalarmactive
|
||||||
|
mydev.Email = myemail
|
||||||
|
mydev.Greenzone = mygreenzone
|
||||||
|
|
||||||
// now we try to save the settings
|
// now we try to save the settings
|
||||||
err := updateTrackerSettings(mydev)
|
err := updateTrackerSettings(mydev)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue