NATION

PASSWORD

Login Scripts?

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.
User avatar
Empire of Narnia
Negotiator
 
Posts: 5577
Founded: Oct 18, 2011
Ex-Nation

Login Scripts?

Postby Empire of Narnia » Sat Sep 08, 2012 9:53 pm

Would I be allowed rules-wise to make a script that would automatically log into my puppet nations to stop them from CTE'ing? If so does anybody have a script I could use or instructions to make one? It would just need to log into the nations within 28 days. I don't need it to answer issues or anything.

User avatar
Improving Wordiness
Diplomat
 
Posts: 641
Founded: Dec 05, 2009
Ex-Nation

Postby Improving Wordiness » Sun Sep 09, 2012 12:22 am

You could contact Ballotonia as he used to use a log in script (not sure if he still does) Also UDL have a log in script I believe they use so you could make contact with Unibot to ask.
As far as I know it is not illegal to use a script to log in.
Klaus Devestatorie wrote:I'm a massive tool. ;)

User avatar
Ballotonia
Senior Admin
 
Posts: 5494
Founded: Antiquity
Liberal Democratic Socialists

Postby Ballotonia » Sun Sep 09, 2012 12:55 am

Yes, that is legal.

Here's a legal login script, in Perl:
Code: Select all
#!/usr/bin/env perl
use strict;
use warnings;
use WWW::Mechanize;

# Enter your MAIN Nation name here:
my $username = "YOURMAINNATIONNAME";

# Enter names and passwords of your nations here:
my @nations = (
  ["nation1", "password1"],
  ["nation2", "password2"],
  ["nation3", "password3"],
);

# ---------------------------------------------------------------------------------------------
# --- Nothing to edit beyond this point ---
my $delayTime = 6; # pause between fetches
my $mech = WWW::Mechanize->new ();
$mech->agent ("Nation:$username ");

foreach my $loginItem (@nations)
{
  my $nation = lc($loginItem->[0]);
  $nation =~ s/ /_/g;
  my $password = $loginItem->[1];
  print "LOGIN: $nation\n";
  my %envelop = ( nation => $nation, password => $password, logging_in => 1);
  while (!defined eval {$mech->post ("http://www.nationstates.net", \%envelop)})
  {
    print "Trying again...\n";
    sleep ($delayTime);
  }
  sleep ($delayTime);
  my $pageContent = $mech->content ();
  utf8::decode ($pageContent);
  if (-1 == rindex ($pageContent, "a href=\"nation=$nation\" class=\"STANDOUT\""))
  {
    print "LOGIN FAILED! Halting run...\n";
    last; # jump out of foreach loop
  }
}


Make sure to fill in the stuff at the top: main nation name (needed for the UserAgent, so Admin knows who is running which script.) and of course the names and passwords of your nations.

Note that this script uses a 6 second delay between calls, which is important for it to be legal (don't run more than one script at a time though).

Ballotonia
"Een volk dat voor tirannen zwicht zal meer dan lijf en goed verliezen, dan dooft het licht…" -- H.M. van Randwijk

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Sun Nov 11, 2012 5:39 pm

Would it be feasible to replicate this in PHP?
KEEP THE BLOOD CAVE FREE

User avatar
Unibot III
Negotiator
 
Posts: 7110
Founded: Mar 11, 2011
Democratic Socialists

Postby Unibot III » Sun Nov 11, 2012 6:14 pm

For Ballo's script use no capitals and use underscores for spaces in regards to nation-names.

Also, be warned, if you have handed out a nation to someone that's on that list and the script is run while your friend is borrowing your nation and using it as a WA Nation while you also have a WA Nation.. it appears as multing to the mods. Speaking from experiencing.
[violet] wrote:I mean this in the best possible way,
but Unibot is not a typical NS player.
Milograd wrote:You're a caring, resolute lunatic
with the best of intentions.
Org. Join Date: 25-05-2008 | Former Delegate of TRR

Factbook // Collected works // Gameplay Alignment Test //
9 GA Res., 14 SC Res. // Headlines from Unibot // WASC HQ: A Guide

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
✯ Duty is Eternal, Justice is Imminent: UDL

User avatar
Ballotonia
Senior Admin
 
Posts: 5494
Founded: Antiquity
Liberal Democratic Socialists

Postby Ballotonia » Sun Nov 11, 2012 11:56 pm

I do not speak php, so someone else will have to translate it into php.

Unibot III wrote:For Ballo's script use no capitals and use underscores for spaces in regards to nation-names.


The above script does not have that as a requirement. The name "Unibot III" should work.

Unibot III wrote:Also, be warned, if you have handed out a nation to someone that's on that list and the script is run while your friend is borrowing your nation and using it as a WA Nation while you also have a WA Nation.. it appears as multing to the mods. Speaking from experiencing.


It doesn't just appear as multying, it IS multying.

Ballotonia
"Een volk dat voor tirannen zwicht zal meer dan lijf en goed verliezen, dan dooft het licht…" -- H.M. van Randwijk

User avatar
Unibot III
Negotiator
 
Posts: 7110
Founded: Mar 11, 2011
Democratic Socialists

Postby Unibot III » Mon Nov 12, 2012 1:00 am

Ballotonia wrote:The above script does not have that as a requirement. The name "Unibot III" should work.


Ah okay, upgrades. :)
[violet] wrote:I mean this in the best possible way,
but Unibot is not a typical NS player.
Milograd wrote:You're a caring, resolute lunatic
with the best of intentions.
Org. Join Date: 25-05-2008 | Former Delegate of TRR

