forked from clue/docker-phpvirtualbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservers-from-env.php
45 lines (34 loc) · 1.21 KB
/
servers-from-env.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$servers = array();
echo 'Exposing the following linked server instances:' . PHP_EOL;
foreach ($_SERVER as $key => $value) {
// ends with vboxwebsrv default port
if (substr($key, -15) === '_PORT_18083_TCP') {
// get prefix of key
$prefix = substr($key, 0, -15);
// actual readable name is stored as "/thiscontainer/givencontainer"
$name = getenv($prefix . '_NAME');
$pos = strrpos($name, '/');
if ($pos !== false) {
$name = substr($name, $pos + 1);
}
if (!$name) {
$name = ucfirst(strtolower($prefix));
}
$location = 'http://' . str_replace('tcp://', '', $value) . '/';
echo '- ' . $name . ' (' . $location .')' . PHP_EOL;
$servers []= array(
'name' => $name,
'username' => 'username',
'password' => 'password',
'authMaster' => true,
'location' => $location
);
}
}
if (!$servers) {
echo 'Error: No vboxwebsrv instance linked? Use "--link containername:myname"' . PHP_EOL;
exit(1);
}
$config = '<?php return ' . var_export($servers, true) . ';';
file_put_contents('/var/www/config-servers.php', $config);