Loading image from external domain in Flash AS3 - security

I have to load XML from external domain, so my code looks like this
var loader:URLLoader = new URLLoader();
configureListeners(loader);
var request:URLRequest = new URLRequest("http://demo.softsolutions4u.com/ss4uplayer/modules/podcast/lib/PlayerAPI.php");
try {
loader.load(request);
} catch (error:Error) {
trace("Unable to load requested document.");
}
function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
}
function completeHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
trace("completeHandler: " + loader.data);
datas.appendText("completeHandler: " +loader.data);
}
function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
datas.appendText("securityErrorHandler: " +event);
}
But it throws exception at run time
securityErrorHandler: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048: Security sandbox violation: http://192.168.2.55/onlinemovie/Development/SS4UPlayer310310/test.swf cannot load data from http://demo.softsolutions4u.com/ss4uplayer/modules/podcast/lib/PlayerAPI.php."
Crossdomain XML file also loaded and security allodomain is in(*).
Please tell me what I missed here.
its not like that. We are not going to use the flash swf file, but our 'N' no of clients going to use this swf in their server, so then in that case how could i place the crossdomain.xml. I dont know where i should put it. Please help me to fix it.

Try adding this line
Security.allowInsecureDomain("demo.softsolutions4u.com");
You should be able to test the movie ONLY inside the Flash IDE or on the client server

I don't see crossdomain.xml at the location http://demo.softsolutions4u.com/crossdomain.xml, it returns a 404 error. You should place the crossdomain.xml at the root of the domain and try again.

Related

request.get() - if url not found

So I want to end the request if the user tries to fetch a url which does not work.
This works:
var remote = "https://storage.googleapis.com/ad-system/testfolder/OUTOFAREA.mp3";
var streama = request.get(remote);
however lets say the following mp3 does not exisit
https://storage.googleapis.com/ad-system/testfolder/playme.mp3
When the request.get('https://storage.googleapis.com/ad-system/testfolder/playme.mp3'); tries and fetch the file it will return a 404 error. What I want to do is file not found I want to run res.end();
Any ideas?
you can write like ### request('endpoint url goes here', { json: true }, (err, res, body) => {
if (err) { // keep your business logic here}
}) ######
hope it helps
I doesn't know about this Cloud Storage but even the link isn't accessible so I recommend you check if something is wrong in this service or if you require some special keys or something else to access the content or the service. Then, check your code or use a library that can handle your requirements (if available).
If I found something, I'll let you know :)
EDIT: I can access to https://storage.googleapis.com/ad-system/testfolder/Video/30%20Second%20Timer-0yZcDeVsj_Y.f137.mp4
You could do
app.get("*",(req,res)=> {
res.end()
});
and insert it just before your 404 handler however, I would challenge why that ever might be a good idea. If it's literally so you scan skip checking the return code I really advice you to think twice if thats something you wanna be doing atleast do:
app.get("*",(req,res)=> {
res.status(404)
res.end()
});

Load Node 'code' from database while server running

