commit | author | age
|
77edf6
|
1 |
<?php |
MC |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2014, Till Brehm, projektfarm Gmbh |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
|
36633e
|
32 |
$path = realpath(dirname(__FILE__) . '/..'); |
TB |
33 |
$iface_path = realpath(dirname(__FILE__) . '/../../interface/web'); |
|
34 |
$iface_base_path = realpath(dirname(__FILE__) . '/../../interface'); |
77edf6
|
35 |
|
MC |
36 |
require $path . '/lib/mysql_clientdb.conf'; |
|
37 |
|
|
38 |
if(isset($argv[1])) $dbname = $argv[1]; |
|
39 |
else $dbname = 'dbispconfig'; |
|
40 |
if(!preg_match('/^[a-zA-Z0-9]+$/', $dbname)) die("Invalid database name\n"); |
|
41 |
|
|
42 |
$link = mysqli_init(); |
|
43 |
$con = mysqli_real_connect($link, $clientdb_host, $clientdb_user, $clientdb_password, $dbname); |
|
44 |
if(!$con) die('DB CON ERROR' . "\n"); |
|
45 |
|
|
46 |
$qry = "SELECT username, passwort FROM sys_user WHERE active = '1'"; |
|
47 |
$result = mysqli_query($link, $qry); |
|
48 |
if(!$result) die('Could not read users' . "\n"); |
|
49 |
|
|
50 |
$cont = ''; |
|
51 |
while($row = mysqli_fetch_assoc($result)) { |
|
52 |
$cont .= $row['username'] . ':' . $row['passwort'] . "\n"; |
|
53 |
} |
|
54 |
mysqli_free_result($result); |
|
55 |
mysqli_close($link); |
|
56 |
|
|
57 |
if($cont == '') die('No users found' . "\n"); |
|
58 |
|
36633e
|
59 |
if(file_exists($iface_base_path . '/.htpasswd')) rename($iface_base_path . '/.htpasswd', $iface_base_path . '/.htpasswd.old'); |
TB |
60 |
file_put_contents($iface_base_path . '/.htpasswd', $cont); |
|
61 |
chmod($iface_base_path . '/.htpasswd', 0644); |
77edf6
|
62 |
|
MC |
63 |
$cont = 'AuthType Basic |
|
64 |
AuthName "Login" |
36633e
|
65 |
AuthUserFile ' . $iface_base_path . '/.htpasswd |
77edf6
|
66 |
require valid-user'; |
MC |
67 |
|
|
68 |
if(file_exists($iface_path . '/.htaccess')) rename($iface_path . '/.htaccess', $iface_path . '/.htaccess.old'); |
|
69 |
file_put_contents($iface_path . '/.htaccess', $cont); |
|
70 |
chmod($iface_path . '/.htaccess', 0644); |
|
71 |
unset($cont); |
|
72 |
|
|
73 |
print 'Data written. Please check, if everything is working correctly.' . "\n"; |
|
74 |
exit; |
|
75 |
|
|
76 |
?> |