Skip to content

Instantly share code, notes, and snippets.

@dutchand
Last active August 29, 2015 14:09
Show Gist options
  • Save dutchand/8f705cb7c540dd8b6f6a to your computer and use it in GitHub Desktop.
Save dutchand/8f705cb7c540dd8b6f6a to your computer and use it in GitHub Desktop.
Validate if specific urls can be accessed or not from a device on a network AS3: Whitelisturl
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" horizontalScrollPolicy="on" width="100%" height="1000" verticalScrollPolicy="off" layout="absolute" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FFFFFF, #FFFFFF]" verticalAlign="middle">
<!--
http://pbskids.org/sprout_games/mama-mirabelle/games/source/ndi/utils/Logger.as
http://www.uh.edu/wtsc_apps/js/uploadify/com/adobe/webapis/URLLoaderBase.as
http://alivepdf.bytearray.org/?p=20
http://books.google.com/books?id=CeMMho6OodcC&pg=PT493&lpg=PT493&dq=onIOError%28event:IOErrorEvent%29&source=bl&ots=KkN3LufGUS&sig=Q28fa0EWe9p2msFtjyc-Wkhawvg&hl=en&sa=X&ei=7YJGVOa3EKrksATDoYDADw&ved=0CDkQ6AEwBQ#v=onepage&q=onIOError%28event%3AIOErrorEvent%29&f=false
-->
<mx:Script>
<![CDATA[
import org.alivepdf.saving.Download;
import mx.messaging.channels.NetConnectionChannel;
import mx.controls.Alert;
import mx.managers.IBrowserManager;
import mx.managers.BrowserManager;
import mx.utils.URLUtil;
import mx.utils.LoaderUtil;
import flash.events.MouseEvent;
import mx.managers.IBrowserManager;
import mx.managers.BrowserManager;
import mx.utils.URLUtil;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import mx.utils.ObjectUtil;
import mx.collections.ArrayCollection;
import flash.net.navigateToURL;
import flash.net.FileReference;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.ByteArray;
import org.alivepdf.pdf.PDF;
import org.alivepdf.layout.Orientation;
import org.alivepdf.layout.Size;
import org.alivepdf.layout.Unit;
import org.alivepdf.display.Display;
import org.alivepdf.saving.Method;
import org.alivepdf.fonts.FontFamily;
import org.alivepdf.fonts.Style;
import org.alivepdf.colors.RGBColor;
import mx.messaging.AbstractConsumer;
public var myPDF:PDF;
private function generatePDF(togglecanvas):void
{
// we create the PDF
// xblocked.text = blockedurls.text.toString();
myPDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.LETTER);
//we set the zoom to 100%
myPDF.setDisplayMode (Display.DEFAULT );
// we add a page
myPDF.addPage();
myPDF.addImage(togglecanvas);
/* var fileReference:FileReference = new FileReference();
var byteArray:ByteArray = myPDF.save(Method.LOCAL);
fileReference.save(byteArray, "drawing.pdf"); */
// myPDF.
// to save the PDF your specificy the path to the create.php script
// alivepdf takes care of the rest, if you are using AIR and want to save the PDF locally just use Method.LOCAL
// and save the returned bytes on the disk through the FileStream class
myPDF.save( Method.REMOTE, "http://localhost/upload/create.php","drawing.pdf" );
}
[Bindable]
public var getunaccessedurls:Array = new Array(70);
public var suma:Number = new Number(0);
public var sumasuc:Number = new Number(0);
public var sumabadurls:String = new String;
private var timer:Timer;
[Bindable]
public var xurl:Array = new Array(
'https://learnosity.com',
'https://accounts.google.com/',
'https://ssl.gstatic.com/',
'http://www.google.com',
'http://www.bing.com/',
'https://www.chase.com/',
'https://www.citibank.com/',
'https://www.yahoo.com/',
);
private function goToURL() : void
{
var i:Number;
i=0;
try
{
while(i<xurl.length)
{
var p:URLRequest = new URLRequest(xurl[i].toString());
navigateToURL(p,target.selectedItem as String );
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, handleComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.load(p);
/* var sock:Socket;
sock = new Socket;
sock.connect("www.google.com",8080); */
parseURL(xurl[i].toString(),i);
i++;
}
}
catch (e:Error) {
trace(e);
}
// numblckurls.visible = true;
// numsucckurls.visible = true;
// viewreport.visible = true;
// reportonurl.visible = true;
runtest.enabled = false;
flagg6.text=xurl.length.toString();
}
private function parseURL(w:String, ii:int) : void
{
//get an instance of the browser manager
var bm:IBrowserManager = BrowserManager.getInstance();
//initialize the browser manager
bm.init(w);
// Alert.show(""+w);
//output the url parameter values
output.text += ""+ii+"\n\n";
output.text += "----------------------------------------------------------------------------------------------------------------------------------------------------------" + "\n\n";
output.text += "Base URL:\n" + bm.url + "\n\n";
//output.text += "Base URL:\n" + bm.base + "\n\n";
output.text += "Target URL:\n" + bm.fragment + "\n\n";
//output.text += "URL Title:\n" + bm.title + "\n\n";
//convert url parameters to an actionscript object using URLUtil
var o:Object = URLUtil.stringToObject(bm.fragment);
output.text += "Object:\n" + ObjectUtil.toString( o ) + "\n\n";
/* output.text += "name:\n" + o.name + "\n\n";
output.text += "index:\n" + o.index + "\n\n";
output.text += "productId:\n" + o.productId + "\n\n";
*/
//parse URL using URLUtil
output.text += "URL Port:\n" + URLUtil.getPort( w ) + "\n\n";
output.text += "URL Protocol:\n" + mx.utils.URLUtil.getProtocol( w ) + "\n \n";
output.text += "URL Server:\n" + mx.utils.URLUtil.getServerName( w ) + "\n\n";
output.text += "URL Server with Port:\n\n" + mx.utils.URLUtil.getServerNameWithPort( w ) + "\n\n";
output.text += "Server Name:\n\n" + URLUtil.SERVER_NAME_TOKEN + "\n\n";
output.text += "Server Port:\n\n" + URLUtil.SERVER_PORT_TOKEN + "\n\n";
// output.text += "URL Server with Port:\n\n" + URLUtil.isHttpURL("web.learning.amplify.com") + "\n\n";
output.text += "Is HTTPS:\n\n" + URLUtil.isHttpsURL(w) + "\n\n";
output.text += "Is HTTP:\n\n" + URLUtil.isHttpURL(w) + "\n\n";
output.text += "URL Server with Port:\n\n" + URLUtil.hasUnresolvableTokens() + "\n\n"+URLUtil.getServerName(Application.application.loaderInfo.url); "\n\n";
output.text += "----------------------------------------------------------------------------------------------------------------------------------------------------------" + "\n\n";
}
public function sendData(url:String):void {
var request:URLRequest = new URLRequest(url);
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
// request.data = _vars;
request.method = URLRequestMethod.POST;
// loader.addEventListener(Event.COMPLETE, handleComplete);
// loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
// loader.load(request);
}
private function handleComplete(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
sumasuc+=1;
flagg0.text=sumasuc.toString();
/* trace("Par: " + loader.data);
trace("Message: " + loader.data.msg); */
//Alert.show(""+loader.data.msg+" "+loader.data.par);
loader.close();
}
var pp:String = new String;
private function onIOError(event:IOErrorEvent):void {
trace("Error loading URL.");
suma+=1;
var graburls:Array=new Array(60);
var loader:URLLoader = URLLoader(event.target);
if(event)
{
blockedurls.text+=""+suma+")"+event.text.slice(32,150)+"\n";
pp+=event.text.slice(32,150);
getunaccessedurls[suma]=event.text.slice(32,150);
}
flagg.text=suma.toString();
loader.close();
}
private function grabsuccessfulurls():void
{
var i:Number = new Number(1);
var suma:Number = new Number(0);
for(i;i<=getunaccessedurls.length;i++){
if(getunaccessedurls[i]!="")
suma+=1;
//Alert.show(""+getunaccessedurls[i]+getunaccessedurls.length+""+suma);
}
while(i<suma)
{
xsuccessurls.text+=+getunaccessedurls[i];
i++;
//Alert.show(""+getunaccessedurls[i]);
}
}
private var index:int = new int(0);
private function init():void{
//sortuser.text = xurl[0];
sortuser.label = "Checking Connectivity...";
sortuser.label = "Connected...";
index ++;
var timer:Timer = new Timer(100);
timer.addEventListener(TimerEvent.TIMER,changeImage);
timer.start();
}
private function changeImage(e:TimerEvent):void{
sortuser.label = "Checking Connectivity...";
sortuser.label = "Connected...";
if(index<=xurl.length && sortuser.label != "DONE")
{
sortuser.label = xurl[index];
index++;
}
else {
try{
index=11111;
sortuser.label = "DONE";
numblckurls.visible = true;
numsucckurls.visible = true;
totalkurls.visible = true;
testmenus.enabled = true;
// viewreport.visible = true;
// reportonurl.visible = true;
}
catch (e:Error) {
trace(e);
}
}
}
private function stopgo():void
{
init();
goToURL();
}
private function startTimer():void {
if (timer.running==false) {
timer.start();
}
else
timer.stop();
}
private function stopTimer():void {
if (timer.running == true) {
timer.stop();
}
}
private function verifyingconnectivity()
{
try{
if (timer.running == true) {
timer.stop();
}
else
goToURL();
timer.stop();
}
catch (e:Error) {
trace(e);
}
goToURL();
}
private function ojo0():void
{
whitelistcover.selectedChild=whitelisttest;
}
private function ojo():void
{
whitelistcover.selectedChild=whitelistsuccessful;
grabsuccessfulurls();
}
private function ojo2():void
{
whitelistcover.selectedChild=whitelistblocked;
// xblocked.text =blockedurls.text ;
}
private function ojo22():void
{
try{
xblocked.text =blockedurls.text ;
if(xblocked.text!="")
{
xblocked.text =blockedurls.text ;
}
else
ojo22();
}
catch (e:Error) {
trace(e);
}
}
private function exporttopdf():void
{
if(whitelistcover.selectedChild==whitelistblocked)
{
generatePDF(whitelistblocked);
}
else
if(whitelistcover.selectedChild==whitelistsuccessful)
{
generatePDF(whitelistsuccessful);
}
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true" fillAlphas="[1.0, 1.0]" fillColors="[#FFFFFF, #FFFFFF]" color="#000000" id="testmenus" enabled="false">
<mx:Button label="Home" cornerRadius="0" icon="@Embed(source='icons/home_orange.png')" fillAlphas="[1.0, 1.0]" fillColors="[#FFFFFF, #FFFFFF]" click="ojo0()"/>
<mx:Button label="View Blocked Urls" icon="@Embed(source='icons/buscardatabase.png')" cornerRadius="0" fillAlphas="[1.0, 1.0]" fillColors="[#FFFFFF, #FFFFFF]" click="ojo2()"/>
<mx:Button label="View Successful Urls" icon="@Embed(source='icons/buscardatabase.png')" cornerRadius="0" fillAlphas="[1.0, 1.0]" fillColors="[#FFFFFF, #FFFFFF]" click="ojo()"/>
<mx:Button label="Export" icon="@Embed(source='icons/Modificar1.png')" cornerRadius="0" fillAlphas="[1.0, 1.0]" fillColors="[#FFFFFF, #FFFFFF]" click="exporttopdf()"/>
<mx:Spacer width="559" height="6"/>
<!-- <mx:HSlider id="slider"
minimum="0"
maximum="3"
liveDragging="true"
snapInterval="1"
tickInterval="1"
change="viewStack.selectedIndex = event.value;" />-->
</mx:ApplicationControlBar>
<mx:ViewStack width="100%" id="whitelistcover" height="100%">
<mx:VBox width="100%" height="100%" id="whitelisttest" horizontalScrollPolicy="off" horizontalAlign="center" verticalAlign="middle" color="#000000">
<mx:Image source="icons/Amplify_RGB_orange_cs3_400px.jpg"/>
<mx:Label text="Whitelist Test" fontFamily="Verdana" fontSize="30"/>
<mx:Label text="Beta Version 1.0" fontSize="10"/>
<mx:Button
label="Run Test"
left="10" top="70"
click=" stopgo()" fontSize="26" fontWeight="normal" cornerRadius="0" id="runtest" icon="@Embed(source='icons/documento.png')"/>
<mx:VBox width="80%" height="36" horizontalAlign="center">
<mx:LinkButton id="sortuser" height="32" icon="@Embed(source='icons/ie_icon.png')" fontSize="22" fontWeight="normal"/>
</mx:VBox>
<mx:FormItem label="Total Number of Urls: " id="totalkurls" visible="false" fontSize="26">
<mx:Label x="16" y="100" id="flagg6" fontSize="26"/>
</mx:FormItem>
<mx:FormItem label="Number Of Blocked Urls: " id="numblckurls" visible="false" fontSize="26">
<mx:Label x="16" y="100" id="flagg" fontSize="26"/>
</mx:FormItem>
<mx:FormItem label="Number Of Successful Urls: " id="numsucckurls" visible="false" fontSize="26">
<mx:Label x="16" y="100" id="flagg0" fontSize="26"/>
</mx:FormItem>
<mx:Button label="View Full Report" fontWeight="normal" click="ojo()" fontSize="26" cornerRadius="0" id="viewreport" visible="false"/>
<mx:HBox id="reportonurl" width="100%" visible="false">
<mx:TextArea id="output" height="234" width="50%" wordWrap="true" fontSize="12"/>
<mx:TextArea width="50%" height="100%" wordWrap="true" id="blockedurls"/>
</mx:HBox>
<mx:Label id="flagg2" fontSize="14"/>
<mx:Label x="16" y="131" id="flagg3" fontSize="14"/>
<mx:ComboBox
id="target"
top="40" left="10"
dataProvider="{ [ '_new' ] }" visible="false"/>
</mx:VBox>
<mx:Canvas width="100%" height="100%" id="whitelistsuccessful" horizontalScrollPolicy="on" color="#000000">
<mx:Image source="icons/Amplify_RGB_orange_cs3_400px.jpg" x="201" y="10" width="201" height="49"/>
<mx:Label text="Whitelist Test Results" fontFamily="Verdana" fontSize="22" x="183.5" y="67"/>
<mx:Label text="Accessible Urls" fontFamily="Verdana" fontSize="14" x="256" y="96"/>
<mx:TextArea width="452.5" height="490" wordWrap="true" y="127" x="10" id="xsuccessurls" borderThickness="0" borderStyle="none" editable="false" fontSize="12"/>
</mx:Canvas>
<mx:Canvas width="100%" creationComplete="ojo22()" height="100%" id="whitelistblocked" color="#000000">
<mx:Image source="icons/Amplify_RGB_orange_cs3_400px.jpg" x="201" y="10" width="201" height="49"/>
<mx:Label text="Whitelist Test Results" fontFamily="Verdana" fontSize="22" x="183.5" y="67"/>
<mx:Label text="Blocked Urls" fontFamily="Verdana" fontSize="14" x="256" y="96"/>
<mx:TextArea width="452.5" height="802" wordWrap="true" y="127" x="10" id="xblocked" borderThickness="0" borderStyle="none" editable="false" fontSize="12"/>
</mx:Canvas>
</mx:ViewStack>
</mx:Application>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment