implement Episode 3 meseta
This commit is contained in:
+65
-55
@@ -134,7 +134,7 @@ Server commands:\n\
|
||||
gc-password=<password> (GC password)\n\
|
||||
access-key=<access-key> (DC/GC/PC access key)\n\
|
||||
serial=<serial-number> (decimal serial number; required for all licenses)\n\
|
||||
privileges=<privilege-mask> (can be normal, mod, admin, root, or numeric)\n\
|
||||
flags=<privilege-mask> (can be normal, mod, admin, root, or numeric)\n\
|
||||
update-license SERIAL-NUMBER PARAMETERS...\n\
|
||||
Update an existing license. <serial-number> specifies which license to\n\
|
||||
update. The options in <parameters> are the same as for the add-license\n\
|
||||
@@ -310,7 +310,7 @@ Proxy session commands:\n\
|
||||
if (token.size() >= 32) {
|
||||
throw invalid_argument("username too long");
|
||||
}
|
||||
l->username = token.substr(12);
|
||||
l->bb_username = token.substr(12);
|
||||
|
||||
} else if (starts_with(token, "bb-password=")) {
|
||||
if (token.size() >= 32) {
|
||||
@@ -333,18 +333,18 @@ Proxy session commands:\n\
|
||||
} else if (starts_with(token, "serial=")) {
|
||||
l->serial_number = stoul(token.substr(7));
|
||||
|
||||
} else if (starts_with(token, "privileges=")) {
|
||||
} else if (starts_with(token, "flags=")) {
|
||||
string mask = token.substr(11);
|
||||
if (mask == "normal") {
|
||||
l->privileges = 0;
|
||||
l->flags = 0;
|
||||
} else if (mask == "mod") {
|
||||
l->privileges = Privilege::MODERATOR;
|
||||
l->flags = License::Flag::MODERATOR;
|
||||
} else if (mask == "admin") {
|
||||
l->privileges = Privilege::ADMINISTRATOR;
|
||||
l->flags = License::Flag::ADMINISTRATOR;
|
||||
} else if (mask == "root") {
|
||||
l->privileges = Privilege::ROOT;
|
||||
l->flags = License::Flag::ROOT;
|
||||
} else {
|
||||
l->privileges = stoul(mask);
|
||||
l->flags = stoul(mask);
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -356,7 +356,8 @@ Proxy session commands:\n\
|
||||
throw invalid_argument("license does not contain serial number");
|
||||
}
|
||||
|
||||
this->state->license_manager->add(l);
|
||||
l->save();
|
||||
this->state->license_index->add(l);
|
||||
fprintf(stderr, "license added\n");
|
||||
|
||||
} else if (command_name == "update-license") {
|
||||
@@ -366,71 +367,80 @@ Proxy session commands:\n\
|
||||
}
|
||||
uint32_t serial_number = stoul(tokens[0]);
|
||||
tokens.erase(tokens.begin());
|
||||
auto orig_l = this->state->license_manager->get(serial_number);
|
||||
auto orig_l = this->state->license_index->get(serial_number);
|
||||
shared_ptr<License> l(new License(*orig_l));
|
||||
|
||||
for (const string& token : tokens) {
|
||||
if (starts_with(token, "bb-username=")) {
|
||||
if (token.size() >= 32) {
|
||||
throw invalid_argument("username too long");
|
||||
}
|
||||
l->username = token.substr(12);
|
||||
this->state->license_index->remove(orig_l->serial_number);
|
||||
try {
|
||||
for (const string& token : tokens) {
|
||||
if (starts_with(token, "bb-username=")) {
|
||||
if (token.size() >= 32) {
|
||||
throw invalid_argument("username too long");
|
||||
}
|
||||
l->bb_username = token.substr(12);
|
||||
|
||||
} else if (starts_with(token, "bb-password=")) {
|
||||
if (token.size() >= 32) {
|
||||
throw invalid_argument("bb-password too long");
|
||||
}
|
||||
l->bb_password = token.substr(12);
|
||||
} else if (starts_with(token, "bb-password=")) {
|
||||
if (token.size() >= 32) {
|
||||
throw invalid_argument("bb-password too long");
|
||||
}
|
||||
l->bb_password = token.substr(12);
|
||||
|
||||
} else if (starts_with(token, "gc-password=")) {
|
||||
if (token.size() > 20) {
|
||||
throw invalid_argument("gc-password too long");
|
||||
}
|
||||
l->gc_password = token.substr(12);
|
||||
} else if (starts_with(token, "gc-password=")) {
|
||||
if (token.size() > 20) {
|
||||
throw invalid_argument("gc-password too long");
|
||||
}
|
||||
l->gc_password = token.substr(12);
|
||||
|
||||
} else if (starts_with(token, "access-key=")) {
|
||||
if (token.size() > 23) {
|
||||
throw invalid_argument("access-key is too long");
|
||||
}
|
||||
l->access_key = token.substr(11);
|
||||
} else if (starts_with(token, "access-key=")) {
|
||||
if (token.size() > 23) {
|
||||
throw invalid_argument("access-key is too long");
|
||||
}
|
||||
l->access_key = token.substr(11);
|
||||
|
||||
} else if (starts_with(token, "serial=")) {
|
||||
l->serial_number = stoul(token.substr(7));
|
||||
} else if (starts_with(token, "serial=")) {
|
||||
l->serial_number = stoul(token.substr(7));
|
||||
|
||||
} else if (starts_with(token, "flags=")) {
|
||||
string mask = token.substr(11);
|
||||
if (mask == "normal") {
|
||||
l->flags = 0;
|
||||
} else if (mask == "mod") {
|
||||
l->flags = License::Flag::MODERATOR;
|
||||
} else if (mask == "admin") {
|
||||
l->flags = License::Flag::ADMINISTRATOR;
|
||||
} else if (mask == "root") {
|
||||
l->flags = License::Flag::ROOT;
|
||||
} else {
|
||||
l->flags = stoul(mask);
|
||||
}
|
||||
|
||||
} else if (starts_with(token, "privileges=")) {
|
||||
string mask = token.substr(11);
|
||||
if (mask == "normal") {
|
||||
l->privileges = 0;
|
||||
} else if (mask == "mod") {
|
||||
l->privileges = Privilege::MODERATOR;
|
||||
} else if (mask == "admin") {
|
||||
l->privileges = Privilege::ADMINISTRATOR;
|
||||
} else if (mask == "root") {
|
||||
l->privileges = Privilege::ROOT;
|
||||
} else {
|
||||
l->privileges = stoul(mask);
|
||||
throw invalid_argument("incorrect field: " + token);
|
||||
}
|
||||
|
||||
} else {
|
||||
throw invalid_argument("incorrect field: " + token);
|
||||
}
|
||||
|
||||
if (!l->serial_number) {
|
||||
throw invalid_argument("license does not contain serial number");
|
||||
}
|
||||
} catch (const exception&) {
|
||||
this->state->license_index->add(orig_l);
|
||||
throw;
|
||||
}
|
||||
|
||||
if (!l->serial_number) {
|
||||
throw invalid_argument("license does not contain serial number");
|
||||
}
|
||||
|
||||
this->state->license_manager->add(l);
|
||||
l->save();
|
||||
this->state->license_index->add(l);
|
||||
fprintf(stderr, "license updated\n");
|
||||
|
||||
} else if (command_name == "delete-license") {
|
||||
uint32_t serial_number = stoul(command_args);
|
||||
this->state->license_manager->remove(serial_number);
|
||||
auto l = this->state->license_index->get(serial_number);
|
||||
l->delete_file();
|
||||
this->state->license_index->remove(l->serial_number);
|
||||
fprintf(stderr, "license deleted\n");
|
||||
|
||||
} else if (command_name == "list-licenses") {
|
||||
for (const auto& l : this->state->license_manager->snapshot()) {
|
||||
string s = l.str();
|
||||
for (const auto& l : this->state->license_index->all()) {
|
||||
string s = l->str();
|
||||
fprintf(stderr, "%s\n", s.c_str());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user