forked from MiguelAxcar/PHP-MSSQL-Server-Admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfiguration.php
executable file
·169 lines (128 loc) · 5.06 KB
/
Configuration.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
ini_set('display_errors', 1);
include ('common.header.php');
include ('common.topmenu.php');
include ('common.library.php');
if (!empty ($_POST['save'])) {
$db_hostname = $_POST['db_hostname'];
$port = $_POST['port'];
$db_name = $_POST['db_name'];
$username = $_POST['username'];
$password = $_POST['password'];
$data = "<?php\n/*\nPHP Query Analyzer\n\nGenerated by Configuration.php\non ".date('r')."\n*/\n\n\$db_hostname='{$_POST['db_hostname']}';\n\$port={$_POST['port']};\n\$db_name='{$_POST['db_name']}';\n\$username='{$_POST['username']}';\n\$password='{$_POST['password']}';\n\n?>";
$handle = @fopen('db.vars.php', "w+");
@fwrite($handle, $data);
@fclose($handle);
}
include ('db.vars.php');
echo "<div id='content'>";
if (! is_writable('db.vars.php')) {
echo "
<div id='primaryContentContainer' style='float:left; padding:20px;'>
<div id='primaryContent'>
<p>
<h3>Need to change some file permissions</h3>
<blockquote style='color: red; border-left: solid 0.75em #FF0000;'>
The files <b>db.vars.php</b> and <b>php-query-analyzer-t*</b> need to be writable.<br>
<br/>
<b>Try:</b><br/>
$ chmod 666 db.vars.php php-query-analyzer-t*
</blockquote>
</p>
</div>
</div>
<div class='clear'></div></div>";
include ('common.footer.php');
echo "</div>";
echo "</body></html>";
exit();
} elseif (! function_exists('mssql_connect')) {
echo "
<div id='primaryContentContainer' style='float:left; padding:20px;'>
<div id='primaryContent'>
<p>
<h3>Some drivers needed</h3>
<blockquote style='color: red; border-left: solid 0.75em #FF0000;'>
Your machine doesn't support to connect to MSSQL Servers.<br>
Please take a look on this article <a href='https://davejamesmiller.com/blog/connecting-php-to-microsoft-sql-server-on-linux'>Connecting PHP to Microsoft SQL Server on Linux</a>.
</blockquote>
</p>
</div>
</div>
<div class='clear'></div></div>";
include ('common.footer.php');
echo "</div>";
echo "</body></html>";
exit();
} else {
echo "
<div id='secondaryContent'>
<h3>Database Information</h3>
<form method='post'>
<ul>
<li>DB hostname<br><input type='text' name='db_hostname' value='$db_hostname'></li><br>
<li>Port<br><input type='text' name='port' value='$port'></li><br>
<li>Username<br><input type='text' name='username' value='$username'></li><br>
<li>Password<br><input type='password' name='password' value='$password'></li><br>";
echo "<li>DB name<br>";
if ($db_hostname && $username && $db_name) {
$_CONEXAO = mssql_connect ("$db_hostname", $username, $password);
mssql_select_db ($db_name, $_CONEXAO);
if ($_CONEXAO)
{
echo "<select name='db_name'>";
$query = "sp_databases";
$resultado = mssql_query($query, $_CONEXAO);
while ($campo = mssql_fetch_array ($resultado, MSSQL_ASSOC))
{
$banco = $campo['DATABASE_NAME'];
echo "<option value='$banco'".((strtolower($banco) == strtolower($db_name)) ? "selected" : "").">$banco</option>";
}
echo "</select>";
}
}
else
{
echo "<input type='text' name='db_name' value='$db_name'>";
}
echo "</li><br>";
echo "<div align='center'><input type='submit' value='Save' name='save'></div>
</ul>
</form>
<div class='xbg'></div>
</div>
";
echo "<div id='primaryContentContainer'><div id='primaryContent'>";
echo "<p><br>";
echo "<h3>Trying to connect on hostname $db_hostname port $port</h3>";
$fp = @fsockopen($db_hostname, $port, $errno, $errstr, 5);
if (!$fp) {
echo "<blockquote style='color: red; border-left: solid 0.75em #FF0000;'>$errstr ($errno)</blockquote>";
} else {
echo "<blockquote style='color: green'>Connection sucessful at <b>$db_hostname:$port</b></blockquote><br>";
echo "<h3>Testing db connection to string <b>$username:".str_repeat("*", strlen($password))."@$db_hostname:$port</b></h3>";
if ( ! ($_CONEXAO = @mssql_connect ("$db_hostname", $username, $password) ) ) {
echo "<blockquote style='color: red; border-left: solid 0.75em #FF0000;'>";
echo "Error on connection, string=[$username:".str_repeat("*", strlen($password))."->$db_name@$db_hostname:$port]. MSSQL return:<br>";
echo mssql_get_last_message();
echo "</blockquote>";
} elseif ( ! ( @mssql_select_db ($db_name, $_CONEXAO) ) ) {
echo "<blockquote style='color: red; border-left: solid 0.75em #FF0000;'>";
echo "Error selecting db <b></b>, string=[$username:".str_repeat("*", strlen($password))."->$db_name@$db_hostname:$port]. MSSQL return:<br>";
echo mssql_get_last_message();
echo "</blockquote>";
} else {
echo "<blockquote style='color: green'><span style='font-color: green'>Connection sucessful at <b>$username:$password@$db_hostname:$port</b></span></blockquote><br><br>";
}
}
}
echo "</p>";
echo "</div></div>";
echo "<div class='clear'></div>";
//closing div id='content'
echo "</div>";
include ('common.footer.php');
//closing div id=outer
echo "</div>";
echo "</body></html>";
?>