1

Topic: Adding alias to user cause Internal Error Server

==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version (check /etc/iredmail-release): 5.0
- Deployed with iRedMail Easy or the downloadable installer? Downloadable installer
- Linux/BSD distribution name and version:  Debian 10.10.
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): LDAP
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro? Yes
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

Hello,

I want to know how enable debug mode in iredadmin restful api beause i'm getting internal server error when i'm trying to add alias to user.
To add alias for user i'm using this endpoint: /api/user/<mail> with put method and aliases parameter (addAlias parameter also didn't work).

----

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

2

Re: Adding alias to user cause Internal Error Server

Any related error in /var/log/syslog?

3

Re: Adding alias to user cause Internal Error Server

When I tried add alias to my test user I got also 500 error and in syslog is this line:
Oct 19 09:38:03 mail iredadmin: [212.122.192.174] PUT /iredadmin/api/user/ldap-iredmail11102021-test@pbs.edu.pl 500 202 "-"

4

Re: Adding alias to user cause Internal Error Server

I'm still waiting for answer in this thread. Maybe anyone else can help?

5

Re: Adding alias to user cause Internal Error Server

mikolaj.werner wrote:

I'm still waiting for answer in this thread. Maybe anyone else can help?

sorry about my late reply.

I expect there’re more detailed log lines in /var/log/syslog, could you help check and extract the log lines?

6

Re: Adding alias to user cause Internal Error Server

ZhangHuangbin wrote:
mikolaj.werner wrote:

I'm still waiting for answer in this thread. Maybe anyone else can help?

sorry about my late reply.

I expect there’re more detailed log lines in /var/log/syslog, could you help check and extract the log lines?

Do you mean the entire syslog file or something else?

7

Re: Adding alias to user cause Internal Error Server

mikolaj.werner wrote:

Do you mean the entire syslog file or something else?

Please check this log file and try to extract related log lines, do not send the whole log file.

8

Re: Adding alias to user cause Internal Error Server

ZhangHuangbin wrote:
mikolaj.werner wrote:

Do you mean the entire syslog file or something else?

Please check this log file and try to extract related log lines, do not send the whole log file.

These are just two lines related to the user alias update error I found in syslog.

Nov  9 09:25:14 mail iredadmin [API] Reset per-user alias address for ldap-iredmail11102021-test@pbs.edu.pl to: ldap-iredmailxxx11@pbs.edu.pl. admin=ired-api@pbs.edu.pl, domain=pbs.edu.pl, username=ldap-iredmail11102021-test@pbs.edu.pl, event=update, ip=212.122.192.174 (/opt/www/iRedAdmin-Pro-LDAP-5.0/libs/logger.py, L76)
Nov  9 09:25:14 mail iredadmin: [212.122.192.174] PUT /iredadmin/api/user/ldap-iredmail11102021-test@pbs.edu.pl 500 202 "-" 

9

Re: Adding alias to user cause Internal Error Server

This is normal log, not (500) error.
Possible to reproduce the error?

10

Re: Adding alias to user cause Internal Error Server

ZhangHuangbin wrote:

This is normal log, not (500) error.
Possible to reproduce the error?

