The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-07-2008
arcnsparc arcnsparc is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 9
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?
  #2 (permalink)  
Old 09-08-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.
  #3 (permalink)  
Old 09-08-2008
arcnsparc arcnsparc is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 9
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!
  #4 (permalink)  
Old 09-08-2008
arcnsparc arcnsparc is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 9
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>&nbsp;</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>
That is the full code of the webpage

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();
}
Am I on the right track here or am I just going off in the wrong direction....
  #5 (permalink)  
Old 09-09-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.)
Closed Thread

Bookmarks

Tags
web page

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0