ispCP - Board - Support
[Shell] Decrypt Mailpasswords - Printable Version

+- ispCP - Board - Support (http://www.isp-control.net/forum)
+-- Forum: ispCP Omega Contributions Area (/forum-40.html)
+--- Forum: Snippets (/forum-42.html)
+--- Thread: [Shell] Decrypt Mailpasswords (/thread-5495.html)

Pages: 1 2


[Shell] Decrypt Mailpasswords - Knut - 01-21-2009 03:59 AM

In some cases, I need the decrypted password of a user's mail.
To make it easier for me, I have written a small php-shell-script.

Here we go:
(of course you need php-cli)

1. Save this code over here -> /root/bin
PHP Code:
#!/usr/bin/php -q

<?php

## Autor: Knut Herter
## Datum: 06.10.2009
## Web  : http://www.systemtechnics.de
##
## Usage: decrypt_mailpw.php |grep whatever_you_want
##
## Example: decrypt_mailpw.php |grep admin


###
# FIRST CHANGE THIS VALUES !
###

$SQLHST  "localhost";
$SQLUSR  "root";
$ISPCPDB "ispcp";

# if error_reporting on, you see some session errors at cli
error_reporting(0);

#################################
#### Do not change from here ####

echo "MySQL password for $SQLUSR@$SQLHST: ";
system('stty -echo');
$SQLPW trim(fgets(STDIN));
system('stty echo'); 

$QUERY "
        SELECT  `mail_users`.mail_acc,
                `mail_users`.mail_pass,
                `domain`.domain_name

        FROM    `domain`

        INNER JOIN `mail_users` ON (`mail_users`.domain_id = `domain`.domain_id)

        WHERE   `mail_type` LIKE 'normal_mail' OR `mail_type` LIKE 'normal_mail,normal_forward'"
;

require 
'/var/www/ispcp/gui/include/ispcp-lib.php';

$link mysql_connect$SQLHST$SQLUSR$SQLPW);
if (!
$link) {
    die(
'keine Verbindung möglich: ' mysql_error());
}

mysql_select_db$ISPCPDB$link) or die('Could not select database.');

$result mysql_query($QUERY);
if (!
$result) {
    die(
'Ungültige Abfrage: ' mysql_error());
}

$FORMAT "Domain MailAdr: [ %s@%s ] Passwort: [ %s ]\n";
while (
$row mysql_fetch_row($result)) {
    
printf $FORMAT$row[0], $row[2],  decrypt_db_password ($row[1]));
}
printf ("\n");

mysql_close($link);

####### DOMAINALIASE

$QUERY "
        SELECT  `mail_users`.mail_acc,
                `mail_users`.mail_pass,
                `domain_aliasses`.alias_name

        FROM    `domain_aliasses`

        INNER JOIN `mail_users` ON (`mail_users`.sub_id = `domain_aliasses`.alias_id)

        WHERE   `mail_type` LIKE 'alias_mail' OR `mail_type` LIKE 'alias_mail,alias_forward'"
;



$link mysql_connect$SQLHST$SQLUSR$SQLPW);
if (!
$link) {
    die(
'keine Verbindung möglich: ' mysql_error());
}

mysql_select_db$ISPCPDB$link) or die('Could not select database.');

$result mysql_query($QUERY);
if (!
$result) {
    die(
'Ungültige Abfrage: ' mysql_error());
}


$FORMAT "Aliasdomain MailAdr: [ %s@%s ] Passwort: [ %s ]\n";
while (
$row mysql_fetch_row($result)) {
    
printf $FORMAT$row[0], $row[2],  decrypt_db_password ($row[1]));
}
printf ("\n");

mysql_close($link); 

2. make it executable
Code:
chmod +x /root/bin/decrypt_mailpw.php

3. run :-)

4. If you want a special mailpassword, run with grep
example:
Code:
decrypt_mailpw.php |grep webmaster
or
Code:
decrypt_mailpw.php |grep mydomain.de



RE: [Shell] Decrypt Mailpasswords - fulltilt - 01-23-2009 04:54 PM

(01-21-2009 03:59 AM)Knut Wrote:  In some cases, I need the decrypted password of a user's mail.
To make it easier for me, I have written a small php-shell-script.

thanks - very nice :-)


RE: [Shell] Decrypt Mailpasswords - Kotty - 01-26-2009 05:22 PM

Hi,

that
WHERE `mail_type` LIKE 'normal_mail'";
should be,
WHERE `mail_type` = 'normal_mail' OR mail_type = 'normal_mail,normal_forward'";


RE: [Shell] Decrypt Mailpasswords - Knut - 01-26-2009 05:28 PM

Yes you're right.
I've changed


RE: [Shell] Decrypt Mailpasswords - freinhard - 04-17-2009 07:33 PM

since i dont like hardcoded passwords:

PHP Code:
echo "MySQL password for $SQLUSER@$SQLHST: ";
system('stty -echo');
$SQLPW trim(fgets(STDIN));
system('stty echo'); 



RE: [Shell] Decrypt Mailpasswords - Knut - 04-17-2009 07:42 PM

OK, it's changed above.

Thx


RE: [Shell] Decrypt Mailpasswords - Knut - 10-06-2009 05:11 PM

EDIT: Domain Alias enhancement, update at first Post


RE: [Shell] Decrypt Mailpasswords - gOOvER - 10-06-2009 05:15 PM

I will add it to the Wiki tonight, so you only have to change it there. Smile


RE: [Shell] Decrypt Mailpasswords - elitepilot - 10-25-2009 12:10 AM

how long does the script work?


RE: [Shell] Decrypt Mailpasswords - rethus - 12-04-2010 11:20 AM

Hi Knut,
nice that you post your scripts. And i see your other nice scripts for munin. Maybe i give them a try, if i setup munin soon.

But watch out with German Law. Im Germany it's didn't allow to decrypt user passwords without their agreement - even if its in on your own Server, or in your own application.
Nevertheless, its a nice script, maybe to create an automated email-password-reminder.