Old 20th June 2009, 12:24   #1
POMATu
Junior Member
 
Join Date: Jun 2009
Location: Russia
Posts: 15
Send a message via ICQ to POMATu
Parse 7.html with javascript

Hello.
My free hosting doesnt support fsockopen, get, and allow_url_fopen. I know that I can parse the 7.html with javascript.

<button onclick='get()'>get</button>
<script>
function get(){
var iframe = document.getElementById("myframe");
var txt = iframe.contentWindow.document.body.innerHTML;
var body = myiframe.contentWindow.document.body.innerText;
var myArr = body.split(",");
alert(body);

}
</script>
<iframe id ='myframe' src='http://s2.myradiostream.com:10440/7.html'></iframe>

But this script is not working/ Any ideas?

Linux is our friend!
POMATu is offline   Reply With Quote
Old 20th June 2009, 15:34   #2
fc*uk
Moderator
 
fc*uk's Avatar
 
Join Date: Dec 2005
Location: Atlantic Beach
Posts: 8,142
moved to SHOUTcast discussions. You are likely to get better help there.
fc*uk is offline   Reply With Quote
Old 21st June 2009, 03:57   #3
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
it's a cross domain security issue

you cannot access contents of an iframe whose contents are loaded from a different domain

"If you don't like DNAS, write your own damn system"

So I did
jaromanda is offline   Reply With Quote
Old 21st June 2009, 04:01   #4
Brutish Sailor
Major Dude
 
Brutish Sailor's Avatar
 
Join Date: Jan 2009
Location: San Diego CA
Posts: 998
Send a message via Skype™ to Brutish Sailor
There is a way I tested and it gets around that.

Tell me exactly what you are trying to do and this will be easier to set it up.

Edit: I think I see what you are trying to do, and NO, it wont work. Get marci host a pretty good service (and yes, Im officially giving him credit for a WELL setup now playing script)

If you can get a friend to host your now playing script...


<?php

// last10.php -- get and display last n tracks...
// URL syntax:
// last10.php?host={xx.xx.xx.xx}&port={8000}&n={lastN}
//
// {bracketed} items need to be replaced or they will default as below.
//
// I can return Javascript or HTML only.
//

/* keep warnings from our output */
error_reporting(E_ERROR);

// -- Server Info here -- //

$yourIP = 'YOUR IP HERE';
$yourPORT = 'YOUR PORT HERE';

// -- Tweak Display Here -- //

$bgcolor = '#ffffff'; // Page background color
$tablew = '400'; // Table width
$toprow = '#c0c0c0'; // Top background color
$bottom = '#ffffff'; // Bottom background color
$border = '#000000'; // Border color
$thickness = '2'; // Border thickness
$padding = '4'; // Cell padding
$font = 'Verdana'; // Font
$fontsize = '2'; // Font size

$refresh = '30'; // How often should it refresh? (seconds)

// Return JavaScript or HTML
$jsOutput=FALSE; // TRUE=js | FALSE=HTML

// try to get the target from the url...
$host = $_REQUEST[host];
if (!$host) $host = $yourIP;
$port = $_REQUEST[port];
if (!$port) $port = $yourPORT;

$lf = chr(10); // 0x0A [\n]

// The lastN is configurable at the DNAS with, ShowLastSongs= it defaults to 10 and has a maximum of 20
$t_max = $_REQUEST[n];
if (!t_max || $t_max<1 || $t_max>19) $t_max=10;
//19 is the max here because 20=current_track+19

// Let's get /index.html first... to keep this short, there is no code to handle the dnas being down
// or not running, so the script will display nothing in those cases.

$connect_timeout=5;
$success=0;

