CHips L MINI SHELL

CHips L pro

Current Path : /opt/cpanel/ea-php54/root/usr/share/pear/RVSeagullMod/modules/authweb/classes/
Upload File :
Current File : //opt/cpanel/ea-php54/root/usr/share/pear/RVSeagullMod/modules/authweb/classes/Api.php

<?php

// Insert Hash ##################################

function insertHash($input)
{
 SGL::logMessage(null, PEAR_LOG_DEBUG);
    $dbh = SGL_DB::singleton();

    // รับค่า config
    $c = SGL_Config::singleton();
    $conf = $c->getAll();    

    // รับค่า input
    $req = SGL_Request::singleton();
    $frm = $req->getAll();

    $query = "
        SELECT `usr_id`
        FROM {$conf['table']['user']} 
        WHERE `username` = " . $dbh->quoteSmart($input->user->username) . "
    ";
    $uid = $dbh->getOne($query);

    $timestamp = time();
    $hash = md5($uid . $timestamp);

    $query = "
        INSERT INTO {$conf['table']['user_auth_hash']} (
            `usr_id` ,
            `username` ,
            `hash` ,
            `createtime`
        ) VALUES (
            '{$uid}', 
            " . $dbh->quoteSmart($input->user->username) . ",
            " . $dbh->quoteSmart($hash) . ",       
            " . $dbh->quoteSmart($timestamp) . "
        );
    ";
    $dbh->query($query);

    return $hash;
}

// Remove Hash ##################################

function removeHash($userId)
{
     SGL::logMessage(null, PEAR_LOG_DEBUG);
    $dbh = SGL_DB::singleton();

    // รับค่า config
    $c = SGL_Config::singleton();
    $conf = $c->getAll();    

    $query = "
        DELETE FROM {$conf['table']['user_auth_hash']} 
        WHERE `usr_id` = '{$userId}'
    ";
    $dbh->query($query);

}

// Remove User ##################################

function removeUser($aUserId)
{   
     SGL::logMessage(null, PEAR_LOG_DEBUG);
    $dbh = SGL_DB::singleton();
    
    // รับค่า config
    $c = SGL_Config::singleton();
    $conf = $c->getAll();    

    if (count($aUserId) < 1) {
        return;  
    }
    $userId = implode(',', $aUserId);
    $query = "
        DELETE FROM {$conf['table']['user']} 
        WHERE usr_id IN ({$userId});
    ";
    $dbh->query($query);
}

// Check Hash ##################################

function checkHash($username)
{
    SGL::logMessage(null, PEAR_LOG_DEBUG);
    $dbh = SGL_DB::singleton();
    
    // รับค่า config
    $c = SGL_Config::singleton();
    $conf = $c->getAll();    
    
    $query = "
        SELECT `usr_id` 
        FROM {$conf['table']['user_auth_hash']} 
        WHERE `username` = " . $dbh->quoteSmart($username) . "
    ";

    $userId = $dbh->getOne($query);

    if ($userId) {
        return false;
    } 

    return true;

}



