-
Notifications
You must be signed in to change notification settings - Fork 3
/
AmpOneManager.hta
322 lines (266 loc) · 11.6 KB
/
AmpOneManager.hta
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<html>
<head>
<title>AmpOne Manager V1.0 - 极简轻量Win平台PHP整合开发环境</title>
<HTA:APPLICATION
ID=AmpOne
APPLICATIONNAME=AmpOne
ICON=material/logo.ico
SINGLEINSTANCE=YES
CAPTION=YES
SYSMENU=YES
MINIMIZEBUTTON=YES
MAXIMIZEBUTTON=NO
SELECTION=NO
WINDOWSTATE=NORMAL
BORDER=THIN
SCROLL=NO
>
<style>
body {background-color: #cccccc}
body,input {font-family:"MicrosoftYaHei"; font-size:14px;}
input {padding: 0px;}
a {text-decoration:none; color: blue;}
</style>
<script language="VBScript">
btDefaultColor = ""
btRunningColor = "#EA735D"
LogFile = "AmpOne.log"
services= array("Apache", "MySQL")
apacheStartValue = "启动Apache"
apacheStopValue = "关闭Apache"
mysqlStartValue = "启动Mysql"
mysqlStopValue = "关闭MySQL"
apacheMenus =array(apacheStartValue, apacheStopValue)
mysqlMenus = array(mysqlStartValue, mysqlStopValue)
Dim mysqlBtObj
Dim apacheBtObj
Dim WshShell
Dim apacheRunning
Dim mysqlRunning
Dim flushing
Dim sCurPath
Sub System_Init
window.resizeTo 600, 340
Set WshShell = CreateObject("WScript.Shell")
sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
Init_Conf
Service_Refresh
End Sub
Sub Disable_Ctr_Button
Set nodes = document.getElementsByTagName("input")
For Each Elem In nodes
If (Elem.className = "ctr") Then
Elem.disabled = True
End If
Next
End Sub
Sub Enable_Ctr_Button
Set nodes = document.getElementsByTagName("input")
For Each Elem In nodes
If (Elem.className = "ctr") Then
Elem.disabled = False
End If
Next
End Sub
Sub Service_Refresh
Disable_Ctr_Button
set mysqlBtObj = document.form.startmysql
set apacheBtObj = document.form.startapache
document.form.servicelist.innerHTML = ""
For Each service In services
If service = "MySQL" Then
set btObj = mysqlBtObj
btMenu = mysqlMenus
ElseIf service = "Apache" Then
set btObj = apacheBtObj
btMenu = apacheMenus
End If
If Check_Service_Running("AmpOne" & service) Then
btObj.value = btMenu(1)
btObj.style.backgroundColor = btRunningColor
set opt = document.createElement("option")
opt.style.backgroundColor = "green"
opt.style.color = "white"
opt.innerHTML = "√ " & service & " 运行中..."
document.form.servicelist.appendChild(opt)
Else
btObj.value = btMenu(0)
btObj.style.backgroundColor = ""
set opt = document.createElement("option")
opt.style.color = "grey"
opt.innerHTML = "X " & service & " 未启动"
document.form.servicelist.appendChild(opt)
End If
Next
Enable_Ctr_Button
End Sub
Function Check_Service_Running(serviceName)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set RunningServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name='" & serviceName & "'")
For Each objService In RunningServices
state = objService.state
Next
Check_Service_Running = False
If (state = "Running") Then
Check_Service_Running = True
End If
End Function
Sub Ctr_Mysql
BtValue = mysqlBtObj.value
mysqlBtObj.style.backgroundColor = ""
If BtValue <> mysqlStopValue Then
mysqlBtObj.value = "MySQL启动中..."
mysqlOpt = "start"
errText = "MySQL启动失败,请查看Mysql错误日志了解更多"
Else
mysqlBtObj.value = "MySQL关闭中..."
mysqlOpt = "stop"
errText = "MySQL关闭异常,请查看Mysql错误日志了解更多"
End If
Disable_Ctr_Button
rc = WshShell.Run("bin\start-mysql.bat " & mysqlOpt, 0, True)
Enable_Ctr_Button
If rc <> 0 Then
MsgBox errText
End If
Service_Refresh
End Sub
Sub Ctr_Apache
BtValue = apacheBtObj.value
apacheBtObj.style.backgroundColor = ""
If BtValue <> apacheStopValue Then
apacheBtObj.value = "Apache启动中..."
apacheOpt = "start"
errText = "Apache启动失败,请查看Apache错误日志了解更多"
Else
apacheBtObj.value = "Apache关闭中..."
apacheOpt = "stop"
errText = "Apache关闭异常,请查看Apache错误日志了解更多"
End If
Disable_Ctr_Button
rc = WshShell.Run("bin\start-apache.bat " & apacheOpt, 0, True)
Enable_Ctr_Button
If rc <> 0 Then
MsgBox errText
End If
Service_Refresh
End Sub
Sub Init_Conf
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("apps\Apache24\conf\httpd.conf", 1)
confText = objFile.ReadAll
objFile.Close
newConfText = Replace(confText, "%serverroot%", sCurPath & "\apps\Apache24")
newConfText = Replace(newConfText, "%documentroot%", sCurPath & "\www")
newConfText = Replace(newConfText, "%php7_module%", "php7_module " & sCurPath & "\apps\php\php7apache2_4.dll")
newConfText = Replace(newConfText, "%phpinidir%", sCurPath & "\apps\php")
Set objFile = objFSO.OpenTextFile("apps\Apache24\conf\httpd.conf", 2)
objFile.WriteLine newConfText
objFile.Close
Set objFile = objFSO.OpenTextFile("apps\mysql-5.7.17\my.ini", 1)
confText = objFile.ReadAll
objFile.Close
newConfText = Replace(confText, "%basedir%", sCurPath & "\apps\mysql-5.7.17")
newConfText = Replace(newConfText, "%datadir%", sCurPath & "\apps\mysql-5.7.17\data")
newConfText = Replace(newConfText, "%errorlog%", sCurPath & "\apps\mysql-5.7.17\mysql_error.log")
Set objFile = objFSO.OpenTextFile("apps\mysql-5.7.17\my.ini", 2)
objFile.WriteLine newConfText
objFile.Close
End Sub
Sub show_info
MsgBox "[AmpOne V1.0]" & vbCrLf & vbCrLf & "Author: Jimmy" & vbCrLf & "Email: 278636108@qq.com" & vbCrLf & "Released: 2017.06.08" & vbCrLf & "Copyright © 2017", 64, "About"
End Sub
Sub Open_Home
WshShell.Run "http://localhost"
End Sub
Sub Open_PMD
WshShell.Run "http://localhost/phpmyadmin"
End Sub
Sub View_Conf
conf = document.form.conflist.value
Select case conf
case "httpd.conf"
WshShell.Run sCurPath & "\apps\Apache24\conf\httpd.conf"
case "php.ini"
WshShell.Run sCurPath & "\apps\php\php.ini"
case "mysql.ini"
WshShell.Run sCurPath & "\apps\mysql-5.7.17\my.ini"
End Select
document.form.conflist.value = ""
End Sub
Sub View_Log
logfile = document.form.loglist.value
Select case logfile
case "apache"
WshShell.Run sCurPath & "\apps\Apache24\logs\error.log"
case "php"
WshShell.Run sCurPath & "\apps\php\php_errors.log"
case "mysql"
WshShell.Run sCurPath & "\apps\mysql-5.7.17\mysql_error.log"
End Select
document.form.loglist.value = ""
End Sub
Sub Stop_Exit
Disable_Ctr_Button
WshShell.Run "bin\start-apache.bat stop", 0, True
WshShell.Run "bin\start-mysql.bat stop", 0, True
window.close()
Enable_Ctr_Button
WshShell.Run "taskkill /im mshta.exe", 0, True
End Sub
</script>
</head>
<body onload="System_Init()">
<div style="margin-bottom:20px;">
<img src="./material/httpd_logo_wide_new.png" style="height:40px;" />
</div>
<form name="form">
<div id="menu-bar">
<input type="button" name="startapache" class="ctr" style="width:115px;" value="启动Apache" onclick="Ctr_Apache()">
<input type="button" name="startmysql" class="ctr" value="启动Mysql" style="width:115px;" onclick="Ctr_Mysql()">
<input type="button" name="about" value="关于" style="width:50px;" onclick="show_info()">
</div>
<div name="quick-startup" style="margin-top:20px;">
<a href="###" onclick="Open_Home()">[默认主页]</a>
|
<a href="###" onclick="Open_PMD()">[管理数据库]</a>
</div>
<div name="status-block" style="margin-top:20px;" >
<fieldset style="">
<legend>服务状态:</legend>
<select name="servicelist" multiple="multiple" style="height: auto;width:100%;">
</select>
</fieldset>
</div>
<div style="margin-top:20px;">
<select name="conflist" onchange="View_Conf()">
<option value="">查看配置文件</option>
<option value="httpd.conf">httpd.conf</option>
<option value="php.ini">php.ini</option>
<option value="mysql.ini">mysql.ini</option>
</select>
<select name="loglist" onchange="View_Log()">
<option value="">查看错误日志</option>
<option value="apache">Apache</option>
<option value="php">PHP</option>
<option value="mysql">MySQL</option>
</select>
<input type="button" class="ctr" name="exit" value="刷新" onclick="window.location.reload()">
<input type="button" class="ctr" name="exit" value="结束并退出" onclick="Stop_Exit()">
</div>
</form>
</body>
<script type="text/javascript">
document.onkeydown = function(){
if(window.event && window.event.keyCode == 116)
{
//window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 505)
{
return false;
}
}
</script>
</html>