-
Notifications
You must be signed in to change notification settings - Fork 38
/
config.php
150 lines (140 loc) · 5.72 KB
/
config.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
<?php
$menu_main = 'setup';
$menu_sub = 'config';
include_once ('php-inc/settings.php');
include_once ('php-inc/header.php');
?>
<!-- **********************************************************************************************************************************************************
MAIN CONTENT
*********************************************************************************************************************************************************** -->
<!--main content start-->
<section id="main-content">
<section class="wrapper">
<h3><i class="fa fa-angle-right"></i> Create Database Configuration File</h3>
<!-- BASIC FORM ELELEMNTS -->
<div class="row mt">
<div class="col-lg-12">
<?php
$dbcreds_path = "sql-connections/db-creds.inc";
if (file_exists($dbcreds_path) && !isset($_POST['db_name']) && !isset($_POST['db_username'])) {
?>
<div class="alert alert-danger">
<b>Wait!</b> Your Configuration file is already present. Please check out the file at <b><?php echo dirname(__FILE__) . "/sql-connections". DIRECTORY_SEPARATOR ?>db-creds.inc</b>
</div>
<?php
}
elseif(isset($_POST['db_name']) && isset($_POST['db_username'])) {
$db_name = $_POST['db_name'];
$db_username = $_POST['db_username'];
$db_password = isset($_POST['db_password'])?$_POST['db_password']:'';
$db_cred_str = "<?php\n\n";
$db_cred_str .= "\$db_username = '$db_username';\n";
$db_cred_str .= "\$db_password = '$db_password';\n";
$db_cred_str .= "\$host = 'localhost';\n";
$db_cred_str .= "\$dbname = '$db_name';\n\n";
$db_cred_str .= "?>\n";
$fp=fopen(dirname(__FILE__) . DIRECTORY_SEPARATOR . "sql-connections". DIRECTORY_SEPARATOR . "db-creds.inc","w");
$fw = fwrite($fp,$db_cred_str."\n");
fclose($fp);
if($fw) {
?>
<div class="alert alert-success">
Your Configuration file has been created. You can check out the file at <b><?php echo dirname(__FILE__) . "sql-credentials". DIRECTORY_SEPARATOR ?>db-creds.inc</b>
</div>
<?php
}
}
?>
<div class="form-panel">
<h4 class="mb"><i class="fa fa-angle-right"></i> Enter Your Database Connection Details</h4>
<form class="form-horizontal style-form" method="post" action="config.php">
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label">Database Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="db_name">
<span class="help-block">Enter the database name the application will connect to.</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label">Database Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="db_username">
<span class="help-block">Enter the database username for your database.</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label">Database Password</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="db_password">
<span class="help-block">Enter your database password.</span>
</div>
</div>
<p>
<center>
A configuration file will be created with your details provided abaove.
</center>
</p>
<center>
<input type="submit" class="btn btn-theme" value="Create File" />
</center>
</form>
</div>
</div><!-- col-lg-12-->
</div><!-- /row -->
<!-- BASIC FORM ELELEMNTS -->
<div class="row mt">
<div class="col-lg-12">
<?php
$settings_path = "php-inc/settings.php";
if (file_exists($settings_path) && !isset($_POST['settings_path'])) {
?>
<div class="alert alert-danger">
<b>Wait!</b> Your Settings file is already present. Please check out the file at <b><?php echo dirname(__FILE__) . "php-inc". DIRECTORY_SEPARATOR ?>settings.php</b>
</div>
<?php
}
elseif(isset($_POST['settings_path'])) {
$settings_path = $_POST['settings_path'];
$settings_path_str = "<?php\n\n";
$settings_path_str .= "define('WEBROOT', '$settings_path');\n\n";
$settings_path_str .= "?>\n";
$fp=fopen(dirname(__FILE__) . DIRECTORY_SEPARATOR . "php-inc". DIRECTORY_SEPARATOR . "settings.php","w");
$fw = fwrite($fp,$settings_path_str."\n");
fclose($fp);
if($fw) {
?>
<div class="alert alert-success">
Your Configuration file has been created. You can check out the file at <b><?php echo dirname(__FILE__) . "php-inc". DIRECTORY_SEPARATOR ?>settings.php</b>
</div>
<?php
}
}
?>
<div class="form-panel">
<h4 class="mb"><i class="fa fa-angle-right"></i> Enter Your Web Root Path</h4>
<form class="form-horizontal style-form" method="post" action="config.php">
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label">Database Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="settings_path" placeholder="http://localhost/sqlilabs/" />
<span class="help-block">Enter the path where you have installed the application. Please always put a slash at the end.</span>
</div>
</div>
<p>
<center>
A settings file will be created with your details provided abaove.
</center>
</p>
<center>
<input type="submit" class="btn btn-theme" value="Create File" />
</center>
</form>
</div>
</div><!-- col-lg-12-->
</div><!-- /row -->
</section><!--/wrapper -->
</section><!-- /MAIN CONTENT -->
<!--main content end-->
<?php
include_once ('php-inc/footer.php');
?>