]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/backupaccount.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / actions / backupaccount.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * Download a backup of your own account to the browser
7  *
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Account
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2010 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Download a backup of your own account to the browser
39  *
40  * We go through some hoops to make this only respond to POST, since
41  * it's kind of expensive and there's probably some downside to having
42  * your account in all kinds of search engines.
43  *
44  * @category  Account
45  * @package   StatusNet
46  * @author    Evan Prodromou <evan@status.net>
47  * @copyright 2010 StatusNet, Inc.
48  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
49  * @link      http://status.net/
50  */
51 class BackupaccountAction extends Action
52 {
53     /**
54      * Returns the title of the page
55      *
56      * @return string page title
57      */
58     function title()
59     {
60         // TRANS: Title for backup account page.
61         return _('Backup account');
62     }
63
64     /**
65      * For initializing members of the class.
66      *
67      * @param array $argarray misc. arguments
68      *
69      * @return boolean true
70      */
71     function prepare($argarray)
72     {
73         parent::prepare($argarray);
74
75         $cur = common_current_user();
76
77         if (empty($cur)) {
78             // TRANS: Client exception thrown when trying to backup an account while not logged in.
79             throw new ClientException(_('Only logged-in users can backup their account.'), 403);
80         }
81
82         if (!$cur->hasRight(Right::BACKUPACCOUNT)) {
83             // TRANS: Client exception thrown when trying to backup an account without having backup rights.
84             throw new ClientException(_('You may not backup your account.'), 403);
85         }
86
87         return true;
88     }
89
90     /**
91      * Handler method
92      *
93      * @param array $argarray is ignored since it's now passed in in prepare()
94      *
95      * @return void
96      */
97     function handle($argarray=null)
98     {
99         parent::handle($argarray);
100
101         if ($this->isPost()) {
102             $this->sendFeed();
103         } else {
104             $this->showPage();
105         }
106         return;
107     }
108
109     /**
110      * Send a feed of the user's activities to the browser
111      *
112      * Uses the UserActivityStream class; may take a long time!
113      *
114      * @return void
115      */
116
117     function sendFeed()
118     {
119         $cur = common_current_user();
120
121         $stream = new UserActivityStream($cur, true, UserActivityStream::OUTPUT_RAW);
122
123         header('Content-Disposition: attachment; filename='.$cur->nickname.'.atom');
124         header('Content-Type: application/atom+xml; charset=utf-8');
125
126         // @fixme atom feed logic is in getString...
127         // but we just want it to output to the outputter.
128         $this->raw($stream->getString());
129     }
130
131     /**
132      * Show a little form so that the person can request a backup.
133      *
134      * @return void
135      */
136
137     function showContent()
138     {
139         $form = new BackupAccountForm($this);
140         $form->show();
141     }
142
143     /**
144      * Return true if read only.
145      *
146      * MAY override
147      *
148      * @param array $args other arguments
149      *
150      * @return boolean is read only action?
151      */
152     function isReadOnly($args)
153     {
154         return true;
155     }
156
157     /**
158      * Return last modified, if applicable.
159      *
160      * MAY override
161      *
162      * @return string last modified http header
163      */
164     function lastModified()
165     {
166         // For comparison with If-Last-Modified
167         // If not applicable, return null
168         return null;
169     }
170
171     /**
172      * Return etag, if applicable.
173      *
174      * MAY override
175      *
176      * @return string etag http header
177      */
178     function etag()
179     {
180         return null;
181     }
182 }
183
184 /**
185  * A form for backing up the account.
186  *
187  * @category  Account
188  * @package   StatusNet
189  * @author    Evan Prodromou <evan@status.net>
190  * @copyright 2010 StatusNet, Inc.
191  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
192  * @link      http://status.net/
193  */
194 class BackupAccountForm extends Form
195 {
196     /**
197      * Class of the form.
198      *
199      * @return string the form's class
200      */
201     function formClass()
202     {
203         return 'form_profile_backup';
204     }
205
206     /**
207      * URL the form posts to
208      *
209      * @return string the form's action URL
210      */
211     function action()
212     {
213         return common_local_url('backupaccount');
214     }
215
216     /**
217      * Output form data
218      *
219      * Really, just instructions for doing a backup.
220      *
221      * @return void
222      */
223     function formData()
224     {
225         $msg =
226             // TRANS: Information displayed on the backup account page.
227             _('You can backup your account data in '.
228               '<a href="http://activitystrea.ms/">Activity Streams</a> '.
229               'format. This is an experimental feature and provides an '.
230               'incomplete backup; private account '.
231               'information like email and IM addresses is not backed up. '.
232               'Additionally, uploaded files and direct messages are not '.
233               'backed up.');
234         $this->out->elementStart('p');
235         $this->out->raw($msg);
236         $this->out->elementEnd('p');
237     }
238
239     /**
240      * Buttons for the form
241      *
242      * In this case, a single submit button
243      *
244      * @return void
245      */
246     function formActions()
247     {
248         $this->out->submit('submit',
249                            // TRANS: Submit button to backup an account on the backup account page.
250                            _m('BUTTON', 'Backup'),
251                            'submit',
252                            null,
253                            // TRANS: Title for submit button to backup an account on the backup account page.
254                            _('Backup your account.'));
255     }
256 }