Gossamer Forum
Home : Products : Links 2.0 : Customization :

Auto Login Script in nph-build.cgi

Quote Reply
Auto Login Script in nph-build.cgi
 
I`m searching for an auto login script written in perl, which automatically creates a forum login at the end of nph-build.cgi.

All I have is this code:

Code:

<form action="http://www.some-forum.de/login.php" method="post" onsubmit="md5hash(vb_login_password,vb_login_md5password,vb_login_md5password_utf)">
<script type="text/javascript" src="clientscript/vbulletin_md5.js"></script>
<table cellpadding="0" cellspacing="3" border="0">
<tr>
<td class="smallfont">Benutzername - USERNAME </td>
<td><input type="text" class="button" name="vb_login_username" id="navbar_username" size="10" accesskey="u" tabindex="1" value="MyUserName" onfocus="if (this.value == 'Benutzername') this.value = '';" /></td>
<td class="smallfont" colspan="2" nowrap="nowrap"><label for="cb_cookieuser_navbar"><input type="checkbox" name="cookieuser" value="1" tabindex="3" id="cb_cookieuser_navbar" accesskey="c" checked="checked" />Angemeldet bleiben?</label>
</td>
</tr>
<tr>
<td class="smallfont">Kennwort - PASSWORD</td>
<td><input type="password" class="button" name="vb_login_password" size="10" accesskey="p" value="MyPASSWORD" tabindex="2" /></td>

<td><input type="submit" class="button" value="Anmelden - LOGIN" tabindex="4" title="Gib zur Anmeldung deinen Benutzernamen und dein Kennwort in die dafür vorgesehenen Textfelder ein oder klicke auf die 'Registrieren'-Schaltfläche, um ein neues Benutzerkonto anzulegen." accesskey="s" /></td>
</tr>
</table>

<!-- ATTENTION: name="s" : value = SessionID -->
<input type="hidden" name="s" value="d2e1f7b5dcfb23729db3d12efae2b06d" />

<input type="hidden" name="do" value="login" />
<input type="hidden" name="forceredirect" value="1" />
<input type="hidden" name="vb_login_md5password" />
<input type="hidden" name="vb_login_md5password_utf" />
</form>
</div>

The idea behind is to log into a forum and post new or updated links each time when the database has been rebuilt.
The new or updated links posting should be posted by nph-build.cgi .

I know it could become difficult ...
... because in later steps nph-build.cgi must receive the response of the website (for example : to store the posting identity).



Thanks for incoming replies Smile

.


Andreas

Dr.Windows








Last edited by:

SevenSpirits: Sep 10, 2007, 7:03 AM
Quote Reply
Re: [SevenSpirits] Auto Login Script in nph-build.cgi In reply to
Hello community -

in the meantime i tried to log in with this script:
( #: = englisch translation )


Code:

sub build_forum_connection {
#--------------------------
# 6 Session ID aus Quelltext extrahieren (extract session_id from source code)
# 6.1 Quelltext holen: #: get source code
print "Location: http://www.forum-auf-server-zwei.de\n\n"; #: url has phantasy name
$ua = LWP::UserAgent->new();
$total = get("http://www.forum-auf-server-zwei/login.php");
print "Content-type: text/plain\n\n";
$total =~ s/</&lt;/g; # elimates < character)

# 6.2 Session-ID extrahieren: # extract session_id : this part of the script does work)
$total =~ s/\|//g;
$total =~ s/(input type="hidden" name="s" value=".+?")/(input type="hidden" name="s" value=|.+?| )/;
$total =~ s/"input"//g;
$total =~ /(^\|(.+?)\|)/;
my $total = $1;
print "Testlauf","\n" ;
$total =~ s/(type="hidden" name="s" value=")//g;
$total =~ s/(")//g;
$total =~ s/(input )//g;
print $total ,"\n";

# 6.3 Aufruf der login.php #: call login.php
use HTTP::Request::Common qw(POST);
$url = 'http://www.forum-auf-server-zwei/login.php';
$req = POST $url,
[ vb_login_username => 'UserName',
vb_login_password => 'UserPasswort',
cookieuser => '1',
s => "$total", #$total = session_id
do => 'login',
forceredirect => '1'

];
print "HTTP-FullRequest-Header: \n";
print $req->headers->as_string() , "\n";
print "HTTP-FullRequest-Header-Content: \n";
print $req->content() ,"\n";

# 6.4 Anfrage absenden #: control request
use LWP::UserAgent;
$ua = LWP::UserAgent->new();
$ua->timeout(3);
$response = $ua->request($req);
if ( $response->is_error() ) {
print "Error-Code : ", $response->code() , "\n";
print "Fehlermeldung: ", $response->message() , "\n";
}
else { print $response->content() , "\n";
}
} # / sub build_forum_connection

The result:
It only seems that I`m logged in.
I can see my Nick in "Who is online" - but the script is not really logged in.
The webmaster (Server2) told me that this is a cookie problem.


Probably the solution:
Nph-build.cgi (installed on Server1) must be enabled to receive/send cookies
coming from the forum script on Server2.


I would be glad if somebody could help me.

.


Andreas

Dr.Windows








