Showing posts with label scripting. Show all posts
Showing posts with label scripting. Show all posts

Thursday, September 3, 2009

AJAX Cross Site Scripting Problem...Solved

As I've mentioned, our HA GUI is built with AJAX, and I thought that I was able to easily integrate the Aviosys 9100A. Turns out some browsers and/or operating systems weren't so willing to allow access to the 9100A since it has a different IP address than the web server. It works great on Firefox on XP, but for some reason, won't on Vista. Opera on Wii wasn't too keen on it either.

Since our GUI runs on the Apache web server, I can take advantage of mod_rewrite, which rewrites the requested URL on the fly. Let's assume my server runs on 192.168.100.100. I've got this code in an html file:

<div class=camera style="z-index:5; position: absolute; left: 49; top: 355px; cursor: pointer;">
<img src=images/camera_left.png border=0 onmousedown="javascript:selectCam('SideCam');" id=SideCam>
</div>

The selectCam function:

function selectCam(camera) {
var newurl,xyz;
if (camera=="SideCam") {
// set channel on 9100A
newurl="192.168.100.200/SetChannel.cgi?Channel=0";
// AJAX call to load URL
xyz=loadXMLDoc(newurl);
}
}

What I need to do is make the AJAX call look like it's going from the same address as the web server. I just need to edit the httpd.conf file for Apache and enabled mod_rewrite and proxy modules:

LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Then, I need to turn on the rewrite engine and give it a rule to rewrite certain URLs:

RewriteEngine On
RewriteRule ^/9100a/(.*) $1 [P]

The above rule will rewrite any URL containing /9100a/ with the text following /9100a/. Now, I can change the URL in the selectCam function above as follows:

newurl="/9100a/http://192.168.100.200/SetChannel.cgi?Channel=0";

This will trick the cross site scripting checks since the URL appears to be local. The URL is rewritten by Apache to http://192.168.100.200/SetChannel.cgi?Channel=0, Apache will serve as a proxy to that URL and everyone's happy!

Tuesday, January 9, 2007

Script to create playlists of VOB files

We have a D-Link DSM-320 media player and we use TVersity as its media server. We use it mainly to watch movies across our network. One thing we can do is watch the original VOB files ripped from a DVD, but the problem is there are multiple VOB files for a movie and after each one ends, the next one has to be manually started. (You can merge to VOBs into one, but the DSM-320 has a 4GB file limit.) One solution is to create a playlist for each movie, containing all movie's VOB files.

I wrote this Perl script to do just that. (It is similar to the script I wrote to auto-generate music playlists.) It traverses a directory and creates playlists for all subdirectories containing VOB files.

Just set $path (source) and $dest (playlist directory) in the script and then run it. It assumes the folder containing the VOBs will be named after the movie and it uses that folder name as the playlist name.

Monday, November 6, 2006

Perl script to autogenerate playlists from mp3s

I wrote this perl script to autogenerate playlist files (.m3u) for each CD we have. Some servers don't play the songs in CD order, but they will with a playlist.

# assumes mp3 directory structure of g:/mp3/artist/album/tracks.mp3
# generates playlist of format: g:/m3u/artist-album.m3u

$mp3dir="g:/mp3";
$m3udir="g:/m3u";

opendir(ARTIST, $mp3dir);
@dir = grep !/^\.\.?$/, readdir ARTIST;
foreach $artist (@dir) {
print "\nartist: $artist\n";
opendir(ALBUM,"g:/mp3/$artist");
@album = grep !/^\.\.?$/, readdir ALBUM;

foreach $album (@album) {
print " album: $album\n";

opendir(TRACK,"g:/mp3/$artist/$album");
@track=grep /\.mp3/,readdir TRACK;
$playlist="";
foreach $track (@track) {
print " track: $track\n";
$playlist.="g:\\mp3\\$artist\\$album\\$track\n";
}
closedir TRACK;

# create playlist
$m3u_name="$m3udir/$artist-$album.m3u";
$m3u_name=~s/\\ /_/g;
print " m3u: $m3u_name\n\n";
PrivoxyWindowOpen(A,">$m3u_name");
print A $playlist;
close(A);
}
closedir ALBUM;
}

Tuesday, October 31, 2006

VBScript to export Outlook contacts to import into HAL

This script exports your Outlook contacts into a format usable by the build_addrbook_dbf.pl script from yesterday. useage:

export_contacts_hal.vbs username

You'll need to edit the file to change this line to your Outlook profile user name:
if user="FirstUser" then

It is written to work with multiple user profiles. I have not tried it with only one user profile. Some instructions inside the script.

Monday, October 30, 2006

Perl script to build HAL addrbook.dbf

Building on the previous post, I've modified that script to create the HAL address book database from a text file. This can be used to import data from Outlook or whatever PIM you use. You just need to export your data into a CSV and massage it into the right format. Instructions in the file. Of course, backup your files before you play.

the script

Sunday, October 29, 2006

Perl Script to Build HAL Tasks Database

Here's a script I just finished to build the HAL tasks database. You can now edit your tasks in text and use this script to create the .DBF and .FPT files. No more kludgy HAL point and click editor :) It requires the XBase package from my previous post.

the script

Make sure you backup your HAL data before using this script!!!