That was reproduction of error (In postman which i'm using to testing iredmail api, I got Internal Server Error without any details). Maybe I should increase level of logging but I don't know how.

11

Re: Adding alias to user cause Internal Error Server

Please try to reproduce the error with postman, with "internal server error", there must be some related detailed error log in /var/log/syslog (on Debian/Ubuntu).

12

Re: Adding alias to user cause Internal Error Server

ZhangHuangbin wrote:

Please try to reproduce the error with postman, with "internal server error", there must be some related detailed error log in /var/log/syslog (on Debian/Ubuntu).

Now I know why in syslog is no errors about inserting alias to user: After insert alias to user, inserted alias is appear in user when i check user in iredadmin panel. The only problem is bad response after insert alias (should be 200 but is 500).

13

Re: Adding alias to user cause Internal Error Server

The "500" is internal server error which means our iRedAdmin-Pro code has some error, i need log for troubleshooting, i can not judge based on your description.

14

Re: Adding alias to user cause Internal Error Server

ZhangHuangbin wrote:

The "500" is internal server error which means our iRedAdmin-Pro code has some error, i need log for troubleshooting, i can not judge based on your description.

/var/log/syslog

Dec 10 11:49:31 mail iredadmin [API] Reset per-user alias address for ldap-iredmail11102021-test@pbs.edu.pl to: ldap-iredmailxxx33xxxx@pbs.edu.pl. admin=ired-api@pbs.edu.pl, domain=pbs.edu.pl, username=ldap-iredmail11102021-test@pbs.edu.pl, event=update, ip=212.122.192.174 (/opt/www/iRedAdmin-Pro-LDAP-5.0/libs/logger.py, L76)
Dec 10 11:49:31 mail iredadmin: [212.122.192.174] PUT /iredadmin/api/user/ldap-iredmail11102021-test@pbs.edu.pl 500 202 "-"

I'm including also /var/nginx/access.log:

 212.122.192.174 - - [10/Dec/2021:11:52:16 +0100] "PUT /iredadmin/api/user/ldap-iredmail11102021-test@pbs.edu.pl HTTP/1.1" 500 32 "-" "PostmanRuntime/7.28.4"

I'm still getting 500 error but aliases are added to user properly.
I think that error is nowhere logged sad .

15

Re: Adding alias to user cause Internal Error Server

Please try this:

- Run iRedAdmin-Pro manually:

cd /opt/www/iredadmin/
python3 iredadmin.py

It will listen on port 8080 by default. Note: it's http not httpS.

- Update your postman to use this 8080 port and run the test again.

I expect iRedAdmin-Pro logs detailed error message on console, please copy me the full console output for troubleshooting.

16

Re: Adding alias to user cause Internal Error Server

ZhangHuangbin wrote:

Please try this:

- Run iRedAdmin-Pro manually:

cd /opt/www/iredadmin/
python3 iredadmin.py

It will listen on port 8080 by default. Note: it's http not httpS.

- Update your postman to use this 8080 port and run the test again.

I expect iRedAdmin-Pro logs detailed error message on console, please copy me the full console output for troubleshooting.

Now We can see what happened, below is log from console after inserting alias to user:

  File "/usr/local/lib/python3.7/dist-packages/web/application.py", line 280, in process
    return self.handle()
  File "/usr/local/lib/python3.7/dist-packages/web/application.py", line 271, in handle
    return self._delegate(fn, self.fvars, args)
  File "/usr/local/lib/python3.7/dist-packages/web/application.py", line 517, in _delegate
    return handle_class(cls)
  File "/usr/local/lib/python3.7/dist-packages/web/application.py", line 495, in handle_class
    return tocall(*args)
  File "/opt/www/iRedAdmin-Pro-LDAP-5.0/libs/ldaplib/decorators.py", line 130, in proxyfunc
    return func(*args, **kw)
  File "/opt/www/iRedAdmin-Pro-LDAP-5.0/controllers/ldap/api_user.py", line 201, in PUT
    return api_render(qr)
  File "/opt/www/iRedAdmin-Pro-LDAP-5.0/controllers/utils.py", line 65, in api_render
    return _render_json(d)
UnboundLocalError: local variable 'd' referenced before assignment

127.0.0.1:59322 - - [13/Dec/2021 12:13:50] "HTTP/1.1 PUT /api/user/ldap-iredmail11102021-test@pbs.edu.pl" - 500 Internal Server Error

17

Re: Adding alias to user cause Internal Error Server

Seems updating user profile failed and returns invalid data.
Here's patch to fix it:

diff --git a/controllers/utils.py b/controllers/utils.py
index cc490127..8a76d810 100644
--- a/controllers/utils.py
+++ b/controllers/utils.py
@@ -61,5 +61,7 @@ def api_render(data):
 
     elif isinstance(data, bool):
         d = {"_success": data}
+    else:
+        d = {"_success": False, "_msg": repr(data)}
 
     return _render_json(d)