Factbook // Collected works // Gameplay Alignment Test //
9 GA Res., 14 SC Res. // Headlines from Unibot // WASC HQ: A Guide

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
✯ Duty is Eternal, Justice is Imminent: UDL

User avatar
Scoochi2
Envoy
 
Posts: 207
Founded: Antiquity
Ex-Nation

Postby Scoochi2 » Mon Nov 12, 2012 5:08 am

Letoilenoir wrote:Would it be feasible to replicate this in PHP?

my login script is in pure PHP.
However most servers have a fixed 30 second execution limit.
If you have control, change the value in php.ini to whatever you need (more nations = more time).

If you run PHP locally, you DO have control.
The problem with a UDP joke is that you have no idea if people got it.

User avatar
The Blaatschapen
Technical Moderator
 
Posts: 63226
Founded: Antiquity
Anarchy

Postby The Blaatschapen » Mon Nov 12, 2012 12:09 pm

Scoochi2 wrote:
Letoilenoir wrote:Would it be feasible to replicate this in PHP?

my login script is in pure PHP.
However most servers have a fixed 30 second execution limit.
If you have control, change the value in php.ini to whatever you need (more nations = more time).

If you run PHP locally, you DO have control.


You can also use set_time_limit(). This has the benefit that you don't need to tweak php.ini by which other scripts might also be affected.
The Blaatschapen should resign

User avatar
Scoochi2
Envoy
 
Posts: 207
Founded: Antiquity
Ex-Nation

Postby Scoochi2 » Mon Nov 12, 2012 3:36 pm

The Blaatschapen wrote:
Scoochi2 wrote:my login script is in pure PHP.
However most servers have a fixed 30 second execution limit.
If you have control, change the value in php.ini to whatever you need (more nations = more time).

If you run PHP locally, you DO have control.


You can also use set_time_limit(). This has the benefit that you don't need to tweak php.ini by which other scripts might also be affected.

likewise, you can add the following to .htaccess as follows (for a 60 second timeout):
php_value max_execution_time 60


