|
26 | 26 | from loginSystem.models import Administrator |
27 | 27 | from plogical.processUtilities import ProcessUtilities |
28 | 28 | import bcrypt |
| 29 | +from websiteFunctions.models import Websites |
29 | 30 |
|
30 | 31 | class MailServerManager: |
31 | 32 |
|
@@ -355,24 +356,19 @@ def submitForwardDeletion(self): |
355 | 356 |
|
356 | 357 | ## Delete Email PIPE |
357 | 358 | sourceusername = source.split("@")[0] |
358 | | - virtualalias = '%s %salias' % (source, sourceusername) |
359 | | - pipealias = '%salias: "|%s"' % (sourceusername, destination) |
360 | | - command = "sed -i 's/^" + source + ".*//g' /etc/postfix/virtual" |
| 359 | + virtualfilter = '%s FILTER %spipe:dummy' % (source, sourceusername) |
| 360 | + command = "sed -i 's/^" + source + ".*//g' /etc/postfix/script_filter" |
361 | 361 | ProcessUtilities.executioner(command) |
362 | | - command = "sed -i 's/^" + sourceusername + ".*//g' /etc/aliases" |
| 362 | + command = "sed -i 's/^" + sourceusername + "pipe.*//g' /etc/postfix/master.cf" |
363 | 363 | ProcessUtilities.executioner(command) |
364 | 364 |
|
365 | | - #### Restarting Postfix and newalias |
366 | | - |
367 | | - command = "postmap /etc/postfix/virtual" |
| 365 | + #### Hashing filter Reloading Postfix |
| 366 | + command = "postmap /etc/postfix/script_filter" |
368 | 367 | ProcessUtilities.executioner(command) |
369 | | - |
370 | | - command = "systemctl restart postfix" |
| 368 | + command = "postfix reload" |
371 | 369 | ProcessUtilities.executioner(command) |
372 | 370 | ## |
373 | 371 |
|
374 | | - command = "newaliases" |
375 | | - ProcessUtilities.executioner(command) |
376 | 372 |
|
377 | 373 | data_ret = {'status': 1, 'deleteForwardingStatus': 1, 'error_message': "None", |
378 | 374 | 'successMessage': 'Successfully deleted!'} |
@@ -421,29 +417,35 @@ def submitEmailForwardingCreation(self): |
421 | 417 | forwarding = Pipeprograms(source=source, destination=destination) |
422 | 418 | forwarding.save() |
423 | 419 |
|
424 | | - ## Create Email PIPE |
425 | | - ## example@domain.com examplealias |
| 420 | + ## Create Email PIPE filter |
| 421 | + ## example@domain.com FILTER support:dummy |
426 | 422 | sourceusername = source.split("@")[0] |
427 | | - virtualalias = '%s %salias' % (source, sourceusername) |
428 | | - command = "echo '" + virtualalias + "' >> /etc/postfix/virtual" |
| 423 | + virtualfilter = '%s FILTER %spipe:dummy' % (source, sourceusername) |
| 424 | + command = "echo '" + virtualfilter + "' >> /etc/postfix/script_filter" |
429 | 425 | ProcessUtilities.executioner(command) |
430 | 426 |
|
431 | | - ## examplealias: "|/usr/bin/php -q /home/domain.com/public_html/ticket/api/pipe.php" |
432 | | - pipealias = '%salias: "|%s"' % (sourceusername, destination) |
433 | | - command = "echo '" + pipealias + "' >> /etc/aliases" |
| 427 | + ## support unix - n n - - pipe flags=Rq user=domain argv=/usr/bin/php -q /home/domain.com/public_html/ticket/api/pipe.php |
| 428 | + ## Find Unix file owner of provided pipe |
| 429 | + domainName = source.split("@")[1] |
| 430 | + website = Websites.objects.get(domain=domainName) |
| 431 | + externalApp = website.externalApp |
| 432 | + pipeowner = externalApp |
| 433 | + ## Add Filter pipe to postfix /etc/postfix/master.cf |
| 434 | + filterpipe = '%spipe unix - n n - - pipe flags=Rq user=%s argv=%s -f $(sender) -- $(recipient)' % (sourceusername, pipeowner, destination) |
| 435 | + command = "echo '" + filterpipe + "' >> /etc/postfix/master.cf" |
434 | 436 | ProcessUtilities.executioner(command) |
435 | | - |
436 | | - #### Restarting Postfix and newalias |
437 | | - |
438 | | - command = "postmap /etc/postfix/virtual" |
| 437 | + ## Add Check Recipient Hash to postfix /etc/postfix/main.cf |
| 438 | + command = "sed -i 's|^smtpd_recipient_restrictions =.*|smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, check_recipient_access hash:/etc/postfix/script_filter, permit|' /etc/postfix/main.cf" |
439 | 439 | ProcessUtilities.executioner(command) |
440 | 440 |
|
441 | | - command = "systemctl restart postfix" |
| 441 | + #### Hashing filter Reloading Postfix |
| 442 | + command = "postmap /etc/postfix/script_filter" |
| 443 | + ProcessUtilities.executioner(command) |
| 444 | + command = "postfix reload" |
442 | 445 | ProcessUtilities.executioner(command) |
443 | 446 | ## |
444 | 447 |
|
445 | | - command = "newaliases" |
446 | | - ProcessUtilities.executioner(command) |
| 448 | + |
447 | 449 |
|
448 | 450 | data_ret = {'status': 1, 'createStatus': 1, 'error_message': "None", 'successMessage': 'Successfully Created!'} |
449 | 451 | json_data = json.dumps(data_ret) |
|
0 commit comments