Skip to content

Commit

Permalink
Add hosting yapic.ru, imageup.ru
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed Nov 28, 2024
1 parent c4c9f5b commit 271a334
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 19 deletions.
Binary file added Data/Favicons/imageup.ru.ico
Binary file not shown.
Binary file added Data/Favicons/yapic.ru.ico
Binary file not shown.
109 changes: 109 additions & 0 deletions Data/Scripts/imageup.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const BASE_HOST = "https://imageup.ru";

function Authenticate() {
local login = ServerParams.getParam("Login");
local password = ServerParams.getParam("Password");

if(login == "" ) {
WriteLog("error", "Login should not be empty!");
return 0;
}

nm.addQueryParam("login",login);
nm.addQueryParam("password", password);
nm.addQueryParam("username", login);
nm.addQueryParam("autologin", "on");
nm.setUrl(BASE_HOST + "/login.html");
nm.doPost("");

if (nm.responseCode() == 200) {
if (nm.responseBody().find("Добро пожаловать на сайт") != null) {
return 1;
}
}
WriteLog("error", "[imageup.ru] authentication failed.");

return 0;
}

function UploadFile(fileName, options) {
nm.doGet(BASE_HOST + "/");
local doc = Document(nm.responseBody());
local maxFileSize = doc.find("input[name=MAX_FILE_SIZE]").attr("value");
local fileFieldName = doc.find("input[type=file]").attr("name");
if (fileFieldName == "") {
fileFieldName = "file2022";
}
local timestamp = 0, token = "";
local captchaAnswer = "";
local reg = CRegExp("token'\\s*:\\s*'(.+?)'", "mi");
if (reg.match(nm.responseBody()) ) {
token = reg.getMatch(1);
}
local reg2 = CRegExp("timestamp'\\s*:\\s*'(.+?)'", "mi");
if ( reg2.match(nm.responseBody()) ) {
timestamp = reg2.getMatch(1);
}

local captchaUrl = doc.find("#captcha").attr("src");
if (captchaUrl != "") {
if (captchaUrl.find("https://") == null) {
captchaUrl = BASE_HOST + captchaUrl;
}
captchaAnswer = AskUserCaptcha(nm, captchaUrl);
if (captchaAnswer == "") {
return -1;
}
}

nm.setUrl(BASE_HOST + "/");
nm.addQueryParam("MAX_FILE_SIZE", maxFileSize);
nm.addQueryParamFile(fileFieldName, fileName, ExtractFileName(fileName), GetFileMimeType(fileName));
if (captchaAnswer != "") {
nm.addQueryParam("captchatext", captchaAnswer);
}

nm.addQueryParam("makepreview", "on");
nm.addQueryParam("previewsize", "300");
nm.addQueryParam("textonpreview", "on");
nm.addQueryParam("textonpreview_opt", "1");
nm.addQueryParam("textonpreview_inp", "");
nm.addQueryParam("radiobox", "1");
nm.addQueryParam("usertext", "");
nm.addQueryParam("resize", "500");
nm.addQueryParam("rotate", "0");

nm.doUploadMultipartData();

if (nm.responseCode() == 200) {
local doc2 = Document(nm.responseBody());
local viewUrl = doc2.find("#id8").attr("value");
local directUrl = doc2.find("#id7").attr("value");
local deleteUrl = doc2.find("#id_delete").attr("value");
local previewBbCode = doc2.find("#id3").attr("value");
local reg = CRegExp("\\[img\\](.+?)\\[/img\\]", "im");
local thumbUrl = "";

if (viewUrl != "" && viewUrl.find("https://") != 0) {
viewUrl = "https://" + viewUrl;
}

options.setDirectUrl(directUrl);
options.setViewUrl(viewUrl);
options.setDeleteUrl(deleteUrl);

if (reg.match(previewBbCode) ) {
options.setThumbUrl(reg.getMatch(1));
}

if (directUrl != "" || viewUrl != ""){
return 1;
} else {
WriteLog("error", "[imageup.ru] Failed to obtain image link");
}
} else {
WriteLog("error", "[imageup.ru] Failed to upload, response code = " + nm.responseCode());
}

return 0;
}
38 changes: 38 additions & 0 deletions Data/Scripts/yapic.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const BASE_HOST = "https://yapic.ru";