However, some hosts do limit those methods as well unfortunately :(
The problem with a UDP joke is that you have no idea if people got it.

User avatar
The Blaatschapen
Technical Moderator
 
Posts: 63226
Founded: Antiquity
Anarchy

Postby The Blaatschapen » Wed Feb 06, 2013 4:50 am

Ballotonia wrote:Yes, that is legal.

Here's a legal login script, in Perl:
Code: Select all
#!/usr/bin/env perl
use strict;
use warnings;
use WWW::Mechanize;

# Enter your MAIN Nation name here:
my $username = "YOURMAINNATIONNAME";

# Enter names and passwords of your nations here:
my @nations = (
  ["nation1", "password1"],
  ["nation2", "password2"],
  ["nation3", "password3"],
);

# ---------------------------------------------------------------------------------------------
# --- Nothing to edit beyond this point ---
my $delayTime = 6; # pause between fetches
my $mech = WWW::Mechanize->new ();
$mech->agent ("Nation:$username ");

foreach my $loginItem (@nations)
{
  my $nation = lc($loginItem->[0]);
  $nation =~ s/ /_/g;
  my $password = $loginItem->[1];
  print "LOGIN: $nation\n";
  my %envelop = ( nation => $nation, password => $password, logging_in => 1);
  while (!defined eval {$mech->post ("http://www.nationstates.net", \%envelop)})
  {
    print "Trying again...\n";
    sleep ($delayTime);
  }
  sleep ($delayTime);
  my $pageContent = $mech->content ();
  utf8::decode ($pageContent);
  if (-1 == rindex ($pageContent, "a href=\"nation=$nation\" class=\"STANDOUT\""))
  {
    print "LOGIN FAILED! Halting run...\n";
    last; # jump out of foreach loop
  }
}


Make sure to fill in the stuff at the top: main nation name (needed for the UserAgent, so Admin knows who is running which script.) and of course the names and passwords of your nations.

Note that this script uses a 6 second delay between calls, which is important for it to be legal (don't run more than one script at a time though).

Ballotonia


Sorry for the revival of this thread, but Ballotonia, can I post an edit on this login script that I made, that will notify the user which puppet has a new telegram?

I just tested it with the new TG system :)
The Blaatschapen should resign

User avatar
Svobodny
Lobbyist
 
Posts: 25
Founded: Aug 08, 2011
Ex-Nation

Postby Svobodny » Wed Feb 06, 2013 4:55 am

What do you use to execute these scripts? Does it require third party software to be downloaded? If so, from where? I've been looking into doing this for sometime but don't know where to start - never thought to post here!
Svobodný Republika

User avatar
Ballotonia
Senior Admin
 
Posts: 5494
Founded: Antiquity
Liberal Democratic Socialists

Postby Ballotonia » Wed Feb 06, 2013 8:13 am

The Blaatschapen wrote:Sorry for the revival of this thread, but Ballotonia, can I post an edit on this login script that I made, that will notify the user which puppet has a new telegram?

I just tested it with the new TG system :)


It's ok to post any legal script for others to use as well.

Ballotonia
"Een volk dat voor tirannen zwicht zal meer dan lijf en goed verliezen, dan dooft het licht…" -- H.M. van Randwijk

User avatar
Jamie Anumia
Senator
 
Posts: 3797
Founded: Feb 15, 2012
Ex-Nation

Postby Jamie Anumia » Wed Feb 06, 2013 8:19 am

Svobodny wrote:What do you use to execute these scripts? Does it require third party software to be downloaded? If so, from where? I've been looking into doing this for sometime but don't know where to start - never thought to post here!

To run Ballotonia's script you need Perl. Though other users have made login scripts using alternative programs such as PHP too.
Last edited by Jamie Anumia on Wed Feb 06, 2013 8:20 am, edited 1 time in total.

User avatar
The Blaatschapen
Technical Moderator
 
Posts: 63226
Founded: Antiquity
Anarchy

Postby The Blaatschapen » Wed Feb 06, 2013 8:21 am

Ballotonia wrote:
The Blaatschapen wrote:Sorry for the revival of this thread, but Ballotonia, can I post an edit on this login script that I made, that will notify the user which puppet has a new telegram?

I just tested it with the new TG system :)


It's ok to post any legal script for others to use as well.

Ballotonia

Good. Though it was more a question on what permissions I have to modify and redistribute your script.

Code: Select all
#!/usr/bin/env perl
use strict;
use warnings;
use WWW::Mechanize;

# Enter your MAIN Nation name here:
my $username = "YOURMAINNATIONNAME";

# Enter names and passwords of your nations here:
my @nations = (
  ["nation1", "password1"],
  ["nation2", "password2"],
  ["nation3", "password3"],
);

# ---------------------------------------------------------------------------------------------
# --- Nothing to edit beyond this point ---
my $delayTime = 6; # pause between fetches
my $mech = WWW::Mechanize->new ();
$mech->agent ("Nation:$username ");

foreach my $loginItem (@nations)
{
  my $nation = lc($loginItem->[0]);
  $nation =~ s/ /_/g;
  my $password = $loginItem->[1];
  print "\nLOGIN: $nation";
  my %envelop = ( nation => $nation, password => $password, logging_in => 1);
  while (!defined eval {$mech->post ("http://century.nationstates.net", \%envelop)})
  {
    print "Trying again...\n";
    sleep ($delayTime);
  }
  sleep ($delayTime);
  my $pageContent = $mech->content ();
  utf8::decode ($pageContent);
  if (-1 == rindex ($pageContent, "a href=\"nation=$nation\" class=\"STANDOUT\""))
  {
    print "LOGIN FAILED! Halting run...\n";
    last; # jump out of foreach loop
  }
if (-1 != rindex ($pageContent, "You have <a href=\"page=telegrams\">"))
  {
    print " has telegrams";
  }
}


