Remove python validation from campaignd
This commit is contained in:
parent
67f96c7874
commit
6f33c69e6a
1 changed files with 0 additions and 102 deletions
|
@ -206,67 +206,6 @@ namespace {
|
|||
}
|
||||
}
|
||||
|
||||
// Given an uploaded campaign, rename all .py files to .py.unchecked, unless
|
||||
// the contents are the same as a .py file in an existing campaign.
|
||||
// This means, a .py.unchecked file can be approved by simply renaming it
|
||||
// on the CS, and it will remain approved as long as it is not changed (but
|
||||
// it can be moved/renamed). If the .py file changes, it needs to be approved
|
||||
// again.
|
||||
std::string check_python_scripts(config &data, std::string filename)
|
||||
{
|
||||
std::vector<config *> python_scripts;
|
||||
find_scripts(data, ".py", python_scripts);
|
||||
if (python_scripts.empty()) return std::string();
|
||||
// Campaign contains python scripts.
|
||||
config old_campaign;
|
||||
scoped_istream stream = istream_file(filename);
|
||||
read_gz(old_campaign, *stream);
|
||||
std::vector<config *> old_scripts;
|
||||
find_scripts(old_campaign, ".py", old_scripts);
|
||||
std::string script_names;
|
||||
// Go through all newly uploaded python scripts.
|
||||
foreach (config *i, python_scripts)
|
||||
{
|
||||
bool already = false;
|
||||
// Compare to existing, approved scripts.
|
||||
foreach (const config *j, old_scripts)
|
||||
{
|
||||
if ((*i)["contents"] != (*j)["contents"]) continue;
|
||||
already = true;
|
||||
break;
|
||||
}
|
||||
if (!already) {
|
||||
std::string name = (*i)["name"];
|
||||
script_names += "\n" + name;
|
||||
(*i)["name"] = name + ".unchecked";
|
||||
}
|
||||
}
|
||||
if (!script_names.empty())
|
||||
return "\nScripts awaiting approval:\n" + script_names;
|
||||
return std::string();
|
||||
}
|
||||
|
||||
// Go through all .py.unchecked files in the given campaign, and rename them to
|
||||
// .py. This is the opposite to check_python_scripts(), and while the latter is
|
||||
// done on campaign upload, this function is called for the validate_scripts
|
||||
// command.
|
||||
std::string validate_all_python_scripts(config &data)
|
||||
{
|
||||
std::vector<config *> python_scripts;
|
||||
find_scripts(data, ".py.unchecked", python_scripts);
|
||||
if (python_scripts.empty()) return std::string();
|
||||
// Campaign contains unchecked python scripts.
|
||||
std::string script_names;
|
||||
foreach (config *i, python_scripts)
|
||||
{
|
||||
std::string name = (*i)["name"];
|
||||
name.resize(name.length() - 10);
|
||||
(*i)["name"] = name;
|
||||
script_names += "\n" + name;
|
||||
}
|
||||
return script_names;
|
||||
}
|
||||
|
||||
// Add a file COPYING.txt with the GPL to an uploaded campaign.
|
||||
void add_license(config &data)
|
||||
{
|
||||
|
@ -607,11 +546,6 @@ namespace {
|
|||
(*campaign).clear_children("translation");
|
||||
find_translations(data, *campaign);
|
||||
|
||||
// Campaigns which have python="allowed" are not checked
|
||||
if ((*campaign)["python"] != "allowed") {
|
||||
message += check_python_scripts(data, filename);
|
||||
}
|
||||
|
||||
add_license(data);
|
||||
|
||||
{
|
||||
|
@ -682,42 +616,6 @@ namespace {
|
|||
network::send_data(construct_message("Passphrase changed."), sock);
|
||||
}
|
||||
}
|
||||
else if (const config &cvalidate = data.child("validate_scripts"))
|
||||
{
|
||||
config &campaign = campaigns().find_child("campaign", "name", cvalidate["name"]);
|
||||
if (!campaign) {
|
||||
network::send_data(construct_error(
|
||||
"No add-on with that name exists."), sock);
|
||||
} else if (campaigns()["master_password"].empty()) {
|
||||
network::send_data(construct_error(
|
||||
"Sever does not allow scripts."), sock);
|
||||
} else if (campaigns()["master_password"] != cvalidate["master_password"]) {
|
||||
network::send_data(construct_error(
|
||||
"Password was incorrect."), sock);
|
||||
} else {
|
||||
// Read the campaign from disk.
|
||||
config campaign_file;
|
||||
scoped_istream stream = istream_file(campaign["filename"]);
|
||||
read_gz(campaign_file, *stream);
|
||||
std::string scripts = validate_all_python_scripts(campaign_file);
|
||||
if (!scripts.empty()) {
|
||||
// Write the campaign with changed filenames back to disk
|
||||
{
|
||||
scoped_ostream ostream = ostream_file(campaign["filename"]);
|
||||
config_writer writer(*ostream, true, compress_level_);
|
||||
writer.write(campaign_file);
|
||||
}
|
||||
// write_compressed(*ostream, campaign_file);
|
||||
campaign["size"] = lexical_cast<std::string>(
|
||||
file_size(campaign["filename"]));
|
||||
|
||||
network::send_data(construct_message("The following scripts have been validated: " +
|
||||
scripts), sock);
|
||||
} else {
|
||||
network::send_data(construct_message("No unchecked scripts found!"), sock);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(network::error& e) {
|
||||
if(!e.socket) {
|
||||
|
|
Loading…
Add table
Reference in a new issue