Merge branch 'development' into LTS_development
# Conflicts: # src/controller/controller_api.cpp
This commit is contained in:
commit
eb15ad41a9
1 changed files with 21 additions and 0 deletions
|
@ -319,6 +319,7 @@ int Controller::handleAPIConnection(Socket::Connection & conn){
|
||||||
//set up defaults
|
//set up defaults
|
||||||
unsigned int logins = 0;
|
unsigned int logins = 0;
|
||||||
bool authorized = false;
|
bool authorized = false;
|
||||||
|
bool isLocal = false;
|
||||||
HTTP::Parser H;
|
HTTP::Parser H;
|
||||||
//while connected and not past login attempt limit
|
//while connected and not past login attempt limit
|
||||||
while (conn && logins < 4){
|
while (conn && logins < 4){
|
||||||
|
@ -326,6 +327,7 @@ int Controller::handleAPIConnection(Socket::Connection & conn){
|
||||||
//Are we local and not forwarded? Instant-authorized.
|
//Are we local and not forwarded? Instant-authorized.
|
||||||
if (!authorized && !H.hasHeader("X-Real-IP") && conn.isLocal()){
|
if (!authorized && !H.hasHeader("X-Real-IP") && conn.isLocal()){
|
||||||
MEDIUM_MSG("Local API access automatically authorized");
|
MEDIUM_MSG("Local API access automatically authorized");
|
||||||
|
isLocal = true;
|
||||||
authorized = true;
|
authorized = true;
|
||||||
}
|
}
|
||||||
#ifdef NOAUTH
|
#ifdef NOAUTH
|
||||||
|
@ -404,6 +406,7 @@ int Controller::handleAPIConnection(Socket::Connection & conn){
|
||||||
//if already authorized, do not re-check for authorization
|
//if already authorized, do not re-check for authorization
|
||||||
if (authorized && Storage["account"]){
|
if (authorized && Storage["account"]){
|
||||||
Response["authorize"]["status"] = "OK";
|
Response["authorize"]["status"] = "OK";
|
||||||
|
if (isLocal){Response["authorize"]["local"] = true;}
|
||||||
}else{
|
}else{
|
||||||
authorized |= authorize(Request, Response, conn);
|
authorized |= authorize(Request, Response, conn);
|
||||||
}
|
}
|
||||||
|
@ -454,7 +457,9 @@ void Controller::handleUDPAPI(void * np){
|
||||||
JSON::Value Response;
|
JSON::Value Response;
|
||||||
if (Request.isObject()){
|
if (Request.isObject()){
|
||||||
tthread::lock_guard<tthread::mutex> guard(configMutex);
|
tthread::lock_guard<tthread::mutex> guard(configMutex);
|
||||||
|
Response["authorize"]["local"] = true;
|
||||||
handleAPICommands(Request, Response);
|
handleAPICommands(Request, Response);
|
||||||
|
Response.removeMember("authorize");
|
||||||
uSock.SendNow(Response.toString());
|
uSock.SendNow(Response.toString());
|
||||||
}else{
|
}else{
|
||||||
WARN_MSG("Invalid API command received over UDP: %s", uSock.data);
|
WARN_MSG("Invalid API command received over UDP: %s", uSock.data);
|
||||||
|
@ -953,6 +958,22 @@ void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response
|
||||||
Response["api_endpoint"] = url.getUrl();
|
Response["api_endpoint"] = url.getUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Request.isMember("shutdown")){
|
||||||
|
if (Response.isMember("authorize") && Response["authorize"].isMember("local")){
|
||||||
|
std::string reason;
|
||||||
|
if (Request["shutdown"].isObject() || Request["shutdown"].isArray()){
|
||||||
|
reason = Request["shutdown"].toString();
|
||||||
|
}else{
|
||||||
|
reason = Request["shutdown"].asString();
|
||||||
|
}
|
||||||
|
WARN_MSG("Shutdown requested through local API: %s", reason.c_str());
|
||||||
|
Controller::conf.is_active = false;
|
||||||
|
Response["shutdown"] = "Shutting down";
|
||||||
|
}else{
|
||||||
|
Response["shutdown"] = "Ignored - only local users may request shutdown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Request.isMember("invalidate_sessions")){
|
if (Request.isMember("invalidate_sessions")){
|
||||||
if (Request["invalidate_sessions"].isArray()){
|
if (Request["invalidate_sessions"].isArray()){
|
||||||
for (unsigned int i = 0; i < Request["invalidate_sessions"].size(); ++i){
|
for (unsigned int i = 0; i < Request["invalidate_sessions"].size(); ++i){
|
||||||
|
|
Loading…
Add table
Reference in a new issue