Alternc  3.2
Alternc logiel libre pour l'h├ębergement
 All Data Structures Namespaces Files Functions Variables Pages
3.1.0~b.php
Go to the documentation of this file.
1 #!/usr/bin/php
2 <?php
3 
4 // We check that mysql php module is loaded
5 if(!function_exists('mysql_connect')) {
6  if(!dl("mysql.so"))
7  exit(1);
8 }
9 
10 // we don't check our AlternC session
11 if(!chdir("/usr/share/alternc/panel"))
12 exit(1);
13 require("/usr/share/alternc/panel/class/config_nochk.php");
14 
15 
16 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17 // FIRST PART : populate the table db_servers
18 
19 
20 # Use the dbusers file if exist, else use default alternc configuration
21 if ( is_readable("/etc/alternc/dbusers.cnf") ) {
22  $mysqlconf=file_get_contents("/etc/alternc/dbusers.cnf");
23 } else {
24  $mysqlconf=file_get_contents("/etc/alternc/my.cnf");
25 }
26 $mysqlconf=explode("\n",$mysqlconf);
27 
28 # Read the configuration
29 foreach ($mysqlconf as $line) {
30 # First, read the "standard" configuration
31  if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) {
32  switch ($regs[1]) {
33  case "user":
34  $user = $regs[2];
35  break;
36  case "password":
37  $password = $regs[2];
38  break;
39  case "host":
40  $host = $regs[2];
41  break;
42  }
43  }
44 # Then, read specific alternc configuration
45  if (preg_match('/^#alternc_var ([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) {
46  $$regs[1]=$regs[2];
47  }
48 }
49 
50 # Set value of human_host if unset
51 if (! isset($human_hostname) || empty($human_hostname)) {
52  if ( checkip($host) || checkipv6($host) ) {
53  $human_hostname = gethostbyaddr($host);
54  } else {
55  $human_hostname = $host;
56  }
57 }
58 
59 // populate it if there is not entry
60 $db->query("select * from db_servers;");
61 if ($db->num_rows()==0) {
62  $db->query(" insert into db_servers (name, host, login, password, client) values ('".mysql_escape_string($human_hostname)."','".mysql_escape_string($host)."','".mysql_escape_string($user)."','".mysql_escape_string($password)."','".mysql_escape_string($L_MYSQL_CLIENT)."');");
63 }
64 
65 // set the membres.db_server_id
66 $db->query(" update membres set db_server_id = (select max(id) from db_servers) where db_server_id is null ;");
67 
68 // END of db_servers part
69 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
70 
71 ?>