File: miastoplusa.cc

package info (click to toggle)
sms-pl 2.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 376 kB
  • ctags: 355
  • sloc: cpp: 2,618; perl: 109; makefile: 103; sh: 26
file content (121 lines) | stat: -rw-r--r-- 3,772 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "miastoplusa.h"
#include "mr_pcre/mr_pcre.h"

using namespace std;

MiastoplusaSMS::MiastoplusaSMS(Config &config) : GenericSMS(config)
{
	mp_user = config["miastoplusa_user"];
	mp_pass = config["miastoplusa_pass"];
	mp_notify = config.isTrue("notify");
}

bool MiastoplusaSMS::Send(const std::string &phone_no, const std::string &message)
{
	bool ok = false;
	CURLcode status;
	Curl_Form form;
	Curl_Result result;
	
	curl.SSL_ignore();
	curl.AutoReferer();
	curl.FollowLocation();
	curl.SetOpt(CURLOPT_COOKIEFILE, "");
	
	while (true) {
		status = curl.PerformGet("http://www.miastoplusa.pl/");
		if (status) throw Exception("[1] - get http://www.miastoplusa.pl/");

		form.AddField("login", mp_user);
		form.AddField("password", mp_pass);
		form.AddField("x", "0");
		form.AddField("y", "0");
		form.AddField("secureLogin", "on");
		status = curl.PerformPost("https://www.miastoplusa.pl/auth/LoginCitizen.do", form.PostFields());
		if (status) throw Exception("[2] - post https://www.miastoplusa.pl/auth/LoginCitizen.do");

		form.Reset();
		form.AddField("smsType", "10");
		form.AddField("prefix", "48");
		form.AddField("phoneNumber", phone_no);
		form.AddField("message", message);
		form.AddField("notifyCode", mp_notify ? "30" : "0");
		form.AddField("validity", "48");
		form.AddField("sendDay", "-1");
		form.AddField("sendHour", "0");
		form.AddField("sendMin", "0");
		form.AddField("archiveMessage", "0");
		form.AddField("flashMessage", "0");
		form.AddField("userId", "0");
		form.AddField("groupId", "0");
		form.AddField("templateCategory", "0");
		form.AddField("targetURL", "/sms/send_sms.jsp");
		status = curl.PerformPost("http://www.miastoplusa.pl/sms/SendSMS2.do", form.PostFields());
		if (status) throw Exception("[3] - post http://www.miastoplusa.pl/sms/SendSMS2.do");
		
		ok = curl.Body().find("SMS przekazany do wys´┐Żania") != string::npos;
		if (!ok) {
			PcreWrap::Array match;
			if (PcreWrap::pcre_match_all("bgcolor=\"#F4C8B6\">(&nbsp;)*([^\\.]*).*<\\/td><\\/tr>", 
				curl.Body(), "mi", match)) 
				throw Exception("[3] - " + match[0][1]);
		}
		
		curl.PerformGet("http://www.miastoplusa.pl/minimal/logout_frameset.jsp");
		
		break;
	}
	
	return ok;
}

bool MiastoplusaSMS::ShowStats()
{
	bool ok = false;
	CURLcode status;
	Curl_Form form;
	Curl_Result result;
	PcreWrap::Array match;
	string st_plus, st_inne;
	
	curl.SSL_ignore();
	curl.AutoReferer();
	curl.FollowLocation();
	curl.SetOpt(CURLOPT_COOKIEFILE, "");
	
	while (true) {
		status = curl.PerformGet("http://www.miastoplusa.pl/");
		if (status) throw Exception("[1] - get http://www.miastoplusa.pl/");

		form.AddField("login", mp_user);
		form.AddField("password", mp_pass);
		form.AddField("x", "0");
		form.AddField("y", "0");
		form.AddField("secureLogin", "on");
		status = curl.PerformPost("https://www.miastoplusa.pl/auth/LoginCitizen.do", form.PostFields());
		if (status) throw Exception("[2] - post https://www.miastoplusa.pl/auth/LoginCitizen.do");
		
		form.Reset();
		form.AddField("targetURL", "/sms/send_sms.jsp");
		status = curl.PerformPost("http://www.miastoplusa.pl/sms/SendSMS2.do", form.PostFields());
		if (status) throw Exception("[3] - post http://www.miastoplusa.pl/sms/SendSMS2.do");
		
		if (PcreWrap::pcre_match_all("do sieci Plus GSM<\\/td><td align(.*?)>(.*?)<\\/td><\\/tr>", 
			curl.Body(), "mi", match)) {
			st_plus = match[0][1];
			if (PcreWrap::pcre_match_all("do innych sieci<\\/td><td align(.*?)>(.*?)<\\/td><\\/tr>",
				curl.Body(), "mi", match)) {
				st_inne = match[0][1];
				ok = true;
			}
		}
		
		cout << "Twoje SMSy do sieci Plus GSM (" << st_plus << "), do innych sieci (" << st_inne << ")." << endl;
		
		curl.PerformGet("http://www.miastoplusa.pl/minimal/logout_frameset.jsp");
		
		break;
	}
	
	return ok;
}