/* This file is part of FediBlock-backend. * Copyright © 2020, 2021 tastytea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ #include "cgi.hpp" #include "config.hpp" #include "files.hpp" #include "fs-compat.hpp" #include "git.hpp" #include "gitea.hpp" #include "json.hpp" #include "types.hpp" #include #include #include #include using std::cerr; using std::cout; using std::exception; using std::getenv; using namespace FediBlock; int main() { cout << "Content-Type: text/plain; charset=utf-8\r\n\r\n"; char *env{getenv("REQUEST_METHOD")}; if (env != nullptr && string(env) != "POST") { return 0; } git::init(true); gitea::init(); try { const entry_type entry{cgi::parse_formdata()}; if (entry.instance.empty() || entry.tags.empty() || entry.receipts.empty() || entry.description.empty()) { // Probably spam, since the input fields are marked as required. cout << "One of the required fields (Instance, Tags, Receipts, " "Description) was not filled.\r\n" << "Please use the back button, complete the form and submit " "again.\r\n"; return 1; } git::update_cached_repo(); git::create_branch(); git::commit(entry); git::push(); gitea::pull_request(git::get_branch_name(), entry); cout << "Created pull request: .\r\n"; cout << "Your entry needs to be approved before it appears on the " "website. You can subscribe to notifications or add comments " "at the URL above.\r\n"; files::remove_tmpdir(); } catch (const SpamException &e) { cerr << e.what() << '\n'; cout << e.what() << "\r\n"; } catch (const exception &e) { cerr << e.what() << '\n'; cout << "An error happened: " << e.what() << "\r\n"; cout << "Please report it at .\r\n"; } gitea::cleanup(); git::cleanup(true); return 0; }