parent
21e231a6fc
commit
ebf0ecc3c0
3 changed files with 36 additions and 26 deletions
|
@ -339,13 +339,13 @@
|
||||||
success: function(data){
|
success: function(data){
|
||||||
$("#statusBar").html('<div class="alert alert-success" role="alert">' +
|
$("#statusBar").html('<div class="alert alert-success" role="alert">' +
|
||||||
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
|
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
|
||||||
'<strong>Successfully saved config for: ' + clientId + '</strong></div>');
|
'Successfully saved config for: ' + clientId + '<strong> - You need push the config to the client to apply the config.</strong></div>');
|
||||||
|
|
||||||
window.setTimeout(function() {
|
window.setTimeout(function() {
|
||||||
$(".alert-success").fadeTo(500, 0).slideUp(500, function(){
|
$(".alert-success").fadeTo(500, 0).slideUp(500, function(){
|
||||||
$(".alert-success").alert('close');
|
$(".alert-success").alert('close');
|
||||||
});
|
});
|
||||||
}, 2500);
|
}, 5000);
|
||||||
},
|
},
|
||||||
error: function (data) {
|
error: function (data) {
|
||||||
$("#statusBar").html('<div class="alert alert-danger" role="alert">' +
|
$("#statusBar").html('<div class="alert alert-danger" role="alert">' +
|
||||||
|
@ -379,13 +379,13 @@
|
||||||
success: function(data){
|
success: function(data){
|
||||||
$("#statusBar").html('<div class="alert alert-success" role="alert">' +
|
$("#statusBar").html('<div class="alert alert-success" role="alert">' +
|
||||||
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
|
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
|
||||||
'<strong>Successfully send ' + action + '</strong></div>');
|
'Successfully send ' + action + '<strong> - It can take up to 30s until the command is processed.</strong></div>');
|
||||||
|
|
||||||
window.setTimeout(function() {
|
window.setTimeout(function() {
|
||||||
$(".alert-success").fadeTo(500, 0).slideUp(500, function(){
|
$(".alert-success").fadeTo(500, 0).slideUp(500, function(){
|
||||||
$(".alert-success").alert('close');
|
$(".alert-success").alert('close');
|
||||||
});
|
});
|
||||||
}, 2500);
|
}, 5000);
|
||||||
},
|
},
|
||||||
error: function (data) {
|
error: function (data) {
|
||||||
$("#statusBar").html('<div class="alert alert-danger" role="alert">' +
|
$("#statusBar").html('<div class="alert alert-danger" role="alert">' +
|
||||||
|
|
|
@ -79,33 +79,43 @@ unsigned Httpd::tokenAuth(struct MHD_Connection* connection)
|
||||||
|
|
||||||
unsigned Httpd::basicAuth(struct MHD_Connection* connection, std::string& resp)
|
unsigned Httpd::basicAuth(struct MHD_Connection* connection, std::string& resp)
|
||||||
{
|
{
|
||||||
|
unsigned result = MHD_HTTP_OK;
|
||||||
|
|
||||||
if (!m_options->ccAdminUser() || !m_options->ccAdminPass()) {
|
if (!m_options->ccAdminUser() || !m_options->ccAdminPass()) {
|
||||||
resp = std::string("<html><body\\>"
|
resp = std::string("<html><body\\>"
|
||||||
"Please configure admin user and pass to view this Page."
|
"Please configure admin user and pass to view this Page."
|
||||||
"</body><html\\>");
|
"</body><html\\>");
|
||||||
|
|
||||||
LOG_WARN("Admin user/password not set. Access Forbidden!");
|
LOG_WARN("Admin user/password not set. Access Forbidden!");
|
||||||
return MHD_HTTP_FORBIDDEN;
|
result = MHD_HTTP_FORBIDDEN;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const char* header = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_AUTHORIZATION);
|
||||||
|
if (header) {
|
||||||
|
char* user;
|
||||||
|
char* pass;
|
||||||
|
|
||||||
|
user = MHD_basic_auth_get_username_password(connection, &pass);
|
||||||
|
if (user == nullptr || strcmp(user, m_options->ccAdminUser()) != 0 ||
|
||||||
|
pass == nullptr || strcmp(pass, m_options->ccAdminPass()) != 0) {
|
||||||
|
|
||||||
|
LOG_WARN("Admin user/password wrong. Access Unauthorized!");
|
||||||
|
result = MHD_HTTP_UNAUTHORIZED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
free(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pass) {
|
||||||
|
free(pass);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = MHD_HTTP_UNAUTHORIZED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* header = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_AUTHORIZATION);
|
return result;
|
||||||
if (!header) {
|
|
||||||
return MHD_HTTP_UNAUTHORIZED;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* user;
|
|
||||||
char* pass;
|
|
||||||
|
|
||||||
user = MHD_basic_auth_get_username_password(connection, &pass);
|
|
||||||
|
|
||||||
if (user == nullptr || strcmp(user, m_options->ccAdminUser()) != 0 ||
|
|
||||||
pass == nullptr || strcmp(pass, m_options->ccAdminPass()) != 0) {
|
|
||||||
|
|
||||||
LOG_WARN("Admin user/password wrong. Access Unauthorized!");
|
|
||||||
return MHD_HTTP_UNAUTHORIZED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return MHD_HTTP_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Httpd::sendResponse(MHD_Connection* connection, unsigned status, MHD_Response* rsp, const char* contentType)
|
int Httpd::sendResponse(MHD_Connection* connection, unsigned status, MHD_Response* rsp, const char* contentType)
|
||||||
|
|
|
@ -139,7 +139,7 @@ unsigned Service::getClientConfig(const Options* options, const std::string& cli
|
||||||
writer.SetMaxDecimalPlaces(10);
|
writer.SetMaxDecimalPlaces(10);
|
||||||
document.Accept(writer);
|
document.Accept(writer);
|
||||||
|
|
||||||
resp = strdup(buffer.GetString());
|
resp = buffer.GetString();
|
||||||
|
|
||||||
resultCode = MHD_HTTP_OK;
|
resultCode = MHD_HTTP_OK;
|
||||||
} else {
|
} else {
|
||||||
|
@ -203,7 +203,7 @@ unsigned Service::getClientStatusList(std::string& resp)
|
||||||
writer.SetMaxDecimalPlaces(10);
|
writer.SetMaxDecimalPlaces(10);
|
||||||
document.Accept(writer);
|
document.Accept(writer);
|
||||||
|
|
||||||
resp = strdup(buffer.GetString());
|
resp = buffer.GetString();
|
||||||
|
|
||||||
return MHD_HTTP_OK;
|
return MHD_HTTP_OK;
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ unsigned Service::getClientCommand(const std::string& clientId, std::string& res
|
||||||
writer.SetMaxDecimalPlaces(10);
|
writer.SetMaxDecimalPlaces(10);
|
||||||
respDocument.Accept(writer);
|
respDocument.Accept(writer);
|
||||||
|
|
||||||
resp = strdup(buffer.GetString());
|
resp = buffer.GetString();
|
||||||
|
|
||||||
return MHD_HTTP_OK;
|
return MHD_HTTP_OK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue