Automatic RCON Password Changer
#1

A very simple RCON automatic password changer, just really to show you how it's changed (for the newbies), may come in useful.

The timer is set to automatically change the RCON password and print it to the server console every half an hour.

FYI.. I don't care about credits for this as long as you don't re-produce this with the exact same code or just modified (unless you're contributing an update/fix, in this thread).

Older Version (a little less efficient)
pawn Код:
#include <a_samp>

/*
    ---------------------------
    Automatic RCON Password Changer (ARPC).
    Created by Calgon.
    ---------------------------
   
    Credits to DracoBlue, using DCMD. Would use ZCMD, but couldn't be bothered to use a billion includes.
    Credits to Popz, for the alphanumeric password idea (and a vast amount of the code for it).
    Credits to ******, for the simple but effective RandomEx().
*/


#define PASSWORD_LENGTH 20

new RconPass[PASSWORD_LENGTH];
new changer;

forward PasswordChange();
forward RandomEx(min, max);

#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

public OnFilterScriptInit()
{
    print(" ARPC has been initiated.");
    PasswordChange();
    changer = SetTimer("PasswordChange", 300000, 1);
    return 1;
}

dcmd_forcepasschange(playerid, params[])
{
    #pragma unused params
    if(IsPlayerAdmin(playerid))
    {
      PasswordChange();
      KillTimer(changer);
      changer = SetTimer("PasswordChange", 300000, 1);
    }
    else
    {
      SendClientMessage(playerid, 0xFFFFFFAA, "You must connect to RCON.");
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(forcepasschange, 15, cmdtext);
    return 0;
}

public RandomEx(min, max)
{
    return random(max - min) + min;
}

public PasswordChange()
{
    new string[128];
  for(new i=0; i<MAX_PLAYERS; i++)
  {
        if(IsPlayerConnected(i) && IsPlayerAdmin(i))
        {
          SendClientMessage(i, 0xFFFFFFAA, "The RCON password is changing!");
        }
  }
 
    new charset[63] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    for(new i = 0; i < PASSWORD_LENGTH; i++)
    {
    RconPass[i] = charset[RandomEx(0,62)];
    }
 
    format(string, sizeof(string), "rcon_password %s", RconPass);
    SendRconCommand(string);
    printf(" [SYSTEM] A new RCON password has been set (%s).", RconPass);
    return 1;
}

public OnFilterScriptExit()
{
    KillTimer(changer);
  print("ARPC is now de-initializing..");
    return 1;
}
Added /forcepasschange for connected RCON admins. It executes PasswordChange() and resets the timer.
Added (thanks to Popz) alphanumeric support; passwords are now alphanumeric and differ in case.
Added definable password length, you can change it by editing the PASSWORD_LENGTH variable.
[31st of August 2010] Added improved code written by ****** (below)

pawn Код:
#include <a_samp>

/*
    ---------------------------
    Automatic RCON Password Changer (ARPC).
    Created by Calgon.
    ---------------------------

    Credits to DracoBlue, using DCMD. Would use ZCMD, but couldn't be bothered to use a billion includes.
    Credits to Popz, for the alphanumeric password idea (and a vast amount of the code for it).
    Credits to ******, for the simple but effective RandomEx() & for re-writing this version.
*/


#define PASSWORD_LENGTH 20

new
    gTimer;

forward PasswordChange();

#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

public OnFilterScriptInit()
{
    print(" ARPC has been initiated.");
    PasswordChange();
    gTimer = SetTimer("PasswordChange", 300000, 1);
    return 1;
}

dcmd_forcepasschange(playerid, params[])
{
    #pragma unused params
    if(IsPlayerAdmin(playerid))
    {
        PasswordChange();
        KillTimer(gTimer);
        gTimer = SetTimer("PasswordChange", 300000, 1);
    }
    else
    {
        SendClientMessage(playerid, 0xFFFFFFAA, "You must connect to RCON.");
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(forcepasschange, 15, cmdtext);
    return 0;
}

RandomEx(min, max)
{
    return random(max - min) + min;
}

public PasswordChange()
{
    new
        string[PASSWORD_LENGTH + 15];
    static const
        charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    for(new i = 0; i < PASSWORD_LENGTH; i++)
    {
        string[i] = charset[RandomEx(0, sizeof (charset) - 1)];
    }
    printf(" [SYSTEM] A new RCON password has been set (%s).", string);
    format(string, sizeof(string), "rcon_password %s", string);
    SendRconCommand(string);
    return 1;
}

public OnFilterScriptExit()
{
    KillTimer(gTimer);
    print("ARPC is now de-initializing..");
    return 1;
}
Reply
#2

This is good for several reasons:
  • Very easy to understand
  • Extremely useful. I cannot stress enough, the positive impact on security a random RCON password can have.
  • Simple but effective
Good job.

One question, say I wanted to add a command so that I could check what the current RCON password is, how would that be done .. store it in a variable?
Reply
#3

Good job Calgon,

youґre one of the pro scripters here for me (because you help me sometimes )

Keep it up. I will probably use your code.
Reply
#4

Nice job, but maybe a release for 0.3, if someone's trying to crack the rcon password, than change it. But this one is good too
Reply
#5

Quote:
Originally Posted by » Pawnst★r «
This is good for several reasons:
  • Very easy to understand
  • Extremely useful. I cannot stress enough, the positive impact on security a random RCON password can have.
  • Simple but effective
Good job.

One question, say I wanted to add a command so that I could check what the current RCON password is, how would that be done .. store it in a variable?
Thank you.

I created a command, I define RconPass in no callbacks though, so you'll want to do that, like this:
pawn Код:
zcmd(getrc, playerid, params[])
{
    #pragma unused params
    if(pStats[playerid][pAdmin] >= 5)
    {
      new string[128];
      format(string, sizeof(string), "Latest RCON password: %d.", RconPass);
      SendClientMessage(playerid, COLOR_WHITE, string);
      SendClientMessage(playerid, COLOR_ADMINCMD, "The password is updated every PayDay.");
    }
    return 1;
}
Obviously alter bits..

Quote:
Originally Posted by Mo3
Good job Calgon,

youґre one of the pro scripters here for me (because you help me sometimes )

Keep it up. I will probably use your code.
Thank you.

Quote:
Originally Posted by Pandabeer1337
Nice job, but maybe a release for 0.3, if someone's trying to crack the rcon password, than change it. But this one is good too
Still, works just as good. You can still use plugins to prevent spammed RCON login attempts in conjunction with this.
Reply
#6

Nice
Reply
#7

GJ
Reply
#8

Quote:
Originally Posted by Ask.Terminator
Nice
Thanks.

Quote:
Originally Posted by mihais17
GJ
Thanks?
Reply
#9

Very nice man. Good for server. i makes protection up
Reply
#10

Nice, Does this print the RCON to all admins?because it looks like it, But else, Nice script, and does this change it under a admins command?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)