Commit | Line | Data |
---|---|---|
427beb08 E |
1 | # GNU MediaGoblin -- federated, autonomous media hosting |
2 | # Copyright (C) 2013 MediaGoblin contributors. See AUTHORS. | |
3 | # | |
4 | # This program is free software: you can redistribute it and/or modify | |
5 | # it under the terms of the GNU Affero General Public License as published by | |
6 | # the Free Software Foundation, either version 3 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU Affero General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
17 | import logging | |
18 | ||
19 | from werkzeug.exceptions import MethodNotAllowed | |
e4e5948c | 20 | from werkzeug.wrappers import BaseResponse |
427beb08 E |
21 | |
22 | from mediagoblin.meddleware.csrf import csrf_exempt | |
4234fffa E |
23 | from mediagoblin.tools.response import render_404 |
24 | from .tools import CmdTable, PwgNamedArray, response_xml | |
427beb08 E |
25 | |
26 | ||
27 | _log = logging.getLogger(__name__) | |
28 | ||
29 | ||
427beb08 E |
30 | @CmdTable("pwg.session.login", True) |
31 | def pwg_login(request): | |
32 | username = request.form.get("username") | |
33 | password = request.form.get("password") | |
34 | _log.info("Login for %r/%r...", username, password) | |
bd3bc044 E |
35 | _log.warn("login: %s %r %r", request.method, |
36 | request.args, request.form) | |
e4e5948c | 37 | return True |
bd3bc044 E |
38 | |
39 | ||
40 | @CmdTable("pwg.session.logout") | |
41 | def pwg_logout(request): | |
42 | _log.info("Logout") | |
e4e5948c | 43 | return True |
bd3bc044 E |
44 | |
45 | ||
46 | @CmdTable("pwg.getVersion") | |
47 | def pwg_getversion(request): | |
48 | _log.info("getversion") | |
e4e5948c E |
49 | return "piwigo 2.5.0" |
50 | ||
51 | ||
52 | @CmdTable("pwg.categories.getList") | |
53 | def pwg_categories_getList(request): | |
54 | catlist = ({'id': -29711},) | |
55 | return { | |
56 | 'categories': PwgNamedArray( | |
57 | catlist, | |
58 | 'category', | |
59 | ( | |
60 | 'id', | |
61 | 'url', | |
62 | 'nb_images', | |
63 | 'total_nb_images', | |
64 | 'nb_categories', | |
65 | 'date_last', | |
66 | 'max_date_last', | |
67 | ) | |
68 | ) | |
69 | } | |
427beb08 E |
70 | |
71 | ||
72 | @csrf_exempt | |
73 | def ws_php(request): | |
74 | if request.method not in ("GET", "POST"): | |
75 | _log.error("Method %r not supported", request.method) | |
76 | raise MethodNotAllowed() | |
77 | ||
78 | func = CmdTable.find_func(request) | |
79 | if not func: | |
80 | _log.warn("wsphp: Unhandled %s %r %r", request.method, | |
81 | request.args, request.form) | |
82 | return render_404(request) | |
83 | ||
84 | result = func(request) | |
85 | ||
e4e5948c E |
86 | if isinstance(result, BaseResponse): |
87 | return result | |
88 | ||
89 | return response_xml(result) |