![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" | iBot | UNIX and Linux RSS News | 0 | 01-04-2008 03:00 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 01:52 AM |
| LinuxCertified Announces its next "Linux Fundamentals" Course. - LXer (press release) | iBot | UNIX and Linux RSS News | 0 | 10-05-2007 04:40 PM |
| By angle-brackets/"pipe" button doesn't work? | riwa | Linux | 1 | 04-02-2006 06:43 PM |
| No "sign in" button | milhan | Post Here to Contact Site Administrators and Moderators | 1 | 07-24-2004 07:57 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Press an "I Accept the Terms" button on a webpage
So I have this script to detect if I am on a certain public network. Before the network can be used I have to press an "I Accept the Terms" button on a redirect page. Is there a way I can script this? I want to do it automatically so that I can start my internet dependent programs once I actually have access. I think i have to use this "PHP" and call it from my basic linux command line script....
Any ideas? |
|
||||
|
What language you use is immaterial. If the link is static, just run wget or curl on the URL. If the link is not static, you have to download the page (again, probably using wget or curl) and parse out the link. If it requires you to have a session cookie from the start page to where the link points to, things get a little complex; perhaps you can drive a browser such as lynx or w3m from Expect, or something. A simple Perl libwww script would be ideal if you are familiar with Perl, or you can use PHP.
|
|
||||
|
It is a static link with no cookies, the permission to use the network lasts 24 hours. So what Ill do is something like this:
get html and parse with grep to see if the link is there if it is I will use perl to press the button (I am googling this now) if it isnt there I will exit. Ive never used perl before and my most complicated script is a mere 20 lines long so this should be a good learning experience. Thanks! |
|
||||
|
So using wget and the option --post-data=string I can use a string to press the button.
To figure out what to use, I should poke around in the Page Source and see what it wants right? Code:
<html>
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<title>Marquette General Health System - Public Internet</title>
<script>
function submitAction(){
var link = document.location.href;
var searchString = "redirect=";
var equalIndex = link.indexOf(searchString);
var redirectUrl = "";
var urlStr = "";
if(equalIndex > 0) {
equalIndex += searchString.length;
urlStr = link.substring(equalIndex);
if(urlStr.length > 0){
redirectUrl += urlStr;
if(redirectUrl.length > 255)
redirectUrl = redirectUrl.substring(0,255);
document.forms[0].redirect_url.value = redirectUrl;
}
}
document.forms[0].buttonClicked.value = 4;
document.forms[0].submit();
}
function reject()
{
alert("You will not be able to access the system!");
}
function loadAction(){
var url = window.location.href;
var args = new Object();
var query = location.search.substring(1);
var pairs = query.split("&");
for(var i=0;i<pairs.length;i++){
var pos = pairs[i].indexOf('=');
if(pos == -1) continue;
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
args[argname] = unescape(value);
}
document.forms[0].action = args.switch_url;
}
</script>
</head>
<body topmargin="50" marginheight="50" onload="loadAction();">
<form method="post">
<input TYPE="hidden" NAME="buttonClicked" SIZE="16" MAXLENGTH="15" value="0">
<input TYPE="hidden" NAME="redirect_url" SIZE="255" MAXLENGTH="255" VALUE="">
<input TYPE="hidden" NAME="err_flag" SIZE="16" MAXLENGTH="15" value="0">
<div align="center">
<p> </p>
<table border="0" cellspacing="0" cellpadding="0">
<tr> <td></td></tr>
<p><img border="0" src="topmain.jpg" width="635" height="166"></p>
</font></td></tr>
<p><font size="2" face="Arial, Helvetica, sans-serif">We are pleased to provide
our visitors and patients with complimentary wireless access to the internet.</font></p>
<p><font size="2" face="Arial, Helvetica, sans-serif">Whether
emailing updates on your family member who is hospitalized, or keeping
up with work commitments, we hope you'll find this service useful
to you.</font></p>
<p><font size="2" face="Arial, Helvetica, sans-serif">We would appreciate
your feedback on any aspect of wireless access provided for your convenience.</font></p>
<p><font size="2" face="Arial, Helvetica, sans-serif">In a time when there
are many intrusive and questionable uses of the internet, we request
that you take a moment to read the following <a href="terms.htm" target="_blank">terms</a> for
your information and protection. By clicking on the button below you
signify that you agree to the terms.</font></p>
<td colspan="2"><div align="center"> <input type="button" name="Submit" value="I Accept the Terms" class="button" onclick="submitAction();"></div>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
It looks like this is what I need to address with a script: Code:
function submitAction(){
var link = document.location.href;
var searchString = "redirect=";
var equalIndex = link.indexOf(searchString);
var redirectUrl = "";
var urlStr = "";
if(equalIndex > 0) {
equalIndex += searchString.length;
urlStr = link.substring(equalIndex);
if(urlStr.length > 0){
redirectUrl += urlStr;
if(redirectUrl.length > 255)
redirectUrl = redirectUrl.substring(0,255);
document.forms[0].redirect_url.value = redirectUrl;
}
}
document.forms[0].buttonClicked.value = 4;
document.forms[0].submit();
}
|
|
||||
|
It looks like the JavaScript picks out anything after redirect= in the current URL as the destination, if I'm interpreting it correctly. If that's the case then you just need to pick it out. There might be more going on behind the scenes, though; in particular, the HTTP headers will reveal if there are cookies involved. (I'm guessing there will be, based on other similar systems I have seen.)
|
![]() |
| Bookmarks |
| Tags |
| web page |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|