How to repeatedly send the PHP version of onload for autologin cacti?

I have html and javascript code like this.

<form action="http://MYCACTI/cacti/logout.php" name="logout_cacti" method="post"></form> 
<form action="http://MYCACTI/cacti/" name="auth_cacti" method="post">
<input type="hidden" name="action" value="login">
<input type="hidden" name="realm" value="local">
<input type="hidden" name="login_username" value="guest">
<input type="hidden" name="login_password" value="guest">
</form> 
<script>
window.onload = PageLoad;
function PageLoad(){
    Logout();
    Login();
}
function Logout(){
    setTimeout(document.forms['logout_cacti'].submit(), 4000);
} 
function Login(){
    setTimeout(document.forms['auth_cacti'].submit(), 4000);
}
</script>

The question is, what do I want to do autologin cacti in iframe, and the problem is that the session in the cacti is destroyed or if we already exit cacti, the script works fine, it can go to the site with autologing. But if we are already entering cacti, an error message like this appears.

You are not allowed access to this section of cacti. If you feel that you need access to this particular section, please contact the Cactus Administrator.

I implemented javascript window.onload, but nothing worked, it is the result of firebug.

Firebug

Thanks.

+4
1

@Manchary Manchaary , , , , .

, auth_login.php

/* Process the user  */
        if (sizeof($user) > 0) {
                cacti_log("LOGIN: User '" . $user["username"] . "' Authenticated", false, "AUTH");
                db_execute("INSERT INTO user_log (username,user_id,result,ip,time) VALUES (" . $cnn_id->qstr($username) . "," . $user["id"] . ",1,'"$
                /* is user enabled */
                $user_enabled = $user["enabled"];
                if ($user_enabled != "on") {
                        /* Display error */
                        auth_display_custom_error_message("Access Denied, user account disabled.");
                        exit;
                }

                /* set the php session */
                $_SESSION["sess_user_id"] = $user["id"];
                $sharesession = fopen("/var/www/html/session/session", "w") or die("Unable to open file!");             
                fwrite($sharesession, "start");
                fclose($sharesession);

php- , , php write "start" session.

php- cacti2.php iframe .

<?php 
$sharesession = fopen("/var/www/html/session/session", "r") or die("Unable to open file!");
$session = fread($sharesession,filesize("/var/www/html/session/session"));
fclose($sharesession);

if ($session == "start"){
        header("Location: http://MYCACTI/cacti/graph_view.php?action=tree&tree_id=1&leaf_id=8&select_first=true");
} 
else {
?>
        <form action="http://MYCACTI/cacti/" name="auth_cacti" method="post">
        <input type="hidden" name="action" value="login">
        <input type="hidden" name="realm" value="local">
        <input type="hidden" name="login_username" value="soc">
        <input type="hidden" name="login_password" value="telkom">
        </form> 
        <script>
        window.onload = PageLoad;
        function PageLoad(){
                Login();
        }
        function Login(){
                setTimeout(document.forms['auth_cacti'].submit(), 4000);
        }
</script>
<?php
}
?>

-, php session, session "start" , cacti graph, "stop" , .

, session , , logout.php

include("./include/auth.php");

api_plugin_hook('logout_pre_session_destroy');

/* Clear session */
setcookie(session_name(),"",time() - 3600,"/");
session_destroy();
$sharesession = fopen("/var/www/html/session/session", "w") or die("Unable to open file!");             
                fwrite($sharesession, "stop");                  
                fclose($sharesession);

"stop" session , cacti2.php , , , , .

+1

Source: https://habr.com/ru/post/1614570/


All Articles