License system now uses downloader

This commit is contained in:
Thulinma 2017-08-05 11:46:42 +02:00
parent de30f9b2a4
commit 528727329b

View file

@ -9,6 +9,7 @@
#include <mist/config.h> #include <mist/config.h>
#include <mist/encryption.h> #include <mist/encryption.h>
#include <mist/encode.h> #include <mist/encode.h>
#include <mist/downloader.h>
namespace Controller{ namespace Controller{
@ -95,21 +96,11 @@ namespace Controller{
INFO_MSG("Running license updater %s", extra.c_str()); INFO_MSG("Running license updater %s", extra.c_str());
JSON::Value response; JSON::Value response;
HTTP::Parser http; HTTP::Downloader dl;
Socket::Connection updrConn("releases.mistserver.org", 80, true); HTTP::URL url("http://releases.mistserver.org/license.php");
if ( !updrConn){ url.args = "release="+Encodings::URL::encode(RELEASE)+"&version="+Encodings::URL::encode(PACKAGE_VERSION)+"&iid="+Encodings::URL::encode(instanceId)+"&lid="+currentLicense["lic_id"].asString() + extra;
WARN_MSG("Failed to reach licensing server");
return;
}
//Sending request to server.
//http.url = "/licensing.php"
//also see statics at start function.
http.url = "/license.php?release="+Encodings::URL::encode(RELEASE)+"&version="+Encodings::URL::encode(PACKAGE_VERSION)+"&iid="+Encodings::URL::encode(instanceId)+"&lid="+currentLicense["lic_id"].asString() + extra;
long long currID = currentLicense["lic_id"].asInt(); long long currID = currentLicense["lic_id"].asInt();
http.method = "GET";
http.SetHeader("Host", "releases.mistserver.org");
http.SetHeader("X-Version", PACKAGE_VERSION);
if (currID){ if (currID){
char aesKey[16]; char aesKey[16];
if (strlen(SUPER_SECRET) >= 32){ if (strlen(SUPER_SECRET) >= 32){
@ -122,35 +113,16 @@ namespace Controller{
} }
char ivec[16]; char ivec[16];
memset(ivec, 0, 16); memset(ivec, 0, 16);
http.SetHeader("X-IRDGAF", Encodings::Base64::encode(Encryption::AES_Crypt(RELEASE "|" PACKAGE_VERSION, sizeof(RELEASE "|" PACKAGE_VERSION), aesKey, ivec))); dl.setHeader("X-IRDGAF", Encodings::Base64::encode(Encryption::AES_Crypt(RELEASE "|" PACKAGE_VERSION, sizeof(RELEASE "|" PACKAGE_VERSION), aesKey, ivec)));
} }
updrConn.SendNow(http.BuildRequest()); if (!dl.get(url) || !dl.isOk()){
http.Clean(); return;
unsigned int startTime = Util::epoch();
while ((Util::epoch() - startTime < 10) && (updrConn || updrConn.Received().size())){
if (updrConn.spool() || updrConn.Received().size()){
if ( *(updrConn.Received().get().rbegin()) != '\n'){
std::string tmp = updrConn.Received().get();
updrConn.Received().get().clear();
if (updrConn.Received().size()){
updrConn.Received().get().insert(0, tmp);
}else{
updrConn.Received().append(tmp);
}
continue;
}
if (http.Read(updrConn.Received().get())){
response = JSON::fromString(http.body);
everContactedServer = true;
break; //break out of while loop
}
}
} }
updrConn.close(); response = JSON::fromString(dl.data());
everContactedServer = true;
//read license //read license
readLicense(response["lic_id"].asInt(), response["license"].asStringRef(), true); readLicense(response["lic_id"].asInt(), response["license"].asStringRef(), true);
} }
void readLicense(uint64_t licID, const std::string & input, bool fromServer){ void readLicense(uint64_t licID, const std::string & input, bool fromServer){