$fp1 = fsockopen($host, $port, &$errno, &$errstr, $connect_timeout); //open connection
if(!$fp1) { //if this fails, I'm done....
fclose($fp1);
$success++;
} else {
$request="GET /index.html HTTP/1.1\r\nHost:" . $host . ":" . $port . "\r\nUser-Agent: SHOUTcast DNAS Status [index] * (Mozilla/PHP)\r\nConnection: close\r\n\r\n"; //get index.html
fputs($fp1,$request,strlen($request));
$page='';
while(!feof($fp1)) {
$page .= fread($fp1, 16384);
}
fclose($fp1);

// now I have the entire /index.html in $page -- all I want from here is the current track...
// (hint-hint)

$song00 = ereg_replace("</b></td>.*", "", ereg_replace(".*Current Song: </font></td><td><font class=default><b>", "", $page)); // easy, right <img src="images/smilies/smile.gif" border="0" alt="">

// now let's get /played.html... (this is kinda long)
$fp = fsockopen($host, $port, &$errno, &$errstr, $connect_timeout);
if(!$fp) { //if connection could not be made
fclose($fp);
$success++;

} else {
$request="GET /played.html HTTP/1.1\r\nHost: " . $host . ":" . $port . "\r\nUser-Agent: SHOUTcast DNAS Status [played] * (Mozilla/PHP)\r\n"."Connection: close\r\n\r\n";
fputs($fp,$request,strlen($request));
$page='';
while (!feof($fp)) {
$page .= fread($fp, 16384);
}
fclose($fp); //close connection
$played_html=$page;

if ($played_html) {
$played_html= ereg_replace('<x>','|-|',ereg_replace('</tr>','',ereg_replace('</td><td>','<x>',ereg_replace('<tr><td>','',ereg_replace('</tr>','</tr>' . $lf,ereg_replace('-->','--]',ereg_replace('<!--','[!--',ereg_replace('</table><br><br>.*','',ereg_replace('.*<b>Current Song</b></td></tr>','',$played_html)))))))));
$xxn=strlen($played_html);
$r=2;
$t_count=0;
$reading=0;
$track[0]=$song00;
while ($r<$xxn & $t_count<=$t_max){
$cur=substr($played_html,$r,1);
if ($cur==$lf) $reading=0;
if ($reading==1) $track[$t_count] .= $cur;
if ($cur=="|" & substr($played_html,$r-1,1)=="-" & substr($played_html,$r-2,1)=="|") {
$reading=1;
$t_count++;
}
$r++;
}
}
}
}

// I now have $track[0-N] containg the current plus last N tracks...
// Output time...

if ($success==0) {

if ($jsOutput) { // JavaScript - used as <script src=...></script>
header('Content-type: text/javascript');
} else { // HTML... (iFrames anyone?)
echo '<HTML>
<HEAD><TITLE>TITLE OF YOUR PAGE HERE - Now Playing: ' . $track[0] . '</title>
<meta http-equiv="refresh" content="' . $refresh . ';URL=' . $_SERVER['PHP_SELF'] . '?host=' . $host . '&port=' . $port . '">
</head>
<BODY bgcolor=' . $bgcolor . '>';
}

$r=0;
$output_string='';

//tweak the output string (the table init) here....
$output_string .= '<table width="' . $tablew . '" style="border-collapse: collapse" border="' . $thickness . '" bordercolor="' . $border . '"><tr bgcolor="' . $toprow . '"><td>
<table width="100%" border="0" cellpadding="' . $padding . '"><tr><td>
<font face=' . $font . ' size=' . $fontsize . '>'; //Now playing...

while ($r<=$t_max){
if ($r==0) $output_string .= 'Now Playing:<br> <b>'.str_replace("'", "'",str_replace('"', '"',$track[$r])).'</b></td></tr></table></td></tr><tr><td><table bgcolor=' . $bottom . ' width="100%" border="0" cellpadding="' . $padding . '"><tr><td><br><font face=' . $font . ' size=' . $fontsize . '><i>Before that you heard:</i><br><br>';
else $output_string .= str_replace("'", "'",str_replace('"', '"',$track[$r])) . '<br>';

$r++;
}

// I also want to close the table code now....
$output_string .= '</td></tr></table></td></tr></font></td></tr></table>';

if ($jsOutput) {
echo "document.write('" . $output_string . "');";
} else {
echo $output_string . '</body></html>';
}

} else { // I couldn't connect to the DNAS
if ($jsOutput) echo "document.write('Off Air');";
else echo "<HTML><HEAD><TITLE>Off-Air</title></head>
<BODY bgcolor=" . $bgcolor . "><font face=" . $font . " size=" . $fontsize . ">Server is <b>Off-Air</b>, try again later.</body></html>";

}
?>


At the top where the (xxx.xxx) 's are, enter his server and the port to use. Then fill in the rest as usual.


But thats the best I can offer.

KNSJ.org 89.1 FM San Diego
Brutish Sailor is offline   Reply With Quote
Old 21st June 2009, 08:42   #5
POMATu
Junior Member
 
Join Date: Jun 2009
Location: Russia
Posts: 15
Send a message via ICQ to POMATu
$fp = fsockopen($host, $port, &$errno, &$errstr, $connect_timeout);

my host doesnt allow this

Server is Off-Air, try again later.
so you see...


I need something that can parse the line with browser, with out my free hosting limits. Like javascript.

Linux is our friend!
POMATu is offline   Reply With Quote
Old 21st June 2009, 10:47   #6
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
Quote:
Originally posted by POMATu
my host doesnt allow this
hence ...
Quote:
Originally posted by Brutish Sailor
If you can get a friend to host your now playing script...
a far simpler php ... simply retrieves 7.html (or played.html for that matter in fact ANY url)
PHP Code:
<?php
$url
=$_GET["url"];
$cb=$_GET["cb"];
header("Content-type: text/javascript");
header("Cache-Control: no-cache");
header("Expires: -1");
ini_set("user_agent""Mozilla/5.0");
echo 
"$cb('".urlencode(@file_get_contents($url))."');";
?>
the PHP HAS TO BE ON A SERVER THAT ALLOWS allow_url_fopen


