diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-06-07 10:27:56 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-06-07 10:27:56 +0000 |
commit | 9ba7e15c4f8248c90f10b4e52439976c624f27cf (patch) | |
tree | b7b2425832779467ac432fdf0fc379913ea9c4ad /protocols/SkypeWeb | |
parent | 5a76a28916e5a329a7056a228dbacbe458e60241 (diff) |
ooops
git-svn-id: http://svn.miranda-ng.org/main/trunk@14041 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/SkypeWeb')
-rw-r--r-- | protocols/SkypeWeb/src/requests/mslogin.h | 80 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_mslogin.cpp | 159 |
2 files changed, 239 insertions, 0 deletions
diff --git a/protocols/SkypeWeb/src/requests/mslogin.h b/protocols/SkypeWeb/src/requests/mslogin.h new file mode 100644 index 0000000000..196be7a548 --- /dev/null +++ b/protocols/SkypeWeb/src/requests/mslogin.h @@ -0,0 +1,80 @@ +/*
+Copyright (c) 2015 Miranda NG project (http://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _SKYPE_REQUEST_LOGINMS_H_
+#define _SKYPE_REQUEST_LOGINMS_H_
+
+class LoginMSRequest : public HttpRequest
+{
+public:
+ LoginMSRequest() :
+ HttpRequest(REQUEST_GET, "login.skype.com/login/oauth/microsoft")
+ {
+ flags |= NLHRF_REDIRECT;
+
+ Url
+ << INT_VALUE ("client_id", 578134)
+ << CHAR_VALUE ("redirect_uri", ptrA(mir_urlEncode("https://web.skype.com")));
+ }
+ LoginMSRequest(const char *login, const char *password, const char *cookies_str, const char *ppft) :
+ HttpRequest(REQUEST_POST, "login.live.com/ppsecure/post.srf")
+ {
+ Url
+ << CHAR_VALUE ("wa", "wsignin1.0")
+ << CHAR_VALUE ("wreply", "https%3A%2F%2Fsecure.skype.com%2Flogin%2Foauth%2Fproxy%3Fclient_id%3D578134%26redirect_uri%3Dhttps%253A%252F%252Fweb.skype.com");
+
+ Headers
+ << CHAR_VALUE ("Content-Type", "application/x-www-form-urlencoded")
+ << CHAR_VALUE ("Cookie", cookies_str);
+
+ Body
+ << CHAR_VALUE ("login", ptrA(mir_urlEncode(login)))
+ << CHAR_VALUE ("passwd", ptrA(mir_urlEncode(password)))
+ << CHAR_VALUE ("PPFT", ppft);
+ }
+ LoginMSRequest(const char *t) :
+ HttpRequest(REQUEST_POST, "login.skype.com/login/oauth/microsoft")
+ {
+ Url
+ << INT_VALUE ("client_id", 578134)
+ << CHAR_VALUE ("redirect_uri", ptrA(mir_urlEncode("https://web.skype.com")));
+
+ Headers
+ << CHAR_VALUE ("Content-Type", "application/x-www-form-urlencoded");
+
+ Body
+ << CHAR_VALUE ("t", t)
+ << INT_VALUE ("oauthPartner", 999)
+ << INT_VALUE ("client_id", 578134)
+ << CHAR_VALUE ("redirect_uri", ptrA(mir_urlEncode("https://web.skype.com")));
+ }
+
+ LoginMSRequest(const char *url,const char *login, const char *cookies_str, const char *ppft, const char *code) :
+ HttpRequest(REQUEST_POST, url)
+ {
+ Headers
+ << CHAR_VALUE ("Cookie", cookies_str);
+ Body
+ << CHAR_VALUE ("oct", code)
+ << INT_VALUE ("AdTD", 1)
+ << CHAR_VALUE ("login", ptrA(mir_urlEncode(login)))
+ << INT_VALUE ("type", 19)
+ << CHAR_VALUE ("PPFT", ptrA(mir_urlEncode(ppft)));
+ }
+};
+
+#endif //_SKYPE_REQUEST_LOGINMS_H_
diff --git a/protocols/SkypeWeb/src/skype_mslogin.cpp b/protocols/SkypeWeb/src/skype_mslogin.cpp new file mode 100644 index 0000000000..5c67b26fba --- /dev/null +++ b/protocols/SkypeWeb/src/skype_mslogin.cpp @@ -0,0 +1,159 @@ +/*
+Copyright (c) 2015 Miranda NG project (http://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+void CSkypeProto::OnMSLoginFirst(const NETLIBHTTPREQUEST *response)
+{
+ if (response == NULL || response->pData == NULL)
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ std::regex regex;
+ std::smatch match;
+ std::map<std::string, std::string> scookies;
+ std::string content = response->pData;
+
+ regex = "<input type=\"hidden\" name=\"PPFT\" id=\"i0327\" value=\"(.+?)\"/>";
+
+ if (!std::regex_search(content, match, regex))
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+ std::string PPTF = match[1];
+
+ for (int i = 0; i < response->headersCount; i++)
+ {
+ if (mir_strcmpi(response->headers[i].szName, "Set-Cookie"))
+ continue;
+
+ regex = "^(.+?)=(.+?);";
+ content = response->headers[i].szValue;
+ if (std::regex_search(content, match, regex))
+ scookies[match[1]] = match[2];
+ }
+
+ CMStringA mscookies(FORMAT, "MSPRequ=%s;MSPOK=%s;CkTst=G%lld;", scookies["MSPRequ"].c_str(), scookies["MSPOK"].c_str(), time(NULL));
+
+ SendRequest (new LoginMSRequest(ptrA(getStringA(SKYPE_SETTINGS_ID)), ptrA(getStringA(SKYPE_SETTINGS_PASSWORD)), mscookies.c_str(), PPTF.c_str()), &CSkypeProto::OnMSLoginSecond);
+}
+
+void CSkypeProto::OnMSLoginSecond(const NETLIBHTTPREQUEST *response)
+{
+ if (response == NULL || response->pData == NULL)
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ std::regex regex;
+ std::smatch match;
+ std::string content = response->pData;
+ ptrA szContent(response->pData);
+
+ regex = "<meta name=\"PageID\" content=\"(.+?)\"/>";
+ if (std::regex_search(content, match, regex))
+ {
+ if (match[1] == "i5600")
+ {
+ CMStringA cookies;
+ for (int i = 0; i < response->headersCount; i++)
+ {
+ if (mir_strcmpi(response->headers[i].szName, "Set-Cookie"))
+ continue;
+
+ regex = "^(.+?)=(.+?);";
+ content = response->headers[i].szValue;
+ if (std::regex_search(content, match, regex))
+ if (!std::string(match[2]).empty() && std::string(match[2]) != " ")
+ cookies.AppendFormat("%s=%s;", std::string(match[1]).c_str(), std::string(match[2]).c_str());
+ }
+
+ CMStringA url(GetStringChunk(szContent, "urlPost:'", "'"));
+ CMStringA ppft(GetStringChunk(szContent, "sFT:'", "'"));
+
+
+ ptrA code(mir_utf8encodeT(RunConfirmationCode()));
+
+ SendRequest(new LoginMSRequest(url.c_str(), ptrA(getStringA(SKYPE_SETTINGS_ID)), cookies.c_str(), ppft.c_str(), code), &CSkypeProto::OnMSLoginEnd);
+ return;
+ }
+ }
+
+
+ regex = "=\"t\" value=\"(.+?)\"/>";
+
+ if (!std::regex_search(content, match, regex))
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+ std::string t = match[1];
+
+ SendRequest(new LoginMSRequest(t.c_str()), &CSkypeProto::OnMSLoginEnd);
+}
+
+void CSkypeProto::OnMSLoginEnd(const NETLIBHTTPREQUEST *response)
+{
+ if (response == NULL || response->pData == NULL)
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ std::regex regex;
+ std::smatch match;
+ std::string content = response->pData;
+
+ regex = "<input type=\"hidden\" name=\"skypetoken\" value=\"(.+?)\"/>";
+ if (!std::regex_search(content, match, regex))
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+ std::string token = match[1];
+ setString("TokenSecret", token.c_str());
+ regex = "<input type=\"hidden\" name=\"expires_in\" value=\"(.+?)\"/>";
+
+ if (std::regex_search(content, match, regex))
+ {
+ std::string expiresIn = match[1];
+ int seconds = atoi(expiresIn.c_str());
+ setDword("TokenExpiresIn", time(NULL) + seconds);
+ }
+
+ OnLoginSuccess();
+}
+
+CMString CSkypeProto::RunConfirmationCode()
+{
+ ENTER_STRING pForm = { sizeof(pForm) };
+ pForm.type = ESF_PASSWORD;
+ pForm.caption = TranslateT("Enter confirmation code");
+ pForm.ptszInitVal = NULL;
+ pForm.szModuleName = m_szModuleName;
+ return (!EnterString(&pForm)) ? CMString() : CMString(ptrT(pForm.ptszResult));
+}
\ No newline at end of file |