diff --git a/public_html/valuestore/browse.php b/public_html/valuestore/browse.php deleted file mode 100644 index f19da467f101fe776eb62d4062f8f8f0f81a793a..0000000000000000000000000000000000000000 --- a/public_html/valuestore/browse.php +++ /dev/null @@ -1,167 +0,0 @@ -<?php - -/** - * - * VERSION HANDLER API - * - * Syntax des Aufrufs (als GET Schreibweise; ein POST soll (später) auch gehen): - * http://dev.ci.iml.unibe.ch:8002/versions/?action=update&project=ci&phase=preview&host=ci.preview.iml.unibe.ch&variable=version&value=007 - * - * Parameter: - * - * action=update (get-Funktionen muss ich später noch bauen) - * project=[Projekt-ID (=Name des Package, das installiert wird)] - * phase=(preview|stage|live) - * host=[FQDN] - * variable=version (andere noch nicht unterstützt/ vorgesehen) - * value=[Versionsdaten] - * - * 2017-04-07 hahn first lines - */ - - -// ---------------------------------------------------------------------- -// functions -// ---------------------------------------------------------------------- - -/** - * show an error message and quit with http status code 400 (Bad request) - * @param string $sMessage message to show - * @return boolean - */ -function quit($sMessage) { - $sProtocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'); - header("$sProtocol 400: Bad request"); - die("<h1>Bad request</h1>" . $sMessage); - return false; -} - -/** - * get a request param from GET and POST scope (POST has priority) and - * verify it with execution of a cleanup array - * @param string $sKey key to search for in GET or POST - * @param string $sRegex4Cleanup regex for filtering - * @return type - */ -function getParam($sKey, $sRegex4Cleanup = false) { - $sValue=false; - if (array_key_exists($sKey, $_GET)) { - $sValue=$_GET[$sKey]; - } - if (array_key_exists($sKey, $_POST)) { - $sValue=$_POST[$sKey]; - } - if(!$sValue){ - return false; - } - $sReturn = $sRegex4Cleanup ? preg_replace($sRegex4Cleanup, '', $sValue) : $sValue; - - if ($sReturn !== $sValue) { - quit("ERROR: the parameter value in [$sKey = ...] has a wrong format."); - } - return $sReturn; -} - -// ---------------------------------------------------------------------- -// check required params -// ---------------------------------------------------------------------- -/* -if (!$_GET || !count($_GET)) { - quit("no parameter was found."); -} - -foreach (array("action", "project") as $sKey) { - if (!array_key_exists($sKey, $_GET)) { - quit("value required: $sKey="); - } -} - */ - - -// ---------------------------------------------------------------------- -// get vars -// ---------------------------------------------------------------------- - - -$sAction = getParam('action', '/[^a-z]/'); - -$sProject = getParam('project', '/[^a-z\-0-9]/'); -$sPhase = getParam('phase', '/[^a-z]/'); -$sPlace = getParam('place', '/[^a-z]/'); -$sHost = getParam('host', '/[^a-z\.\-0-9]/'); - -if ($sHost && !$sPlace) { - $sPlace = 'installed'; -} - -$sVarname = getParam('variable', '/[^a-z]/'); -$sValue = getParam('value', ''); - - -// ---------------------------------------------------------------------- -// init class -// ---------------------------------------------------------------------- - -$sOut=''; -$sHeader=''; -$sOut.='<h1>data browser</h1>'; -require './classes/valuestore.class.php'; - -$oVersion = new valuestore(); - -$aData=$oVersion->dumpdb(); -$sTable=''; -$sTableHead=''; -if(is_array($aData) && count($aData)){ - // echo '<pre>' . print_r($aData, 1); - foreach ($aData as $aRow){ - $sItemUrl='index.php?action=show&project='.$aRow['project'].'&package='.$aRow['package'].'&phase='.$aRow['phase'].'&host='.$aRow['host'].'&variable='.$aRow['variable'].''; - $sTable.='<tr ondblclick="location.href=\''.$sItemUrl.'\'">'; - // $sTable.='<tr>'; - foreach ($aRow as $sKey=>$sValue){ - // $sTable.='<td class="'.$sKey.'"><a href="'.$sUrl.'">'.$sValue.'</a></td>'; - $sOnclick=''; - $sLabel=strstr($sValue, '"') - ? htmlentities($sValue) - : '<a href="#" onclick="$(\'#eFilter\').val(\''.$sValue.'\');filterTable();" title="click to filter by ['.$sValue.']">'.htmlentities($sValue).'</a>' - ; - $sTable.='<td class="'.$sKey.'" '.$sOnclick.'>'.$sLabel.'</td>'."\n"; - } - $sTable.='<td>' - // . '<button onclick="location.href=\''.$sItemUrl.'&action=get\'">View</button>' - . '<form method="POST" action="'.$sItemUrl.'">' - . '<input type="hidden" name="action" value="delete">' - . '<button>Delete</button>' - . '</form>' - . '</td>' - . '</tr>'."\n"; - - } - foreach (array_keys($aRow) as $sKey){ - $sTableHead.='<th class="'.$sKey.'">'.$sKey.'</th>'; - } - $sOut.='' - . '<form method="POST" action="index.php">' - . '<input type="hidden" name="action" value="cleanup">' - . '<button>Cleanup (older 1d)</button>' - . '</form><hr>' - - . '<table id="tbldata"><thead>' - . '<tr>'.$sTableHead. '<th>action</th></tr>' - . '</thead>' - . '<tbody>'.$sTable.'</tbody></table>'; - -} else { - $sOut.='no data yet.'; -} -// $sOut.='<script>addFilterToTable("tbldata"); filterTable();</script>'; - -require_once("../deployment/classes/page.class.php"); -$oPage = new Page(); -$oPage->addResponseHeader("Pragma: no-cache"); -$oPage->setOutputtype('html'); -$oPage->setHeader($sHeader); -$oPage->addJsOnReady('addFilterToTable(); filterTable();'); - -$oPage->setContent($sOut); -echo $oPage->render(); diff --git a/public_html/versions/classes/versions.class.php b/public_html/versions/classes/versions.class.php deleted file mode 100644 index c3da08da4423a581cffa778cdd080d00c1f85587..0000000000000000000000000000000000000000 --- a/public_html/versions/classes/versions.class.php +++ /dev/null @@ -1,311 +0,0 @@ -<?php -/** - * version data handler for the deployment tool - * - * @author hahn - */ -class versions { - //put your code here - - public $sProject = false; - public $sPhase = false; - public $sPlace = false; - public $sVariable = false; - public $sData = false; - - /** - * filename of sqlite database file - * @var type - */ - private $_dbfile = false; - - /** - * create statement for the database - * @var type - */ - private $_sCreate = ' - CREATE TABLE "versions" ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , - `time` DATETIME, - `project` TEXT, - `phase` TEXT, - `place` TEXT, - `host` TEXT, - `variable` TEXT, - `data` TEXT, - UNIQUE (project, phase, place, host, variable) ON CONFLICT REPLACE - );' - ; - - // ---------------------------------------------------------------------- - // CONSTRUCTOR - // ---------------------------------------------------------------------- - - /** - * constructor ... no params - */ - public function __construct(){ - - // cache dir is hardcoded to versions directory :-/ - $this->_dbfile = __DIR__ . '/../data/versioncache.db'; - - if (!file_exists($this->_dbfile)) { - $this->_createDb(); - } - } - - // ---------------------------------------------------------------------- - // PRIVATE - // ---------------------------------------------------------------------- - - /** - * create sqlite database - called in constructor if the file does not exist - */ - private function _createDb() { - if (file_exists($this->_dbfile)) { - echo "removing existing file $this->_dbfile ...<br>\n"; - unlink($this->_dbfile); - } - echo "create database as file $this->_dbfile ...<br>\n"; - $this->_makeQuery($this->_sCreate); - if (!file_exists($this->_dbfile)) { - die("ERROR: unable to create sqlite database " . $this->_dbfile); - } - return true; - } - - /** - * execute a sql statement - * @param string $sSql sql statement - * @param array $aVars array with values (uses PDO::prepare(); $sSql must contain placeholders :key) - * @return database object - */ - private function _makeQuery($sSql, $aVars=false) { - // $this->_log(__FUNCTION__."($sSql)"); - // echo "DEBUG: executing SQL<pre>$sSql</pre>"; - $oDb = new PDO("sqlite:" . $this->_dbfile); - if ($aVars && is_array($aVars)){ - $sth = $oDb->prepare($sSql); - $result = $sth->execute($aVars); - } else { - $result = $oDb->query($sSql); - } - return $result; - } - - /** - * execute a sql statement - * @param string $sSql sql statement - * @return database object - */ - private function _makeSelectQuery($sSql, $aKey=false) { - // $this->_log(__FUNCTION__."($sSql)"); - // echo "DEBUG: executing select SQL<pre>$sSql</pre>"; - $oDb = new PDO("sqlite:" . $this->_dbfile); - $oStatement = $oDb->prepare($sSql); - $oStatement->execute(); - $aReturn=array(); - while ($row = $oStatement->fetch(PDO::FETCH_ASSOC)) { - if ($aKey && array_key_exists($aKey, $row)){ - $aReturn[] = $row[$aKey]; - } else { - $aReturn[] = $row; - } - } - return $aReturn; - } - - - // ---------------------------------------------------------------------- - // PUBLIC GETTER - // ---------------------------------------------------------------------- - - - /** - * get list of current projects - * @return type - */ - public function getProjects(){ - $sSql="select distinct(project) from `versions`"; - return $this->_makeSelectQuery($sSql, 'project'); - } - - /** - * get phases of the current project; a project must be set be set before - * @return type - */ - public function getPhases(){ - if (!$this->sProject){ - die("ERROR: you need to set a project first. Use the setProject() method to do so."); - } - $sSql="select distinct(phase) from `versions` - WHERE - project='" . $this->sProject . "' - " - ; - return $this->_makeSelectQuery($sSql,'phase'); - } - - /** - * get places of the current project; a project and must be set be set before - * @return type - */ - public function getPlaces(){ - if (!$this->sProject || !$this->sPhase){ - die("ERROR: you need to set a project, and phase first. Use the setProject() method to do so."); - } - $sSql="select distinct(place) from `versions` - WHERE - project='" . $this->sProject . "' - AND phase='" . $this->sPhase . "' - "; - return $this->_makeSelectQuery($sSql, 'place'); - } - - /** - * get hosts that have installed a project - * @return type - */ - public function getHosts(){ - if (!$this->sProject || !$this->sPhase){ - die("ERROR: you need to set a project, and phase first. Use the setProject() method to do so."); - } - $sSql="select distinct(host) from `versions` - WHERE - project='" . $this->sProject . "' - AND phase='" . $this->sPhase . "' - AND place='deployed' - "; - return $this->_makeSelectQuery($sSql, 'host'); - } - - /** - * get versions of the current place (project, phase and place must be - * set before) - * @see setProject() - * @return type - */ - public function getVersion(){ - if (!$this->sProject || !$this->sPhase || !$this->sPlace ){ - die("ERROR: you need to set a project, phase and place first. Use the setProject() method to do so."); - } - $sSql="select data from `versions` - WHERE - project='" . $this->sProject . "' - AND phase='" . $this->sPhase . "' - AND place='" . $this->sPlace . "' - AND host='" . $this->sHost . "' - AND variable='version' - "; - return $this->_makeSelectQuery($sSql, 'data'); - } - - /** - * return currebntly set project, phase, place and host - * @return type - */ - public function whereiam(){ - return array( - 'project'=>$this->sProject, - 'phase'=>$this->sPhase, - 'place'=>$this->sPlace, - 'host'=>$this->sHost, - ); - } - /** - * return currebntly set project, phase, place and host - * @return type - */ - public function dumpdb(){ - $sSql="select * from `versions`"; - return $this->_makeSelectQuery($sSql); - } - - - // ---------------------------------------------------------------------- - // PUBLIC SETTER - // ---------------------------------------------------------------------- - - public function setProject($sProject, $sPhase=false, $sPlace=false, $sHost=false){ - $this->sProject=$sProject; - $this->setPhase($sPhase, $sPlace, $sHost); - return $this->sProject; - } - - public function setPhase($sPhase, $sPlace=false, $sHost=false){ - if (!$this->sProject){ - die("ERROR: you need to set a project. Use the setProject() method to do so."); - return false; - } - $this->sPhase=$sPhase; - $this->setPlace($sPlace, $sHost); - return $this->sPhase; - } - - public function setPlace($sPlace, $sHost=false){ - if (!$this->sProject || !$this->sPhase){ - die("ERROR: you need to set a project and phase. Use the setProject() method to do so."); - return false; - } - if($sPlace!=='onhold' && $sPlace!=='ready2install' && $sPlace!=='deployed'){ - die("ERROR: you set a wrong place [$sPlace]"); - } - $this->sPlace=$sPlace; - $this->setHost($sHost); - return $this->sPlace; - } - - public function setHost($sHost=false){ - if (!$this->sProject || !$this->sPhase || !$this->sPlace){ - die("ERROR: you need to set a project, phase and place. Use the setProject() method to do so."); - return false; - } - if($sHost && $this->sPlace!=='deployed'){ - die("ERROR: a host can be set on place [deployed] only."); - } - if(!$sHost && $this->sPlace==='deployed'){ - die("ERROR: on place [deployed] a host MUST be set."); - } - $this->sHost=$sHost; - return $this->sHost; - } - - /** - * update a version - * @return boolean - */ - public function updateVar($sVarname,$sValue){ - if (!$this->sProject || !$this->sPhase || !$this->sPlace ){ - die("ERROR: you need to set a project, phase and place. use the setProject() method to do so."); - } - $sSql=" - INSERT into `versions` - (`time`, `project`, `phase`, `place`, `host`, `variable`, `data` ) - VALUES - ( - '" . date("Y-m-d H:i:s") . "', - '" . $this->sProject . "', - '" . $this->sPhase . "', - '" . $this->sPlace . "', - '" . $this->sHost . "', - :variable, - :value - ); - "; - return $this->_makeQuery( - $sSql, - array( - 'variable'=>$sVarname, - 'value'=>$sValue, - ) - ); - } - /** - * update a version - * @return boolean - */ - public function updateVersion($sVersioninfos){ - return $this->updateVar('version', $sVersioninfos); - } - -} diff --git a/public_html/versions/data/.htkeep b/public_html/versions/data/.htkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/public_html/versions/index.php b/public_html/versions/index.php deleted file mode 100644 index 8fbb34621e34ff0726834e92b03f430b06a15d54..0000000000000000000000000000000000000000 --- a/public_html/versions/index.php +++ /dev/null @@ -1,140 +0,0 @@ -<?php - -/** - * - * VERSION HANDLER API - * - * Syntax des Aufrufs (als GET Schreibweise; ein POST soll (später) auch gehen): - * http://dev.ci.iml.unibe.ch:8002/versions/?action=update&project=ci&phase=preview&host=ci.preview.iml.unibe.ch&variable=version&value=007 - * - * Parameter: - * - * action=update (get-Funktionen muss ich später noch bauen) - * project=[Projekt-ID (=Name des Package, das installiert wird)] - * phase=(preview|stage|live) - * host=[FQDN] - * variable=version (andere noch nicht unterstützt/ vorgesehen) - * value=[Versionsdaten] - * - * 2017-04-07 hahn first lines - */ - - -// ---------------------------------------------------------------------- -// functions -// ---------------------------------------------------------------------- - -/** - * show an error message and quit with http status code 400 (Bad request) - * @param string $sMessage message to show - * @return boolean - */ -function quit($sMessage) { - $sProtocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'); - header("$sProtocol 400: Bad request"); - die("<h1>Bad request</h1>" . $sMessage); - return false; -} - -/** - * get a request param from GET and POST scope (POST has priority) and - * verify it with execution of a cleanup array - * @param string $sKey key to search for in GET or POST - * @param string $sRegex4Cleanup regex for filtering - * @return type - */ -function getParam($sKey, $sRegex4Cleanup = false) { - $sValue=false; - if (array_key_exists($sKey, $_GET)) { - $sValue=$_GET[$sKey]; - } - if (array_key_exists($sKey, $_POST)) { - $sValue=$_POST[$sKey]; - } - if(!$sValue){ - return false; - } - $sReturn = $sRegex4Cleanup ? preg_replace($sRegex4Cleanup, '', $sValue) : $sValue; - - if ($sReturn !== $sValue) { - quit("ERROR: the parameter value in [$sKey = ...] has a wrong format."); - } - return $sReturn; -} - -// ---------------------------------------------------------------------- -// check required params -// ---------------------------------------------------------------------- -if (!$_GET || !count($_GET)) { - quit("no parameter was found."); -} - - -foreach (array("action", "project") as $sKey) { - if (!array_key_exists($sKey, $_GET)) { - quit("value required: $sKey="); - } -} - -// ---------------------------------------------------------------------- -// get vars -// ---------------------------------------------------------------------- - - -$sAction = getParam('action', '/[^a-z]/'); -if ($sAction !== "get" && $sAction !== "update") { - quit("action is unknown or not implemented yet."); -} - -$sProject = getParam('project', '/[^a-z\-0-9]/'); -$sPhase = getParam('phase', '/[^a-z]/'); -$sPlace = getParam('place', '/[^a-z]/'); -$sHost = getParam('host', '/[^a-z\.\-0-9]/'); - -if ($sHost && !$sPlace) { - $sPlace = 'deployed'; -} - -$sVarname = getParam('variable', '/[^a-z]/'); -$sValue = getParam('value', ''); - - -// ---------------------------------------------------------------------- -// init class -// ---------------------------------------------------------------------- - -require './classes/versions.class.php'; - -$oVersion = new versions(); -$oVersion->setProject($sProject, $sPhase, $sPlace, $sHost); - -switch ($sAction) { - case 'get': - print_r($oVersion->getVersion()); - - break; - case 'update': - if (!$sVarname) { - quit("ERROR: the update action requires a variable and a value."); - } - switch ($sVarname) { - // case 'other-varname': - case 'version': - if ($oVersion->updateVar($sVarname, $sValue)){ - echo "OK: $sVarname was updated."; - } else { - echo "ERROR: update for $sVarname failed."; - } - break; - - default: - quit("ERROR: update of variable [$sVarname] is not supported."); - break; - } - break; - - - default: - quit("ERROR: the action is not supported."); - break; -}