|
6 | 6 | class databaseConnector |
7 | 7 | { |
8 | 8 | private $serverName; |
| 9 | + private $port; |
9 | 10 | private $username; |
10 | 11 | private $password; |
11 | 12 | private $databaseName; |
12 | 13 | private $identityProvidersTableName; |
13 | 14 | private $serviceProvidersTableName; |
| 15 | + private $encryption; |
| 16 | + private $sslCA; |
| 17 | + private $sslCert; |
| 18 | + private $sslKey; |
| 19 | + private $sslCAPath; |
14 | 20 |
|
15 | 21 | const CONFIG_FILE_NAME = 'module_statisticsproxy.php'; |
16 | 22 | const SERVER = 'serverName'; |
| 23 | + const PORT = 'port'; |
17 | 24 | const USER = 'userName'; |
18 | 25 | const PASSWORD = 'password'; |
19 | 26 | const DATABASE = 'databaseName'; |
20 | 27 | const IDP_TABLE_NAME = 'identityProvidersTableName'; |
21 | 28 | const SP_TABLE_NAME = 'serviceProvidersTableName' ; |
| 29 | + const ENCRYPTION = 'encryption'; |
| 30 | + const SSL_CA = 'ssl_ca'; |
| 31 | + const SSL_CERT = 'ssl_cert_path'; |
| 32 | + const SSL_KEY = 'ssl_key_path'; |
| 33 | + const SSL_CA_PATH = 'ssl_ca_path'; |
22 | 34 |
|
23 | 35 |
|
24 | 36 |
|
25 | 37 | public function __construct () |
26 | 38 | { |
27 | 39 | $conf = SimpleSAML_Configuration::getConfig(self::CONFIG_FILE_NAME); |
28 | 40 | $this->serverName = $conf->getString(self::SERVER); |
| 41 | + $this->port = $conf->getInteger(self::PORT, null); |
29 | 42 | $this->username = $conf->getString(self::USER); |
30 | 43 | $this->password = $conf->getString(self::PASSWORD); |
31 | 44 | $this->databaseName = $conf->getString(self::DATABASE); |
32 | 45 | $this->identityProvidersTableName = $conf->getString(self::IDP_TABLE_NAME); |
33 | 46 | $this->serviceProvidersTableName = $conf->getString(self::SP_TABLE_NAME); |
| 47 | + $this->encryption = $conf->getBoolean(self::ENCRYPTION); |
| 48 | + $this->sslCA = $conf->getString(self::SSL_CA); |
| 49 | + $this->sslCert = $conf->getString(self::SSL_CERT); |
| 50 | + $this->sslKey = $conf->getString(self::SSL_KEY); |
| 51 | + $this->sslCAPath = $conf->getString(self::SSL_CA_PATH); |
34 | 52 | } |
35 | 53 |
|
36 | 54 | public function getConnection() |
37 | 55 | { |
38 | | - $conn = NULL; |
39 | | - $conn = new mysqli($this->serverName, $this->username, $this->password, $this->databaseName); |
| 56 | + $conn = mysqli_init(); |
| 57 | + if ($this->encryption ===true){ |
| 58 | + SimpleSAML_Logger::debug("Getting connection with encryption."); |
| 59 | + mysqli_ssl_set($conn, $this->sslKey,$this->sslCert, $this->sslCA, $this->sslCAPath, null); |
| 60 | + if ($this->port === null){ |
| 61 | + mysqli_real_connect($conn, $this->serverName, $this->username, $this->password, $this->databaseName); |
| 62 | + } else{ |
| 63 | + mysqli_real_connect($conn, $this->serverName, $this->username, $this->password, $this->databaseName, $this->port ); |
| 64 | + } |
| 65 | + } |
| 66 | + else{ |
| 67 | + if ($this->port === null){ |
| 68 | + mysqli_real_connect($conn, $this->serverName, $this->username, $this->password, $this->databaseName); |
| 69 | + } else{ |
| 70 | + mysqli_real_connect($conn, $this->serverName, $this->username, $this->password, $this->databaseName, $this->port ); |
| 71 | + } |
| 72 | + } |
40 | 73 | return $conn; |
41 | 74 | } |
42 | 75 |
|
|
0 commit comments