// Delete Expire Hash ##################################
function deleteExpireHash()
{
     SGL::logMessage(null, PEAR_LOG_DEBUG);
    $dbh = SGL_DB::singleton();
    $timestamp = time();
    $aUserExpire = Array();
    $aUserId = Array();
    
    // รับค่า config
    $c = SGL_Config::singleton();
    $conf = $c->getAll();

    if ($conf['RegisterMgr']['allowAuthWeb'] === false) {
        return true;
    }

    // หา expire time โดยเอาเวลาปัจจุบันไปลบกับ expire time แล้วกำหนดเป็นตัวแปร checktime คิดเป็น ชั่วโมง * 3600
    $checktime = $timestamp - ($conf['RegisterMgr']['authExpire'] * 3600);
    $checktime = @strftime("%Y-%m-%d %H:%M:%S", $checktime);
    $query = "
        SELECT `usr_id`,`date_created`,`username`, `is_acct_active` 
        FROM {$conf['table']['user']} 
        WHERE `date_created` < '{$checktime}' 
    ";
    //Fix PHP5.3 (use MDB2)
    $aUserExpire = $dbh->getAll($query, SGL_DB_FETCHMODE_ASSOC);

    // ลบ  Hash Key และ update is_acct_active user ที่ ไม่ได้ ยืนยันตัวตนตามเวลาที่กำหนด
    $oUserDAO = UserDAO::singleton();
    for ($i = 0; $i < count($aUserExpire); $i++) {
        //เช็คว่า มี user ใน table user_auth_hash ถ้า 
        //false :มี คือ ยังไม่คลิก ยืนยัน ตัวตน
        //true : ไม่มี คือ ยืนยัน ตัวตนแล้ว
        $checkHash = checkHash($aUserExpire[$i]['username']);
        if ($aUserExpire[$i]['usr_id'] == SGL_ADMIN || $aUserExpire[$i]['usr_id'] == '999999999') {
            continue;
        }
        
        if ($checkHash === true) {
            continue;
        }

        removeHash($aUserExpire[$i]['usr_id']);


        $query = "
            UPDATE {$conf['table']['user']} 
            SET `is_acct_active` = 0
            WHERE `usr_id` = '{$aUserExpire[$i]['usr_id']}' 
            AND `is_acct_active` = 1
             ";
        $ok = $dbh->query($query);

    }

}

function userIsExpire($username)
{
    SGL::logMessage(null, PEAR_LOG_DEBUG);
    $dbh = SGL_DB::singleton();
        // รับค่า config
    $c = SGL_Config::singleton();
    $conf = $c->getAll();
    $unExpire = '0000-00-00 00:00:00';
    $today = getdate();
    
    $query = "
        SELECT usr_id, role_id, user_expire
        FROM {$conf['table']['user']} 
        WHERE username = '{$username}' 
    ";
    //Fix PHP5.3 (use MDB2)
    $aUserExpire = $dbh->getRow($query, SGL_DB_FETCHMODE_ASSOC);
    if ($aUserExpire['role_id'] != SGL_ADMIN 
        && $aUserExpire['user_expire'] !='' 
        && $aUserExpire['user_expire'] != $unExpire
        ) {
        $dateExpired = strtotime($aUserExpire['user_expire']);
        if ($dateExpired < $today[0]) {
           return true;
        }
   }
   return false;
}


// Send Activate Email ##################################
function sendActivateEmail($oUser, $moduleName, $conf, $hashKey)
{
    require_once SGL_CORE_DIR . '/Emailer.php';
     SGL::logMessage(null, PEAR_LOG_DEBUG);
    $realName = $oUser->first_name . ' ' . $oUser->last_name;
    $recipientName = (trim($realName)) ? $realName : '&lt;no name supplied&gt;';

    $options = array(
                'toEmail'       => $oUser->email,
                'toRealName'    => $recipientName,
                'fromEmail'     => $conf['email']['admin'],
                'replyTo'       => $conf['email']['admin'],
                'subject'       => 'Welcome to' . $conf['site']['name'],
                'template'  => SGL_THEME_DIR . '/' . $_SESSION['aPrefs']['theme'] . '/' . $moduleName . '/email_registration_activation.php',
                'username'      => $oUser->username,
                'password'      => $oUser->passwdClear,
                'email'        => $conf['email']['admin'],
                'activateURL'      => $conf['site']['baseUrl'] . '/' . $conf['site']['frontScriptName'] . '/authweb/useractivate/action/update/key/' . $hashKey,
                'hashkey' => $hashKey,
    );

    $message = new SGL_Emailer($options);
     ///fix PHP 5.3
     $message = &$message;
     
    $message->prepare();
    $message->send();
    //  check error stack
    return (SGL_Error::count()) ? false : true;
}

?>

Copyright 2K16 - 2K18 Indonesian Hacker Rulez