the javascript on the webpage in question

PHP Code:
<script>
function 
addScript(url) {
    
// the following 4 lines remove the "old" script first
    
var x=document.getElementById('zzzreplaceme');
    if(
x) {
        
x.parentNode.removeChild(x);
    }
    var 
script document.createElement('script');
    
script.src url;
    
script.id 'zzzreplaceme';
    
document.body.appendChild(script);
}
function 
getSeven() {
    
addScript('http://domain.com.xx/getSeven.php?url=http://yoursc.host.com.xx:8000/7.html&cb=sevenCb');
    
// change domain.com.xx and yoursc.host.com.xx:8000 as appropriate
}
function 
sevenCb(obj) { // this is the same as the cb=sevenCb argument above
    
var rawSeven decodeURIComponent(s).replace(/%7E/g,'~').replace(/\+/g,' ');
    
// parse the 7.html data here ... do with it as you will, it's in variable rawSeven
}
window.setInterval(getSeven30000);
</script> 
again ... the PHP HAS TO BE ON A SERVER THAT ALLOWS allow_url_fopen in the above case - there is no way around this problem

another consideration for the server side, it has to allow connections to arbitrary ports ... I've had a host with allow_url_fopen true ... but trying to retrieve external data on other than port 80 did not work

another consideration for the server ... cache the result of the read, for 30 seconds or more (not too much) ... if you expect a LOT of people to be using your web page


the above has been tested and proven to work

"If you don't like DNAS, write your own damn system"

So I did

Last edited by jaromanda; 21st June 2009 at 11:11.
jaromanda is offline   Reply With Quote
Old 21st June 2009, 11:29   #7
POMATu
Junior Member
 
Join Date: Jun 2009
Location: Russia
Posts: 15
Send a message via ICQ to POMATu
Oh f*ck... my hosting doesnt allow url foppen. Can you advice some free hosting which support domains (I use ******** domain), php, mysql, sockets, ssh, allow_url_fopen?

Linux is our friend!
POMATu is offline   Reply With Quote
Old 21st June 2009, 11:35   #8
POMATu
Junior Member
 
Join Date: Jun 2009
Location: Russia
Posts: 15
Send a message via ICQ to POMATu
php info of my hosting

http://free-host********/phpinfo.html

Linux is our friend!
POMATu is offline   Reply With Quote
Old 21st June 2009, 11:39   #9
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
I've looked before ... I've found some the allow_url_fopen ... but only well known ports like 80

yet to find one that allows arbitrary ports

"If you don't like DNAS, write your own damn system"

So I did
jaromanda is offline   Reply With Quote
Old 21st June 2009, 11:52   #10
POMATu
Junior Member
 
Join Date: Jun 2009
Location: Russia
Posts: 15
Send a message via ICQ to POMATu
on my hosting curl is enabled. maybe I can do something with it?

Linux is our friend!
POMATu is offline   Reply With Quote
Old 21st June 2009, 11:56   #11
POMATu
Junior Member
 
Join Date: Jun 2009
Location: Russia
Posts: 15
Send a message via ICQ to POMATu
<?php

$request = curl_init();
curl_setopt($request,CURLOPT_URL,'http://s1.myradiostream.com:9678/7.html');
curl_setopt($request,CURLOPT_RETURNTRANSFER,1);
curl_setopt($request,CURLOPT_TIMEOUT,0);

$response = curl_exec($request);
curl_close($request);
print $response;
?>

