]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apignusocialconfig.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / actions / apignusocialconfig.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Dump of configuration variables
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  API
23  * @package   GNUsocial
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Zach Copley <zach@status.net>
26  * @copyright 2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://www.gnu.org/software/social/
29  */
30
31 if (!defined('GNUSOCIAL')) { exit(1); }
32
33 /**
34  * Gives a full dump of configuration variables for this instance
35  * of GNU social, minus variables that may be security-sensitive (like
36  * passwords).
37  * URL: https://example.com/api/gnusocial/config.(xml|json)
38  * Formats: xml, json
39  *
40  * @category API
41  * @package  GNUsocial
42  * @author   Evan Prodromou <evan@status.net>
43  * @author   Zach Copley <zach@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://www.gnu.org/software/social/
46  */
47 class ApiGNUsocialConfigAction extends ApiAction
48 {
49     var $keys = array(
50         'site' => array('name', 'server', 'theme', 'path', 'logo', 'fancy', 'language',
51                         'email', 'broughtby', 'broughtbyurl', 'timezone', 'closed',
52                         'inviteonly', 'private', 'textlimit', 'ssl', 'sslserver'),
53         'license' => array('type', 'owner', 'url', 'title', 'image'),
54         'nickname' => array('featured'),
55         'profile' => array('biolimit'),
56         'group' => array('desclimit'),
57         'notice' => array('contentlimit'),
58         'throttle' => array('enabled', 'count', 'timespan'),
59         'xmpp' => array('enabled', 'server', 'port', 'user'),
60         'integration' => array('source'),
61         'attachments' => array('uploads', 'file_quota'),
62         'url' => array('maxurllength', 'maxnoticelength'),
63     );
64
65     protected function handle()
66     {
67         parent::handle();
68
69         switch ($this->format) {
70         case 'xml':
71             $this->initDocument('xml');
72             $this->elementStart('config');
73
74             // XXX: check that all sections and settings are legal XML elements
75
76             foreach ($this->keys as $section => $settings) {
77                 $this->elementStart($section);
78                 foreach ($settings as $setting) {
79                     $value = $this->setting($section, $setting);
80                     if (is_array($value)) {
81                         $value = implode(',', $value);
82                     } else if ($value === false || $value == '0') {
83                         $value = 'false';
84                     } else if ($value === true || $value == '1') {
85                         $value = 'true';
86                     }
87
88                     // return theme logo if there's no site specific one
89                     if (empty($value)) {
90                         if ($section == 'site' && $setting == 'logo') {
91                             $value = Theme::path('logo.png');
92                         }
93                     }
94
95                     $this->element($setting, null, $value);
96                 }
97                 $this->elementEnd($section);
98             }
99             $this->elementEnd('config');
100             $this->endDocument('xml');
101             break;
102         case 'json':
103             $result = array();
104             foreach ($this->keys as $section => $settings) {
105                 $result[$section] = array();
106                 foreach ($settings as $setting) {
107                     $result[$section][$setting]
108                         = $this->setting($section, $setting);
109                 }
110             }
111             $this->initDocument('json');
112             $this->showJsonObjects($result);
113             $this->endDocument('json');
114             break;
115         default:
116             // TRANS: Client error displayed when coming across a non-supported API method.
117             $this->clientError(_('API method not found.'), 404);
118         }
119     }
120
121     function setting($section, $key) {
122         $result = common_config($section, $key);
123         if ($key == 'file_quota') {
124             // hack: adjust for the live upload limit
125             if (common_config($section, 'uploads')) {
126                 $max = ImageFile::maxFileSizeInt();
127             } else {
128                 $max = 0;
129             }
130             return min($result, $max);
131         }
132         return $result;
133     }
134
135     /**
136      * Return true if read only.
137      *
138      * MAY override
139      *
140      * @param array $args other arguments
141      *
142      * @return boolean is read only action?
143      */
144     function isReadOnly($args)
145     {
146         return true;
147     }
148 }