1

Topic: not an issue, just a wish....

==== Required information ====
- iRedMail version: 0.9.2
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx):Apache
- Linux/BSD distribution name and version: Ubuntu 14.04.2 LTS
- Related log if you're reporting an issue:
====
This is purely a fancy add-on and nothing urgent.
This is my fail :

{#fo = open("/etc/iredmail-release","r")}
{#str = fo.read()}
                    <tr>
                        <th> Mail version</th>
                        <td>
                        {% print str %}
                        </td>
                    </tr>

With the second box i get the following error :

 File "/usr/share/apache2/iredadmin/libs/../templates/default/dashboard.html", line 168, in template 
  {% endblock main %}
TemplateSyntaxError: Encountered unknown tag 'endblock'.

If i change the variable to {{ print str}} i get this error :

File "/usr/share/apache2/iredadmin/libs/../templates/default/dashboard.html", line 100, in template
  {{print str}}
TemplateSyntaxError: expected token 'end of print statement', got 'str'

I want to alter the dashboard.html that it displays the iredmail version, e.g. /etc/iredmail-release
But my knowledge isn't fluent enough to do it in both jinja and python.

Could you help me out?

thx,

Jochie

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: not an issue, just a wish....

try {{ str }}

3 (edited by Jochie 2015-06-12 23:07:10)

Re: not an issue, just a wish....

Thanks ZhangHuangbin

That killed the error ;-)

both

 
{# versionfile = open('/etc/iredmail-release','r')}
{# mailversion = versionfile.readline()}
{{ mailversion }}
{# versionfile.close()}

and

{#    with open('/etc/iredmail-release', 'r') as fin: }
{#  print fin.readline() }

are accepted, but now the output is just empty.
Any tips?

4

Re: not an issue, just a wish....

File /etc/iredmail-release is not very clean, its content might be:

0.9.2

Or:

0.9.2 Upgraded by XXX <user@domain.com>, Jun 16, 2015.
0.8.6

Unless you keep this file contains only one line (the version number), it's not a good idea to read /etc/iredmail-release directly.

Anyway, if you want to implement it this way, you should use '{% ... python code ... %}' instead of '{# ... #}' (this is comment line). For example:

{# Read iRedMail version number #}
{% set version = open('/etc/iredmail-release','r').read() %}

{# Display version number #}
{{ version }}

5

Re: not an issue, just a wish....

Thanks for thinking along.

We're almost there ;-)

the code results in :

{% set mailversion = open('/etc/iredmail-release','r').read() %}

 UndefinedError: 'open' is undefined

6

Re: not an issue, just a wish....

It's not a good idea to allow using 'open()' in template file. here's another solution: read /etc/iredmail-release and store the version number in session, show the version number in template file.

Patch to read version number:

diff -r f3da3bbeafd6 libs/iredbase.py
--- a/libs/iredbase.py    Sat Jun 20 10:55:31 2015 +0800
+++ b/libs/iredbase.py    Mon Jun 22 19:06:49 2015 +0800
@@ -89,6 +89,12 @@
 # Initialize application object.
 app = web.application(urls, globals())
 
+iredmail_version = None
+try:
+    iredmail_version = open('/etc/iredmail-release', 'r').readline()
+except:
+    pass
+
 session = web.session.Session(
     app,
     sessionStore,
@@ -118,6 +124,9 @@
         'amavisd_enable_quarantine': settings.amavisd_enable_quarantine,
         'amavisd_enable_logging': settings.amavisd_enable_logging,
         'amavisd_enable_policy_lookup': settings.amavisd_enable_policy_lookup,
+
+        # iRedMail version number.
+        'iredmail_version': iredmail_version,
     }
 )
 

To show the version number, just use "{{ session.get('iredmail_version') }}" (without double quotes) in template file.