This is not working too((

Linux is our friend!
POMATu is offline   Reply With Quote
Old 21st June 2009, 12:14   #12
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
very important thing with DNAS is the User-Agent sent in the request

not sure how to do that with curl
edit:
code:

curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9');


"If you don't like DNAS, write your own damn system"

So I did
jaromanda is offline   Reply With Quote
Old 21st June 2009, 12:18   #13
POMATu
Junior Member
 
Join Date: Jun 2009
Location: Russia
Posts: 15
Send a message via ICQ to POMATu
I knew EXCELENT free web hosting, whith ewerething I need now, 000webhost.com, but now it is not working((

Linux is our friend!
POMATu is offline   Reply With Quote
Old 21st June 2009, 13:05   #14
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
Quote:
Originally posted by POMATu
I knew EXCELENT free web hosting, whith ewerething I need now, 000webhost.com, but now it is not working((
hmm .. i tried to sign up to them ... the ip_confirm.exe link doesn't work ... found an alternative ... virus!

so ... dunno

"If you don't like DNAS, write your own damn system"

So I did
jaromanda is offline   Reply With Quote
Old 21st June 2009, 16:39   #15
POMATu
Junior Member
 
Join Date: Jun 2009
Location: Russia
Posts: 15
Send a message via ICQ to POMATu
WOW! I found THAT hostig!!

Everything devoted to shoutcast works EXELENT!!

demontage.hyperphp.com/winstats/current.php

look!

the hosting is hyperphp.com!!!!!!!!!!!!!!!!!!!!

Linux is our friend!
POMATu is offline   Reply With Quote
Old 21st June 2009, 16:40   #16
POMATu
Junior Member
 
Join Date: Jun 2009
Location: Russia
Posts: 15
Send a message via ICQ to POMATu
Topic can now be closed!

Linux is our friend!
POMATu is offline   Reply With Quote
Old 22nd June 2009, 00:03   #17
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
do hyperphp require you to install a virus to setup free hosting as well ?


"If you don't like DNAS, write your own damn system"

So I did
jaromanda is offline   Reply With Quote
Old 22nd June 2009, 05:20   #18
Brutish Sailor
Major Dude
 
Brutish Sailor's Avatar
 
Join Date: Jan 2009
Location: San Diego CA
Posts: 998
Send a message via Skype™ to Brutish Sailor
If thats all your looking for, sign up with www.roxu.US and let one of the mods there (other than muahhhh LOL lazy) know your a station. They will provide you with a now playing PHP script, and a nice little page like so to boot.

The php display is Ifraimed, so you can put it on your site (I use the Icecast2 one on mine, because with the last Icecast update, NONE of the old scripts work right.)

heres what they give me, FREE MIND YOU!

http://roxu.us/Brutish

Im a big supporter, as its the best independent artist/ caster station/ hosting group I have seen.


While your there, join my group: Tin Can Broadcasters.

http://roxu.us/groups/entry/Tin-Can-Broadcasters


ts not a directory for profit site. The guy that runs it, Wildun, is a Hardcore voice in the JLA/ webcaster revolution. Scripted in dolphin all by himself and dedicated to hooking us up with independent artist and small labels that will send broadcasters like us artist demos.

KNSJ.org 89.1 FM San Diego

Last edited by Brutish Sailor; 22nd June 2009 at 06:03.
Brutish Sailor is offline   Reply With Quote
Old 22nd June 2009, 08:24   #19
POMATu
Junior Member
 
Join Date: Jun 2009
Location: Russia
Posts: 15
Send a message via ICQ to POMATu
jaromanda No of course not.

If you are so afraid of viruses, why don't you install linux? It is very easy. I am using linux for 3 years and I seem to be normal... If you want to try kubuntu.com. This is the easiest one

Linux is our friend!
POMATu is offline   Reply With Quote
Old 22nd June 2009, 10:47   #20
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
I've used linux since before Slackware 2.0 came out (which was July 2, 1994)

the point is ... the site asks you to download a program to "complete the registration" ... the program is a trojan ...

"If you don't like DNAS, write your own damn system"

So I did
jaromanda is offline   Reply With Quote
Old 22nd June 2009, 17:46   #21
POMATu
Junior Member
 
Join Date: Jun 2009
Location: Russia
Posts: 15
Send a message via ICQ to POMATu
Quote:
Originally posted by jaromanda
I've used linux since before Slackware 2.0 came out (which was July 2, 1994)

the point is ... the site asks you to download a program to "complete the registration" ... the program is a trojan ...
Yes that was at 000webhost.com, but not here...

Linux is our friend!
POMATu is offline   Reply With Quote
Old 22nd June 2009, 18:46   #22
Brutish Sailor
Major Dude
 
Brutish Sailor's Avatar
 
Join Date: Jan 2009
Location: San Diego CA
Posts: 998
Send a message via Skype™ to Brutish Sailor
Still dont like them, I had an add pop right into the middle of the page as soon as I went to that page, and that was with pop up blocker enabled in FF!

KNSJ.org 89.1 FM San Diego
Brutish Sailor is offline   Reply With Quote
Old 23rd June 2009, 12:34   #23
Killzone_Kid
Member
 
Join Date: Jan 2009
Posts: 88
You have PHP 5? Try file_get_contents it works with urls

$fileContents = file_get_contents("httppath")
Killzone_Kid is offline   Reply With Quote
Old 23rd June 2009, 13:56   #24
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,289
Quote:
Originally posted by Killzone_Kid
You have PHP 5? Try file_get_contents it works with urls

$fileContents = file_get_contents("httppath")
not if allow_url_fopen is false

"If you don't like DNAS, write your own damn system"

So I did
jaromanda is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Discussions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump