forked from DmitrySandalov/twitter2gplus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gplus.php
executable file
·215 lines (192 loc) · 6.88 KB
/
gplus.php
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/php
<?php
/**
* Google+ (plus.google.com) PHP Curl bot
* @since Sep 29 2011
* @version 15.12.2011
* @link http://360percents.com/
* @author Luka Pušić <[email protected]>
*/
/**
* REQUIRED PARAMETERS
*/
$email = '[email protected]';
$pass = 'mypassword';
// And the status as a command line argument...
/**
* OPTIONAL PARAMETERS
* sleeptime is an optional timeout parameter which makes us look less suspicious to Google
* Enter pageid if you want to post to a page.
*/
$pageid = false;
$cookies = 'cookie.txt';
$sleeptime = 0;
$uagent = 'Mozilla/4.0 (compatible; MSIE 5.0; S60/3.0 NokiaN73-1/2.0(2.0617.0.0.7) Profile/MIDP-2.0 Configuration/CLDC-1.1)';
$pc_uagent = 'Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1';
$debug = FALSE;
$status = implode(" ", array_slice($argv, 1));
function tidy($str) {
return rtrim($str, "&");
}
/**
* Handle cookie file
*/
@unlink($cookies); //delete previous cookie file if exists
touch($cookies); //create a cookie file
/**
* MAIN BLOCK
* login_data() just collects login form info
* login($postdata) logs you in and you can do pretty much anything you want from here on
*/
login(login_data());
sleep($sleeptime);
if ($pageid) {
update_page_status();
} else {
update_profile_status();
} //update status with $GLOBAL['status'];
sleep($sleeptime);
logout(); //optional - log out
/**
* 1. GET: http://plus.google.com/
* Parse the webpage and collect form data
* @return array (string postdata, string postaction)
*/
function login_data() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $GLOBALS['cookies']);
curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['uagent']);
curl_setopt($ch, CURLOPT_URL, "https://plus.google.com/");
curl_setopt($ch, CURLOPT_COOKIEFILE, $GLOBALS['cookies']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$buf = utf8_decode(html_entity_decode(curl_exec($ch)));
$buf = str_replace( '&', '&', $buf ); // just in case any correctly encoded
$buf = str_replace( '&', '&', $buf ); // now encode them all again
curl_close($ch);
echo "\n[+] Sending GET request to: https://plus.google.com/\n\n";
$toreturn = '';
$doc = new DOMDocument;
$doc->loadxml($buf);
$inputs = $doc->getElementsByTagName('input');
foreach ($inputs as $input) {
switch ($input->getAttribute('name')) {
case 'Email':
$toreturn .= 'Email=' . urlencode($GLOBALS['email']) . '&';
break;
case 'Passwd':
$toreturn .= 'Passwd=' . urlencode($GLOBALS['pass']) . '&';
break;
default:
$toreturn .= $input->getAttribute('name') . '=' . urlencode($input->getAttribute('value')) . '&';
}
}
return array(tidy($toreturn), $doc->getElementsByTagName('form')->item(0)->getAttribute('action'));
}
/**
* 2. POST login: https://accounts.google.com/ServiceLoginAuth
*/
function login($postdata) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $GLOBALS['cookies']);
curl_setopt($ch, CURLOPT_COOKIEFILE, $GLOBALS['cookies']);
curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['uagent']);
curl_setopt($ch, CURLOPT_URL, $postdata[1]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata[0]);
$buf = curl_exec($ch); #this is not the g+ home page, because the b**** doesn't redirect properly
curl_close($ch);
if ($GLOBALS['debug']) {
echo $buf;
}
echo "\n[+] Sending POST request to: " . $postdata[1] . "\n\n";
}
/**
* 3. GET status update form:
* Parse the webpage and collect form data
*/
function update_profile_status() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $GLOBALS['cookies']);
curl_setopt($ch, CURLOPT_COOKIEFILE, $GLOBALS['cookies']);
curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['uagent']);
curl_setopt($ch, CURLOPT_URL, 'https://m.google.com/app/plus/?v=compose&group=m1c&hideloc=1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$buf = utf8_decode(html_entity_decode(str_replace('&', '', curl_exec($ch))));
$header = curl_getinfo($ch);
curl_close($ch);
if ($GLOBALS['debug']) {
echo $buf;
}
$params = '';
$doc = new DOMDocument;
$doc->loadxml($buf);
$inputs = $doc->getElementsByTagName('input');
foreach ($inputs as $input) {
if (($input->getAttribute('name') != 'editcircles')) {
$params .= $input->getAttribute('name') . '=' . urlencode($input->getAttribute('value')) . '&';
}
}
$params .= 'newcontent=' . urlencode($GLOBALS['status']);
//$baseurl = $doc->getElementsByTagName('base')->item(0)->getAttribute('href');
$baseurl = 'https://m.google.com' . parse_url($header['url'], PHP_URL_PATH);
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $GLOBALS['cookies']);
curl_setopt($ch, CURLOPT_COOKIEFILE, $GLOBALS['cookies']);
curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['uagent']);
//delete group=b0& in the line below, to post just to your circles, not to public
curl_setopt($ch, CURLOPT_URL, $baseurl . '?v=compose&group=m1c&group=b0&hideloc=1&a=post');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $baseurl . '?v=compose&group=m1c&group=b0&hideloc=1');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$buf = curl_exec($ch);
$header = curl_getinfo($ch);
curl_close($ch);
if ($GLOBALS['debug']) {
echo $buf;
}
echo "\n[+] POST Updating status on: " . $baseurl . "\n\n";
}
/**
* Not implemented yet!
* just ignore this function for now
*/
function update_page_status() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $GLOBALS['cookies']);
curl_setopt($ch, CURLOPT_COOKIEFILE, $GLOBALS['cookies']);
curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['pc_uagent']);
curl_setopt($ch, CURLOPT_URL, 'https://plus.google.com/u/0/b/' . $GLOBALS['pageid'] . '/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$buf = utf8_decode(html_entity_decode(str_replace('&', '', curl_exec($ch))));
curl_close($ch);
if ($GLOBALS['debug']) {
echo $buf;
}
}
/**
* 3. GET logout:
* Just logout to look more human like and reset cookie :)
*/
function logout() {
echo "\n[+] GET Logging out: \n\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $GLOBALS['cookies']);
curl_setopt($ch, CURLOPT_COOKIEFILE, $GLOBALS['cookies']);
curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['uagent']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/m/logout');
$buf = curl_exec($ch);
curl_close($ch);
if ($GLOBALS['debug']) {
echo $buf;
}
}
?>