-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathload_databases.php
More file actions
60 lines (47 loc) · 1.67 KB
/
load_databases.php
File metadata and controls
60 lines (47 loc) · 1.67 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
echo "Warning. This program will overwrite the current contents of the DURC_XXXX databases\n";
echo "This is a destructive process, and if there is anything custom there (there should not be) then this will overwrite them\n";
$password = prompt_silent();
$databases = [
'DURC_aaa',
'DURC_irs',
'DURC_northwind_data',
'DURC_northwind_model',
];
$commands = [];
foreach($databases as $this_db){
$commands[] = "mysqladmin -f -u root --password=$password drop $this_db";
$commands[] = "mysqladmin -u root --password=$password create $this_db";
$commands[] = "mysql -u root --password=$password $this_db < $this_db.sql";
}
foreach($commands as $this_command){
$safe_print_command = str_replace($password,'*******',$this_command);
echo "Running\n$safe_print_command\n";
system($this_command);
}
//from https://stackoverflow.com/a/1674175/144364
function prompt_silent($prompt = "Enter Password:") {
if (preg_match('/^win/i', PHP_OS)) {
$vbscript = sys_get_temp_dir() . 'prompt_password.vbs';
file_put_contents(
$vbscript, 'wscript.echo(InputBox("'
. addslashes($prompt)
. '", "", "password here"))');
$command = "cscript //nologo " . escapeshellarg($vbscript);
$password = rtrim(shell_exec($command));
unlink($vbscript);
return $password;
} else {
$command = "/usr/bin/env bash -c 'echo OK'";
if (rtrim(shell_exec($command)) !== 'OK') {
trigger_error("Can't invoke bash");
return;
}
$command = "/usr/bin/env bash -c 'read -s -p \""
. addslashes($prompt)
. "\" mypassword && echo \$mypassword'";
$password = rtrim(shell_exec($command));
echo "\n";
return $password;
}
}