16,12 → 16,13 |
protected $db = NULL; |
protected $prefix = NULL; |
protected $secure = NULL; |
protected $cookie = NULL; |
|
|
function __construct($database, $prefix, $secure) { |
function __construct($database, $prefix, $secure, $cookie) { |
$this->db = $database; |
$this->prefix = $prefix; |
$this->secure = $secure; |
$this->secure = $secure; |
$this->cookie = $cookie; |
} |
|
// Получение данных о настройке |
40,6 → 41,46 |
return $result; |
} |
|
// Установка данных о настройке |
function setOption($attr, $value) { |
$result = array(); |
|
if ($attr != "passwd") { |
$sValue = $this->secure->checkStr($value); |
} else { |
$sValue = $value; |
} |
|
$query = "UPDATE ".$this->prefix."settings SET optvalue='".$sValue."' WHERE opt='".$attr."'"; |
$rq =& $this->db->query($query); |
if (PEAR::isError($this->db)) { |
$result["ERR"] = 1; |
$result["ERRINFO"] = $this->db->getMessage(); |
} else { |
$result["ERR"] = 0; |
} |
|
return $result; |
} |
|
// Создание настройки |
function addOption($attr, $value) { |
$result = array(); |
$sValue = $this->secure->checkStr($value); |
|
$query = "INSERT INTO ".$this->prefix."settings SET opt='".$attr."', optvalue='".$sValue."'"; |
$rq =& $this->db->query($query); |
if (PEAR::isError($this->db)) { |
$result["ERR"] = 1; |
$result["ERRINFO"] = $this->db->getMessage(); |
} else { |
$result["ERR"] = 0; |
} |
|
return $result; |
} |
|
|
// Получение и отображение списка дистрибутивов |
function showDistributionList($name, $info = "", $format = 'html') { |
$query = "SELECT * FROM ".$this->prefix."distribution ORDER BY dist_id ASC"; |
245,11 → 286,57 |
//TODO Написать генератор sources.list |
} |
|
// Аутентификация пользователя |
function checkUser($user, $hash) { |
//TODO Написать функцию |
// Проверка пароля (из формы авторизации) |
function checkSign($word) { |
$result = array(); |
|
$sHash = $this->secure->encryptStr($word); |
$pwd = $this->getOption("passwd"); |
if ($sHash == $pwd["OptValue"]) { |
$result["ERR"] = 0; |
$result["Location"] = "manager.php"; |
setcookie($this->cookie, $sHash); |
} else { |
$result["ERR"] = 1; |
$result["ERRINFO"] = "Password not valid"; |
$result["Location"] = "sign.php?error=1"; |
} |
|
return $result; |
} |
|
// Проверка пароля (из cookies) |
function checkCookieSign($hash) { |
$result = array(); |
|
$pwd = $this->getOption("passwd"); |
if ($hash == $pwd["OptValue"]) { |
$result["ERR"] = 0; |
} else { |
$result["ERR"] = 1; |
$result["ERRINFO"] = "Hash not valid"; |
$result["Location"] = "sign.php"; |
} |
|
return $result; |
} |
|
// Обновление пароля |
function updatePassword($word1, $word2) { |
$result = array(); |
|
if ($word1 == $word2) { |
$sWord = $this->secure->encryptStr($word1); |
$r = $this->setOption("passwd", $sWord); |
$result = $r; |
} else { |
$result["ERR"] = 1; |
$result["ERRINFO"] = "Passwords is mismatch"; |
} |
|
return $result; |
} |
|
} |
|
?> |