I'm looking to build my project in a modular fashion so that API endpoints can be added while the server is added.
Adding routes dynamically I should be able to figure out, it's getting the recently uploaded server code running that I can't figure out.
My project has a 'class-per-endpoint' structure. An endpoint has a class attached that can run code and do this and that.
An endpoint can also be dependent on another endpoint/class, so what I want to be able to do is call the constructor of a dynamically added class and run the code efficiently on the server (without the API calling itself).
Example where "NewAdder" endpoint was just added. Rudimentary stuff, but I just hope it's clear what I'm trying to achieve. Basically trying to add to the server's code base dynamically.
modifier.ts
class Modifier {
constructor(initiatedBy) {
this.initBy = initiatedBy;
this.modifierValue = db.getValue("modifier", {user = this.initBy})
}
function modify(toModify) {
return toModify * this.modifierValue
}
}
newAdder.ts
class NewAdder {
constructor(initiatedBy) {
this.initBy = initiatedBy;
}
modifier = new Modifier(this.initBy);
function addAndModify(a,b) {
return modifier.modify(a + b)
}
}
router.ts (this would be dynamic in real life)
app.get('/newadder/addandmodify/', function(req, res){
adder = new NewAdder(req.params.user);
res.send(adder.addAndModify(req.params.first, req.params.second);
});
Hope I made some sense.
After some more research I suppose I could use http to get and then require the module dynamically.
The code will come from our own server, so it should be safe to run in the server.
But if anyone has any idea how to go about this, would be much appreciated.

node.js simple HTTP server with content html not showing images

I am following along with the tutorials on The New Boston from Bucky and cant seem to get images to show up in the HTML file running a simple static index page in node.js
please note: this is a school project, I am tasked with doing this without using middle-ware such as express or connect which we have not reached yet. :D
var http = require('http');
var fs = require('fs');
var accessTime = new Date();
var accessCount = 0;
function send404Response(response) {
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("Error 404: Page not found!");
response.end();
}
function onRequest(request, response) {
if (request.method == 'GET' && request.url == '/' ){
response.writeHead(200, {"Content-Type": "text/html"});
fs.createReadStream("./index.html").pipe(response);
fs.writeFileSync("logfile.txt", "\n Someone has accessed the index page \n" + accessTime + "\n ", "UTF-8",{'flags': 'a'});
console.log("A user made a request");
accessCount += 1;
console.log(accessCount + " page requests so far . . .");
}else {
send404Response(response);
}
}
http.createServer(onRequest).listen(8888);
console.log("Server is running...");
When I run it, the html page loads fine as localhost:8888 but no images will show up unless I use external images. for example the html would just have standard image tags?
<img src='photo.jpg' .... /> // doesnt work
<img src='http://www.AWebSite.com/photo.jpg' .... /> // naturally works
Thanks!!
Right, so at the moment you're not providing a code path for the images. Your first code block responds to 'http://localhost:8888/' and nothing else; you wouldn't even serve 'http://localhost:8888/index.html' if someone requested it.
If you want to serve all static content, then there's a few ways to go about it. To be the most web server-like, you'd probably start off by having a known folder with your static assets (e.g. ./public). Then you'd want to just take request.url and look for that under the public path using fs.stat(). If that path exists in that location, then you'd check the file extension to figure out the Content-Type header and serve it like you're doing now. If not, then you'd return a 404 like you are currently doing.
If you're not allowed to use third party libraries at all, I'd also recommend chunking each logical bit into its own file that you can require. If you can use third party libraries (just not middleware), then I'd say look into async.js to help the file handling workflow a bit, and to avoid callback hell.

can Chrome option page access indexedDB created by my background script?

I am working on a chrome extension, and really want to have my chrome option page access the data in the IndexedDB, but there seems no support for this?
Error as:
Uncaught TypeError: Cannot read property 'transaction' of undefined option.js:42
var request = indexedDB.open(DB_NAME, DB_VERSION);
//console.log(request); /* The created indexedDB can be checked */
request.onsuccess = function (evt) {
console.log("Database Open Successfully: " + evt);
db = this.result;
/* Get the initialised logIndex*/
var storeLog = db.transaction(DB_STORE1, 'readonly').objectStore(DB_STORE1);
var req = storeLog.openCursor(null, 'prev');
req.onsuccess = function (evt) {
console.log("Inner Successfully");
}
req.onerror = function(evt){
console.error("Inner error" + evt.target.errorCode);
}
};
request.onerror = function (evt) {
console.error("Database Error: " + evt.target.errorCode);
};
want to know whether it is possible to access the IndexedDB in the "chrome option_page"
A short answer to your stated question is "yes, IndexedDB is fully supported in extension pages". The fact that your request.onsuccess is fired is sufficient evidence to that.
It seems like your problems are not specific to Chrome Extensions; I suggest that you look at some IndexedDB tutorials like this one to debug your code.
Note that you might need to request "unlimitedStorage" permission in the manifest to store large amounts of data.

Calling an XAgent from a traditional Domino web app via AJAX

I have an XAgent I have created that works just fine via window.location but I can't get it to work via AJAX. This agent is called from a delete button on a popup div, so rather than writing to my responseStream in my XAgent, I'd prefer to just run my agent and close my popup via javascript when it is finished.
My XAgent is called by the URL doc.$DBPath.value + "/xAgent_DeleteDemand.xsp?open&id=" + doc.$DocUNID.value and looks like this:
javascript:importPackage(foo);
try {
var url:java.lang.String = context.getUrl().toString();
print(url);
if (param.containsKey("id")) {
var unid = param.get("id");
} else {
throw "No unid given";
}
XAgent.deleteDemand(unid);
} catch (e) {
print(e);
}
My actual code is in the foo package but that doesn't seem relevant because I'm not even getting my URL printed. I can say the the URL being generated and called works just fine using window.location so it is safe to assume that the problem is elsewhere.
I have a sneaking suspicion that maybe context doesn't have any meaning when called via AJAX from a non XPage app, but I don't know for sure.
I don't think there is anything special about my AJAX code but here it is just in case. It has been working fine for a long time.
function createAJAXRequest(retrievalURL, responseFunction) {
if (window.ActiveXObject) {
AJAXReq = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
AJAXReq = new XMLHttpRequest();
}
showHideIndicator("block")
var currentTime = new Date()
AJAXReq.open("GET", retrievalURL + "&z=" + currentTime.getTime());
AJAXReq.onreadystatechange = eval(responseFunction);
AJAXReq.send(null);
}
I'm not sure what the immediate problem would be, but as some troubleshooting steps:
The resultant URL is just server-relative and not on a different server+protocol combination, right?
Do you see anything on the browser's debug console when clicking the button?
Is there an entry in the browser's debug Network panel for the request at all?

Resources