From 6c7adadf6d5c85d5e280e965d4dee1563bf46821 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 1 Dec 2019 18:05:16 +0100 Subject: Add 4chan posting --- src/plugins/Fourchan.cpp | 326 +++++------------------------------------------ src/plugins/Plugin.cpp | 59 --------- 2 files changed, 30 insertions(+), 355 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp index 4df77c4..cd3f7e7 100644 --- a/src/plugins/Fourchan.cpp +++ b/src/plugins/Fourchan.cpp @@ -10,302 +10,6 @@ static const std::string fourchan_url = "https://a.4cdn.org/"; static const std::string fourchan_image_url = "https://i.4cdn.org/"; -// Legacy recaptcha command: curl 'https://www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc' -H 'Referer: https://boards.4channel.org/' -H 'Cookie: CONSENT=YES' - -/* -Answering recaptcha: -curl 'https://www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc' --H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0' --H 'Referer: https://www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc' --H 'Content-Type: application/x-www-form-urlencoded' ---data 'c=03AOLTBLQ66PjSi9s8S-R1vUS2Jgm-Z_ghEejvvjAaeF3FoR9MiM0zHhCxuertrCo7MAcFUEqcIg4l2WJzVtrJhJVLkncF12OzCaeIvbm46hgDZDZjLD89-LMn1Zs0TP37P-Hd4cuRG8nHuEBXc2ZBD8CVX-6HAs9VBgSmsgQeKF1PWm1tAMBccJhlh4rAOkpjzaEXMMGOe17N0XViwDYZxLGhe4H8IAG2KNB1fb4rz4YKJTPbL30_FvHw7zkdFtojjWiqVW0yCN6N192dhfd9oKz2r9pGRrR6N4AkkX-L0DsBD4yNK3QRsQn3dB1fs3JRZPAh1yqUqTQYhOaqdggyc1EwL8FZHouGRkHTOcCmLQjyv6zuhi6CJbg&response=1&response=4&response=5&response=7' -*/ -/* -Response: - - - - - - reCAPTCHA challenge - - - -
-
-
- -
-
-
Copy this code and paste it in the empty box below
-
- -
This code is valid for 2 minutes
-
-
- -
- - - -*/ - -/* Posting message: -curl 'https://sys.4chan.org/bant/post' --H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0' --H 'Referer: https://boards.4chan.org/' --H 'Content-Type: multipart/form-data; boundary=---------------------------119561554312148213571335532670' --H 'Origin: https://boards.4chan.org' --H 'Cookie: __cfduid=d4bd4932e46bc3272fae4ce7a4e2aac511546800687; 4chan_pass=_SsBuZaATt3dIqfVEWlpemhU5XLQ6i9RC' ---data-binary $'-----------------------------119561554312148213571335532670\r\nContent-Disposition: form-data; name="resto"\r\n\r\n8640736\r\n-----------------------------119561554312148213571335532670\r\nContent-Disposition: form-data; name="com"\r\n\r\n>>8640771\r\nShe looks finnish\r\n-----------------------------119561554312148213571335532670\r\nContent-Disposition: form-data; name="mode"\r\n\r\nregist\r\n-----------------------------119561554312148213571335532670\r\nContent-Disposition: form-data; name="pwd"\r\n\r\n_SsBuZaATt3dIqfVEWlpemhU5XLQ6i9RC\r\n-----------------------------119561554312148213571335532670\r\nContent-Disposition: form-data; name="g-recaptcha-response"\r\n\r\n03AOLTBLS5lshp5aPj5pG6xdVMQ0pHuHxAtJoCEYuPLNKYlsRWNCPQegjB9zgL-vwdGMzjcT-L9iW4bnQ5W3TqUWHOVqtsfnx9GipLUL9o2XbC6r9zy-EEiPde7l6J0WcZbr9nh_MGcUpKl6RGaZoYB3WwXaDq74N5hkmEAbqM_CBtbAVVlQyPmemI2HhO2J6K0yFVKBrBingtIZ6-oXBXZ4jC4rT0PeOuVaH_gf_EBjTpb55ueaPmTbeLGkBxD4-wL1qA8F8h0D8c\r\n-----------------------------119561554312148213571335532670--\r\n' -*/ -/* Response if banned: - - - - - - - - - - - - - - -/g/ - Technology - 4chan - - - - - - -
- -[a / -b / -c / -d / -e / -f / -g / -gif / -h / -hr / -k / -m / -o / -p / -r / -s / -t / -u / -v / -vg / -vr / -w - / wg] - -[i / -ic] - -[r9k / -s4s / -vip / -qa] - -[cm / -hm / -lgbt - / y] - -[3 / -aco / -adv / -an / -asp / -bant / -biz / -cgl / -ck / -co / -diy / -fa / -fit / -gd / -hc / -his / -int / -jp / -lit / -mlp / -mu / -n / -news / -out / -po / -pol / -qst / -sci / -soc / -sp / -tg / -toy / -trv / -tv / -vp / -wsg / -wsr / -x] - - - -[Settings] -[Search] -[Mobile] -[Home] -
- -
-
- Board - -
- -
- - Settings - Mobile - Home -
- -
- - -
-
-
/g/ - Technology
- -
-
Error: You are banned.

[Return]



- - - - -All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster. - - -
- -
- -*/ -/* Banned page: - - - - - -4chan - Banned - - - - - - - - - - - -
-
-
-4chan -
-
-
-
-
-

You are banned! ;_;

-
-
-Banned - -You have been banned from /g/ for posting >>73505519, a violation of Rule 1:

-Off-topic; all images and discussion should pertain to technology and related topics.

-Your ban was filed on November 9th, 2019 and expires on November 10th, 2019 at 22:10 ET, which is 23 hours and 14 minutes from now. -

-According to our server, your IP is: YOURIP. The name you were posting with was Anonymous.
-
-Because of the short length of your ban, you may not appeal it. Please check back when your ban has expired. -
-
-
-
-
-
-
-
-
-
-
-
- -
- - - - - -*/ - namespace QuickMedia { PluginResult Fourchan::get_front_page(BodyItems &result_items) { std::string server_response; @@ -658,4 +362,34 @@ namespace QuickMedia { return PluginResult::OK; } + + PostResult Fourchan::post_comment(const std::string &board, const std::string &thread, const std::string &captcha_id, const std::string &comment) { + std::string url = "https://sys.4chan.org/" + board + "/post"; + std::vector form_data = { + FormData{"resto", thread}, + FormData{"com", comment}, + FormData{"mode", "regist"}, + FormData{"g-recaptcha-response", captcha_id} + }; + + std::vector additional_args = { + CommandArg{"-H", "Referer: https://boards.4chan.org/"}, + CommandArg{"-H", "Content-Type: multipart/form-data; boundary=---------------------------119561554312148213571335532670"}, + CommandArg{"-H", "Origin: https://boards.4chan.org"} + }; + std::vector form_data_args = create_command_args_from_form_data(form_data); + additional_args.insert(additional_args.end(), form_data_args.begin(), form_data_args.end()); + + std::string response; + if(download_to_string(url, response, additional_args, use_tor) != DownloadResult::OK) + return PostResult::ERR; + + if(response.find("successful") != std::string::npos) + return PostResult::OK; + if(response.find("banned") != std::string::npos) + return PostResult::BANNED; + if(response.find("try again") != std::string::npos || response.find("No valid captcha") != std::string::npos) + return PostResult::TRY_AGAIN; + return PostResult::ERR; + } } \ No newline at end of file diff --git a/src/plugins/Plugin.cpp b/src/plugins/Plugin.cpp index 7c31292..a9adf15 100644 --- a/src/plugins/Plugin.cpp +++ b/src/plugins/Plugin.cpp @@ -1,15 +1,8 @@ #include "../../plugins/Plugin.hpp" -#include "../../include/Program.h" #include #include #include -static int accumulate_string(char *data, int size, void *userdata) { - std::string *str = (std::string*)userdata; - str->append(data, size); - return 0; -} - namespace QuickMedia { SearchResult Plugin::search(const std::string &text, BodyItems &result_items) { (void)text; @@ -28,44 +21,11 @@ namespace QuickMedia { return {}; } - static bool is_whitespace(char c) { - return c == ' ' || c == '\n' || c == '\t' || c == '\v'; - } - - std::string strip(const std::string &str) { - if(str.empty()) - return str; - - int start = 0; - for(; start < (int)str.size(); ++start) { - if(!is_whitespace(str[start])) - break; - } - - int end = str.size() - 1; - for(; end >= start; --end) { - if(!is_whitespace(str[end])) - break; - } - - return str.substr(start, end - start + 1); - } - struct HtmlEscapeSequence { std::string escape_sequence; std::string unescaped_str; }; - void string_replace_all(std::string &str, const std::string &old_str, const std::string &new_str) { - size_t index = 0; - while(true) { - index = str.find(old_str, index); - if(index == std::string::npos) - return; - str.replace(index, old_str.size(), new_str); - } - } - void html_unescape_sequences(std::string &str) { const std::array escape_sequences = { HtmlEscapeSequence { """, "\"" }, @@ -97,23 +57,4 @@ namespace QuickMedia { return result.str(); } - - DownloadResult Plugin::download_to_string(const std::string &url, std::string &result, const std::vector &additional_args) { - sf::Clock timer; - std::vector args; - if(use_tor) - args.push_back("torsocks"); - args.insert(args.end(), { "curl", "-f", "-H", "Accept-Language: en-US,en;q=0.5", "--compressed", "-s", "-L" }); - for(const CommandArg &arg : additional_args) { - args.push_back(arg.option.c_str()); - args.push_back(arg.value.c_str()); - } - args.push_back("--"); - args.push_back(url.c_str()); - args.push_back(nullptr); - if(exec_program(args.data(), accumulate_string, &result) != 0) - return DownloadResult::NET_ERR; - fprintf(stderr, "Download duration for %s: %d ms\n", url.c_str(), timer.getElapsedTime().asMilliseconds()); - return DownloadResult::OK; - } } \ No newline at end of file -- cgit v1.2.3