login_pre.sh issue

Kronus

Verified User
Joined
May 31, 2007
Messages
48
I would love to get this working but can't I have tried many things

I have ip_list.txt with my IP in it

I have the login_pre.sh file chmod 775

When I put file in directory i try to log in and page refreshes I delete file and lg in and check log and I get i see Invalid IP
i have narrowed it down to the code not reading IP's from the ip_list.txt

I have tried many ways like array_search and !== false statements but no luck

Need ideas please

Code:
#!/usr/local/bin/php
<?php

$user = getenv('username');
$ip = getenv('ip');

$ip_list = "/usr/local/directadmin/scripts/custom/ip_list.txt";

if ($user == 'demo_user' || $user == 'demo_reseller' || $user == 'demo_admin')
{
           //not worried about demos
            exit(0);
}

$lines = file($ip_list);

foreach ($lines as $ip_val)
{
        if ($ip == $ip_val)
        {
                   exit(0);
        }
}

echo "Invalid IP";
exit(1);

?>
 
Ok finally fixed it


Code:
#!/usr/local/bin/php
<?php
    
    $user = getenv('username'); 
    $ips_file_path = '/usr/local/directadmin/scripts/custom/ip_list.txt';
    $my_ip = getenv('ip');

    if ($user == 'demo_user' || $user == 'demo_reseller' || $user == 'demo_admin')
{
           //not worried about demos
            exit(0);
}
       
    $ips_list = file($ips_file_path);
    foreach (array_values($ips_list) AS $ip){
        if (trim($ip) == $my_ip){

                   exit(0);
        }
}

echo "Invalid IP";
exit(1);

?>
 
Last edited:
Since this script made it to help/384
I'd like to place some remarks.
It happened to me that i was editing the login_pre.sh via File Editor.
Then i decided to leave it empty --> no more logging in :)

So it seems that when there is an empty login_pre.sh, DA seems to interpret this as an exit(1).

I don't know what happens when you have errors in your php statements.
Maybe it's wise to start checking your home IP and then exit(0)

Also i think it is better to 1st make your ip_list.txt !!
And it could be handy to check a user_list. txt after the ip_list.txt.
I am going now with the given sample in help/384.
Before i considered 2 switch statements, because i have < 10 users :)
 
Back
Top