Код: Выделить всё
<?php
$MOD_TITLE='login_user';
$MOD_GROUP='Автоматический вход';
$MOD_VISIBLE=true;
$MOD_CLASS='LoginAutoModule';
$MOD_LOGIN=true;
$MOD_SYSTEM=1;
if(!class_exists($MOD_CLASS)) {
class LoginAutoModule extends Module {
function init() {
$config = file('/netup/utm5/utm5.cfg');
foreach($config as $line){if(preg_match("/^([^#].+?)=(.*)$/", $line, $param)){$$param[1]=$param[2];}}
mysql_connect($database_host, $database_login, $database_password);
mysql_select_db($database);
$client=ip2long($_SERVER['REMOTE_ADDR']);
$result = mysql_query("SELECT users.login, users.password FROM ip_groups
LEFT JOIN iptraffic_service_links ON iptraffic_service_links.ip_group_id = ip_groups.ip_group_id
LEFT JOIN service_links ON service_links.id = iptraffic_service_links.id
LEFT JOIN users_accounts ON users_accounts.id = service_links.account_id
LEFT JOIN users ON users.id = users_accounts.uid
WHERE ip_groups.ip LIKE ($client & 4294967295) AND ip_groups.is_deleted = 0 AND (ip_groups.ip_type & 0x1) = 0x0");
$credentials = mysql_fetch_assoc($result);
mysql_free_result($result);
global $MOD_TITLE,$MOD_GROUP,$MOD_VISIBLE,$MOD_LOGIN,$MOD_SYSTEM;
parent::init($MOD_TITLE,$MOD_GROUP,$MOD_VISIBLE,$MOD_LOGIN);
if(isset($credentials['login']) && isset($credentials['password'])) {
if($credentials['login'] == '' || $credentials['password'] == '') {
$this->addErrorMessage(langGet('login_or_password_is_empty'));
return false;
}
global $CONF_CORE_HOST,$CONF_CORE_PORT,$CONF_PATH;
if($this->urfa->connect($CONF_CORE_HOST,$CONF_CORE_PORT) != false)
if($this->urfa->open_session($credentials['login'],trim($credentials['password']),false,$_SERVER['REMOTE_ADDR']) != false && $this->urfa->call(-0x4052) && $this->urfa->send()) {
setcookie('utm5',$this->urfa->get_key());
setcookie('user',$credentials['login']);
setcookie('system', $MOD_SYSTEM);
$this->urfa->close_session();
$this->urfa->disconnect();
header("Location: ".$CONF_PATH);
return true;
} else {
$this->addErrorMessage(langGet('username_or_password_incorrect'));
return false;
}
}
}
function writeBody() {
global $MOD_TITLE,$MOD_GROUP,$MOD_VISIBLE;
parent::init($MOD_TITLE,$MOD_GROUP,$MOD_VISIBLE);
global $CONF_PATH;
$this->urfa->close_session(true);
$this->urfa->disconnect();
setcookie('utm5','',time()-3600);
setcookie('system','',time()-3600);
header("Location: ".$CONF_PATH);
die;
}
}
}
?>