root/trunk/gui/include/ispcp-config.php

Revision 1349, 2.8 kB (checked in by scitech, 3 months ago)

Encrypt email password in database. Encrypt sql password in database. Fixed #1535: Wrong error text in user Email creation. Fixed #1396: Wordwrap in ticket system. Fixed #1533 Hardcoded FTP sepparator

Line 
1 <?php
2 /**
3  * ispCP ω (OMEGA) a Virtual Hosting Control System
4  *
5  * @copyright     2001-2006 by moleSoftware GmbH
6  * @copyright     2006-2008 by ispCP | http://isp-control.net
7  * @version     SVN: $Id$
8  * @link         http://isp-control.net
9  * @author         ispCP Team
10  *
11  * @license
12  *   This program is free software; you can redistribute it and/or modify it under
13  *   the terms of the MPL General Public License as published by the Free Software
14  *   Foundation; either version 1.1 of the License, or (at your option) any later
15  *   version.
16  *   You should have received a copy of the MPL Mozilla Public License along with
17  *   this program; if not, write to the Open Source Initiative (OSI)
18  *   http://opensource.org | osi@opensource.org
19  */
20
21 require_once(INCLUDEPATH . '/class.config.php');
22
23 if (@file_exists('/usr/local/etc/ispcp/ispcp.conf')) {
24     $cfgfile = '/usr/local/etc/ispcp/ispcp.conf';
25 }
26 else {
27     $cfgfile = '/etc/ispcp/ispcp.conf';
28 }
29
30 // Load config variables from file
31 try {
32     Config::load($cfgfile);
33 } catch (Exception $e) {
34     die('<div style="text-align: center; color: red; font-weight: strong;">' . $e->getMessage() . '<br />Please contact your system administrator</div>');
35 }
36
37
38 function decrypt_db_password ($db_pass) {
39     global $ispcp_db_pass_key, $ispcp_db_pass_iv;
40
41     if ($db_pass == '')
42         return '';
43
44     if (extension_loaded('mcrypt') || @dl('mcrypt.' . PHP_SHLIB_SUFFIX)) {
45         $text = @base64_decode($db_pass . "\n");
46         // Open the cipher
47         $td = @mcrypt_module_open ('blowfish', '', 'cbc', '');
48         // Create key
49         $key = $ispcp_db_pass_key;
50         // Create the IV and determine the keysize length
51         $iv = $ispcp_db_pass_iv;
52
53         // Intialize encryption
54         @mcrypt_generic_init ($td, $key, $iv);
55         // Decrypt encrypted string
56         $decrypted = @mdecrypt_generic ($td, $text);
57         @mcrypt_module_close ($td);
58
59         // Show string
60         return trim($decrypted);
61     } else {
62         system_message("ERROR: The php-extension 'mcrypt' not loaded!");
63         die();
64     }
65 }
66
67 function encrypt_db_password($db_pass){
68     global $ispcp_db_pass_key, $ispcp_db_pass_iv;
69     
70     if (extension_loaded('mcrypt') || @dl('mcrypt.' . PHP_SHLIB_SUFFIX)) {
71         $td = @mcrypt_module_open (MCRYPT_BLOWFISH, '', 'cbc', '');
72         // Create key
73         $key = $ispcp_db_pass_key;
74         // Create the IV and determine the keysize length
75         $iv = $ispcp_db_pass_iv;
76         
77         //compatibility with used perl pads
78         $block_size=@mcrypt_enc_get_block_size($td);
79         $strlen=strlen($db_pass);
80
81         $pads=$block_size-$strlen % $block_size;
82
83         for ($i=0; $i<$pads;$i++){
84             $db_pass.=" ";
85         }
86         // Intialize encryption
87         @mcrypt_generic_init ($td, $key, $iv);
88         //Encrypt string
89         $encrypted = @mcrypt_generic ($td, $db_pass);
90         @mcrypt_generic_deinit($td);
91         @mcrypt_module_close($td);
92
93         $text = @base64_encode("$encrypted");
94         $text=trim($text);
95         return $text;
96     } else {
97         //system_message("ERROR: The php-extension 'mcrypt' not loaded!");
98         die("ERROR: The php-extension 'mcrypt' not loaded!");
99     }
100 }
101
102 ?>
Note: See TracBrowser for help on using the browser.