Quote Reply
Re: [SevenSpirits] Auto Login Script in nph-build.cgi In reply to
You will need some changes in the forum script, so that it recognizes your Links script is talking to it, and will allow some exceptions, such as no cookie and no confirmation messages.


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Auto Login Script in nph-build.cgi In reply to
Forum on server2 is a vbulletin forum.
It is very hard to use without cookies although it`s possible.

My link script (server1) can communicate with the forum script (server2) -
but my link script must be able to manage cookies from server2.

As a result of the code I posted in my previous post I can see my Nick in Who`s Online.
But at the top of the start page there is still the login form ... instead of logout form.

Webmaster of server2 told me that without cookie management in link script the problem cannot be solved.

For several reasons it is not possible to change the vbulletin forum script -
link script must log in as "user" without direct database access on server2 ( avoid damage).

But anyway - thanks for your advice Smile


Andreas

Dr.Windows








Last edited by:

SevenSpirits: Sep 16, 2007, 3:12 PM
Quote Reply
Re: [PerlFlunkie] Auto Login Script in nph-build.cgi In reply to
I found a solution:

What we need is the name of the cookie of http://www.forum-auf-server-zwei.de .
Use Internet Explorer for the forum login (cookies must be enabled) and find out the name of the cookie.

Name of the cookie = Name_of_the_cookie in the code below.

Example:
Your windows user name is andrew.
The name of the cookie : andrew@www.forum-auf-server-zwei[1].txt

Code:

sub build_forum_connection {

# Step 0 : (require Perl modules)
use LWP::UserAgent;
use HTTP::Request::Common qw(POST GET);
use HTTP::Cookies;

# Step 1 : (prepare cookie)
$ua = LWP::UserAgent->new;
$ua->cookie_jar(HTTP::Cookies->new(file => "Name_of_ the_cookie", autosave => 1));

# Step 2 : (proof url)
$res = $ua->request(HTTP::Request->new(GET => "http://www.forum-auf-server-zwei.de"));
print $res->status_line, "\n";

# step 3 :
my $ua = LWP::UserAgent->new;
# Define user agent type
$ua->agent('Mozilla/8.0');
# Cookies
$ua->cookie_jar(HTTP::Cookies->new(file => 'Name des Cookies', autosave => 1 ));
# Request object
my $req = GET 'http://www.forum-auf-server-zwei.de';
# Make the request
my $res = $ua->request($req);
# Check the response - deactivated
#if ($res->is_success) {print $res->content;}
#else {print $res->status_line . "\n";}

# Step 4 : (send login data to login form)
# Login Form über Quelltext : URL des Forums ermitteln
my $req = POST 'http://www.forum-auf-server-zwei.de/login.php' , [ vb_login_username => 'User Name', vb_login_password => 'User Passwort', cookieuser => '1', s => "", do => 'login', forceredirect => '1' ] ;
# Make the request
my $res = $ua->request($req);
# Check the response (deactivated because response does contain an unwanted redirection)
#if ($res->is_success) {print $res->content;}
#else {print $res->status_line . "\n";}

# Step 5 : Now we control whether the login was successful
my $req = GET 'http://www.forum-auf-server-zwei.de';
my $res = $ua->request($req);
if ($res->is_success) {print $res->content;} # nur zur Kontrolle erforderlich # optinal
else {print $res->status_line . "\n";} # nur zur Kontrolle erforderlich # optional


### Hurra - login was succesful ###



### How can we write or do anything else in the forum? ###

# Gewünschten Forumsbeitrag anforden:
# <1> Request the URL of the wanted thread : URL_Thread
my $req = GET 'URL_Thread';
my $res = $ua->request($req);
## if ($res->is_success) {print $res->content;} # nur zur Kontrolle erforderlich # optional
## else {print $res->status_line . "\n";} # nur zur Kontrolle erforderlich # optional


# Quelltext des Forumsbeitrages ermitteln ( URL der gewünschten Funktion wird benötigt ) und
# aus Quelltext der dann aufgerufenen Seite die notwendigen Variablen für POST und die "Sende an URL" der Seite ermiteln
# Bzw. im Quelltext : FORM TAG analysieren
# Nachfolgendes Beispiel bezieht sich auf die Beitrag Melden Funktion ,
# welche registrierten Usern eines Vbulletin Forums zur Verfügung steht

## We have to look at the source code of the requested thread : Do this by using your browser
## In subject to what you want to do (to reply or something else)
## You must extract the URL of the wanted function
## Analyze the form action tag in the source code by using your browser
## Example below refers to the Beitrag Melden function,
## which is available for registered user of VBulletin forums

# Beitrag Melden Seite anfordern :
# Request Beitrag Melden page
my $req = GET 'URL_of_Beitrag_Melden ';
my $res = $ua->request($req);

# POST formulieren:
# write the post request:
# Senden an URL der Antwortseite : Analyze the form action tag in the source code of the Beitrag Melden page and
# use the extracted url
my $req = POST 'Senden an URL der Antwortseite' , [do => '...' , s => "" , reason => '...' , p => '...' , url =>'...' ] ;
my $res = $ua->request($req);

# Erfolgskontrolle (optional):
# Now we control whether we had success
my $req = GET 'URL_Thread';
my $res = $ua->request($req);
if ($res->is_success) {print $res->content;} # nur zur Kontrolle erforderlich
else {print $res->status_line . "\n";} # nur zur Kontrolle erforderlich

### / How can we write or do anything else in the forum? ###

} # / sub build_forum_connection


Of course this is no paste and copy code.
You must have a basic knowledge of perl and html.

But I hope that it will be useful for most of the users of this forum.
I hope too that my comments in the code are understandable.

.


Andreas

Dr.Windows