minecraftd/utils.php
// get message to show for given password
get message to show for given password
get message to show for given password
function auth($pass) {
    $auth_table = array();
    $auth_file = fopen("passwd", "r");
    while (! feof($auth_file)) {
        $line = fgets($auth_file);
        $line_parts = explode("::", $line);
        if (count($line_parts) == 2) {
            $auth_table += array(trim($line_parts[0]) => trim($line_parts[1]));
        }
    }
    fclose($auth_file);
    $append_log = date("Y/m/d-H:i:s");
    $pass5 = md5($pass);
    if (array_key_exists($pass5, $auth_table)) {
        $auth = $auth_table[$pass5];
        $append_log .= " auth='$auth'";
    } else {
        $auth = "error: invalid password";
        $append_log .= " invalid pass='$pass'";
    }
    if (strcmp($pass, "69") != 0) {
        $ip = "0.0.0.0";
        if (isset($_SERVER['HTTP_CLIENT_IP'])
            && $_SERVER['HTTP_CLIENT_IP'] != ''
        ) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])
            && $_SERVER['HTTP_X_FORWARDED_FOR'] != ''
        ) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } elseif (isset($_SERVER['REMOTE_ADDR'])
            && $_SERVER['REMOTE_ADDR'] != ''
        ) {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        if (($CommaPos = strpos($ip, ',')) > 0) {
            $ip = substr($ip, 0, ($CommaPos - 1));
        }
        $append_log .= " ip='$ip'\n";
        file_put_contents("/srv/minecraft/auth_log.txt", $append_log, FILE_APPEND);
    }
    return "<h4>$auth</h4>";
}
function auth ( $ pass ) { $ auth_table = array ( ) ; $ auth_file = fopen ( " passwd " , " r " ) ; while ( ! feof ( $ auth_file ) ) { $ line = fgets ( $ auth_file ) ; $ line_parts = explode ( " :: " , $ line ) ; if ( count ( $ line_parts ) == 2 ) { $ auth_table += array ( trim ( $ line_parts [ 0 ] ) => trim ( $ line_parts [ 1 ] ) ) ; } } fclose ( $ auth_file ) ; $ append_log = date ( " Y/m/d-H:i:s " ) ; $ pass5 = md5 ( $ pass ) ; if ( array_key_exists ( $ pass5 , $ auth_table ) ) { $ auth = $ auth_table [ $ pass5 ] ; $ append_log .= "  auth=' $ auth ' " ; } else { $ auth = " error: invalid password " ; $ append_log .= "  invalid pass=' $ pass ' " ; } if ( strcmp ( $ pass , " 69 " ) != 0 ) { $ ip = " 0.0.0.0 " ; if ( isset ( $ _SERVER [ 'HTTP_CLIENT_IP' ] ) && $ _SERVER [ 'HTTP_CLIENT_IP' ] != '' ) { $ ip = $ _SERVER [ 'HTTP_CLIENT_IP' ] ; } elseif ( isset ( $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) && $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] != '' ) { $ ip = $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ; } elseif ( isset ( $ _SERVER [ 'REMOTE_ADDR' ] ) && $ _SERVER [ 'REMOTE_ADDR' ] != '' ) { $ ip = $ _SERVER [ 'REMOTE_ADDR' ] ; } if ( ( $ CommaPos = strpos ( $ ip , ',' ) ) > 0 ) { $ ip = substr ( $ ip , 0 , ( $ CommaPos - 1 ) ) ; } $ append_log .= "  ip=' $ ip ' \n " ; file_put_contents ( " /srv/minecraft/auth_log.txt " , $ append_log , FILE_APPEND ) ; } return " <h4> $ auth </h4> " ; }
get message to show for given password
get message to show for given password
// table of passwords and message if authenticated // check if authenticated // add attempt to log unless passwd attempt was "69"