annotate MoinMoin/action/backup.py @ 6133:a6283e189869 tip

fixup: remove nonexisting passlib.utils._blowfish this was removed by the passlib 1.7.1 upgrade.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 01 Jun 2017 18:10:19 +0200
parents 68f8bea727e5
children
rev   line source
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
2 """
4054
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 MoinMoin - download a backup via http.
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
4
4054
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5 Triggering backup action will check if you are authorized to do a backup
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 and if yes, just send a <siteid>-<date>--<time>.tar.<format> to you.
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 What exactly is contained in your backup depends on your wiki's
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 configuration - please make sure you have everything you need BEFORE you
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 really need it.
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
10
4054
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 Note: there is no restore support, you need somebody having access to your
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 wiki installation via the server's file system, knowing about tar
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 and restoring your data CAREFULLY (AKA "the server admin").
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15 @copyright: 2005-2008 by MoinMoin:ThomasWaldmann
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
16 @license: GNU GPL, see COPYING for details.
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
17 """
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
18
2174
f5f4dbbd0c51 added tarfile.py from py 2.5.1 (backported to work with py 2.3/2.4), fix imports to use it for tests/backup (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
19 import os, re, time
6104
68f8bea727e5 remove usage of MoinMoin.support.tarfile
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5687
diff changeset
20 import tarfile
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
21
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
22 from MoinMoin import wikiutil
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
23
4054
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24
4109
e88baf535b48 fix backup action configuration (broke on windows due to backslashes in e.g. cache_dir), try 2.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4108
diff changeset
25 def addFiles(path, tar, exclude_func):
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
26 """ Add files in path to tar """
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
27 for root, dirs, files in os.walk(path):
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
28 files.sort() # sorted page revs may compress better
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
29 for name in files:
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
30 path = os.path.join(root, name)
4109
e88baf535b48 fix backup action configuration (broke on windows due to backslashes in e.g. cache_dir), try 2.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4108
diff changeset
31 if exclude_func(path):
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
32 continue
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
33 tar.add(path)
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
34
4054
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
36 def sendBackup(request):
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
37 """ Send compressed tar file """
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
38 dateStamp = time.strftime("%Y-%m-%d--%H-%M-%S-UTC", time.gmtime())
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
39 filename = "%s-%s.tar.%s" % (request.cfg.siteid, dateStamp, request.cfg.backup_compression)
5591
1dff6cfdcf90 http headers: for most cases, do not use .add, but .__setitem__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4579
diff changeset
40 request.headers['Content-Type'] = 'application/octet-stream'
1dff6cfdcf90 http headers: for most cases, do not use .add, but .__setitem__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4579
diff changeset
41 request.headers['Content-Disposition'] = 'inline; filename="%s"' % filename
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
42 tar = tarfile.open(fileobj=request, mode="w|%s" % request.cfg.backup_compression)
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2174
diff changeset
43 # allow GNU tar's longer file/pathnames
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
44 tar.posix = False
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
45 for path in request.cfg.backup_include:
4109
e88baf535b48 fix backup action configuration (broke on windows due to backslashes in e.g. cache_dir), try 2.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4108
diff changeset
46 addFiles(path, tar, request.cfg.backup_exclude)
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
47 tar.close()
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
48
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
49
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
50 def sendBackupForm(request, pagename):
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
51 _ = request.getText
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
52 request.setContentLanguage(request.lang)
4054
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53 title = _('Wiki Backup')
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4109
diff changeset
54 request.theme.send_title(title, pagename=pagename)
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
55 request.write(request.formatter.startContent("content"))
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
56
4054
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 request.write(_("""= Downloading a backup =
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
58
4054
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
59 Please note:
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
60 * Store backups in a safe and secure place - they contain sensitive information.
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61 * Make sure your wiki configuration backup_* values are correct and complete.
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
62 * Make sure the backup file you get contains everything you need in case of problems.
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63 * Make sure it is downloaded without problems.
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
64
4054
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65 To get a backup, just click here:""", wiki=True))
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
66
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
67 request.write("""
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
68 <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
69 <input type="hidden" name="action" value="backup">
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
70 <input type="hidden" name="do" value="backup">
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
71 <input type="submit" value="%(backup_button)s">
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
72 </form>
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
73 """ % {
4579
87d97510de79 getScriptname() -> script_root, getBaseURL() -> url_root (for werkzeug API)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4577
diff changeset
74 'baseurl': request.script_root,
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
75 'pagename': wikiutil.quoteWikinameURL(pagename),
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
76 'backup_button': _('Backup'),
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
77 })
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
78
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
79 request.write(request.formatter.endContent())
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 391
diff changeset
80 request.theme.send_footer(pagename)
617
cf420addd95c removed MoinMoinNoFooter at many places, added call to theme.send_closing_html() where needed
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 616
diff changeset
81 request.theme.send_closing_html()
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
82
5685
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 3525
diff changeset
83 # NOTE: consider using ActionBase.render_msg instead of this function.
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2725
diff changeset
84 def sendMsg(request, pagename, msg, msgtype):
5685
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 3525
diff changeset
85 """
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 3525
diff changeset
86 @param msg: Message to show. Should be escaped.
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 3525
diff changeset
87 """
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
88 from MoinMoin import Page
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2725
diff changeset
89 request.theme.add_msg(msg, msgtype)
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2725
diff changeset
90 return Page.Page(request, pagename).send_page()
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
91
4054
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
93 def backupAllowed(request):
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
94 """ Return True if backup is allowed """
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
95 action = __name__.split('.')[-1]
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
96 user = request.user
3525
ee0644a26e30 action Attachfile, Despam, backup, thread_monitor: removed duplicated checks done by request.__init__
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3122
diff changeset
97 return user.valid and user.name in request.cfg.backup_users
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
98
4054
691e12f53408 backup action: add missing file
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
100 def execute(pagename, request):
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
101 _ = request.getText
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
102 if not backupAllowed(request):
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
103 return sendMsg(request, pagename,
2966
ba14d391c2ba Refactor all modules to use the new add_msg interface in 1.7 (done by Frederico Lorenzi). Should not be backported to 1.6 but
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2725
diff changeset
104 msg=_('You are not allowed to do remote backup.'), msgtype="error")
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
105
4424
5ad5753ae311 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4109
diff changeset
106 dowhat = request.form.get('do')
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
107 if dowhat == 'backup':
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
108 sendBackup(request)
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
109 elif dowhat is None:
99
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
110 sendBackupForm(request, pagename)
ce657f0e577b implement restore backup subaction, with a already local backup file
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
111 else:
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
112 return sendMsg(request, pagename,
5685
37306fba2189 Fixing security issues related to MoinMoinBugs/1.9.2UnescapedInputForThemeAddMsg (possible XSS)
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 3525
diff changeset
113 msg=_('Unknown backup subaction: %s.') % wikiutil.escape(dowhat), msgtype="error")