Редакция 511 | Редакция 515 | К новейшей редакции | Авторство | Сравнить с предыдущей | Последнее изменение | Открыть журнал | Скачать | RSS
<?php
/**
*
* Codename: ant-ng - generator of sources.list for Debian and
* distributives, based on Debian
* http://alex-w.org.ru/p/antng/
*
* Copyright (c) 2009 Alexander Wolf
* Dual licensed under the MIT and GNU LGPL licenses.
* http://alex-w.org.ru/p/antng/license
*
*/
class Core {
protected $db = NULL;
protected $prefix = NULL;
protected $secure = NULL;
protected $cookie = NULL;
/**
* Конструктор класса Core - ядро генератора
*
* @author Alexander Wolf
* @category Core
*
* @param string $database
* @param string $prefix
* @param object $secure
* @param string $cookie
*/
public function __construct($database, $prefix, $secure, $cookie) {
$this->db = $database;
$this->prefix = $prefix;
$this->secure = $secure;
$this->cookie = $cookie;
}
/**
* Получение данных о настройке
*
* @author Alexander Wolf
* @category Core
*
* @param string $attr
* @return array
*/
public function getOption($attr) {
$result = array();
$query = "SELECT optvalue FROM ".$this->prefix."settings WHERE opt='".$this->secure->checkStr($attr)."'";
$rq =& $this->db->query($query);
if ($rq->numRows()!=0) {
$rq->fetchInto($element);
$result["ERR"] = 0;
$result["OptValue"] = $element["optvalue"];
} else {
$result["ERR"] = 1;
$result["ERRINFO"] = "Empty result";
}
return $result;
}
/**
* Установка данных о настройке
*
* @author Alexander Wolf
* @category Core
*
* @param string $attr
* @param string $value
* @return array
*/
public 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;
}
/**
* Создание настройки
*
* @author Alexander Wolf
* @category Core
*
* @param string $attr
* @param string $value
* @return array
*/
public 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;
}
/**
* Получение и отображение списка дистрибутвов
*
* @author Alexander Wolf
* @category Core
* @deprecated may be deprecated XXX
*
* @param string $name
* @param string $heads
* @param string $info
* @param string $format
* @return string
*/
public function showDistributionList($name, $heads = "", $info = "", $format = 'html') {
$query = "SELECT * FROM ".$this->prefix."distribution ORDER BY dist_id ASC";
$rq =& $this->db->query($query);
switch ($format) {
case 'html':
$show = "<fieldset><legend>".$heads."</legend>\n<select id='".$name."' name='".$name."'>\n";
$show .= "<option value=''>".$info."</option>\n";
while ($rq->fetchInto($element)) {
$show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
}
$show .= "</select></fieldset>";
break;
case 'json':
$show = '[{value:"",text:"'.$info.'"}';
while ($rq->fetchInto($element)) {
$show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
}
$show .= ']';
break;
case 'innerhtml':
$show = "<select id='".$name."' name='".$name."'>\n";
while ($rq->fetchInto($element)) {
$show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
}
$show .= "</select>";
break;
case 'list':
$show = "<ul>";
while ($rq->fetchInto($element)) {
$show .= "<li>[<a href='".$heads."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["dist_id"])."'>править</a>][<a href='".$heads."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["dist_id"])."'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)."</li>\n";
}
$show .= "</ul>";
break;
}
return $show;
}
/**
* Получение названия дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param integer $distID
* @return array
*/
public function getDistName($distID) {
$result = array();
$query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
$rq =& $this->db->query($query);
if (PEAR::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$rq->fetchInto($element);
$result["ERR"] = 0;
$result["DistName"] = $this->secure->checkStr($element["distname"],1);
}
return $result;
}
/**
* Получение названия программы, ее версии и описания
*
* @author Alexander Wolf
* @category Core
*
* @param string $attr
* @return string
*/
public function getEngineAttr($attr = 'codename') {
$cname = $this->getOption($attr);
return $this->secure->checkStr($cname["OptValue"],1);
}
/**
* Получение и отображение списка версий дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param integer $distID
* @param string $format
* @return string
*/
public function showDistVersionsList($name, $distID, $format = 'html', $actor = '') {
$distname = $this->getDistName($distID);
if ($distID == 0) {
$query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id ORDER BY d.dist_id,v.version ASC";
} else {
$query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
}
$rq =& $this->db->query($query);
switch ($format) {
case 'html':
$show = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n";
$show .= "<option value=''>Выбери версию ".$distname["DistName"]."</option>\n";
while ($rq->fetchInto($element)) {
$show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["version"],1)." ".$this->secure->checkStr($element["vname"],1)."</option>\n";
}
$show .= "</select></fieldset>";
break;
case 'json':
$show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}';
while ($rq->fetchInto($element)) {
$show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}';
}
$show .= ']';
break;
case 'list':
$show = "<ul>\n";
while ($rq->fetchInto($element)) {
$show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["version_id"])."'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["version_id"])."'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)." ".$this->secure->checkStr($element["version"],1)." “<em>".$this->secure->checkStr($element["vname"],1)."</em>”</li>\n";
}
$show .= "</ul>";
break;
}
return $show;
}
/**
* Получение и отображение списка секций основного (официального) репозитория
*
* @author Alexander Wolf
* @category Core
*
* @param integer $version
* @param string $format
* @return string
*/
public function showBranchesList($version, $format = 'html') {
$query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
$rq =& $this->db->query($query);
$rq->fetchInto($types);
$query = "SELECT s.*,t.rtype FROM ".$this->prefix."section s ";
$query .= "JOIN ".$this->prefix."sect2rep l ON s.sect_id=l.sect_id ";
$query .= "JOIN ".$this->prefix."repository r ON r.rep_id=l.rep_id ";
$query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
$query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."'";
$rq =& $this->db->query($query);
switch ($format) {
case 'html':
$show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
while ($rq->fetchInto($element)) {
$show .= "<div class='sections'><input type='checkbox' name='section[]' value='".$element["sect_id"]."'> ".$this->secure->checkStr($element["secname"],1)." — ".$this->secure->checkStr($element["sectinfo"],1)."</div>\n";
}
$show .= "</fieldset>\n";
break;
case 'json':
//TODO Доделать JSON-вывод списка секций основного репозитория
break;
}
return $show;
}
/**
* Получение и отображение списка репозиториев
*
* @author Alexander Wolf
* @category Core
*
* @param integer $version
* @param integer $reptype
* @param string $format
* @return string
*/
public function showRepList($version, $reptype, $format = 'html') {
$query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='".$this->secure->checkInt($reptype)."'";
$rq =& $this->db->query($query);
$rq->fetchInto($types);
$query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'";
$rq =& $this->db->query($query);
switch ($format) {
case 'html':
$show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
while ($rq->fetchInto($types)) {
$show .= "<div class='repository'><input type='checkbox' name='repository[]' value='".$element["rep_id"]."'> ".$this->secure->checkStr($element["repname"],1)." — ".$this->secure->checkStr($element["repinfo"],1)."</div>\n";
}
$show .= "</fieldset>\n";
break;
case 'json':
//TODO Доделать JSON-вывод списка репозиториев
break;
}
return $show;
}
/**
* Добавление поддержки нового apt-дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param string $distname
* @param integer $disttype
* @param string $distua
* @param byte $distlogo
* @return array
*/
public function addDistribution($distname, $disttype, $distua = '', $distlogo = 0) {
$result = array();
$sDName = $this->secure->checkStr($distname);
$sDType = $this->secure->checkInt($disttype);
$sDUAgt = $this->secure->checkStr($distua);
$sDLogo = $this->secure->checkInt($distlogo);
$query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'";
$rq =& $this->db->query($query);
if (PEAR::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$rq->fetchInto($element);
$result["ERR"] = 0;
}
return $result;
}
/**
* Обновление информации о дистрибутиве
*
* @author Alexander Wolf
* @category Core
*
* @param integer $distID
* @param string $distname
* @param integer $disttype
* @param string $distua
* @param integer $distlogo
* @return array
*/
public function updateDistribution($distID, $distname, $disttype, $distua, $distlogo) {
$result = array();
$sDID = $this->secure->checkInt($distID);
$sDName = $this->secure->checkStr($distname);
$sDType = $this->secure->checkInt($disttype);
$sDUAgt = $this->secure->checkStr($distua);
$sDLogo = $this->secure->checkInt($distlogo);
$query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."' WHERE dist_id='".$sDID."'";
$rq =& $this->db->query($query);
if (PEAR::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$rq->fetchInto($element);
$result["ERR"] = 0;
}
return $result;
}
/**
* Удаление информации о дистрибутиве
*
* @author Alexander Wolf
* @category Core
*
* @param integer $distID
* @return array
*/
public function dropDistribution($distID) {
$result = array();
$sDID = $this->secure->checkInt($distID);
// Удаление дистрибутива
$query = "DELETE FROM ".$this->prefix."distribution WHERE dist_id='".$sDID."'";
$rq =& $this->db->query($query);
if (PEAR::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$rq->fetchInto($element);
$result["ERR"] = 0;
}
// Удаление версий дистрибутива
$query = "DELETE FROM ".$this->prefix."version WHERE dist_id='".$sDID."'";
$rq =& $this->db->query($query);
if (PEAR::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$rq->fetchInto($element);
$result["ERR"] = 0;
}
return $result;
}
/**
* Добавление поддержки новой версии apt-дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param integer $distID
* @param integer $version
* @param string $vname
* @param integer $vcodename
* @return array
*/
public function addDistVersion($distID, $version, $vname = "", $vcodename = "") {
$result = array();
$sDistID = $this->secure->checkInt($distID);
$sDVersion = $this->secure->checkStr($version);
$sDVName = $this->secure->checkStr($vname);
$sDVCName = $this->secure->checkInt($vcodename);
$query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'";
$rq =& $this->db->query($query);
if (PEAR::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$rq->fetchInto($element);
$result["ERR"] = 0;
}
return $result;
}
/**
* Редактирование информации о версии дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param integer $versionID
* @param string $version
* @param string $vname
* @param string $vcodename
* @return array
*/
public function updateDistVersion($versionID, $version, $vname = "", $vcodename = "") {
$result = array();
$sVersID = $this->secure->checkInt($versionID);
$sDVersion = $this->secure->checkStr($version);
$sDVName = $this->secure->checkStr($vname);
$sDVCName = $this->secure->checkInt($vcodename);
$query = "UPDATE ".$this->prefix."version SET vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."' WHERE version_id='".$sVersID."'";
$rq =& $this->db->query($query);
if (PEAR::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$rq->fetchInto($element);
$result["ERR"] = 0;
}
return $result;
}
/**
* Удаление информации о версии дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param integer $versionID
* @return array
*/
public function dropDistVersion($versionID) {
$result = array();
$sVersID = $this->secure->checkInt($versionID);
// Удаление версии дистрибутива
$query = "DELETE FROM ".$this->prefix."version WHERE version_id='".$sVersID."'";
$rq =& $this->db->query($query);
if (PEAR::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$rq->fetchInto($element);
$result["ERR"] = 0;
}
// Удаление репозиториев этой версии дистрибутива
$query = "DELETE FROM ".$this->prefix."repository WHERE version='".$sVersID."'";
$rq =& $this->db->query($query);
if (PEAR::isError($this->db)) {
$result["ERR"] = 1;
$result["ERRINFO"] = $this->db->getMessage();
} else {
$rq->fetchInto($element);
$result["ERR"] = 0;
}
return $result;
}
/**
* Отображение типа дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param byte $type
* @return string
*/
public function showDistTypeForm($name = "dtype",$type = 0) {
$query = "SELECT * FROM ".$this->prefix."dtype";
$rq =& $this->db->query($query);
$show = "<select name='".$name."' id='".$name."'>\n";
while ($rq->fetchInto($element)) {
if ($element["type_id"] == $type) {
$show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n";
} else {
$show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n";
}
}
$show .= "</select>";
return $show;
}
/**
* Отображение формы создания и редактирования apt-дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param integer $distID
* @return string
*/
public function showDistributionForm($distID = 0, $info = '') {
$sDistID = $this->secure->checkInt($distID);
$sInfo = $this->secure->checkStr($info, 1);
if ($sInfo == "") {
$sInfo = "Дистрибутив";
}
if ($sDistID != 0) {
// Режим редактирования
$query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'";
$rq =& $this->db->query($query);
$rq->fetchInto($element);
}
if ($element["distlogo"] == 1) {
$image = "<img src='./img/d/".$this->secure->checkStr($element["distua"],1).".png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."' title='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."'>";
} else {
$image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>";
}
$show = "<fieldset><legend>".$sInfo."</legend>\n";
$show .= "<div class='inputbox'><label for='dname'>Название дистрибутива:</label> <input type='text' name='dname' id='dname' value='".$this->secure->checkStr($element["distname"],1)."'></div>\n";
$show .= "<div class='inputbox'><label for='dua'>UA дистрибутива:</label> <input type='text' name='dua' id='dua' value='".$this->secure->checkStr($element["distua"],1)."'></div>\n";
$show .= "<div class='inputbox'><label for='dtype'>Тип дистрибутива:</label> ".$this->showDistTypeForm("dtype",$element["dtype_id"])."</div>\n";
$show .= "<div class='inputbox'><table><tr><td class='td-name'>Логотип дистрибутива:</td>\n";
$show .= "<td>".$image."</td>\n<td><input type='file' name='distlogo'></td>\n</tr></table>\n</div>\n";
$show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
return $show;
}
// sourses.list
public function showSourcesList($distID,$versID,$sectIDs,$repIDs) {
//TODO Написать генератор sources.list
}
/**
* Проверка пароля (из формы авторизации)
*
* @author Alexander Wolf
* @category Core
*
* @param string $word
* @return array
*/
public 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"] = "manager.php?error=1";
}
return $result;
}
/**
* Проверка пароля (из cookies)
*
* @author Alexander Wolf
* @category Core
*
* @param string $hash
* @return array
*/
public 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"] = "manager.php";
}
return $result;
}
/**
* Форма ввода пароля
*
* @author Alexander Wolf
* @category Core
*
* @return string
*/
public function showSigninForm() {
$show = "<div id='regform'>";
$show .= "<form action='process.php' method='post'>\n";
$show .= "<fieldset><legend>Пароль</legend>\n";
$show .= "<input type='hidden' name='mode' value='authorize'>\n";
$show .= "<input type='password' name='word' value=''>\n";
$show .= "<input type='submit' value=' Войти '>\n";
$show .= "</fieldset>\n</form></div>\n";
return $show;
}
/**
* Обновление пароля
*
* @author Alexander Wolf
* @category Core
*
* @param string $word1
* @param string $word2
* @return array
*/
public 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;
}
/**
* Отображение формы создания и редактирования версии apt-дистрибутива
*
* @author Alexander Wolf
* @category Core
*
* @param string $name
* @param string $actor
* @param integer $versionID
* @return string
*/
public function showDistVersionsForm($versionID = 0, $info = '') {
$sVersionID = $this->secure->checkInt($versionID);
$sInfo = $this->secure->checkStr($info, 1);
if ($sInfo == "") {
$sInfo = "Версия дистрибутива";
}
if ($sVersionID != 0) {
// Режим редактирования
$query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id WHERE v.version_id='".$versionID."'";
$rq =& $this->db->query($query);
$rq->fetchInto($element);
}
$show = "<fieldset><legend>".$sInfo."</legend>\n";
if ($sVersionID != 0) {
$show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n";
} else {
$show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> ".$this->showDistributionList("distname", "", "", "innerhtml")."</div>\n";
}
$show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."'></div>\n";
$show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."'></div>\n";
$show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."'></div>\n";
$show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
return $show;
}
}
?>
Generated by GNU Enscript 1.6.5.90.