]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/oauth/oauth_post_notice.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / tests / oauth / oauth_post_notice.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - a distributed open-source microblogging tool
5  * Copyright (C) 2010, StatusNet, Inc.
6  *
7  *  This program is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU Affero General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU Affero General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Affero General Public License
18  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  **/
20
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
22
23 require_once INSTALLDIR . '/extlib/OAuth.php';
24
25 $shortoptions = 't:s:u:';
26 $longoptions = array('oauth_token=', 'oauth_token_secret=', 'update=');
27
28 $helptext = <<<END_OF_VERIFY_HELP
29     oauth_post_notice.php [options]
30     Update your status via OAuth
31
32     -t --oauth_token        access token
33     -s --oauth_token_secret access token secret
34     -u --update             status update
35
36
37 END_OF_VERIFY_HELP;
38
39 $token        = null;
40 $token_secret = null;
41 $update       = null;
42
43 require_once INSTALLDIR . '/scripts/commandline.inc';
44
45 if (have_option('t', 'oauth_token')) {
46     $token = get_option_value('t', 'oauth_token');
47 }
48
49 if (have_option('s', 'oauth_token_secret')) {
50     $token_secret = get_option_value('s', 'oauth_token_secret');
51 }
52
53 if (have_option('u', 'update')) {
54     $update = get_option_value('u', 'update');
55 }
56
57 if (empty($token)) {
58     print "Please specify an access token.\n";
59     exit(1);
60 }
61
62 if (empty($token_secret)) {
63     print "Please specify an access token secret.\n";
64     exit(1);
65 }
66
67 if (empty($update)) {
68     print "You forgot to update your status!\n";
69     exit(1);
70 }
71
72 $ini      = parse_ini_file("oauth.ini");
73 $consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
74 $endpoint = $ini['apiroot'] . '/statuses/update.xml';
75
76 $atok = new OAuthToken($token, $token_secret);
77
78 $parsed = parse_url($endpoint);
79 parse_str($parsed['query'], $params);
80
81 $params['status'] = $update;
82
83 $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
84
85 try {
86
87     $oauthReq = OAuthRequest::from_consumer_and_token(
88         $consumer,
89         $atok,
90         'POST',
91         $endpoint,
92         $params
93     );
94
95     $oauthReq->sign_request($hmac_method, $consumer, $atok);
96
97     $httpReq = httpRequest($endpoint, $oauthReq->to_postdata());
98
99     print $httpReq->getBody();
100
101 } catch (Exception $e) {
102     print "Error! . $e->getMessage() . 'HTTP reponse body: " . $httpReq->getBody();
103     exit(1);
104 }
105
106 function httpRequest($endpoint, $poststr)
107 {
108     $request = HTTPClient::start();
109
110     $request->setConfig(
111         array(
112             'follow_redirects' => true,
113             'connect_timeout' => 120,
114             'timeout' => 120,
115             'ssl_verify_peer' => false,
116             'ssl_verify_host' => false
117         )
118     );
119
120     // Turn signed request query string back into an array
121     parse_str($poststr, $postdata);
122     return $request->post($endpoint, null, $postdata);
123 }
124