Menu

[r11]: / trunk / SWFInvestigator / src / utils / MiniWebServer.mxml  Maximize  Restore  History

Download this file

165 lines (145 with data), 5.3 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
 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
<?xml version="1.0" encoding="utf-8"?>
<s:Window xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="605" height="290" title="Mini Web Server" backgroundColor="#60f3ea" showStatusBar="false" windowComplete="onOpen()" close="onClose()">
<fx:Script>
<![CDATA[
import databaseUtils.PreferencesDB;
import mx.controls.Alert;
import mx.events.FlexEvent;
import osUtils.WebServer;
import osUtils.WebServerEvent;
/**
* @private
* The web server for cross-site flashing tests
*/
private var webServer:WebServer;
/**
* @private
* A ptr to the preferences DB
*/
public var prefDB:PreferencesDB;
/**
* @private
*/
private function onOpen():void {
this.ipAddress.text = this.prefDB.getPref("serverIP");
this.docRoot.text = this.prefDB.getPref("serverPath");
this.listenPort.text = this.prefDB.getIntPref("serverPort").toString();
}
/**
* @private
* Stop the web server when the window closes
*/
private function onClose():void {
if (this.webServer != null && this.webServer.listening) {
this.webServer.close();
}
}
/**
* @private
* Display information from any server errors.
*
* @param evt The WebServerEvent for general errors
*/
private function serverError(evt:WebServerEvent):void {
this.statusOutput.text += evt.message + "\n";
}
/**
* @private
* Sets the text box to the location of the document root
*
* @param evt The FileActionEvent
*/
private function onDirSelection(evt:Event):void {
this.docRoot.text = evt.target.url;
try {
this.webServer = new WebServer(this.docRoot.text);
this.webServer.addEventListener(WebServerEvent.GENERAL_ERROR, serverError);
} catch (e:Error) {
mx.controls.Alert.show("Document path does not exist!","Error", 4, this);
}
}
/**
* @private
* This function creates the popUp window to select the directory file
*/
private function getDirectory():void {
var filePtr:File = File.documentsDirectory;
filePtr.addEventListener(Event.SELECT,onDirSelection);
filePtr.browseForDirectory("Choose the document root");
}
/**
* @private
* Called by the Start Listening button to start the server and ensure variables are correct
*/
private function startListening():void {
if (this.docRoot.text.length < 1) {
mx.controls.Alert.show("Please choose a document root for the server.","Error", 4, this);
return;
}
if (this.ipAddress.text.length < 7) {
mx.controls.Alert.show("Please specify a valid IP address","Error", 4, this);
return;
}
if (this.listenPort.text.length < 1) {
mx.controls.Alert.show("Please specify a port number","Error", 4, this);
return;
}
var port:Number = parseInt(this.listenPort.text);
if (isNaN(port)) {
mx.controls.Alert.show("Please specify a valid port number","Error", 4, this);
return;
}
try {
if (this.webServer == null) {
this.webServer = new WebServer(this.docRoot.text);
this.webServer.addEventListener(WebServerEvent.GENERAL_ERROR, serverError);
}
if (this.webServer.listening) {
this.webServer.close();
}
this.webServer.listen(this.ipAddress.text, port);
} catch (e:Error) {
mx.controls.Alert.show(e.message,"Error", 4, this);
return;
}
this.statusOutput.text = "Successfully listening on " + this.ipAddress.text + ":" + port.toString() + "\n";
}
/**
* @private
* Stop the web server from listening
*/
private function stopListening():void {
if (this.webServer != null) {
this.webServer.close();
this.statusOutput.text = "Stopped listening...\n";
}
}
/**
* @private
* Save these settings as the new defaults
*/
private function saveDefaults():void {
this.prefDB.updatePref("serverIP", this.ipAddress.text, false);
this.prefDB.updatePref("serverPort", this.listenPort.text, false);
this.prefDB.updatePref("serverPath", this.docRoot.text);
}
]]>
</fx:Script>
<s:Group>
<s:Label x="19" y="19" text="Choose the root directory for the web server:"/>
<s:TextInput x="19" y="39" width="419" id="docRoot"/>
<s:Button x="456" y="40" label="Choose Directory" click="getDirectory()" />
<s:Label x="19" y="88" text="IP Address:"/>
<s:TextInput id="ipAddress" x="90" y="82" text="127.0.0.1"/>
<s:Label x="273" y="88" text="Port:"/>
<s:TextInput x="310" y="82" text="9080" id="listenPort"/>
<s:Button x="12" y="131" label="Start Listening" click="startListening()" />
<s:Button x="128" y="131" label="Stop Listening" click="stopListening()"/>
<s:Button x="405" y="131" label="Remember these settings" click="saveDefaults()"/>
<s:Label x="15" y="181" text="Status"/>
<s:TextArea x="10" y="201" width="562" height="79" id="statusOutput" text="Not listening..." editable="false"/>
</s:Group>
</s:Window>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.