I added 1 new if clause in the whole thing and rearranged where it does a linebreak. I hope this helps people.
Last edited by The Blaatschapen on Thu Feb 26, 2015 1:19 pm, edited 1 time in total.
Reason: Changed 'www' into 'century' to keep it working with the new theme
The Blaatschapen should resign

User avatar
QuietDad of TNP
Civil Servant
 
Posts: 7
Founded: Feb 14, 2015
Left-Leaning College State

Postby QuietDad of TNP » Mon Dec 30, 2019 8:41 pm

I've been running this script once a month for years without issue. Recently, after running it, I was warned by the admins that it violates the rules by direct HTML calls and not using the API. Looking at it (I'm a programmer for decades),it uses PERL's POST funtion and logs you on thru the web site and not the API. I see that this does violate terms of service,I just have run it monthly for years (scheduled chron job) without an issue supporting my 650+ puppets.
While I fully see the issues and will use one of the other solutions that do a direct API call, I'm just warning everyone while I ran it forever without issue, it doesn't make it right

User avatar
All Wild Things
Diplomat
 
Posts: 526
Founded: Apr 24, 2017
Inoffensive Centrist Democracy

Postby All Wild Things » Tue Dec 31, 2019 3:02 am

QuietDad of TNP wrote:I've been running this script once a month for years without issue. Recently, after running it, I was warned by the admins that it violates the rules by direct HTML calls and not using the API. Looking at it (I'm a programmer for decades),it uses PERL's POST funtion and logs you on thru the web site and not the API. I see that this does violate terms of service,I just have run it monthly for years (scheduled chron job) without an issue supporting my 650+ puppets.
While I fully see the issues and will use one of the other solutions that do a direct API call, I'm just warning everyone while I ran it forever without issue, it doesn't make it right

There's more updated ones included here:
https://www.nationstates.net/page=dispa ... 34239#tech

If you come across others, please let me know!
Browse The NewsStand
Watch the Wild Life

User avatar
The JELLEAIN Republic
Ambassador
 
Posts: 1517
Founded: Jul 15, 2019
Ex-Nation

Postby The JELLEAIN Republic » Tue Dec 31, 2019 5:24 am

How would use such a script? Where do you, ... put it ?
May the autocorrect be with you...
Cannot think of a name wrote:It's a narrative, and narratives don't require masterminds or persian cats.
Male. Lives in USA. Quotes
The Greater Ohio Valley wrote:Same here. I wash my hands religiously to keep the medical debt away.

User avatar
Cekoviu
Post Marshal
 
Posts: 16954
Founded: Oct 18, 2017
Ex-Nation

Postby Cekoviu » Tue Dec 31, 2019 3:03 pm

The JELLEAIN Republic wrote:How would use such a script? Where do you, ... put it ?

https://www.nationstates.net/pages/api.html#examples
If you write a Perl script, you can put it anywhere and call it using the perl command with the filename as an argument. PHP scripts can be run by installing XAMPP and either opening the script in a browser or (better option for this) directly accessing PHP from the shell. Then to periodically run the script, use cron (on Unix-like systems; no idea how to do it in Windows). You can just Google this - there are simple tutorials for executing scripts in all kinds of languages and for scheduling commands.
pro: women's rights
anti: men's rights

User avatar
[violet]
Executive Director
 
Posts: 16205
Founded: Antiquity

Postby [violet] » Tue Dec 31, 2019 5:31 pm

QuietDad of TNP wrote:I've been running this script once a month for years without issue. Recently, after running it, I was warned by the admins that it violates the rules by direct HTML calls and not using the API.

Actually you were warned for violating the rate limit, because you were making ~30 requests per minute, which is three times more than the rules permit.

I see this script has a delay built-in, but it seems like each request triggers a couple of redirects, which means you're making 3x more requests than you think.

Nowadays it's strongly recommended that people use the API instead, which is faster, more reliable, and avoids all of these kinds of problems, but we don't insist on it.

User avatar
QuietDad of TNP
Civil Servant
 
Posts: 7
Founded: Feb 14, 2015
Left-Leaning College State

Postby QuietDad of TNP » Tue Dec 31, 2019 11:05 pm

