/
change_database.php
executable file
·186 lines (179 loc) · 5.26 KB
/
change_database.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
// 修改数据库信息
if(@ $_POST['dbUser']!='' && $_POST['dbPassword']!='' && $_POST['dbName']!='' && $_POST['emailUser']!='' && $_POST['emailPWD']!='') {
// 接收
$username = $_POST['dbUser'];
$password = $_POST['dbPassword'];
$database = $_POST['dbName'];
$emailUser = $_POST['emailUser'];
$emailPWD = $_POST['emailPWD'];
$jsemail = $_POST['jsemail'];
/** part one **/
// 修改邮箱信息
// user里面
$file_url = 'application/controllers/user.php';
$str = file_get_contents($file_url);
$patter = array(
"/toEmail = '(.*)'/",
"/fromEmail = '(.*)'/"
);
$replace = array(
"toEmail = '{$jsemail}'",
"fromEmail = '{$emailUser}'"
);
$result = preg_replace($patter, $replace, $str);
file_put_contents($file_url, $result);
// config文件里面
$file_url = 'application/config/email.php';
$str = file_get_contents($file_url);
$patter = array(
"/'smtp_user' => '(.*)'/",
"/'smtp_pass' => '(.*)'/"
);
$replace = array(
"'smtp_user' => '{$emailUser}'",
"'smtp_pass' => '{$emailPWD}'"
);
$result = preg_replace($patter, $replace, $str);
file_put_contents($file_url, $result);
/** part two **/
// 修改数据库信息
$file_url = "application/config/database.php"; // 设置文件地址
$str = file_get_contents($file_url); // 读取文件地址
// start 替换字符串
$patter = array(
"/db\['default'\]\['username'\] = '(\w*)'/",
"/db\['default'\]\['password'\] = '(\w*)'/",
"/db\['default'\]\['database'\] = '(\w*)'/"
);
$replace = array(
"db['default']['username'] = '{$username}'",
"db['default']['password'] = '{$password}'",
"db['default']['database'] = '{$database}'"
);
$result = preg_replace($patter, $replace, $str);
// end 替换字符串
file_put_contents($file_url, $result); // 修改文件
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>设置数据库</title>
<style type="text/css">
html,body { margin:0; padding:0; }
.wrapper {
font-family:"微软雅黑";
color:#444;
margin-top:10px;
padding-top:50px;
background:url(/images/index_03.png) center top no-repeat;
}
table {
border-collapse:collapse;
background-color:white;
text-align:left;
border:1px solid #ccc;
box-shadow:5px 5px 10px #888;
}
table td {
padding:10px 10px;
}
input.text {
width:200px;
padding:5px;
}
.field {
font-size:14px;
text-align:right;
font-weight:bold;
}
caption {
font-size:18px;
color:red;
font-weight:bold;
padding-bottom:10px;
padding-top:10px;
border-radius:10px;
margin-bottom:10px;
}
td.bot {
background-color:#eee;
text-align:center;
}
input.btn {
margin:0 10px;
}
.copyright {
font-size:12px;
color:gray;
margin-top:20px;
text-align:center;
}
#db {
border-bottom:1px solid #ccc;
}
#email {
border-top:1px solid #ddd;
}
</style>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<div class="wrapper">
<form method="post">
<table align="center">
<caption>配置系统信息</caption>
<tbody id="db">
<tr>
<td class="field">数据库账号:</td>
<td><input type="text" name="dbUser" class="text" required placeholder="请填写数据库账号" /></td>
<td style="color:red">*</td>
</tr>
<tr>
<td class="field">数据库密码:</td>
<td><input type="password" name="dbPassword" class="text" required placeholder="请填写数据库密码" /></td>
<td style="color:red">*</td>
</tr>
<tr>
<td class="field">数据库名称:</td>
<td><input type="text" name="dbName" class="text" required placeholder="请填写数据库名称" /></td>
<td style="color:red">*</td>
</tr>
</tbody>
<tbody id="email">
<tr>
<td class="field">发送邮箱帐号:</td>
<td><input type="text" name="emailUser" class="text" required placeholder="格式:xxxx@163.com(网易邮箱)"/></td>
<td style="color:red">*</td>
</tr>
<tr>
<td class="field">发送邮箱密码:</td>
<td><input type="password" name="emailPWD" class="text" required placeholder="请填写邮箱密码"/></td>
<td style="color:red">*</td>
</tr>
<tr>
<td class="field">接收邮箱账号:</td>
<td><input type="text" name="jsemail" class="text" required placeholder="格式:xxxx@xxx.xxx"/></td>
<td style="color:red">*</td>
</tr>
</tbody>
<tr>
<td colspan="3" class="bot">
<input type="submit" value="确认提交" class="btn" id="send" />
<input type="reset" value="重新填写" class="btn" />
</td>
</tr>
</table>
</form>
<p class="copyright">Copyright © 2014 PF, All rights reserved.</p>
</div>
<script type="text/javascript">
$('#send').click(function(){
alert("修改完成!若测试成功,为安全起见请手动将此文件change_database.php删除!");
window.open('index.php','数据统计系统首页','_blank');
});
</script>
</body>
</html>