]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Bookmark/scripts/importbookmarks.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / Bookmark / scripts / importbookmarks.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010 StatusNet, Inc.
5  *
6  * Import a bookmarks file as notices
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  Bookmark
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 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
32
33 $shortoptions = 'i:n:f:';
34 $longoptions  = array('id=', 'nickname=', 'file=');
35
36 $helptext = <<<END_OF_IMPORTBOOKMARKS_HELP
37 importbookmarks.php [options]
38 Restore a backed-up Delicious.com bookmark file
39
40 -i --id       ID of user to import bookmarks for
41 -n --nickname nickname of the user to import for
42 -f --file     file to read from (STDIN by default)
43 END_OF_IMPORTBOOKMARKS_HELP;
44
45 require_once INSTALLDIR.'/scripts/commandline.inc';
46
47 /**
48  * Get the bookmarks file as a string
49  *
50  * Uses the -f or --file parameter to open and read a
51  * a bookmarks file
52  *
53  * @return string Contents of the file
54  */
55
56 function getBookmarksFile()
57 {
58     $filename = get_option_value('f', 'file');
59
60     if (empty($filename)) {
61         show_help();
62         exit(1);
63     }
64
65     if (!file_exists($filename)) {
66         // TRANS: Exception thrown when a file upload cannot be found.
67         // TRANS: %s is the file that could not be found.
68         throw new Exception(sprintf(_m('No such file "%s".'),$filename));
69     }
70
71     if (!is_file($filename)) {
72         // TRANS: Exception thrown when a file upload is incorrect.
73         // TRANS: %s is the irregular file.
74         throw new Exception(sprintf(_m('Not a regular file: "%s".'),$filename));
75     }
76
77     if (!is_readable($filename)) {
78         // TRANS: Exception thrown when a file upload is not readable.
79         // TRANS: %s is the file that could not be read.
80         throw new Exception(sprintf(_m('File "%s" not readable.'),$filename));
81     }
82
83     // TRANS: %s is the filename that contains a backup for a user.
84     printfv(_m('Getting backup from file "%s".')."\n", $filename);
85
86     $html = file_get_contents($filename);
87
88     return $html;
89 }
90
91 try {
92     $user = getUser();
93     $html = getBookmarksFile();
94
95     $qm = QueueManager::get();
96
97     $qm->enqueue(array($user, $html), 'dlcsback');
98
99 } catch (Exception $e) {
100     print $e->getMessage()."\n";
101     exit(1);
102 }