Mercurial > p > roundup > code
annotate website/issues/extensions/templating.py @ 6478:a35d4e0c4e07
Fix permissions check. Use role not perm check.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 30 Aug 2021 16:17:46 -0400 |
| parents | 0ecfa817299b |
| children | bc95f7431efb |
| rev | line source |
|---|---|
|
6477
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
1 import logging |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
2 logger = logging.getLogger('extension') |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
3 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
4 import sys |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
5 from roundup import __version__ as roundup_version |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
6 def AboutPage(db): |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
7 "report useful info about this tracker" |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
8 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
9 def is_module_loaded(module): |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
10 modules = list(sys.modules.keys()) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
11 return module in modules |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
12 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
13 def get_status_of_module(module, prefix=None, version=True): |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
14 modules = list(sys.modules.keys()) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
15 is_enabled = module in modules |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
16 if is_enabled: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
17 if module == 'pyme': |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
18 from pyme import version |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
19 version="version %s"%version.versionstr |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
20 elif module == 'pychart': |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
21 from pychart import version |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
22 version="version %s"%version.version |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
23 elif module == 'sqlite3': |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
24 from sqlite3 import version |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
25 version="version %s"%version |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
26 elif module == 'xapian': |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
27 from xapian import version_string |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
28 version="version %s"%version_string() |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
29 else: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
30 if version: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
31 m = __import__(module) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
32 try: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
33 version="version %s"%m.__version__ |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
34 except AttributeError: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
35 version="version unavailable - exception thrown" |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
36 else: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
37 version="version unavailable" |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
38 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
39 if prefix: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
40 return "%s %s %s enabled: %s"%(prefix, module, version, is_enabled) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
41 else: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
42 return "Module: %s %s enabled: %s"%(module, version, is_enabled) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
43 else: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
44 if prefix: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
45 return "%s %s enabled: %s"%(prefix, module, is_enabled) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
46 else: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
47 return "Module: %s enabled: %s"%(module, is_enabled) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
48 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
49 info = [] |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
50 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
51 info.append("Tracker name: %s<br>"%db.config['TRACKER_NAME']) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
52 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
53 info.append("<h2>Operating environment</h2>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
54 info.append('<a href="http://roundup.sourceforge.net/">Roundup</a> version: %s<br>'%roundup_version) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
55 info.append("Python Version: %s<br>"%sys.version) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
56 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
57 info.append("<h2>Configuration</h2>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
58 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
59 backend = db.config['RDBMS_BACKEND'] |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
60 info.append("Roundup backend: %s<br>"%backend) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
61 if backend != 'anydbm': |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
62 info.append("Roundup db cache: %s<br>"%db.config['RDBMS_CACHE_SIZE']) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
63 info.append("Roundup isolation_level: %s<br>"%db.config['RDBMS_ISOLATION_LEVEL']) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
64 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
65 info.append("Roundup template: %s<br>"%db.config['TEMPLATE_ENGINE']) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
66 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
67 info.append("<h2>Database modules</h2>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
68 info.append(get_status_of_module('anydbm', version=False) + "<br>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
69 info.append(get_status_of_module('dbm', version=False) + "<br>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
70 info.append(get_status_of_module('sqlite3') + "<br>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
71 info.append(get_status_of_module('MySQLdb') + "<br>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
72 info.append(get_status_of_module('psycopg2') + "<br>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
73 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
74 info.append("<h2>Other modules</h2>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
75 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
76 indexer = db.config['INDEXER'] |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
77 if not indexer: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
78 if is_module_loaded('xapian'): |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
79 indexer="unset using xapian" |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
80 elif is_module_loaded('whoosh'): |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
81 indexer="unset using woosh" |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
82 else: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
83 indexer="unset using native" |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
84 else: |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
85 indexer="set to " + indexer |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
86 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
87 info.append("Indexer used for full-text: %s<br>"%indexer) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
88 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
89 info.append("Available indexers:<br><ul>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
90 if is_module_loaded('xapian'): |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
91 info.append("<li>%s</li>"%get_status_of_module('xapian', prefix="Indexer loaded:")) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
92 if is_module_loaded('whoosh'): |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
93 info.append("<li>%s</li>"%get_status_of_module('whoosh', prefix="Indexer loaded:")) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
94 info.append("<li>Indexer loaded: native: True</li>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
95 info.append("</ul>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
96 info.append(get_status_of_module('pytz') + "<br>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
97 info.append(get_status_of_module('pyme') + "<br>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
98 info.append(get_status_of_module('OpenSSL') + "<br>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
99 info.append(get_status_of_module('pychart') + "<br>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
100 info.append(get_status_of_module('pygal') + "<br>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
101 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
102 info.append(get_status_of_module('jinja2') + "<br>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
103 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
104 uid = db._db.getuid() |
|
6478
a35d4e0c4e07
Fix permissions check. Use role not perm check.
John Rouillard <rouilj@ieee.org>
parents:
6477
diff
changeset
|
105 if uid == "1" or db._db.user.has_role(uid,"Admin"): |
|
6477
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
106 #may leak sensitive info about system, directory paths etc. |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
107 #and keys so require admin user access. Consider expanding |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
108 #to Admin rights for tracker. |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
109 info.append("") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
110 info.append("Module Path: %r"%sys.path) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
111 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
112 info.append("<h2>Environment Variables</h2>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
113 info.append("<pre>") # include pre to prevent wrapping of values |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
114 for key in db._client.env.keys(): |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
115 info.append("%s=%s"%(key,db._client.env[key]) + "<br>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
116 info.append("</pre>") |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
117 return "\n".join(info) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
118 |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
119 def init(instance): |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
120 instance.registerUtil('AboutPage', AboutPage) |
|
0ecfa817299b
Added code for utils.AboutPage called from home.about.html
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
121 |