function UploadFile(fileName, options) {
nm.doGet(BASE_HOST + "/");
if (nm.responseCode() != 200) {
WriteLog("error", "[yapic.ru] Cannot obtain token!");
return 0;
}
local timestamp = 0, token = "";
local reg = CRegExp("token'\\s*:\\s*'(.+?)'", "mi");
if (reg.match(nm.responseBody()) ) {
token = reg.getMatch(1);
}
local reg2 = CRegExp("timestamp'\\s*:\\s*'(.+?)'", "mi");
if ( reg2.match(nm.responseBody()) ) {
timestamp = reg2.getMatch(1);
}
nm.setUrl(BASE_HOST + "/includes/upload.php");
nm.addQueryParamFile("Filedata", fileName, ExtractFileName(fileName), GetFileMimeType(fileName));
nm.addQueryParam("timestamp", timestamp);
nm.addQueryParam("token", token);
nm.doUploadMultipartData();

if (nm.responseCode() == 200) {
local t = ParseJSON(nm.responseBody());
if ("success" in t && t.success) {
options.setDirectUrl(t.preview);
options.setViewUrl(t.url);
if (t.url != ""){
return 1;
}
}
} else {
WriteLog("error", "[yapic.ru] Failed to upload, response code = " + nm.responseCode());
}

return 0;
}
11 changes: 11 additions & 0 deletions Data/servers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@
</Actions>
<Result ImageUrlTemplate="stub" ThumbUrlTemplate="stub"/>
</Server>
<Server Name="yapic.ru" Plugin="yapic" WebsiteUrl="https://yapic.ru">
<Actions>
</Actions>
<Result ImageUrlTemplate="stub" DownloadUrlTemplate="stub"/>
</Server>
<Server Name="imageup.ru" Authorize="2" Plugin="imageup" WebsiteUrl="https://imageup.ru" RegistrationUrl="https://imageup.ru/registration.html">
<Actions>
</Actions>
<Result ImageUrlTemplate="stub" DownloadUrlTemplate="stub" ThumbUrlTemplate="stub"/>
</Server>
<Server Name="sendspace.com" FileHost="1" Debug="0" Authorize="1" Plugin="sendspace" SupportsFolders="1" MaxFileSize="300000000" DefaultForTypes="file"
WebsiteUrl="https://www.sendspace.com" RegistrationUrl="https://www.sendspace.com/register.html">
<Result DownloadUrlTemplate="stub" ImageUrlTemplate="stub" ThumbUrlTemplate="stub"/>
Expand All @@ -110,6 +120,7 @@
</Actions>
<Result ImageUrlTemplate="stub"/>
</Server>
<!-- Blocked ?-->
<Server Name="imagevenue.com" Authorize="1" Plugin="imagevenue" WebsiteUrl="https://www.imagevenue.com" RegistrationUrl="https://www.imagevenue.com/auth/register">
<Actions>
</Actions>
Expand Down
2 changes: 1 addition & 1 deletion Source/CLI/ConsoleScriptDialogProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "Core/Utils/ConsoleUtils.h"
#include "Core/Utils/StringUtils.h"