Again,rules are rules and I am not "defending" anything. I've just run it since it came out and have never had an issue with it. I am editing the script and incereasing the built in delay from 6 to 60 and we'll see if that helps. The issue have is that due to gameplay I have over 650 puppet nations and some of the other "solutions" require loging on to every puppet at least once and I just dont have the patience

User avatar
Canyamel
Attaché
 
Posts: 69
Founded: Oct 31, 2017
Ex-Nation

Postby Canyamel » Wed Jan 01, 2020 8:23 am

One question about the scripts, are these two legal?
viewtopic.php?f=15&t=401352
viewtopic.php?f=12&t=423382&start=58

User avatar
[violet]
Executive Director
 
Posts: 16205
Founded: Antiquity

Postby [violet] » Wed Jan 01, 2020 5:33 pm

Unfortunately admin doesn't usually have the capacity to read other people's source code and try to figure out what it does. So we can't certify third-party scripts.

As a general rule, you're fine with any script that uses the NationStates API. There's really only one thing you can screw up there: Failing to set an identifying UserAgent. So long as you do that, the worst that can happen is that the API might lock your script out for a brief period if it detects you've gone over the rate limit. You can't accidentally make any illegal requests or break site rules.

A script that interacts with the HTML site instead, however, has to make sure it sticks to the rules all by itself. There's no automatic enforcement of this; instead, there's just an admin like me checking site logs every now and again. And I see a script breaking the rules, your IP address can get banned, which locks you (not just your script) out of the whole site.

Some older scripts (like the one in this thread) were written before the API existed as it does today. There are newer alternatives available that do the same thing only better, because they use the API. The older HTML scripts are still legal, but potentially dangerous, for the reasons mentioned above.

User avatar
Random Card Farmer 6
Civilian
 
Posts: 1
Founded: Mar 20, 2023
Authoritarian Democracy

How do i execute this?

Postby Random Card Farmer 6 » Tue Sep 19, 2023 1:18 pm

Ballotonia wrote:Yes, that is legal.

Here's a legal login script, in Perl:
Code: Select all
#!/usr/bin/env perl
use strict;
use warnings;
use WWW::Mechanize;

# Enter your MAIN Nation name here:
my $username = "YOURMAINNATIONNAME";

# Enter names and passwords of your nations here:
my @nations = (
  ["nation1", "password1"],
  ["nation2", "password2"],
  ["nation3", "password3"],
);

# ---------------------------------------------------------------------------------------------
# --- Nothing to edit beyond this point ---
my $delayTime = 6; # pause between fetches
my $mech = WWW::Mechanize->new ();
$mech->agent ("Nation:$username ");

foreach my $loginItem (@nations)
{
  my $nation = lc($loginItem->[0]);
  $nation =~ s/ /_/g;
  my $password = $loginItem->[1];
  print "LOGIN: $nation\n";
  my %envelop = ( nation => $nation, password => $password, logging_in => 1);
  while (!defined eval {$mech->post ("http://www.nationstates.net", \%envelop)})
  {
    print "Trying again...\n";
    sleep ($delayTime);
  }
  sleep ($delayTime);
  my $pageContent = $mech->content ();
  utf8::decode ($pageContent);
  if (-1 == rindex ($pageContent, "a href=\"nation=$nation\" class=\"STANDOUT\""))
  {
    print "LOGIN FAILED! Halting run...\n";
    last; # jump out of foreach loop
  }
}


Make sure to fill in the stuff at the top: main nation name (needed for the UserAgent, so Admin knows who is running which script.) and of course the names and passwords of your nations.

Note that this script uses a 6 second delay between calls, which is important for it to be legal (don't run more than one script at a time though).

Ballotonia

User avatar
Roavin
Admin
 
Posts: 1777
Founded: Apr 07, 2016
Democratic Socialists

Postby Roavin » Tue Sep 19, 2023 2:14 pm

You shouldn't run that anymore; it's old, slow, based on an outdated method, and likely won't even work anymore.

There are a variety of API-using tools these days that you could use. They are faster, safer, and easier to use. I personally use Auralia's NSLogin (there's a web version here), but there are a number of other tools around as well.
Helpful Resources: One Stop Rules Shop | API documentation | NS Coders Discord
About me: Longest serving Prime Minister in TSP | Former First Warden of TGW | aka Curious Observations

Feel free to TG me, but not about moderation matters.


Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: 7 Trees, Azmeny, Catsfern, Democratic Republic of Belarus, Dharmasya, Greater New Orleans, Hetaru, Sorocamirim, Tepertopia, World dictating

Advertisement

Remove ads