std::string ConsoleScriptDialogProvider::askUserCaptcha(NetworkClient* nm, const std::string& url) {
std::string ConsoleScriptDialogProvider::askUserCaptcha(INetworkClient* nm, const std::string& url) {
std::lock_guard<std::mutex> guard(ConsoleUtils::instance()->getOutputMutex());
DesktopUtils::ShellOpenUrl(url);
std::cerr << "Enter text from the image:" << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion Source/CLI/ConsoleScriptDialogProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class ConsoleScriptDialogProvider : public IDialogProvider {
public:
std::string askUserCaptcha(NetworkClient *nm, const std::string& url) override;
std::string askUserCaptcha(INetworkClient *nm, const std::string& url) override;
std::string inputDialog(const std::string& text, const std::string& defaultValue) override;
std::string messageBox(const std::string& message, const std::string& title, const std::string& buttons, const std::string& type) override;
};
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Scripting/API/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ std::string Translate(const std::string& key, const std::string& originalText) {
return originalText;
}

std::string AskUserCaptcha(NetworkClient* nm, const std::string& url)
std::string AskUserCaptcha(INetworkClient* nm, const std::string& url)
{
return ServiceLocator::instance()->dialogProvider()->askUserCaptcha(nm, url);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Scripting/API/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>
#include "../Squirrelnc.h"

class NetworkClient;
class INetworkClient;

#undef random

Expand Down Expand Up @@ -130,7 +130,7 @@ namespace ScriptAPI {
* url - address of the image with captcha.
* The return value is the text entered by the user.
*/
std::string AskUserCaptcha(NetworkClient* nm, const std::string& url);
std::string AskUserCaptcha(INetworkClient* nm, const std::string& url);

/**
* Converts a string from ANSI encoding to UTF-8.
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Scripting/DialogProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <string>
#include <mutex>

class NetworkClient;
class INetworkClient;

class IDialogProvider {
public:
virtual ~IDialogProvider() = default;
virtual std::string askUserCaptcha(NetworkClient *nm, const std::string& url) = 0;
virtual std::string askUserCaptcha(INetworkClient *nm, const std::string& url) = 0;
virtual std::string inputDialog(const std::string& text, const std::string& defaultValue) = 0;
virtual std::string messageBox(const std::string& message, const std::string& title, const std::string& buttons, const std::string& type) = 0;

Expand Down
4 changes: 2 additions & 2 deletions Source/Func/WtlScriptDialogProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
#include "Core/Network/NetworkClient.h"
#include "Core/AppParams.h"

std::string WtlScriptDialogProvider::askUserCaptcha(NetworkClient* nm, const std::string& url) {
std::string WtlScriptDialogProvider::askUserCaptcha(INetworkClient* nm, const std::string& url) {
std::lock_guard<std::mutex> guard(dialogMutex_);
const CString wFileName = WinUtils::GetUniqFileName(AppParams::instance()->tempDirectoryW() + Utf8ToWstring("captcha").c_str());

nm->setOutputFile(W2U(wFileName));
if (!nm->doGet(url))
return {};
CInputDialog dlg(_T("Image Uploader"), TR("Please enter the text you see in the image:"), CString(IuCoreUtils::Utf8ToWstring("").c_str()), wFileName);
CInputDialog dlg(_T("Image Uploader"), TR("Please enter the text you see in the image:"), {}, wFileName);
nm->setOutputFile({});
IProgramWindow* window = ServiceLocator::instance()->programWindow();
if (dlg.DoModal(window ? window->getHandle() : GetActiveWindow()) == IDOK)
Expand Down
2 changes: 1 addition & 1 deletion Source/Func/WtlScriptDialogProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class WtlScriptDialogProvider : public IDialogProvider {
public:
std::string askUserCaptcha(NetworkClient *nm, const std::string& url) override;
std::string askUserCaptcha(INetworkClient *nm, const std::string& url) override;
std::string inputDialog(const std::string& text, const std::string& defaultValue) override;
std::string messageBox(const std::string& message, const std::string& title, const std::string& buttons, const std::string& type) override;

Expand Down
19 changes: 12 additions & 7 deletions Source/Image Uploader.rc
Original file line number Diff line number Diff line change
Expand Up @@ -830,16 +830,16 @@ BEGIN
PUSHBUTTON "Cancel",IDCANCEL,205,155,50,14
END

IDD_INPUTDIALOG DIALOGEX 0, 0, 263, 98
IDD_INPUTDIALOG DIALOGEX 0, 0, 263, 128
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "title"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
LTEXT "Description",IDC_DESCRIPTIONLABEL,6,7,251,43
EDITTEXT IDC_VALUEEDIT,6,57,251,13,ES_AUTOHSCROLL
PUSHBUTTON "OK",IDOK,148,79,50,14
PUSHBUTTON "Cancel",IDCANCEL,207,79,50,14
LTEXT "",IDC_IMAGE,6,16,251,8
LTEXT "Description",IDC_DESCRIPTIONLABEL,6,7,251,24
EDITTEXT IDC_VALUEEDIT,6,89,251,13,ES_AUTOHSCROLL
PUSHBUTTON "OK",IDOK,148,109,50,14
PUSHBUTTON "Cancel",IDCANCEL,207,109,50,14
LTEXT "",IDC_IMAGE,6,39,251,42
END

IDD_IMAGEREUPLOADER DIALOGEX 0, 0, 367, 387
Expand Down Expand Up @@ -1459,7 +1459,7 @@ BEGIN
LEFTMARGIN, 6
RIGHTMARGIN, 257
TOPMARGIN, 7
BOTTOMMARGIN, 93
BOTTOMMARGIN, 123
END

IDD_IMAGEREUPLOADER, DIALOG
Expand Down Expand Up @@ -1861,6 +1861,11 @@ BEGIN
0
END

IDD_INPUTDIALOG AFX_DIALOG_LAYOUT
BEGIN
0
END

#endif // Russian (Russia) resources
/////////////////////////////////////////////////////////////////////////////

Expand Down
2 changes: 1 addition & 1 deletion Source/qimageuploader/QtScriptDialogProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ QtScriptDialogProvider::QtScriptDialogProvider() {
dialogResult_ = 0;
}

std::string QtScriptDialogProvider::askUserCaptcha(NetworkClient* nm, const std::string& url) {
std::string QtScriptDialogProvider::askUserCaptcha(INetworkClient* nm, const std::string& url) {
std::lock_guard<std::mutex> lk(mutex_);
// TODO: Implement this
DesktopUtils::ShellOpenUrl(url);
Expand Down
2 changes: 1 addition & 1 deletion Source/qimageuploader/QtScriptDialogProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class QtScriptDialogProvider : public QObject, public IDialogProvider {
Q_OBJECT
public:
QtScriptDialogProvider();
std::string askUserCaptcha(NetworkClient *nm, const std::string& url) override;
std::string askUserCaptcha(INetworkClient *nm, const std::string& url) override;
std::string inputDialog(const std::string& text, const std::string& defaultValue) override;
std::string messageBox(const std::string& message, const std::string& title, const std::string& buttons, const std::string& type) override;
protected:
Expand Down

0 comments on commit 271a334

Please sign in to comment.