mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-11-15 04:27:14 +01:00
Compare commits
10 Commits
6df7be74b7
...
23f390a74f
Author | SHA1 | Date | |
---|---|---|---|
|
23f390a74f | ||
|
8cc64aee19 | ||
|
36501a5013 | ||
|
c1c963624d | ||
|
a041c6a82c | ||
|
4815e61883 | ||
|
1a343b4b55 | ||
|
b70676f4a0 | ||
|
9b62b7c247 | ||
|
ae261d7a47 |
@ -1,726 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
**** COPYRIGHT & LICENSE NOTICE *** DO NOT REMOVE ****
|
||||
*
|
||||
* Xentral (c) Xentral ERP Sorftware GmbH, Fuggerstrasse 11, D-86150 Augsburg, * Germany 2019
|
||||
*
|
||||
* This file is licensed under the Embedded Projects General Public License *Version 3.1.
|
||||
*
|
||||
* You should have received a copy of this license from your vendor and/or *along with this file; If not, please visit www.wawision.de/Lizenzhinweis
|
||||
* to obtain the text of the corresponding license version.
|
||||
*
|
||||
**** END OF COPYRIGHT & LICENSE NOTICE *** DO NOT REMOVE ****
|
||||
*/
|
||||
?>
|
||||
<?php
|
||||
|
||||
final class DatabaseUpgrade
|
||||
{
|
||||
/** @var Application $app */
|
||||
private $app;
|
||||
|
||||
/** @var array $CheckColumnTableCache */
|
||||
private $CheckColumnTableCache;
|
||||
|
||||
/** @var bool $check_column_missing_run */
|
||||
private $check_column_missing_run=false;
|
||||
|
||||
/** @var array $check_column_missing */
|
||||
private $check_column_missing=array();
|
||||
|
||||
/** @var array $check_index_missing */
|
||||
private $check_index_missing=array();
|
||||
|
||||
/** @var array */
|
||||
private $allTables = [];
|
||||
|
||||
/** @var array */
|
||||
private $indexe = [];
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
*/
|
||||
public function __construct($app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
public function emptyTableCache(){
|
||||
$this->CheckColumnTableCache = [];
|
||||
$this->allTables = [];
|
||||
$this->indexe = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @var bool $force
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllTables($force = false)
|
||||
{
|
||||
if($force || empty($this->allTables)) {
|
||||
$this->allTables = $this->app->DB->SelectFirstCols('SHOW TABLES');
|
||||
}
|
||||
|
||||
return $this->allTables;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param string $pk
|
||||
*/
|
||||
public function createTable($table, $pk = 'id')
|
||||
{
|
||||
$sql = "CREATE TABLE `$table` (`".$pk."` INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`".$pk."`)) ENGINE = InnoDB DEFAULT CHARSET=utf8";
|
||||
$this->app->DB->Query($sql);
|
||||
$this->addPrimary($table, $pk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param string $pk
|
||||
*/
|
||||
public function addPrimary($table, $pk = 'id')
|
||||
{
|
||||
$this->CheckAlterTable(
|
||||
"ALTER TABLE `$table`
|
||||
ADD PRIMARY KEY (`".$pk."`)",
|
||||
true
|
||||
);
|
||||
$this->CheckAlterTable(
|
||||
"ALTER TABLE `$table`
|
||||
MODIFY `".$pk."` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1",
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param bool $force
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIndexeCached($table, $force = false)
|
||||
{
|
||||
if($force || !isset($this->indexe[$table])){
|
||||
$this->indexe[$table] = $this->app->DB->SelectArr(sprintf('SHOW INDEX FROM `%s`', $table));
|
||||
if($this->indexe[$table] === null) {
|
||||
$this->indexe[$table] = [];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->indexe[$table];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
*/
|
||||
public function clearIndexCached($table)
|
||||
{
|
||||
if(!isset($this->indexe[$table])) {
|
||||
return;
|
||||
}
|
||||
unset($this->indexe[$table]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param string $pk
|
||||
*/
|
||||
public function hasPrimaryKey($table, $pk = 'id')
|
||||
{
|
||||
$indexe = $this->getIndexeCached($table);
|
||||
if(empty($indexe)) {
|
||||
return false;
|
||||
}
|
||||
foreach($indexe as $index) {
|
||||
if($index['Column_name'] === $pk
|
||||
&& $index['Key_name'] === 'PRIMARY'
|
||||
&& (int)$index['Non_unique'] === 0
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param string $pk
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function CheckTable($table, $pk = 'id')
|
||||
{
|
||||
if($pk === 'id') {
|
||||
$tables = $this->getAllTables();
|
||||
if(!empty($tables)){
|
||||
if(!in_array($table, $tables)){
|
||||
$this->createTable($table, $pk);
|
||||
return;
|
||||
}
|
||||
if(!$this->hasPrimaryKey($table, $pk)) {
|
||||
$this->addPrimary($table, $pk);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
$found = false;
|
||||
$tables = $this->getAllTables(true);
|
||||
if($tables) {
|
||||
$found = in_array($table, $tables);
|
||||
}
|
||||
else{
|
||||
$check = $this->app->DB->Select("SELECT $pk FROM `$table` LIMIT 1");
|
||||
if($check) {
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
if($found==false)
|
||||
{
|
||||
$sql = "CREATE TABLE `$table` (`".$pk."` INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`".$pk."`)) ENGINE = InnoDB DEFAULT CHARSET=utf8";
|
||||
$this->app->DB->Update($sql);
|
||||
$this->CheckAlterTable("ALTER TABLE `$table`
|
||||
ADD PRIMARY KEY (`".$pk."`)");
|
||||
$this->CheckAlterTable("ALTER TABLE `$table`
|
||||
MODIFY `".$pk."` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1");
|
||||
}
|
||||
if($pk !== 'id') {
|
||||
$this->CheckColumn('created_at','timestamp',$table,"DEFAULT CURRENT_TIMESTAMP NOT NULL");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
* @param string $type
|
||||
* @param string $table
|
||||
* @param string $default
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function UpdateColumn($column,$type,$table,$default="NOT NULL")
|
||||
{
|
||||
$fields = $this->app->DB->SelectArr("show columns from `".$table."`");
|
||||
if($fields)
|
||||
{
|
||||
foreach($fields as $val)
|
||||
{
|
||||
$field_array[] = $val['Field'];
|
||||
}
|
||||
}
|
||||
if (in_array($column, $field_array))
|
||||
{
|
||||
$this->app->DB->Query('ALTER TABLE `'.$table.'` CHANGE `'.$column.'` `'.$column.'` '.$type.' '.$default.';');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
* @param string $table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function DeleteColumn($column,$table)
|
||||
{
|
||||
$this->app->DB->Query('ALTER TABLE `'.$table.'` DROP `'.$column.'`;');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
* @param string $type
|
||||
* @param string $table
|
||||
* @param string $default
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function CheckColumn($column,$type,$table,$default="")
|
||||
{
|
||||
if($table === 'firmendaten')
|
||||
{
|
||||
if($this->app->DB->Select("SELECT `id` FROM `firmendaten_werte` WHERE `name` = '$column' LIMIT 1"))return;
|
||||
}
|
||||
if(!isset($this->CheckColumnTableCache[$table]))
|
||||
{
|
||||
$tmp=$this->app->DB->SelectArr("show columns from `".$table."`");
|
||||
if($tmp)
|
||||
{
|
||||
foreach($tmp as $val)
|
||||
{
|
||||
$this->CheckColumnTableCache[$table][] = $val['Field'];
|
||||
//$types[$val['Field']] = strtolower($val['Type']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($this->CheckColumnTableCache[$table]) && !in_array($column, $this->CheckColumnTableCache[$table]))
|
||||
{
|
||||
if($this->check_column_missing_run)
|
||||
{
|
||||
//$result = mysqli_query($this->app->DB->connection,'ALTER TABLE `'.$table.'` ADD `'.$column.'` '.$type.' '.$default.';');
|
||||
$this->check_column_missing[$table][]=$column;
|
||||
} else {
|
||||
$result = $this->app->DB->Query('ALTER TABLE `'.$table.'` ADD `'.$column.'` '.$type.' '.$default.';');
|
||||
if($table === 'firmendaten' && $this->app->DB->error())
|
||||
{
|
||||
if((method_exists($this->app->DB, 'errno2') && $this->app->DB->errno() == '1118')
|
||||
|| strpos($this->app->DB->error(),'Row size too large') !== false
|
||||
)
|
||||
{
|
||||
$this->ChangeFirmendatenToMyIsam();
|
||||
$this->app->DB->Query('ALTER TABLE `'.$table.'` ADD `'.$column.'` '.$type.' '.$default.';');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $indexe
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getGroupedIndexe($indexe)
|
||||
{
|
||||
if(empty($indexe)) {
|
||||
return $indexe;
|
||||
}
|
||||
$return = [];
|
||||
foreach($indexe as $index) {
|
||||
$keyName = $index['Key_name'];
|
||||
$isUnique = $index['Non_unique'] == '0';
|
||||
$seq = $index['Seq_in_index'];
|
||||
$columnName = $index['Column_name'];
|
||||
$return[$isUnique?'unique':'index'][$keyName][(int)$seq - 1] = $columnName;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $indexe
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getDoubleIndexeFromGroupedIndexe($indexe)
|
||||
{
|
||||
if(empty($indexe)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
foreach($indexe as $type => $indexArrs) {
|
||||
$columnStrings = [];
|
||||
foreach($indexArrs as $indexKey => $columns) {
|
||||
$columnString = implode('|', $columns);
|
||||
if(in_array($columnString, $columnStrings)) {
|
||||
$ret[$type][] = $indexKey;
|
||||
continue;
|
||||
}
|
||||
$columnStrings[] = $columnString;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param array $indexe
|
||||
* @param bool $noCache
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function CheckDoubleIndex($table, $indexe, $noCache = false)
|
||||
{
|
||||
$query = $noCache?null:$this->CheckAlterTable("SHOW INDEX FROM `$table`");
|
||||
if(!$query) {
|
||||
$indexeGrouped = $this->getGroupedIndexe($indexe);
|
||||
$doubleIndexe = $this->getDoubleIndexeFromGroupedIndexe($indexeGrouped);
|
||||
if(!empty($doubleIndexe)) {
|
||||
$indexe = $this->getIndexeCached($table, true);
|
||||
$indexeGrouped = $this->getGroupedIndexe($indexe);
|
||||
$doubleIndexe = $this->getDoubleIndexeFromGroupedIndexe($indexeGrouped);
|
||||
if(empty($doubleIndexe)) {
|
||||
return $indexe;
|
||||
}
|
||||
|
||||
foreach($doubleIndexe as $type => $doubleIndex) {
|
||||
foreach($doubleIndex as $indexName) {
|
||||
$this->app->DB->Query("ALTER TABLE `".$table."` DROP INDEX `".$indexName."`");
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($noCache) {
|
||||
return $indexe;
|
||||
}
|
||||
$this->CheckAlterTable("SHOW INDEX FROM `$table`", true);
|
||||
|
||||
return $this->getIndexeCached($table, true);
|
||||
}
|
||||
if(empty($indexe) || count($indexe) == 1){
|
||||
return $indexe;
|
||||
}
|
||||
$uniquearr = array();
|
||||
$indexarr = array();
|
||||
foreach($indexe as $index)
|
||||
{
|
||||
if($index['Key_name'] !== 'PRIMARY' && !empty($index['Column_name']))
|
||||
{
|
||||
if($index['Non_unique'])
|
||||
{
|
||||
$indexarr[$index['Key_name']][] = $index['Column_name'];
|
||||
}else{
|
||||
$uniquearr[$index['Key_name']][] = $index['Column_name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$cindex = count($indexarr);
|
||||
$cuniqe = count($uniquearr);
|
||||
$changed = false;
|
||||
if($cindex > 1)
|
||||
{
|
||||
$check = array();
|
||||
foreach($indexarr as $key => $value)
|
||||
{
|
||||
if(empty($value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(count($value) > 1){
|
||||
sort($value);
|
||||
}
|
||||
$vstr = implode(',', $value);
|
||||
if(in_array($vstr, $check))
|
||||
{
|
||||
$this->app->DB->Query("DROP INDEX `".$key."` ON `".$table."`");
|
||||
$changed = true;
|
||||
}else{
|
||||
$check[] = $vstr;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($cuniqe > 1)
|
||||
{
|
||||
$check = array();
|
||||
foreach($uniquearr as $key => $value)
|
||||
{
|
||||
if(empty($value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(count($value) > 1){
|
||||
sort($value);
|
||||
}
|
||||
$vstr = implode(',', $value);
|
||||
if(in_array($vstr, $check))
|
||||
{
|
||||
$this->app->DB->Query("DROP UNIQUE `".$key."` ON `".$table."`");
|
||||
$changed = true;
|
||||
}else{
|
||||
$check[] = $vstr;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($changed) {
|
||||
return $this->getIndexeCached($table, true);
|
||||
}
|
||||
return $indexe;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param string|array $column
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function CheckFulltextIndex($table,$column)
|
||||
{
|
||||
if(empty($table) || empty($column))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(!is_array($column))
|
||||
{
|
||||
$column = [$column];
|
||||
}
|
||||
$columnmasked = [];
|
||||
foreach($column as $keyColumn => $valueColumn)
|
||||
{
|
||||
if(!empty($valueColumn))
|
||||
{
|
||||
$columnmasked[] = "`$valueColumn`";
|
||||
}else{
|
||||
unset($column[$keyColumn]);
|
||||
}
|
||||
}
|
||||
if(empty($column))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$columnsFound = [];
|
||||
$indexe = $this->getIndexeCached($table, true);
|
||||
$indexeFound = [];
|
||||
if(!empty($indexe))
|
||||
{
|
||||
foreach($indexe as $index)
|
||||
{
|
||||
if($index['Index_type'] === 'FULLTEXT')
|
||||
{
|
||||
$indexeFound[] = $index['Column_name'];
|
||||
if(!in_array($index['Column_name'], $columnsFound))
|
||||
{
|
||||
$columnsFound[] = $index['Column_name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$cindexeFound = count($indexeFound);
|
||||
$column = count($column);
|
||||
if(($column === $cindexeFound) && (count($columnsFound) === $column))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if($cindexeFound > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
$this->app->DB->Query(
|
||||
"ALTER TABLE `$table`
|
||||
ADD FULLTEXT INDEX `FullText`
|
||||
(".implode(',',$columnmasked).");"
|
||||
);
|
||||
$error = $this->app->DB->error();
|
||||
|
||||
return empty($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
* @param bool $unique
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function CheckIndex($table, $column, $unique = false)
|
||||
{
|
||||
$indexex = null;
|
||||
$indexexother = null;
|
||||
$indexe = $this->getIndexeCached($table);
|
||||
if($indexe)
|
||||
{
|
||||
$indexe = $this->CheckDoubleIndex($table, $indexe, true);
|
||||
foreach($indexe as $index)
|
||||
{
|
||||
if(is_array($column) && $index['Key_name'] !== 'PRIMARY')
|
||||
{
|
||||
if($unique && !$index['Non_unique'])
|
||||
{
|
||||
if(in_array($index['Column_name'], $column))
|
||||
{
|
||||
$indexex[$index['Key_name']][$index['Column_name']] = true;
|
||||
}else{
|
||||
$indexexother[$index['Key_name']][$index['Column_name']] = true;
|
||||
}
|
||||
}
|
||||
elseif(!$unique){
|
||||
if(in_array($index['Column_name'], $column)) {
|
||||
$indexex[$index['Key_name']][$index['Column_name']] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif(!is_array($column)){
|
||||
if($index['Column_name'] == $column)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($this->check_column_missing_run)
|
||||
{
|
||||
$this->check_index_missing[$table][] = $column;
|
||||
}
|
||||
if(!$unique)
|
||||
{
|
||||
if(is_array($column))
|
||||
{
|
||||
if($indexex)
|
||||
{
|
||||
foreach($indexex as $k => $v) {
|
||||
if(count($v) === 1 && count($column) > 1) {
|
||||
$this->app->DB->Query("DROP INDEX `".$k."` ON `".$table."`");
|
||||
$this->clearIndexCached($table);
|
||||
unset($indexex[$k]);
|
||||
}
|
||||
}
|
||||
foreach($indexex as $k => $v)
|
||||
{
|
||||
if(count($v) == count($column)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
foreach($indexex as $k => $v)
|
||||
{
|
||||
if(!isset($indexexother[$k]))
|
||||
{
|
||||
$this->app->DB->Query("DROP INDEX `".$k."` ON `".$table."`");
|
||||
$cols = null;
|
||||
foreach($column as $c) {
|
||||
$cols[] = "`$c`";
|
||||
}
|
||||
$this->CheckAlterTable("ALTER TABLE `$table` ADD INDEX(".implode(', ',$cols)."); ",true);
|
||||
$this->clearIndexCached($table);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$cols = null;
|
||||
foreach($column as $c) {
|
||||
$cols[] = "`$c`";
|
||||
}
|
||||
$this->CheckAlterTable("ALTER TABLE `$table` ADD INDEX(".implode(', ',$cols)."); ", true);
|
||||
$this->clearIndexCached($table);
|
||||
}
|
||||
else{
|
||||
$this->CheckAlterTable("ALTER TABLE `$table` ADD INDEX(`$column`); ", true);
|
||||
$this->clearIndexCached($table);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(is_array($column))
|
||||
{
|
||||
if($indexex)
|
||||
{
|
||||
foreach($indexex as $k => $v)
|
||||
{
|
||||
if(count($v) == count($column))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
foreach($indexex as $k => $v)
|
||||
{
|
||||
if(!isset($indexexother[$k]))
|
||||
{
|
||||
$this->app->DB->Query("DROP INDEX `".$k."` ON `".$table."`");
|
||||
$cols = null;
|
||||
foreach($column as $c) {
|
||||
$cols[] = "`$c`";
|
||||
}
|
||||
$this->CheckAlterTable("ALTER TABLE `$table` ADD UNIQUE(".implode(', ',$cols)."); ", true);
|
||||
$this->clearIndexCached($table);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$cols = null;
|
||||
foreach($column as $c) {
|
||||
$cols[] = "`$c`";
|
||||
}
|
||||
$this->CheckAlterTable("ALTER TABLE `$table` ADD UNIQUE(".implode(', ',$cols)."); ", true);
|
||||
$this->clearIndexCached($table);
|
||||
}else{
|
||||
$this->CheckAlterTable("ALTER TABLE `$table` ADD UNIQUE(`$column`); ", true);
|
||||
$this->clearIndexCached($table);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif(!is_array($column))
|
||||
{
|
||||
if(!$unique)
|
||||
{
|
||||
$this->CheckAlterTable("ALTER TABLE `$table` ADD INDEX(`$column`); ");
|
||||
}else{
|
||||
$this->CheckAlterTable("ALTER TABLE `$table` ADD UNIQUE(`$column`); ");
|
||||
}
|
||||
$this->clearIndexCached($table);
|
||||
}
|
||||
elseif(is_array($column))
|
||||
{
|
||||
$cols = null;
|
||||
foreach($column as $c) {
|
||||
$cols[] = "`$c`";
|
||||
}
|
||||
$this->CheckAlterTable("ALTER TABLE `$table` ADD UNIQUE(".implode(', ',$cols)."); ");
|
||||
$this->clearIndexCached($table);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sql
|
||||
* @param bool $force
|
||||
*
|
||||
* @return mysqli_result|bool
|
||||
*/
|
||||
function CheckAlterTable($sql, $force = false)
|
||||
{
|
||||
$sqlmd5 = md5($sql);
|
||||
$check = $this->app->DB->Select("SELECT id FROM checkaltertable WHERE checksum='$sqlmd5' LIMIT 1");
|
||||
if($check > 0 && !$force) return;
|
||||
$query = $this->app->DB->Query($sql);
|
||||
if($query && empty($check) && !$this->app->DB->error()){
|
||||
$this->app->DB->Insert("INSERT INTO checkaltertable (id,checksum) VALUES ('','$sqlmd5')");
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function ChangeFirmendatenToMyIsam()
|
||||
{
|
||||
$this->app->DB->Query("ALTER TABLE firmendaten ENGINE = MyISAM;");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSortedIndexColumnsByIndexName($table): array
|
||||
{
|
||||
$indexesByName = [];
|
||||
$indexes = $this->app->DB->SelectArr(sprintf('SHOW INDEX FROM `%s`', $table));
|
||||
if(empty($indexes)) {
|
||||
return $indexesByName;
|
||||
}
|
||||
foreach($indexes as $index) {
|
||||
$indexesByName[$index['Key_name']][] = $index['Column_name'];
|
||||
}
|
||||
foreach($indexesByName as $indexName => $columns) {
|
||||
$columns = array_unique($columns);
|
||||
sort($columns);
|
||||
$indexesByName[$indexName] = $columns;
|
||||
}
|
||||
|
||||
return $indexesByName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated will be removed in 21.4
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $columns
|
||||
*/
|
||||
public function dropIndex($table, $columns): void
|
||||
{
|
||||
if(empty($table) || empty($columns)) {
|
||||
return;
|
||||
}
|
||||
$columns = array_unique($columns);
|
||||
sort($columns);
|
||||
$countColumns = count($columns);
|
||||
$indexes = $this->getSortedIndexColumnsByIndexName($table);
|
||||
if(empty($indexes)) {
|
||||
return;
|
||||
}
|
||||
foreach($indexes as $indexName => $indexColumns) {
|
||||
if(count($indexColumns) !== $countColumns) {
|
||||
continue;
|
||||
}
|
||||
if(count(array_intersect($indexColumns, $columns)) === $countColumns) {
|
||||
$this->app->DB->Query(sprintf('ALTER TABLE `%s` DROP INDEX `%s`', $table, $indexName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -53,9 +53,7 @@ MariaDB [openxe]> show keys from wiki;
|
||||
|
||||
*/
|
||||
|
||||
function implode_with_quote(string $quote, string $delimiter, array $array_to_implode) : string {
|
||||
return($quote.implode($quote.$delimiter.$quote, $array_to_implode).$quote);
|
||||
}
|
||||
require('mustal_mysql_upgrade_tool.php');
|
||||
|
||||
$connection_info_file_name = "connection_info.json";
|
||||
$target_folder = ".";
|
||||
@ -71,12 +69,6 @@ $color_green = "\033[32m";
|
||||
$color_yellow = "\033[33m";
|
||||
$color_default = "\033[39m";
|
||||
|
||||
// These default values will not be in quotes
|
||||
$replacers = [
|
||||
['current_timestamp','current_timestamp()'],
|
||||
['on update current_timestamp','on update current_timestamp()']
|
||||
];
|
||||
|
||||
// -------------------------------- START
|
||||
|
||||
echo("\n");
|
||||
@ -144,7 +136,7 @@ if ($argc > 1) {
|
||||
$schema = $connection_info['database'];
|
||||
|
||||
echo("--------------- Loading from database '$schema@$host'... ---------------\n");
|
||||
$db_def = load_tables_from_db($host, $schema, $user, $passwd, $replacers);
|
||||
$db_def = mustal_load_tables_from_db($host, $schema, $user, $passwd, $mustal_replacers);
|
||||
|
||||
if (empty($db_def)) {
|
||||
echo ("Could not load from $schema@$host\n");
|
||||
@ -157,7 +149,7 @@ if ($argc > 1) {
|
||||
|
||||
echo("--------------- Export to JSON... ---------------\n");
|
||||
// $result = save_tables_to_csv($db_def, $target_folder, $tables_file_name_wo_folder, $delimiter, $quote, $keys_postfix, $force);
|
||||
$result = save_tables_to_json($db_def, $target_folder, $tables_file_name_wo_folder, $force);
|
||||
$result = mustal_save_tables_to_json($db_def, $target_folder, $tables_file_name_wo_folder, $force);
|
||||
|
||||
if ($result != 0) {
|
||||
|
||||
@ -177,7 +169,7 @@ if ($argc > 1) {
|
||||
$compare_differences = array();
|
||||
|
||||
echo("--------------- Loading from JSON... ---------------\n");
|
||||
$compare_def = load_tables_from_json($target_folder, $tables_file_name_wo_folder);
|
||||
$compare_def = mustal_load_tables_from_json($target_folder, $tables_file_name_wo_folder);
|
||||
|
||||
if (empty($compare_def)) {
|
||||
echo ("Could not load from JSON $tables_file_name_w_folder\n");
|
||||
@ -205,7 +197,7 @@ if ($argc > 1) {
|
||||
}*/
|
||||
|
||||
echo("--------------- Comparing database '$schema@$host' vs. JSON '".$compare_def['database']."@".$compare_def['host']."' ---------------\n");
|
||||
$compare_differences = compare_table_array($compare_def,"in JSON",$db_def,"in DB",true);
|
||||
$compare_differences = mustal_compare_table_array($compare_def,"in JSON",$db_def,"in DB",true);
|
||||
echo((empty($compare_differences)?0:count($compare_differences))." differences.\n");
|
||||
|
||||
if ($verbose) {
|
||||
@ -227,194 +219,14 @@ if ($argc > 1) {
|
||||
echo("--------------- Calculating database upgrade for '$schema@$host'... ---------------\n");
|
||||
|
||||
$upgrade_sql = array();
|
||||
if (count($compare_differences) > 0) {
|
||||
$upgrade_sql[] = ("SET SQL_MODE='ALLOW_INVALID_DATES';");
|
||||
|
||||
$result = mustal_calculate_db_upgrade($compare_def, $db_def, $upgrade_sql);
|
||||
|
||||
if ($result != 0) {
|
||||
echo("Error: $result\n");
|
||||
exit;
|
||||
}
|
||||
|
||||
$compare_differences = compare_table_array($compare_def,"in JSON",$db_def,"in DB",true);
|
||||
|
||||
foreach ($compare_differences as $compare_difference) {
|
||||
switch ($compare_difference['type']) {
|
||||
case 'Table existance':
|
||||
|
||||
// Get table definition from JSON
|
||||
|
||||
$table_name = $compare_difference['in JSON'];
|
||||
|
||||
$table_key = array_search($table_name,array_column($compare_def['tables'],'name'));
|
||||
|
||||
if ($table_key !== false) {
|
||||
$table = $compare_def['tables'][$table_key];
|
||||
|
||||
switch ($table['type']) {
|
||||
case 'BASE TABLE':
|
||||
|
||||
// Create table in DB
|
||||
$sql = "";
|
||||
$sql = "CREATE TABLE `".$table['name']."` (";
|
||||
$comma = "";
|
||||
|
||||
foreach ($table['columns'] as $column) {
|
||||
$sql .= $comma."`".$column['Field']."` ".column_sql_definition($table_name, $column,array_column($replacers,1));
|
||||
$comma = ", ";
|
||||
}
|
||||
|
||||
// Add keys
|
||||
$comma = ", ";
|
||||
foreach ($table['keys'] as $key) {
|
||||
if ($key['Key_name'] == 'PRIMARY') {
|
||||
$keystring = "PRIMARY KEY ";
|
||||
} else {
|
||||
|
||||
if(array_key_exists('Index_type', $key)) {
|
||||
$index_type = $key['Index_type'];
|
||||
} else {
|
||||
$index_type = "";
|
||||
}
|
||||
|
||||
$keystring = $index_type." KEY `".$key['Key_name']."` ";
|
||||
}
|
||||
$sql .= $comma.$keystring."(`".implode("`,`",$key['columns'])."`) ";
|
||||
}
|
||||
$sql .= ")";
|
||||
$upgrade_sql[] = $sql;
|
||||
break;
|
||||
default:
|
||||
echo("Upgrade type '".$table['type']."' on table '".$table['name']."' not supported.\n");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
echo("Error table_key while creating upgrade for table existance `$table_name`.\n");
|
||||
}
|
||||
|
||||
break;
|
||||
case 'Column existance':
|
||||
$table_name = $compare_difference['table'];
|
||||
$column_name = $compare_difference['in JSON'];
|
||||
$table_key = array_search($table_name,array_column($compare_def['tables'],'name'));
|
||||
if ($table_key !== false) {
|
||||
$table = $compare_def['tables'][$table_key];
|
||||
$columns = $table['columns'];
|
||||
$column_key = array_search($column_name,array_column($columns,'Field'));
|
||||
if ($column_key !== false) {
|
||||
$column = $table['columns'][$column_key];
|
||||
$sql = "ALTER TABLE `$table_name` ADD COLUMN `".$column_name."` ";
|
||||
$sql .= column_sql_definition($table_name, $column, array_column($replacers,1));
|
||||
$sql .= ";";
|
||||
$upgrade_sql[] = $sql;
|
||||
}
|
||||
else {
|
||||
echo("Error column_key while creating column '$column_name' in table '".$table['name']."'\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo("Error table_key while creating upgrade for column existance '$column_name' in table '$table_name'.\n");
|
||||
}
|
||||
// Add Column in DB
|
||||
break;
|
||||
case 'Column definition':
|
||||
$table_name = $compare_difference['table'];
|
||||
$column_name = $compare_difference['column'];
|
||||
$table_key = array_search($table_name,array_column($compare_def['tables'],'name'));
|
||||
if ($table_key !== false) {
|
||||
$table = $compare_def['tables'][$table_key];
|
||||
$columns = $table['columns'];
|
||||
|
||||
$column_names = array_column($columns,'Field');
|
||||
$column_key = array_search($column_name,$column_names);
|
||||
|
||||
if ($column_key !== false) {
|
||||
$column = $table['columns'][$column_key];
|
||||
|
||||
$sql = "ALTER TABLE `$table_name` MODIFY COLUMN `".$column_name."` ";
|
||||
$sql .= column_sql_definition($table_name, $column,array_column($replacers,1));
|
||||
$sql .= ";";
|
||||
$upgrade_sql[] = $sql;
|
||||
}
|
||||
else {
|
||||
echo("Error column_key while modifying column '$column_name' in table '".$table['name']."'\n");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo("Error table_key while modifying column '$column_name' in table '$table_name'.\n");
|
||||
}
|
||||
// Modify Column in DB
|
||||
break;
|
||||
case "Key definition":
|
||||
$table_name = $compare_difference['table'];
|
||||
$key_name = $compare_difference['key'];
|
||||
$table_key = array_search($table_name,array_column($compare_def['tables'],'name'));
|
||||
if ($table_key !== false) {
|
||||
$table = $compare_def['tables'][$table_key];
|
||||
$keys = $table['keys'];
|
||||
|
||||
$key_names = array_column($keys,'Key_name');
|
||||
$key_key = array_search($key_name,$key_names);
|
||||
|
||||
if ($key_key !== false) {
|
||||
$key = $table['keys'][$key_key];
|
||||
|
||||
$sql = "ALTER TABLE `$table_name` DROP KEY `".$key_name."`;";
|
||||
$upgrade_sql[] = $sql;
|
||||
|
||||
$sql = "ALTER TABLE `$table_name` ADD KEY `".$key_name."` ";
|
||||
$sql .= "(`".implode("`,`",$key['columns'])."`)";
|
||||
$sql .= ";";
|
||||
$upgrade_sql[] = $sql;
|
||||
}
|
||||
else {
|
||||
echo("Error key_key while changing key '$key_name' in table '".$table['name']."'\n");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo("Error table_key while changing key '$key_name' in table '$table_name'.\n");
|
||||
}
|
||||
break;
|
||||
case 'Key existance':
|
||||
|
||||
$table_name = $compare_difference['table'];
|
||||
$key_name = $compare_difference['in JSON'];
|
||||
$table_key = array_search($table_name,array_column($compare_def['tables'],'name'));
|
||||
if ($table_key !== false) {
|
||||
$table = $compare_def['tables'][$table_key];
|
||||
$keys = $table['keys'];
|
||||
|
||||
$key_names = array_column($keys,'Key_name');
|
||||
$key_key = array_search($key_name,$key_names);
|
||||
|
||||
if ($key_key !== false) {
|
||||
$key = $table['keys'][$key_key];
|
||||
|
||||
$sql = "ALTER TABLE `$table_name` ADD KEY `".$key_name."` ";
|
||||
$sql .= "(`".implode("`,`",$key['columns'])."`)";
|
||||
$sql .= ";";
|
||||
$upgrade_sql[] = $sql;
|
||||
}
|
||||
else {
|
||||
echo("Error key_key while adding key '$key_name' in table '".$table['name']."'\n");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo("Error table_key while adding key '$key_name' in table '$table_name'.\n");
|
||||
}
|
||||
break;
|
||||
case 'Table count':
|
||||
// Nothing to do
|
||||
break;
|
||||
case 'Table type':
|
||||
echo("Upgrade type '".$compare_difference['type']."' on table '".$compare_difference['table']."' not supported.\n");
|
||||
break;
|
||||
default:
|
||||
echo("Upgrade type '".$compare_difference['type']."' not supported.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$upgrade_sql = array_unique($upgrade_sql);
|
||||
|
||||
echo("--------------- Database upgrade for '$schema@$host'... ---------------\n");
|
||||
if ($verbose) {
|
||||
foreach($upgrade_sql as $statement) {
|
||||
@ -426,8 +238,7 @@ if ($argc > 1) {
|
||||
echo("--------------- Database upgrade calculated for '$schema@$host' (show SQL with -v). ---------------\n");
|
||||
|
||||
if ($doupgrade) {
|
||||
echo("--------------- Executing database upgrade for '$schema@$host' database will be written! ---------------\n");
|
||||
|
||||
echo("--------------- Executing database upgrade for '$schema@$host' database will be written! ---------------\n");
|
||||
|
||||
// First get the contents of the database table structure
|
||||
$mysqli = mysqli_connect($host, $user, $passwd, $schema);
|
||||
@ -467,7 +278,7 @@ if ($argc > 1) {
|
||||
echo("--------------- Executing database upgrade for '$schema@$host' done. ---------------\n");
|
||||
|
||||
echo("--------------- Checking database upgrade for '$schema@$host'... ---------------\n");
|
||||
$db_def = load_tables_from_db($host, $schema, $user, $passwd, $replacers);
|
||||
$db_def = mustal_load_tables_from_db($host, $schema, $user, $passwd, $mustal_replacers);
|
||||
|
||||
echo("--------------- Comparing database '$schema@$host' vs. JSON '".$compare_def['database']."@".$compare_def['host']."' ---------------\n");
|
||||
$compare_differences = compare_table_array($compare_def,"in JSON",$db_def,"in DB",true);
|
||||
@ -488,372 +299,6 @@ if ($argc > 1) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Load all db_def from a DB connection into a db_def array
|
||||
|
||||
function load_tables_from_db(string $host, string $schema, string $user, string $passwd, $replacers) : array {
|
||||
|
||||
// First get the contents of the database table structure
|
||||
$mysqli = mysqli_connect($host, $user, $passwd, $schema);
|
||||
|
||||
/* Check if the connection succeeded */
|
||||
if (!$mysqli) {
|
||||
return(array());
|
||||
}
|
||||
|
||||
// Get db_def and views
|
||||
|
||||
$sql = "SHOW FULL tables";
|
||||
$query_result = mysqli_query($mysqli, $sql);
|
||||
if (!$query_result) {
|
||||
return(array());
|
||||
}
|
||||
while ($row = mysqli_fetch_assoc($query_result)) {
|
||||
$table = array();
|
||||
$table['name'] = $row['Tables_in_'.$schema];
|
||||
$table['type'] = $row['Table_type'];
|
||||
$tables[] = $table; // Add table to list of tables
|
||||
}
|
||||
|
||||
// Get and add columns of the table
|
||||
foreach ($tables as &$table) {
|
||||
$sql = "SHOW FULL COLUMNS FROM ".$table['name'];
|
||||
$query_result = mysqli_query($mysqli, $sql);
|
||||
|
||||
if (!$query_result) {
|
||||
return(array());
|
||||
}
|
||||
|
||||
$columns = array();
|
||||
while ($column = mysqli_fetch_assoc($query_result)) {
|
||||
// Do some harmonization
|
||||
|
||||
if ($column['Default'] !== NULL) {
|
||||
sql_replace_reserved_functions($column,$replacers);
|
||||
$column['Default'] = mysql_put_text_type_in_quotes($column['Type'],$column['Default']);
|
||||
}
|
||||
|
||||
$columns[] = $column; // Add column to list of columns
|
||||
}
|
||||
$table['columns'] = $columns;
|
||||
|
||||
$sql = "SHOW KEYS FROM ".$table['name'];
|
||||
$query_result = mysqli_query($mysqli, $sql);
|
||||
if (!$query_result) {
|
||||
return(array());
|
||||
}
|
||||
$keys = array();
|
||||
while ($key = mysqli_fetch_assoc($query_result)) {
|
||||
$keys[] = $key; // Add key to list of keys
|
||||
}
|
||||
// Compose comparable format for keys
|
||||
$composed_keys = array();
|
||||
foreach ($keys as $key) {
|
||||
|
||||
// Check if this key exists already
|
||||
|
||||
$key_pos = array_search($key['Key_name'],array_column($composed_keys,'Key_name'));
|
||||
|
||||
if ($key_pos == false) {
|
||||
// New key
|
||||
$composed_key = array();
|
||||
$composed_key['Key_name'] = $key['Key_name'];
|
||||
$composed_key['Index_type'] = $key['Index_type'];
|
||||
$composed_key['columns'][] = $key['Column_name'];
|
||||
$composed_keys[] = $composed_key;
|
||||
} else {
|
||||
// Given key, add column
|
||||
$composed_keys[$key_pos]['columns'][] .= $key['Column_name'];
|
||||
}
|
||||
}
|
||||
unset($key);
|
||||
$table['keys'] = $composed_keys;
|
||||
unset($composed_keys);
|
||||
}
|
||||
unset($table);
|
||||
|
||||
$result = array();
|
||||
$result['host'] = $host;
|
||||
$result['database'] = $schema;
|
||||
$result['user'] = $user;
|
||||
$result['tables'] = $tables;
|
||||
return($result);
|
||||
}
|
||||
|
||||
function save_tables_to_json(array $db_def, string $path, string $tables_file_name, bool $force) : int {
|
||||
|
||||
// Prepare db_def file
|
||||
if (!is_dir($path)) {
|
||||
mkdir($path);
|
||||
}
|
||||
if (!$force && file_exists($path."/".$tables_file_name)) {
|
||||
return(2);
|
||||
}
|
||||
|
||||
$tables_file = fopen($path."/".$tables_file_name, "w");
|
||||
if (empty($tables_file)) {
|
||||
return(2);
|
||||
}
|
||||
|
||||
fwrite($tables_file, json_encode($db_def,JSON_PRETTY_PRINT));
|
||||
|
||||
fclose($tables_file);
|
||||
return(0);
|
||||
}
|
||||
|
||||
// Load all db_def from JSON file
|
||||
function load_tables_from_json(string $path, string $tables_file_name) : array {
|
||||
|
||||
$db_def = array();
|
||||
|
||||
$contents = file_get_contents($path."/".$tables_file_name);
|
||||
|
||||
if (!$contents) {
|
||||
return(array());
|
||||
}
|
||||
|
||||
$db_def = json_decode($contents, true);
|
||||
|
||||
if (!$db_def) {
|
||||
return(array());
|
||||
}
|
||||
|
||||
return($db_def);
|
||||
}
|
||||
|
||||
// Compare two definitions
|
||||
// Report based on the first array
|
||||
// Return Array
|
||||
function compare_table_array(array $nominal, string $nominal_name, array $actual, string $actual_name, bool $check_column_definitions) : array {
|
||||
|
||||
$compare_differences = array();
|
||||
|
||||
if (count($nominal['tables']) != count($actual['tables'])) {
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Table count";
|
||||
$compare_difference[$nominal_name] = count($nominal['tables']);
|
||||
$compare_difference[$actual_name] = count($actual['tables']);
|
||||
$compare_differences[] = $compare_difference;
|
||||
}
|
||||
|
||||
foreach ($nominal['tables'] as $database_table) {
|
||||
|
||||
$found_table = array();
|
||||
foreach ($actual['tables'] as $compare_table) {
|
||||
if ($database_table['name'] == $compare_table['name']) {
|
||||
$found_table = $compare_table;
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($compare_table);
|
||||
|
||||
if ($found_table) {
|
||||
|
||||
// Check type table vs view
|
||||
|
||||
if ($database_table['type'] != $found_table['type']) {
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Table type";
|
||||
$compare_difference['table'] = $database_table['name'];
|
||||
$compare_difference[$nominal_name] = $database_table['type'];
|
||||
$compare_difference[$actual_name] = $found_table['type'];
|
||||
$compare_differences[] = $compare_difference;
|
||||
}
|
||||
|
||||
// Only BASE TABLE supported now
|
||||
if ($found_table['type'] != 'BASE TABLE') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check columns
|
||||
$compare_table_columns = array_column($found_table['columns'],'Field');
|
||||
foreach ($database_table['columns'] as $column) {
|
||||
|
||||
$column_name_to_find = $column['Field'];
|
||||
$column_key = array_search($column_name_to_find,$compare_table_columns,true);
|
||||
if ($column_key !== false) {
|
||||
|
||||
// Compare the properties of the columns
|
||||
if ($check_column_definitions) {
|
||||
$found_column = $found_table['columns'][$column_key];
|
||||
foreach ($column as $key => $value) {
|
||||
if ($found_column[$key] != $value) {
|
||||
|
||||
if ($key != 'Key') { // Keys will be handled separately
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Column definition";
|
||||
$compare_difference['table'] = $database_table['name'];
|
||||
$compare_difference['column'] = $column['Field'];
|
||||
$compare_difference['property'] = $key;
|
||||
$compare_difference[$nominal_name] = $value;
|
||||
$compare_difference[$actual_name] = $found_column[$key];
|
||||
$compare_differences[] = $compare_difference;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($value);
|
||||
} // $check_column_definitions
|
||||
} else {
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Column existance";
|
||||
$compare_difference['table'] = $database_table['name'];
|
||||
$compare_difference[$nominal_name] = $column['Field'];
|
||||
$compare_differences[] = $compare_difference;
|
||||
}
|
||||
}
|
||||
unset($column);
|
||||
|
||||
|
||||
// Check keys
|
||||
$compare_table_sql_indexs = array_column($found_table['keys'],'Key_name');
|
||||
foreach ($database_table['keys'] as $sql_index) {
|
||||
|
||||
$sql_index_name_to_find = $sql_index['Key_name'];
|
||||
$sql_index_key = array_search($sql_index_name_to_find,$compare_table_sql_indexs,true);
|
||||
if ($sql_index_key !== false) {
|
||||
|
||||
// Compare the properties of the sql_indexs
|
||||
if ($check_column_definitions) {
|
||||
$found_sql_index = $found_table['keys'][$sql_index_key];
|
||||
foreach ($sql_index as $key => $value) {
|
||||
if ($found_sql_index[$key] != $value) {
|
||||
|
||||
// if ($key != 'permissions') {
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Key definition";
|
||||
$compare_difference['table'] = $database_table['name'];
|
||||
$compare_difference['key'] = $sql_index['Key_name'];
|
||||
$compare_difference['property'] = $key;
|
||||
$compare_difference[$nominal_name] = implode(',',$value);
|
||||
$compare_difference[$actual_name] = implode(',',$found_sql_index[$key]);
|
||||
$compare_differences[] = $compare_difference;
|
||||
// }
|
||||
}
|
||||
}
|
||||
unset($value);
|
||||
} // $check_sql_index_definitions
|
||||
} else {
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Key existance";
|
||||
$compare_difference['table'] = $database_table['name'];
|
||||
$compare_difference[$nominal_name] = $sql_index['Key_name'];
|
||||
$compare_differences[] = $compare_difference;
|
||||
}
|
||||
}
|
||||
unset($sql_index);
|
||||
|
||||
|
||||
} else {
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Table existance";
|
||||
$compare_difference[$nominal_name] = $database_table['name'];
|
||||
$compare_differences[] = $compare_difference;
|
||||
}
|
||||
}
|
||||
unset($database_table);
|
||||
|
||||
return($compare_differences);
|
||||
}
|
||||
|
||||
|
||||
// Generate SQL to create or modify column
|
||||
function column_sql_definition(string $table_name, array $column, array $reserved_words_without_quote) : string {
|
||||
|
||||
foreach($column as $key => &$value) {
|
||||
$value = (string) $value;
|
||||
$value = column_sql_create_property_definition($key,$value,$reserved_words_without_quote);
|
||||
}
|
||||
|
||||
// Default handling here
|
||||
if ($column['Default'] == " DEFAULT ''") {
|
||||
$column['Default'] = "";
|
||||
}
|
||||
|
||||
$sql =
|
||||
$column['Type'].
|
||||
$column['Null'].
|
||||
$column['Default'].
|
||||
$column['Extra'].
|
||||
$column['Collation'];
|
||||
|
||||
return($sql);
|
||||
}
|
||||
|
||||
// Generate SQL to modify a single column property
|
||||
function column_sql_create_property_definition(string $property, string $property_value, array $reserved_words_without_quote) : string {
|
||||
|
||||
switch ($property) {
|
||||
case 'Type':
|
||||
break;
|
||||
case 'Null':
|
||||
if ($property_value == "NO") {
|
||||
$property_value = " NOT NULL"; // Idiotic...
|
||||
}
|
||||
if ($property_value == "YES") {
|
||||
$property_value = " NULL"; // Also Idiotic...
|
||||
}
|
||||
break;
|
||||
case 'Default':
|
||||
// Check for MYSQL function call as default
|
||||
|
||||
if (in_array(strtolower($property_value),$reserved_words_without_quote)) {
|
||||
$quote = "";
|
||||
} else {
|
||||
// Remove quotes if there are
|
||||
$property_value = trim($property_value,"'");
|
||||
$quote = "'";
|
||||
}
|
||||
$property_value = " DEFAULT $quote".$property_value."$quote";
|
||||
break;
|
||||
case 'Extra':
|
||||
if ($property_value != '') {
|
||||
$property_value = " ".$property_value;
|
||||
}
|
||||
break;
|
||||
case 'Collation':
|
||||
if ($property_value != '') {
|
||||
$property_value = " COLLATE ".$property_value;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$property_value = "";
|
||||
break;
|
||||
}
|
||||
|
||||
return($property_value);
|
||||
}
|
||||
|
||||
// Replaces different variants of the same function to allow comparison
|
||||
function sql_replace_reserved_functions(array &$column, array $replacers) {
|
||||
|
||||
$result = strtolower($column['Default']);
|
||||
foreach ($replacers as $replace) {
|
||||
if ($result == $replace[0]) {
|
||||
$result = $replace[1];
|
||||
}
|
||||
}
|
||||
$column['Default'] = $result;
|
||||
|
||||
$result = strtolower($column['Extra']);
|
||||
foreach ($replacers as $replace) {
|
||||
if ($result == $replace[0]) {
|
||||
$result = $replace[1];
|
||||
}
|
||||
}
|
||||
$column['Extra'] = $result;
|
||||
}
|
||||
|
||||
// Is it a text type? -> Use quotes then
|
||||
function mysql_put_text_type_in_quotes(string $checktype, string $value) : string {
|
||||
$types = array('char','varchar','tinytext','text','mediumtext','longtext');
|
||||
|
||||
foreach($types as $type) {
|
||||
if (stripos($checktype, $type) !== false) {
|
||||
return("'".$value."'");
|
||||
}
|
||||
}
|
||||
return($value);
|
||||
}
|
||||
|
||||
function info() {
|
||||
echo("OpenXE database compare\n");
|
||||
echo("Copyright 2022 (c) OpenXE project\n");
|
||||
|
114725
tools/database_compare/db_schema.json.mb3
Normal file
114725
tools/database_compare/db_schema.json.mb3
Normal file
File diff suppressed because it is too large
Load Diff
654
tools/database_compare/mustal_mysql_upgrade_tool.php
Normal file
654
tools/database_compare/mustal_mysql_upgrade_tool.php
Normal file
@ -0,0 +1,654 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
MUSTAL Mysql Upgrade Schema Tool by Alex Ledis
|
||||
Helper to compare database structures from JSON files vs. database and upgrade database
|
||||
Copyright (c) 2022 Alex Ledis
|
||||
Licensed under AGPL v3
|
||||
|
||||
Version 1.0
|
||||
|
||||
function mustal_load_tables_from_db(string $host, string $schema, string $user, string $passwd, $replacers) : array
|
||||
Load structure from db connection to an array.
|
||||
|
||||
function mustal_save_tables_to_json(array $db_def, string $path, string $tables_file_name, bool $force) : int
|
||||
Save structure from array to a JSON file.
|
||||
|
||||
function mustal_load_tables_from_json(string $path, string $tables_file_name) : array
|
||||
Load structure from JSON file into array.
|
||||
|
||||
function mustal_compare_table_array(array $nominal, string $nominal_name, array $actual, string $actual_name, bool $check_column_definitions) : array
|
||||
Compare two database structures
|
||||
Returns a structured array containing information on all the differences.
|
||||
|
||||
function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$upgrade_sql) : int
|
||||
Generate the SQL needed to upgrade the database to match the definition, based on a comparison.
|
||||
|
||||
Data structure in Array and JSON
|
||||
{
|
||||
"host": "hostname",
|
||||
"database": "schemaname",
|
||||
"user": "username",
|
||||
"tables": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "",
|
||||
"columns": [
|
||||
{
|
||||
"Field": "",
|
||||
"Type": "",
|
||||
"Collation": "",
|
||||
"Null": "",
|
||||
"Key": "",
|
||||
"Default": "",
|
||||
"Extra": "",
|
||||
"Privileges": "",
|
||||
"Comment": ""
|
||||
}
|
||||
],
|
||||
"keys": [
|
||||
{
|
||||
"Key_name": "",
|
||||
"columns": [
|
||||
"",
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
// These default values will not be in quotes, converted to lowercase and be replaced by the second entry
|
||||
$mustal_replacers = [
|
||||
['current_timestamp','current_timestamp()'],
|
||||
['on update current_timestamp','on update current_timestamp()']
|
||||
];
|
||||
|
||||
// Load all db_def from a DB connection into a db_def array
|
||||
function mustal_load_tables_from_db(string $host, string $schema, string $user, string $passwd, $replacers) : array {
|
||||
|
||||
// First get the contents of the database table structure
|
||||
$mysqli = mysqli_connect($host, $user, $passwd, $schema);
|
||||
|
||||
/* Check if the connection succeeded */
|
||||
if (!$mysqli) {
|
||||
return(array());
|
||||
}
|
||||
|
||||
// Get db_def and views
|
||||
|
||||
$sql = "SHOW FULL tables";
|
||||
$query_result = mysqli_query($mysqli, $sql);
|
||||
if (!$query_result) {
|
||||
return(array());
|
||||
}
|
||||
while ($row = mysqli_fetch_assoc($query_result)) {
|
||||
$table = array();
|
||||
$table['name'] = $row['Tables_in_'.$schema];
|
||||
$table['type'] = $row['Table_type'];
|
||||
$tables[] = $table; // Add table to list of tables
|
||||
}
|
||||
|
||||
// Get and add columns of the table
|
||||
foreach ($tables as &$table) {
|
||||
$sql = "SHOW FULL COLUMNS FROM ".$table['name'];
|
||||
$query_result = mysqli_query($mysqli, $sql);
|
||||
|
||||
if (!$query_result) {
|
||||
return(array());
|
||||
}
|
||||
|
||||
$columns = array();
|
||||
while ($column = mysqli_fetch_assoc($query_result)) {
|
||||
// Do some harmonization
|
||||
|
||||
if ($column['Default'] !== NULL) {
|
||||
mustal_sql_replace_reserved_functions($column,$replacers);
|
||||
$column['Default'] = mustal_mysql_put_text_type_in_quotes($column['Type'],$column['Default']);
|
||||
}
|
||||
|
||||
$columns[] = $column; // Add column to list of columns
|
||||
}
|
||||
$table['columns'] = $columns;
|
||||
|
||||
$sql = "SHOW KEYS FROM ".$table['name'];
|
||||
$query_result = mysqli_query($mysqli, $sql);
|
||||
if (!$query_result) {
|
||||
return(array());
|
||||
}
|
||||
$keys = array();
|
||||
while ($key = mysqli_fetch_assoc($query_result)) {
|
||||
$keys[] = $key; // Add key to list of keys
|
||||
}
|
||||
// Compose comparable format for keys
|
||||
$composed_keys = array();
|
||||
foreach ($keys as $key) {
|
||||
|
||||
// Check if this key exists already
|
||||
|
||||
$key_pos = array_search($key['Key_name'],array_column($composed_keys,'Key_name'));
|
||||
|
||||
if ($key_pos == false) {
|
||||
// New key
|
||||
$composed_key = array();
|
||||
$composed_key['Key_name'] = $key['Key_name'];
|
||||
$composed_key['Index_type'] = $key['Index_type'];
|
||||
$composed_key['columns'][] = $key['Column_name'];
|
||||
$composed_keys[] = $composed_key;
|
||||
} else {
|
||||
// Given key, add column
|
||||
$composed_keys[$key_pos]['columns'][] .= $key['Column_name'];
|
||||
}
|
||||
}
|
||||
unset($key);
|
||||
$table['keys'] = $composed_keys;
|
||||
unset($composed_keys);
|
||||
}
|
||||
unset($table);
|
||||
|
||||
$result = array();
|
||||
$result['host'] = $host;
|
||||
$result['database'] = $schema;
|
||||
$result['user'] = $user;
|
||||
$result['tables'] = $tables;
|
||||
return($result);
|
||||
}
|
||||
|
||||
function mustal_save_tables_to_json(array $db_def, string $path, string $tables_file_name, bool $force) : int {
|
||||
|
||||
// Prepare db_def file
|
||||
if (!is_dir($path)) {
|
||||
mkdir($path);
|
||||
}
|
||||
if (!$force && file_exists($path."/".$tables_file_name)) {
|
||||
return(2);
|
||||
}
|
||||
|
||||
$tables_file = fopen($path."/".$tables_file_name, "w");
|
||||
if (empty($tables_file)) {
|
||||
return(2);
|
||||
}
|
||||
|
||||
fwrite($tables_file, json_encode($db_def,JSON_PRETTY_PRINT));
|
||||
|
||||
fclose($tables_file);
|
||||
return(0);
|
||||
}
|
||||
|
||||
// Load all db_def from JSON file
|
||||
function mustal_load_tables_from_json(string $path, string $tables_file_name) : array {
|
||||
|
||||
$db_def = array();
|
||||
|
||||
$contents = file_get_contents($path."/".$tables_file_name);
|
||||
|
||||
if (!$contents) {
|
||||
return(array());
|
||||
}
|
||||
|
||||
$db_def = json_decode($contents, true);
|
||||
|
||||
if (!$db_def) {
|
||||
return(array());
|
||||
}
|
||||
|
||||
return($db_def);
|
||||
}
|
||||
|
||||
// Compare two definitions
|
||||
// Report based on the first array
|
||||
// Return Array
|
||||
function mustal_compare_table_array(array $nominal, string $nominal_name, array $actual, string $actual_name, bool $check_column_definitions) : array {
|
||||
|
||||
$compare_differences = array();
|
||||
|
||||
if (count($nominal['tables']) != count($actual['tables'])) {
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Table count";
|
||||
$compare_difference[$nominal_name] = count($nominal['tables']);
|
||||
$compare_difference[$actual_name] = count($actual['tables']);
|
||||
$compare_differences[] = $compare_difference;
|
||||
}
|
||||
|
||||
foreach ($nominal['tables'] as $database_table) {
|
||||
|
||||
$found_table = array();
|
||||
foreach ($actual['tables'] as $compare_table) {
|
||||
if ($database_table['name'] == $compare_table['name']) {
|
||||
$found_table = $compare_table;
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($compare_table);
|
||||
|
||||
if ($found_table) {
|
||||
|
||||
// Check type table vs view
|
||||
|
||||
if ($database_table['type'] != $found_table['type']) {
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Table type";
|
||||
$compare_difference['table'] = $database_table['name'];
|
||||
$compare_difference[$nominal_name] = $database_table['type'];
|
||||
$compare_difference[$actual_name] = $found_table['type'];
|
||||
$compare_differences[] = $compare_difference;
|
||||
}
|
||||
|
||||
// Only BASE TABLE supported now
|
||||
if ($found_table['type'] != 'BASE TABLE') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check columns
|
||||
$compare_table_columns = array_column($found_table['columns'],'Field');
|
||||
foreach ($database_table['columns'] as $column) {
|
||||
|
||||
$column_name_to_find = $column['Field'];
|
||||
$column_key = array_search($column_name_to_find,$compare_table_columns,true);
|
||||
if ($column_key !== false) {
|
||||
|
||||
// Compare the properties of the columns
|
||||
if ($check_column_definitions) {
|
||||
$found_column = $found_table['columns'][$column_key];
|
||||
foreach ($column as $key => $value) {
|
||||
if ($found_column[$key] != $value) {
|
||||
|
||||
if ($key != 'Key') { // Keys will be handled separately
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Column definition";
|
||||
$compare_difference['table'] = $database_table['name'];
|
||||
$compare_difference['column'] = $column['Field'];
|
||||
$compare_difference['property'] = $key;
|
||||
$compare_difference[$nominal_name] = $value;
|
||||
$compare_difference[$actual_name] = $found_column[$key];
|
||||
$compare_differences[] = $compare_difference;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($value);
|
||||
} // $check_column_definitions
|
||||
} else {
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Column existence";
|
||||
$compare_difference['table'] = $database_table['name'];
|
||||
$compare_difference[$nominal_name] = $column['Field'];
|
||||
$compare_differences[] = $compare_difference;
|
||||
}
|
||||
}
|
||||
unset($column);
|
||||
|
||||
|
||||
// Check keys
|
||||
$compare_table_sql_indexs = array_column($found_table['keys'],'Key_name');
|
||||
foreach ($database_table['keys'] as $sql_index) {
|
||||
|
||||
$sql_index_name_to_find = $sql_index['Key_name'];
|
||||
$sql_index_key = array_search($sql_index_name_to_find,$compare_table_sql_indexs,true);
|
||||
if ($sql_index_key !== false) {
|
||||
|
||||
// Compare the properties of the sql_indexs
|
||||
if ($check_column_definitions) {
|
||||
$found_sql_index = $found_table['keys'][$sql_index_key];
|
||||
foreach ($sql_index as $key => $value) {
|
||||
if ($found_sql_index[$key] != $value) {
|
||||
|
||||
// if ($key != 'permissions') {
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Key definition";
|
||||
$compare_difference['table'] = $database_table['name'];
|
||||
$compare_difference['key'] = $sql_index['Key_name'];
|
||||
$compare_difference['property'] = $key;
|
||||
$compare_difference[$nominal_name] = implode(',',$value);
|
||||
$compare_difference[$actual_name] = implode(',',$found_sql_index[$key]);
|
||||
$compare_differences[] = $compare_difference;
|
||||
// }
|
||||
}
|
||||
}
|
||||
unset($value);
|
||||
} // $check_sql_index_definitions
|
||||
} else {
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Key existence";
|
||||
$compare_difference['table'] = $database_table['name'];
|
||||
$compare_difference[$nominal_name] = $sql_index['Key_name'];
|
||||
$compare_differences[] = $compare_difference;
|
||||
}
|
||||
}
|
||||
unset($sql_index);
|
||||
|
||||
|
||||
} else {
|
||||
$compare_difference = array();
|
||||
$compare_difference['type'] = "Table existence";
|
||||
$compare_difference[$nominal_name] = $database_table['name'];
|
||||
$compare_differences[] = $compare_difference;
|
||||
}
|
||||
}
|
||||
unset($database_table);
|
||||
|
||||
return($compare_differences);
|
||||
}
|
||||
|
||||
|
||||
// Generate SQL to create or modify column
|
||||
function mustal_column_sql_definition(string $table_name, array $column, array $reserved_words_without_quote) : string {
|
||||
|
||||
foreach($column as $key => &$value) {
|
||||
$value = (string) $value;
|
||||
$value = mustal_column_sql_create_property_definition($key,$value,$reserved_words_without_quote);
|
||||
}
|
||||
|
||||
// Default handling here
|
||||
if ($column['Default'] == " DEFAULT ''") {
|
||||
$column['Default'] = "";
|
||||
}
|
||||
|
||||
$sql =
|
||||
$column['Type'].
|
||||
$column['Null'].
|
||||
$column['Default'].
|
||||
$column['Extra'].
|
||||
$column['Collation'];
|
||||
|
||||
return($sql);
|
||||
}
|
||||
|
||||
// Generate SQL to modify a single column property
|
||||
function mustal_column_sql_create_property_definition(string $property, string $property_value, array $reserved_words_without_quote) : string {
|
||||
|
||||
switch ($property) {
|
||||
case 'Type':
|
||||
break;
|
||||
case 'Null':
|
||||
if ($property_value == "NO") {
|
||||
$property_value = " NOT NULL"; // Idiotic...
|
||||
}
|
||||
if ($property_value == "YES") {
|
||||
$property_value = " NULL"; // Also Idiotic...
|
||||
}
|
||||
break;
|
||||
case 'Default':
|
||||
// Check for MYSQL function mustal_call as default
|
||||
|
||||
if (in_array(strtolower($property_value),$reserved_words_without_quote)) {
|
||||
$quote = "";
|
||||
} else {
|
||||
// Remove quotes if there are
|
||||
$property_value = trim($property_value,"'");
|
||||
$quote = "'";
|
||||
}
|
||||
$property_value = " DEFAULT $quote".$property_value."$quote";
|
||||
break;
|
||||
case 'Extra':
|
||||
if ($property_value != '') {
|
||||
$property_value = " ".$property_value;
|
||||
}
|
||||
break;
|
||||
case 'Collation':
|
||||
if ($property_value != '') {
|
||||
$property_value = " COLLATE ".$property_value;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$property_value = "";
|
||||
break;
|
||||
}
|
||||
|
||||
return($property_value);
|
||||
}
|
||||
|
||||
// Replaces different variants of the same function mustal_to allow comparison
|
||||
function mustal_sql_replace_reserved_functions(array &$column, array $replacers) {
|
||||
|
||||
$result = strtolower($column['Default']);
|
||||
foreach ($replacers as $replace) {
|
||||
if ($result == $replace[0]) {
|
||||
$result = $replace[1];
|
||||
}
|
||||
}
|
||||
$column['Default'] = $result;
|
||||
|
||||
$result = strtolower($column['Extra']);
|
||||
foreach ($replacers as $replace) {
|
||||
if ($result == $replace[0]) {
|
||||
$result = $replace[1];
|
||||
}
|
||||
}
|
||||
$column['Extra'] = $result;
|
||||
}
|
||||
|
||||
// Is it a text type? -> Use quotes then
|
||||
function mustal_mysql_put_text_type_in_quotes(string $checktype, string $value) : string {
|
||||
$types = array('char','varchar','tinytext','text','mediumtext','longtext');
|
||||
|
||||
foreach($types as $type) {
|
||||
if (stripos($checktype, $type) !== false) {
|
||||
return("'".$value."'");
|
||||
}
|
||||
}
|
||||
return($value);
|
||||
}
|
||||
|
||||
function mustal_implode_with_quote(string $quote, string $delimiter, array $array_to_implode) : string {
|
||||
return($quote.implode($quote.$delimiter.$quote, $array_to_implode).$quote);
|
||||
}
|
||||
|
||||
|
||||
// Calculate the sql neccessary to update the database
|
||||
// Error codes:
|
||||
// 0 ok
|
||||
// 1 Upgrade type of table not supported
|
||||
// 2 Error on table upgrade
|
||||
// 3 Error on column existence upgrade
|
||||
// 4 Error on column existence upgrade
|
||||
// 5 Error on column definition upgrade
|
||||
// 6 Error on column definition upgrade
|
||||
// 7 Error on key existence upgrade
|
||||
// 8 Error on key existence upgrade
|
||||
// 9 Error on key definition upgrade
|
||||
// 10 Error on key definition upgrade
|
||||
// 11 Table type upgrade not supported
|
||||
// 12 Upgrade type not supported
|
||||
function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$upgrade_sql, array $replacers) : int {
|
||||
$upgrade_sql = array();
|
||||
|
||||
$compare_differences = mustal_compare_table_array($compare_def,"in JSON",$db_def,"in DB",true);
|
||||
if (count($compare_differences) > 0) {
|
||||
$upgrade_sql[] = ("SET SQL_MODE='ALLOW_INVALID_DATES';");
|
||||
}
|
||||
|
||||
foreach ($compare_differences as $compare_difference) {
|
||||
switch ($compare_difference['type']) {
|
||||
case 'Table existence':
|
||||
|
||||
// Get table definition from JSON
|
||||
|
||||
$table_name = $compare_difference['in JSON'];
|
||||
|
||||
$table_key = array_search($table_name,array_column($compare_def['tables'],'name'));
|
||||
|
||||
if ($table_key !== false) {
|
||||
$table = $compare_def['tables'][$table_key];
|
||||
|
||||
switch ($table['type']) {
|
||||
case 'BASE TABLE':
|
||||
|
||||
// Create table in DB
|
||||
$sql = "";
|
||||
$sql = "CREATE TABLE `".$table['name']."` (";
|
||||
$comma = "";
|
||||
|
||||
foreach ($table['columns'] as $column) {
|
||||
$sql .= $comma."`".$column['Field']."` ".mustal_column_sql_definition($table_name, $column,array_column($replacers,1));
|
||||
$comma = ", ";
|
||||
}
|
||||
|
||||
// Add keys
|
||||
$comma = ", ";
|
||||
foreach ($table['keys'] as $key) {
|
||||
if ($key['Key_name'] == 'PRIMARY') {
|
||||
$keystring = "PRIMARY KEY ";
|
||||
} else {
|
||||
|
||||
if(array_key_exists('Index_type', $key)) {
|
||||
$index_type = $key['Index_type'];
|
||||
} else {
|
||||
$index_type = "";
|
||||
}
|
||||
|
||||
$keystring = $index_type." KEY `".$key['Key_name']."` ";
|
||||
}
|
||||
$sql .= $comma.$keystring."(`".implode("`,`",$key['columns'])."`) ";
|
||||
}
|
||||
$sql .= ")";
|
||||
$upgrade_sql[] = $sql;
|
||||
break;
|
||||
default:
|
||||
//echo("Upgrade type '".$table['type']."' on table '".$table['name']."' not supported.\n");
|
||||
return(1);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// echo("Error table_key while creating upgrade for table existence `$table_name`.\n");
|
||||
return(2);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'Column existence':
|
||||
$table_name = $compare_difference['table'];
|
||||
$column_name = $compare_difference['in JSON'];
|
||||
$table_key = array_search($table_name,array_column($compare_def['tables'],'name'));
|
||||
if ($table_key !== false) {
|
||||
$table = $compare_def['tables'][$table_key];
|
||||
$columns = $table['columns'];
|
||||
$column_key = array_search($column_name,array_column($columns,'Field'));
|
||||
if ($column_key !== false) {
|
||||
$column = $table['columns'][$column_key];
|
||||
$sql = "ALTER TABLE `$table_name` ADD COLUMN `".$column_name."` ";
|
||||
$sql .= mustal_column_sql_definition($table_name, $column, array_column($replacers,1));
|
||||
$sql .= ";";
|
||||
$upgrade_sql[] = $sql;
|
||||
}
|
||||
else {
|
||||
// echo("Error column_key while creating column '$column_name' in table '".$table['name']."'\n");
|
||||
return(3);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// echo("Error table_key while creating upgrade for column existence '$column_name' in table '$table_name'.\n");
|
||||
return(4);
|
||||
}
|
||||
// Add Column in DB
|
||||
break;
|
||||
case 'Column definition':
|
||||
$table_name = $compare_difference['table'];
|
||||
$column_name = $compare_difference['column'];
|
||||
$table_key = array_search($table_name,array_column($compare_def['tables'],'name'));
|
||||
if ($table_key !== false) {
|
||||
$table = $compare_def['tables'][$table_key];
|
||||
$columns = $table['columns'];
|
||||
|
||||
$column_names = array_column($columns,'Field');
|
||||
$column_key = array_search($column_name,$column_names);
|
||||
|
||||
if ($column_key !== false) {
|
||||
$column = $table['columns'][$column_key];
|
||||
|
||||
$sql = "ALTER TABLE `$table_name` MODIFY COLUMN `".$column_name."` ";
|
||||
$sql .= mustal_column_sql_definition($table_name, $column,array_column($replacers,1));
|
||||
$sql .= ";";
|
||||
$upgrade_sql[] = $sql;
|
||||
}
|
||||
else {
|
||||
//echo("Error column_key while modifying column '$column_name' in table '".$table['name']."'\n");
|
||||
return(5);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// echo("Error table_key while modifying column '$column_name' in table '$table_name'.\n");
|
||||
return(6);
|
||||
}
|
||||
// Modify Column in DB
|
||||
break;
|
||||
case 'Key existence':
|
||||
|
||||
$table_name = $compare_difference['table'];
|
||||
$key_name = $compare_difference['in JSON'];
|
||||
$table_key = array_search($table_name,array_column($compare_def['tables'],'name'));
|
||||
if ($table_key !== false) {
|
||||
$table = $compare_def['tables'][$table_key];
|
||||
$keys = $table['keys'];
|
||||
|
||||
$key_names = array_column($keys,'Key_name');
|
||||
$key_key = array_search($key_name,$key_names);
|
||||
|
||||
if ($key_key !== false) {
|
||||
$key = $table['keys'][$key_key];
|
||||
|
||||
$sql = "ALTER TABLE `$table_name` ADD KEY `".$key_name."` ";
|
||||
$sql .= "(`".implode("`,`",$key['columns'])."`)";
|
||||
$sql .= ";";
|
||||
$upgrade_sql[] = $sql;
|
||||
}
|
||||
else {
|
||||
//echo("Error key_key while adding key '$key_name' in table '".$table['name']."'\n");
|
||||
return(7);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//echo("Error table_key while adding key '$key_name' in table '$table_name'.\n");
|
||||
return(8);
|
||||
}
|
||||
break;
|
||||
case "Key definition":
|
||||
$table_name = $compare_difference['table'];
|
||||
$key_name = $compare_difference['key'];
|
||||
$table_key = array_search($table_name,array_column($compare_def['tables'],'name'));
|
||||
if ($table_key !== false) {
|
||||
$table = $compare_def['tables'][$table_key];
|
||||
$keys = $table['keys'];
|
||||
|
||||
$key_names = array_column($keys,'Key_name');
|
||||
$key_key = array_search($key_name,$key_names);
|
||||
|
||||
if ($key_key !== false) {
|
||||
$key = $table['keys'][$key_key];
|
||||
|
||||
$sql = "ALTER TABLE `$table_name` DROP KEY `".$key_name."`;";
|
||||
$upgrade_sql[] = $sql;
|
||||
|
||||
$sql = "ALTER TABLE `$table_name` ADD KEY `".$key_name."` ";
|
||||
$sql .= "(`".implode("`,`",$key['columns'])."`)";
|
||||
$sql .= ";";
|
||||
$upgrade_sql[] = $sql;
|
||||
}
|
||||
else {
|
||||
//echo("Error key_key while changing key '$key_name' in table '".$table['name']."'\n");
|
||||
return(9);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// echo("Error table_key while changing key '$key_name' in table '$table_name'.\n");
|
||||
return(10);
|
||||
}
|
||||
break;
|
||||
case 'Table count':
|
||||
// Nothing to do
|
||||
break;
|
||||
case 'Table type':
|
||||
// echo("Upgrade type '".$compare_difference['type']."' on table '".$compare_difference['table']."' not supported.\n");
|
||||
return(11);
|
||||
break;
|
||||
default:
|
||||
// echo("Upgrade type '".$compare_difference['type']."' not supported.\n");
|
||||
return(12);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$upgrade_sql = array_unique($upgrade_sql);
|
||||
return(0);
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
<?php
|
||||
header('Location: ./www/update.php?rand=' . sha1(mt_rand()));
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
include("upgradesystemclient2.php");
|
||||
include("upgradedbonly.php");
|
16
upgrade/UPGRADE.md
Normal file
16
upgrade/UPGRADE.md
Normal file
@ -0,0 +1,16 @@
|
||||
Upgrade the OpenXE system.
|
||||
|
||||
NOTE:
|
||||
The upgrade system is for use in LINUX only and needs to have git installed.
|
||||
|
||||
1. get files from git
|
||||
2. run database upgrade
|
||||
|
||||
Files in this directory:
|
||||
UPGRADE.md -> This file
|
||||
upgrade.php -> The upgrade program
|
||||
|
||||
Files in the data subdirectory:
|
||||
.in_progress.flag -> if this file exists, an upgrade is in progress, system will be locked
|
||||
db_schema.json -> Contains the nominal database structure
|
||||
remote.json -> Contains the git remote & branch which should be used for upgrade
|
114725
upgrade/data/db_schema.json
Normal file
114725
upgrade/data/db_schema.json
Normal file
File diff suppressed because it is too large
Load Diff
4
upgrade/data/remote.json
Normal file
4
upgrade/data/remote.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"host": "https://github.com/openxe-org/openxe.git",
|
||||
"branch": "master"
|
||||
}
|
241
upgrade/upgrade.php
Normal file
241
upgrade/upgrade.php
Normal file
@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Upgrader using git for file upgrade and mustal to update the database definition
|
||||
*
|
||||
* Copyright (c) 2022 OpenXE project
|
||||
*
|
||||
*/
|
||||
|
||||
class DatabaseConnectionInfo {
|
||||
function __construct() {
|
||||
require('../conf/user.inc.php');
|
||||
}
|
||||
}
|
||||
|
||||
$dbci = new DatabaseConnectionInfo;
|
||||
|
||||
$host = $dbci->WFdbhost;
|
||||
$user = $dbci->WFdbuser;
|
||||
$passwd = $dbci->WFdbpass;
|
||||
$schema = $dbci->WFdbname;
|
||||
|
||||
require('../tools/database_compare/mustal_mysql_upgrade_tool.php');
|
||||
|
||||
$lockfile_name = "data/.in_progress.flag";
|
||||
$remote_file_name = "data/remote.json";
|
||||
$datafolder = "data";
|
||||
$schema_file_name = "db_schema.json";
|
||||
|
||||
function git(string $command, &$output, bool $verbose, string $error_text) : int {
|
||||
$output = array();
|
||||
if ($verbose) {
|
||||
echo("git ".$command."\n");
|
||||
}
|
||||
exec("git ".$command,$output,$retval);
|
||||
if (!empty($output)) {
|
||||
if ($verbose || $retval != 0) {
|
||||
echo_output($output);
|
||||
}
|
||||
}
|
||||
return($retval);
|
||||
}
|
||||
|
||||
function echo_output(array $output) {
|
||||
echo("\n".implode("\n",$output)."\n");
|
||||
}
|
||||
|
||||
function abort(string $message) {
|
||||
echo($message."\n");
|
||||
echo("--------------- Aborted! ---------------\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// -------------------------------- START
|
||||
|
||||
if (in_array('-v', $argv)) {
|
||||
$verbose = true;
|
||||
} else {
|
||||
$verbose = false;
|
||||
}
|
||||
|
||||
if (in_array('-f', $argv)) {
|
||||
$force = true;
|
||||
} else {
|
||||
$force = false;
|
||||
}
|
||||
|
||||
echo("--------------- OpenXE upgrade ---------------\n");
|
||||
|
||||
if (basename(getcwd()) != 'upgrade') {
|
||||
abort("Must be executed from 'upgrade' directory.");
|
||||
}
|
||||
|
||||
$remote_info_contents = file_get_contents($remote_file_name);
|
||||
if (!$remote_info_contents) {
|
||||
abort("Unable to load $remote_file_name");
|
||||
}
|
||||
$remote_info = json_decode($remote_info_contents, true);
|
||||
|
||||
// Get changed files on system -> Should be empty
|
||||
$output = array();
|
||||
$retval = git("ls-files -m ..", $output,$verbose,"Git not initialized.");
|
||||
|
||||
// Not a git repository -> Create it and then go ahead
|
||||
if ($retval == 128) {
|
||||
echo("Setting up git...");
|
||||
$retval = git("init ..", $output,$verbose,"Error while initializing git!");
|
||||
if ($retval != 0) {
|
||||
abort("");
|
||||
}
|
||||
$retval = git("add ../.", $output,$verbose,"Error while initializing git!");
|
||||
if ($retval != 0) {
|
||||
abort("");
|
||||
}
|
||||
$retval = git("fetch ".$remote_info['host']." ".$remote_info['branch'], $output,$verbose,"Error while initializing git!");
|
||||
if ($retval != 0) {
|
||||
abort("");
|
||||
}
|
||||
$retval = git("checkout FETCH_HEAD -f", $output,$verbose,"Error while initializing git!");
|
||||
if ($retval != 0) {
|
||||
abort("");
|
||||
}
|
||||
}
|
||||
|
||||
if ($retval != 0) {
|
||||
abort("Error while executing git!");
|
||||
}
|
||||
|
||||
if (!empty($output)) {
|
||||
echo("There are modified files:");
|
||||
echo_output($output);
|
||||
if (!$force) {
|
||||
abort("Clear modified files or use -f");
|
||||
}
|
||||
}
|
||||
|
||||
echo("--------------- Locking system ---------------\n");
|
||||
if (file_exists($lockfile_name)) {
|
||||
echo("System is already locked.\n");
|
||||
} else {
|
||||
file_put_contents($lockfile_name," ");
|
||||
}
|
||||
|
||||
echo("--------------- Pulling files... ---------------\n");
|
||||
|
||||
if ($force) {
|
||||
$retval = git("reset --hard",$output,$verbose,"Error while resetting modified files!");
|
||||
if ($retval != 0) {
|
||||
echo_output($output);
|
||||
abort("");
|
||||
}
|
||||
}
|
||||
|
||||
$retval = git("pull ".$remote_info['host']." ".$remote_info['branch'],$output,$verbose,"Error while pulling files!");
|
||||
if ($retval != 0) {
|
||||
echo_output($output);
|
||||
abort("");
|
||||
}
|
||||
|
||||
$retval = git("reset --hard",$output,$verbose,"Error while applying files!");
|
||||
if ($retval != 0) {
|
||||
echo_output($output);
|
||||
abort("");
|
||||
}
|
||||
|
||||
echo("--------------- Files upgrade completed ---------------\n");
|
||||
$retval = git("log -1 ",$output,$verbose,"Error while checking files!");
|
||||
if ($retval != 0) {
|
||||
echo_output($output);
|
||||
abort("");
|
||||
}
|
||||
echo_output($output);
|
||||
|
||||
echo("--------------- Loading from database '$schema@$host'... ---------------\n");
|
||||
$db_def = mustal_load_tables_from_db($host, $schema, $user, $passwd, $mustal_replacers);
|
||||
|
||||
if (empty($db_def)) {
|
||||
echo ("Could not load from $schema@$host\n");
|
||||
exit;
|
||||
}
|
||||
$compare_differences = array();
|
||||
|
||||
echo("--------------- Loading from JSON... ---------------\n");
|
||||
$compare_def = mustal_load_tables_from_json($datafolder, $schema_file_name);
|
||||
|
||||
if (empty($compare_def)) {
|
||||
echo ("Could not load from JSON $schema_file_name\n");
|
||||
exit;
|
||||
}
|
||||
echo("--------------- Comparing database '$schema@$host' vs. JSON '".$compare_def['database']."@".$compare_def['host']."' ---------------\n");
|
||||
$compare_differences = mustal_compare_table_array($compare_def,"in JSON",$db_def,"in DB",true);
|
||||
echo((empty($compare_differences)?0:count($compare_differences))." differences.\n");
|
||||
|
||||
echo("--------------- Calculating database upgrade for '$schema@$host'... ---------------\n");
|
||||
|
||||
$upgrade_sql = array();
|
||||
|
||||
$result = mustal_calculate_db_upgrade($compare_def, $db_def, $upgrade_sql, $mustal_replacers);
|
||||
|
||||
if ($result != 0) {
|
||||
echo("Error: $result\n");
|
||||
exit;
|
||||
}
|
||||
|
||||
echo(count($upgrade_sql)." upgrade statements\n");
|
||||
|
||||
echo("--------------- Executing database upgrade for '$schema@$host' database... ---------------\n");
|
||||
|
||||
// First get the contents of the database table structure
|
||||
$mysqli = mysqli_connect($host, $user, $passwd, $schema);
|
||||
|
||||
/* Check if the connection succeeded */
|
||||
if (!$mysqli) {
|
||||
echo ("Failed to connect!\n");
|
||||
} else {
|
||||
|
||||
$counter = 0;
|
||||
$error_counter = 0;
|
||||
$number_of_statements = count($upgrade_sql);
|
||||
|
||||
foreach ($upgrade_sql as $sql) {
|
||||
|
||||
$counter++;
|
||||
echo("\rUpgrade step $counter of $number_of_statements... ");
|
||||
|
||||
$query_result = mysqli_query($mysqli, $sql);
|
||||
if (!$query_result) {
|
||||
$error = " not ok: ". mysqli_error($mysqli);
|
||||
echo($error);
|
||||
echo("\n");
|
||||
file_put_contents("./errors.txt",date()." ".$error.$sql."\n",FILE_APPEND);
|
||||
$error_counter++;
|
||||
} else {
|
||||
echo("ok.\r");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
echo("$error_counter errors.\n");
|
||||
if ($error_counter > 0) {
|
||||
echo("See 'errors.txt'\n");
|
||||
}
|
||||
|
||||
echo("--------------- Checking database upgrade for '$schema@$host'... ---------------\n");
|
||||
$db_def = mustal_load_tables_from_db($host, $schema, $user, $passwd, $mustal_replacers);
|
||||
|
||||
echo("--------------- Comparing database '$schema@$host' vs. JSON '".$compare_def['database']."@".$compare_def['host']."' ---------------\n");
|
||||
$compare_differences = mustal_compare_table_array($compare_def,"in JSON",$db_def,"in DB",true);
|
||||
echo((empty($compare_differences)?0:count($compare_differences))." differences.\n");
|
||||
|
||||
}
|
||||
|
||||
echo("--------------- Unlocking system ---------------\n");
|
||||
unlink($lockfile_name);
|
||||
echo("--------------- Done! ---------------\n");
|
||||
exit(0);
|
||||
|
||||
|
||||
|
||||
|
@ -1,98 +0,0 @@
|
||||
<?php
|
||||
//include("wawision.inc.php");
|
||||
|
||||
use Xentral\Core\Installer\Installer;
|
||||
use Xentral\Core\Installer\InstallerCacheConfig;
|
||||
use Xentral\Core\Installer\InstallerCacheWriter;
|
||||
use Xentral\Core\Installer\ClassMapGenerator;
|
||||
use Xentral\Core\Installer\Psr4ClassNameResolver;
|
||||
use Xentral\Core\Installer\TableSchemaEnsurer;
|
||||
use Xentral\Components\Database\DatabaseConfig;
|
||||
|
||||
// Nur einfache Fehler melden
|
||||
error_reporting(E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_RECOVERABLE_ERROR | E_USER_ERROR | E_PARSE);
|
||||
if(file_exists(__DIR__.'/xentral_autoloader.php')){
|
||||
include_once (__DIR__.'/xentral_autoloader.php');
|
||||
}
|
||||
|
||||
include_once("conf/main.conf.php");
|
||||
include_once("phpwf/plugins/class.mysql.php");
|
||||
include_once("www/lib/class.erpapi.php");
|
||||
if(file_exists("www/lib/class.erpapi_custom.php")){
|
||||
include_once("www/lib/class.erpapi_custom.php");
|
||||
}
|
||||
/*
|
||||
class app_t
|
||||
{
|
||||
var $DB;
|
||||
var $user;
|
||||
var $Conf;
|
||||
}
|
||||
|
||||
$app = new app_t();
|
||||
*/
|
||||
|
||||
$config = new Config();
|
||||
|
||||
// Delete ServiceMap-CacheFile
|
||||
$installConf = new InstallerCacheConfig($config->WFuserdata . '/tmp/' . $config->WFdbname);
|
||||
$serviceCacheFile = $installConf->getServiceCacheFile();
|
||||
@unlink($serviceCacheFile);
|
||||
|
||||
$app = new ApplicationCore();
|
||||
|
||||
$DEBUG = 0;
|
||||
|
||||
$app->Conf = $config;
|
||||
$app->DB = new DB($app->Conf->WFdbhost,$app->Conf->WFdbname,$app->Conf->WFdbuser,$app->Conf->WFdbpass, $app, $app->Conf->WFdbport);
|
||||
if(class_exists('erpAPICustom'))
|
||||
{
|
||||
$erp = new erpAPICustom($app);
|
||||
}else{
|
||||
$erp = new erpAPI($app);
|
||||
}
|
||||
|
||||
echo "STARTE DB Upgrade\r\n";
|
||||
$erp->UpgradeDatabase();
|
||||
echo "ENDE DB Upgrade\r\n\r\n";
|
||||
|
||||
try {
|
||||
echo "STARTE Installer\r\n";
|
||||
|
||||
$resolver = new Psr4ClassNameResolver();
|
||||
$resolver->addNamespace('Xentral\\', __DIR__ . '/classes');
|
||||
$resolver->excludeFile(__DIR__ . '/classes/bootstrap.php');
|
||||
|
||||
$generator = new ClassMapGenerator($resolver, __DIR__);
|
||||
$installer = new Installer($generator, $resolver);
|
||||
$writer = new InstallerCacheWriter($installConf, $installer);
|
||||
|
||||
$dbConfig = new DatabaseConfig(
|
||||
$app->Conf->WFdbhost,
|
||||
$app->Conf->WFdbuser,
|
||||
$app->Conf->WFdbpass,
|
||||
$app->Conf->WFdbname,
|
||||
null,
|
||||
$app->Conf->WFdbport
|
||||
);
|
||||
$tableSchemaCreator = new TableSchemaEnsurer(
|
||||
$app->Container->get('SchemaCreator'),
|
||||
$installConf,
|
||||
$dbConfig
|
||||
);
|
||||
|
||||
echo "SCHREIBE ServiceMap\r\n";
|
||||
$writer->writeServiceCache();
|
||||
|
||||
echo "SCHREIBE JavascriptMap\r\n";
|
||||
$writer->writeJavascriptCache();
|
||||
|
||||
echo "ERZEUGE Table Schemas\r\n";
|
||||
$schemaCollection = $installer->getTableSchemas();
|
||||
$tableSchemaCreator->ensureSchemas($schemaCollection);
|
||||
|
||||
echo "ENDE Installer\r\n";
|
||||
//
|
||||
} catch (Exception $e) {
|
||||
echo "FEHLER " . $e->getMessage() . "\r\n";
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
$intern = true;
|
||||
if(!empty($argv[1]) && strtolower($argv[1]) === 'changeversion'){
|
||||
$allowChangeVersion = true;
|
||||
}
|
||||
|
||||
include __DIR__.'/www/update.php';
|
@ -1,812 +0,0 @@
|
||||
<?php
|
||||
//include("wawision.inc.php");
|
||||
|
||||
// Nur einfache Fehler melden
|
||||
//error_reporting(E_ERROR | E_WARNING | E_PARSE);
|
||||
error_reporting(E_ERROR | E_PARSE);
|
||||
|
||||
include_once("conf/main.conf.php");
|
||||
include_once("phpwf/plugins/class.mysql.php");
|
||||
include_once("www/lib/class.erpapi.php");
|
||||
|
||||
class app_t {
|
||||
var $DB;
|
||||
var $user;
|
||||
var $Conf;
|
||||
}
|
||||
|
||||
$app = new app_t();
|
||||
|
||||
$DEBUG = 0;
|
||||
|
||||
$app->Conf = new Config();
|
||||
$app->DB = new DB($app->Conf->WFdbhost,$app->Conf->WFdbname,$app->Conf->WFdbuser,$app->Conf->WFdbpass,null,$app->Conf->WFdbport);
|
||||
$erp = new erpAPI($app);
|
||||
|
||||
$WAWISION['host'] = $app->Conf->updateHost ?? 'removed.upgrade.host';
|
||||
$WAWISION['port']="443";
|
||||
|
||||
$myUpd = new UpgradeClient($WAWISION);
|
||||
|
||||
|
||||
echo "STARTE UPDATE\n";
|
||||
echo "Im folgenden stehen die Dateien die geaendert wurden.\n
|
||||
Erscheinen keine Dateien sind Sie auf der neusten Version.\n";
|
||||
|
||||
$myUpd->Connect();
|
||||
//$myUpd->CheckCRT();
|
||||
$myUpd->CheckUpdate();
|
||||
$myUpd->CheckUpdateCustom();
|
||||
$myUpd->CheckUpdateModules();
|
||||
|
||||
echo "ENDE UPDATE\n";
|
||||
|
||||
//echo "STARTE DB UPGRADE\n";
|
||||
//$erp->UpgradeDatabase();
|
||||
//echo "ENDE DB UPGRADE\n";
|
||||
|
||||
//include("version.php");
|
||||
//echo "\r\nRevision: $version_revision\r\n";
|
||||
|
||||
|
||||
//$myUpd->Request();
|
||||
|
||||
|
||||
|
||||
//echo
|
||||
|
||||
|
||||
|
||||
class UpgradeClient
|
||||
{
|
||||
var $localmd5sums;
|
||||
|
||||
function __construct($conf)
|
||||
{
|
||||
$this->conf = $conf;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function Connect()
|
||||
{
|
||||
// check connection then stop
|
||||
|
||||
}
|
||||
|
||||
|
||||
function CheckCRT()
|
||||
{
|
||||
$cert = shell_exec("openssl s_client -connect {$this->conf['host']}:{$this->conf['port']} < /dev/null 2>/dev/null | openssl x509 -in /dev/stdin");
|
||||
if($cert==$this->conf['cert']."\n") return 1;
|
||||
else {
|
||||
echo "wrong\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function CheckUpdate()
|
||||
{
|
||||
$parameter['version']=@$this->conf['version'];
|
||||
$result = $this->Request("md5list",$parameter);
|
||||
|
||||
if($result=="ERROR") { echo "Updates: ERROR FROM SERVER (Perhaps a wrong license?)\n"; return;}
|
||||
|
||||
$rows = explode(";",$result);
|
||||
|
||||
if(count($rows)>0)
|
||||
{
|
||||
foreach($rows as $value)
|
||||
{
|
||||
unset($single_row);
|
||||
$single_row = explode(":",$value);
|
||||
|
||||
if(count($single_row)>=2 && strlen($single_row[0])>3 && strlen($single_row[1])>3)
|
||||
{
|
||||
|
||||
$file = $single_row[0];
|
||||
$md5sum = $single_row[1];
|
||||
|
||||
$parameter['file']=$file;
|
||||
$parameter['md5sum']=$md5sum;
|
||||
|
||||
if($file=="./upgradesystemclient.php")
|
||||
{
|
||||
|
||||
}
|
||||
else if(is_file($file))
|
||||
{
|
||||
// pruefe md5sum
|
||||
if(md5_file($file)!=$md5sum)
|
||||
{
|
||||
// wenn update dann UPD_
|
||||
echo "update <- $file\n";
|
||||
$result = $this->Request("getfile",$parameter);
|
||||
$output = (base64_decode($result));
|
||||
//$output = preg_replace('/[^(\x22-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."UPD", $output);
|
||||
/*
|
||||
$fp = fopen($file."UPD","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
// pruefsuemme neu berechnen wenn passt umbenennen und ins archiv
|
||||
echo md5_file($file."UPD");
|
||||
echo "-".$md5sum."\n";
|
||||
if(md5_file($file."UPD")==$md5sum)
|
||||
{
|
||||
echo "update ok $file\n";
|
||||
rename($file."UPD",$file);
|
||||
}
|
||||
}
|
||||
} else if($file!="") {
|
||||
echo "datei <- $file\n";
|
||||
// pruefe ob es verzeichnis gibt
|
||||
$verzeichnis = dirname($file);
|
||||
if(!is_dir($verzeichnis))
|
||||
{
|
||||
echo "verzeichnis <- $verzeichnis\n";
|
||||
mkdir($verzeichnis,0777,true);
|
||||
}
|
||||
$result = $this->Request("getfile",$parameter);
|
||||
$output = base64_decode($result);
|
||||
//$output = iconv("UTF-8","ISO-8859-1//IGNORE",$output);
|
||||
//$output = iconv("ISO-8859-1","UTF-8",$output);
|
||||
//$output = preg_replace('/[^(\x20-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."NEW", $output);
|
||||
/*$fp = fopen($file."NEW","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
if(md5_file($file."NEW")==$md5sum)
|
||||
{
|
||||
echo "datei ok $file\n";
|
||||
rename($file."NEW",$file);
|
||||
} else {
|
||||
// echo "datei XX $file local: ".md5_file($file."NEW")." remote: ".$md5sum."\n";
|
||||
|
||||
}
|
||||
} else { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//pruefe, update, lege verzeichnis an, lege datei an, loesche datei????
|
||||
|
||||
|
||||
|
||||
// download all files with UPD_ prefix
|
||||
|
||||
|
||||
// get md5 liste von server
|
||||
|
||||
// pruefe ob alle dateien passen, wenn ja dann alle updaten am schluss
|
||||
|
||||
// wenn nein fehler abbrechen und ganzen prozess nochmal starten
|
||||
|
||||
//echo $md5sums;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function CheckUpdateModules()
|
||||
{
|
||||
$parameter['version']=@$this->conf['version'];
|
||||
$result = $this->Request("md5listmodules",$parameter);
|
||||
|
||||
if($result=="ERROR") { echo "Modules: ERROR FROM SERVER (Perhaps a wrong license?)\n"; return;}
|
||||
|
||||
$rows = explode(";",$result);
|
||||
|
||||
if(count($rows)>0)
|
||||
{
|
||||
foreach($rows as $value)
|
||||
{
|
||||
unset($single_row);
|
||||
$single_row = explode(":",$value);
|
||||
|
||||
if(count($single_row)>=2 && strlen($single_row[0])>3 && strlen($single_row[1])>3)
|
||||
{
|
||||
|
||||
$file = $single_row[0];
|
||||
$md5sum = $single_row[1];
|
||||
|
||||
$parameter['file']=$file;
|
||||
$parameter['md5sum']=$md5sum;
|
||||
|
||||
if($file=="./upgradesystemclient.php")
|
||||
{
|
||||
|
||||
}
|
||||
else if(is_file($file))
|
||||
{
|
||||
// pruefe md5sum
|
||||
if(md5_file($file)!=$md5sum)
|
||||
{
|
||||
// wenn update dann UPD_
|
||||
echo "update (M) <- $file\n";
|
||||
$result = $this->Request("getfilemodules",$parameter);
|
||||
$output = (base64_decode($result));
|
||||
//$output = preg_replace('/[^(\x22-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."UPD", $output);
|
||||
/*
|
||||
$fp = fopen($file."UPD","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
// pruefsuemme neu berechnen wenn passt umbenennen und ins archiv
|
||||
echo md5_file($file."UPD");
|
||||
echo "-".$md5sum."\n";
|
||||
if(md5_file($file."UPD")==$md5sum)
|
||||
{
|
||||
echo "update (M) ok $file\n";
|
||||
rename($file."UPD",$file);
|
||||
}
|
||||
}
|
||||
} else if($file!="") {
|
||||
echo "datei (M) <- $file\n";
|
||||
// pruefe ob es verzeichnis gibt
|
||||
$verzeichnis = dirname($file);
|
||||
if(!is_dir($verzeichnis))
|
||||
{
|
||||
echo "verzeichnis (M) <- $verzeichnis\n";
|
||||
mkdir($verzeichnis,0777,true);
|
||||
}
|
||||
$result = $this->Request("getfilemodules",$parameter);
|
||||
$output = base64_decode($result);
|
||||
//$output = iconv("UTF-8","ISO-8859-1//IGNORE",$output);
|
||||
//$output = iconv("ISO-8859-1","UTF-8",$output);
|
||||
//$output = preg_replace('/[^(\x20-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."NEW", $output);
|
||||
/*$fp = fopen($file."NEW","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
if(md5_file($file."NEW")==$md5sum)
|
||||
{
|
||||
echo "datei (M) ok $file\n";
|
||||
rename($file."NEW",$file);
|
||||
} else {
|
||||
// echo "datei XX $file local: ".md5_file($file."NEW")." remote: ".$md5sum."\n";
|
||||
|
||||
}
|
||||
} else { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//pruefe, update, lege verzeichnis an, lege datei an, loesche datei????
|
||||
|
||||
|
||||
|
||||
// download all files with UPD_ prefix
|
||||
|
||||
|
||||
// get md5 liste von server
|
||||
|
||||
// pruefe ob alle dateien passen, wenn ja dann alle updaten am schluss
|
||||
|
||||
// wenn nein fehler abbrechen und ganzen prozess nochmal starten
|
||||
|
||||
//echo $md5sums;
|
||||
|
||||
|
||||
}
|
||||
|
||||
function CheckUpdateCustom()
|
||||
{
|
||||
$parameter['version']=@$this->conf['version'];
|
||||
$result = $this->Request("md5listcustom",$parameter);
|
||||
|
||||
if($result=="ERROR") { echo "Custom: ERROR FROM SERVER (Perhaps a wrong license?)\n"; return;}
|
||||
|
||||
$rows = explode(";",$result);
|
||||
|
||||
if(count($rows)>0)
|
||||
{
|
||||
foreach($rows as $value)
|
||||
{
|
||||
unset($single_row);
|
||||
$single_row = explode(":",$value);
|
||||
|
||||
if(count($single_row)>=2 && strlen($single_row[0])>3 && strlen($single_row[1])>3)
|
||||
{
|
||||
|
||||
$file = $single_row[0];
|
||||
$md5sum = $single_row[1];
|
||||
|
||||
$parameter['file']=$file;
|
||||
$parameter['md5sum']=$md5sum;
|
||||
|
||||
if($file=="./upgradesystemclient.php")
|
||||
{
|
||||
|
||||
}
|
||||
else if(is_file($file))
|
||||
{
|
||||
// pruefe md5sum
|
||||
if(md5_file($file)!=$md5sum)
|
||||
{
|
||||
// wenn update dann UPD_
|
||||
echo "update (C) <- $file\n";
|
||||
$result = $this->Request("getfilecustom",$parameter);
|
||||
$output = (base64_decode($result));
|
||||
//$output = preg_replace('/[^(\x22-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."UPD", $output);
|
||||
/*
|
||||
$fp = fopen($file."UPD","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
// pruefsuemme neu berechnen wenn passt umbenennen und ins archiv
|
||||
echo md5_file($file."UPD");
|
||||
echo "-".$md5sum."\n";
|
||||
if(md5_file($file."UPD")==$md5sum)
|
||||
{
|
||||
echo "update (C) ok $file\n";
|
||||
rename($file."UPD",$file);
|
||||
}
|
||||
}
|
||||
} else if($file!="") {
|
||||
echo "datei (C) <- $file\n";
|
||||
// pruefe ob es verzeichnis gibt
|
||||
$verzeichnis = dirname($file);
|
||||
if(!is_dir($verzeichnis))
|
||||
{
|
||||
echo "verzeichnis (C) <- $verzeichnis\n";
|
||||
mkdir($verzeichnis,0777,true);
|
||||
}
|
||||
$result = $this->Request("getfilecustom",$parameter);
|
||||
$output = base64_decode($result);
|
||||
//$output = iconv("UTF-8","ISO-8859-1//IGNORE",$output);
|
||||
//$output = iconv("ISO-8859-1","UTF-8",$output);
|
||||
//$output = preg_replace('/[^(\x20-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."NEW", $output);
|
||||
/*$fp = fopen($file."NEW","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
if(md5_file($file."NEW")==$md5sum)
|
||||
{
|
||||
echo "datei (C) ok $file\n";
|
||||
rename($file."NEW",$file);
|
||||
} else {
|
||||
// echo "datei XX $file local: ".md5_file($file."NEW")." remote: ".$md5sum."\n";
|
||||
|
||||
}
|
||||
} else { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//pruefe, update, lege verzeichnis an, lege datei an, loesche datei????
|
||||
|
||||
|
||||
|
||||
// download all files with UPD_ prefix
|
||||
|
||||
|
||||
// get md5 liste von server
|
||||
|
||||
// pruefe ob alle dateien passen, wenn ja dann alle updaten am schluss
|
||||
|
||||
// wenn nein fehler abbrechen und ganzen prozess nochmal starten
|
||||
|
||||
//echo $md5sums;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function DownloadUpdate()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
function CheckDownloadedUpdate()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
function ExecuteUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
function Request($command,$parameter)
|
||||
{
|
||||
global $erp;
|
||||
$auth['serial']=trim($erp->Firmendaten("lizenz"));//$this->conf['serial'];
|
||||
$auth['authkey']=trim($erp->Firmendaten("schluessel"));//$this->conf['authkey'];
|
||||
|
||||
$auth = base64_encode(json_encode($auth));
|
||||
$parameter = base64_encode(json_encode($parameter));
|
||||
|
||||
$client = new HttpClient($this->conf['host'],$this->conf['port']);
|
||||
$client->post('/upgradesystem.php', array( "authjson" => $auth, "parameterjson"=>$parameter,"command"=>"$command" ));
|
||||
$pageContents = $client->getContent();
|
||||
return $pageContents;
|
||||
}
|
||||
|
||||
function dir_rekursiv($verzeichnis)
|
||||
{
|
||||
$handle = opendir($verzeichnis);
|
||||
|
||||
while ($datei = readdir($handle))
|
||||
{
|
||||
if ($datei != "." && $datei != "..")
|
||||
{
|
||||
if (is_dir($verzeichnis.$datei)) // Wenn Verzeichniseintrag ein Verzeichnis ist
|
||||
{
|
||||
// Erneuter Funktionsaufruf, um das aktuelle Verzeichnis auszulesen
|
||||
$this->dir_rekursiv($verzeichnis.$datei.'/');
|
||||
}
|
||||
else
|
||||
{
|
||||
// Wenn Verzeichnis-Eintrag eine Datei ist, diese ausgeben
|
||||
$this->localmd5sums[$verzeichnis.$datei] = md5_file($verzeichnis.$datei);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Version 0.9, 6th April 2003 - Simon Willison ( http://simon.incutio.com/ )
|
||||
Manual: http://scripts.incutio.com/httpclient/
|
||||
*/
|
||||
|
||||
class HttpClient {
|
||||
// Request vars
|
||||
var $host;
|
||||
var $port;
|
||||
var $path;
|
||||
var $method;
|
||||
var $postdata = '';
|
||||
var $cookies = array();
|
||||
var $referer;
|
||||
var $accept = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,image/jpeg,image/gif,*/*';
|
||||
var $accept_encoding = 'gzip';
|
||||
var $accept_language = 'en-us';
|
||||
var $user_agent = 'Incutio HttpClient v0.9';
|
||||
// Options
|
||||
var $timeout = 20;
|
||||
var $use_gzip = true;
|
||||
var $persist_cookies = true; // If true, received cookies are placed in the $this->cookies array ready for the next request
|
||||
// Note: This currently ignores the cookie path (and time) completely. Time is not important,
|
||||
// but path could possibly lead to security problems.
|
||||
var $persist_referers = true; // For each request, sends path of last request as referer
|
||||
var $debug = false;
|
||||
var $handle_redirects = true; // Auaomtically redirect if Location or URI header is found
|
||||
var $max_redirects = 5;
|
||||
var $headers_only = false; // If true, stops receiving once headers have been read.
|
||||
// Basic authorization variables
|
||||
var $username;
|
||||
var $password;
|
||||
// Response vars
|
||||
var $status;
|
||||
var $headers = array();
|
||||
var $content = '';
|
||||
var $errormsg;
|
||||
// Tracker variables
|
||||
var $redirect_count = 0;
|
||||
var $cookie_host = '';
|
||||
function __construct($host, $port=80) {
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
}
|
||||
function get($path, $data = false) {
|
||||
$this->path = $path;
|
||||
$this->method = 'GET';
|
||||
if ($data) {
|
||||
$this->path .= '?'.$this->buildQueryString($data);
|
||||
}
|
||||
return $this->doRequest();
|
||||
}
|
||||
function post($path, $data) {
|
||||
$this->path = $path;
|
||||
$this->method = 'POST';
|
||||
$this->postdata = $this->buildQueryString($data);
|
||||
return $this->doRequest();
|
||||
}
|
||||
function buildQueryString($data) {
|
||||
$querystring = '';
|
||||
if (is_array($data)) {
|
||||
// Change data in to postable data
|
||||
foreach ($data as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
foreach ($val as $val2) {
|
||||
$querystring .= urlencode($key).'='.urlencode($val2).'&';
|
||||
}
|
||||
} else {
|
||||
$querystring .= urlencode($key).'='.urlencode($val).'&';
|
||||
}
|
||||
}
|
||||
$querystring = substr($querystring, 0, -1); // Eliminate unnecessary &
|
||||
} else {
|
||||
$querystring = $data;
|
||||
}
|
||||
return $querystring;
|
||||
}
|
||||
function doRequest() {
|
||||
// Performs the actual HTTP request, returning true or false depending on outcome
|
||||
|
||||
if(!fsockopen("ssl://".$this->host, $this->port, $errno, $errstr, $this->timeout) && $this->port==443)
|
||||
{
|
||||
$this->port=80;
|
||||
}
|
||||
|
||||
if($this->port==443)
|
||||
$url = "ssl://".$this->host;
|
||||
else
|
||||
$url = $this->host;
|
||||
|
||||
if (!$fp = @fsockopen($url, $this->port, $errno, $errstr, $this->timeout)) {
|
||||
// Set error message
|
||||
switch($errno) {
|
||||
case -3:
|
||||
$this->errormsg = 'Socket creation failed (-3)';
|
||||
case -4:
|
||||
$this->errormsg = 'DNS lookup failure (-4)';
|
||||
case -5:
|
||||
$this->errormsg = 'Connection refused or timed out (-5)';
|
||||
default:
|
||||
$this->errormsg = 'Connection failed ('.$errno.')';
|
||||
$this->errormsg .= ' '.$errstr;
|
||||
$this->debug($this->errormsg);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
stream_set_timeout($fp, $this->timeout);
|
||||
$request = $this->buildRequest();
|
||||
$this->debug('Request', $request);
|
||||
fwrite($fp, $request);
|
||||
// Reset all the variables that should not persist between requests
|
||||
$this->headers = array();
|
||||
$this->content = '';
|
||||
$this->errormsg = '';
|
||||
// Set a couple of flags
|
||||
$inHeaders = true;
|
||||
$atStart = true;
|
||||
// Now start reading back the response
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp, 4096);
|
||||
if ($atStart) {
|
||||
// Deal with first line of returned data
|
||||
$atStart = false;
|
||||
if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
|
||||
$this->errormsg = "Status code line invalid: ".htmlentities($line);
|
||||
$this->debug($this->errormsg);
|
||||
//return false;
|
||||
}
|
||||
$http_version = $m[1]; // not used
|
||||
$this->status = $m[2];
|
||||
$status_string = $m[3]; // not used
|
||||
$this->debug(trim($line));
|
||||
continue;
|
||||
}
|
||||
if ($inHeaders) {
|
||||
if (trim($line) == '') {
|
||||
$inHeaders = false;
|
||||
$this->debug('Received Headers', $this->headers);
|
||||
if ($this->headers_only) {
|
||||
break; // Skip the rest of the input
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) {
|
||||
// Skip to the next header
|
||||
continue;
|
||||
}
|
||||
$key = strtolower(trim($m[1]));
|
||||
$val = trim($m[2]);
|
||||
// Deal with the possibility of multiple headers of same name
|
||||
if (isset($this->headers[$key])) {
|
||||
if (is_array($this->headers[$key])) {
|
||||
$this->headers[$key][] = $val;
|
||||
} else {
|
||||
$this->headers[$key] = array($this->headers[$key], $val);
|
||||
}
|
||||
} else {
|
||||
$this->headers[$key] = $val;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// We're not in the headers, so append the line to the contents
|
||||
$this->content .= $line;
|
||||
}
|
||||
fclose($fp);
|
||||
// If data is compressed, uncompress it
|
||||
if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] == 'gzip') {
|
||||
$this->debug('Content is gzip encoded, unzipping it');
|
||||
$this->content = substr($this->content, 10); // See http://www.php.net/manual/en/function.gzencode.php
|
||||
$this->content = gzinflate($this->content);
|
||||
}
|
||||
// If $persist_cookies, deal with any cookies
|
||||
if ($this->persist_cookies && isset($this->headers['set-cookie']) && $this->host == $this->cookie_host) {
|
||||
$cookies = $this->headers['set-cookie'];
|
||||
if (!is_array($cookies)) {
|
||||
$cookies = array($cookies);
|
||||
}
|
||||
foreach ($cookies as $cookie) {
|
||||
if (preg_match('/([^=]+)=([^;]+);/', $cookie, $m)) {
|
||||
$this->cookies[$m[1]] = $m[2];
|
||||
}
|
||||
}
|
||||
// Record domain of cookies for security reasons
|
||||
$this->cookie_host = $this->host;
|
||||
}
|
||||
// If $persist_referers, set the referer ready for the next request
|
||||
if ($this->persist_referers) {
|
||||
$this->debug('Persisting referer: '.$this->getRequestURL());
|
||||
$this->referer = $this->getRequestURL();
|
||||
}
|
||||
// Finally, if handle_redirects and a redirect is sent, do that
|
||||
if ($this->handle_redirects) {
|
||||
if (++$this->redirect_count >= $this->max_redirects) {
|
||||
$this->errormsg = 'Number of redirects exceeded maximum ('.$this->max_redirects.')';
|
||||
$this->debug($this->errormsg);
|
||||
$this->redirect_count = 0;
|
||||
return false;
|
||||
}
|
||||
$location = isset($this->headers['location']) ? $this->headers['location'] : '';
|
||||
$uri = isset($this->headers['uri']) ? $this->headers['uri'] : '';
|
||||
if ($location || $uri) {
|
||||
$url = parse_url($location.$uri);
|
||||
// This will FAIL if redirect is to a different site
|
||||
return $this->get($url['path']);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function buildRequest() {
|
||||
$headers = array();
|
||||
$headers[] = "{$this->method} {$this->path} HTTP/1.0"; // Using 1.1 leads to all manner of problems, such as "chunked" encoding
|
||||
$headers[] = "Host: {$this->host}";
|
||||
$headers[] = "User-Agent: {$this->user_agent}";
|
||||
$headers[] = "Accept: {$this->accept}";
|
||||
if ($this->use_gzip) {
|
||||
$headers[] = "Accept-encoding: {$this->accept_encoding}";
|
||||
}
|
||||
$headers[] = "Accept-language: {$this->accept_language}";
|
||||
if ($this->referer) {
|
||||
$headers[] = "Referer: {$this->referer}";
|
||||
}
|
||||
// Cookies
|
||||
if ($this->cookies) {
|
||||
$cookie = 'Cookie: ';
|
||||
foreach ($this->cookies as $key => $value) {
|
||||
$cookie .= "$key=$value; ";
|
||||
}
|
||||
$headers[] = $cookie;
|
||||
}
|
||||
// Basic authentication
|
||||
if ($this->username && $this->password) {
|
||||
$headers[] = 'Authorization: BASIC '.base64_encode($this->username.':'.$this->password);
|
||||
}
|
||||
// If this is a POST, set the content type and length
|
||||
if ($this->postdata) {
|
||||
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
||||
$headers[] = 'Content-Length: '.strlen($this->postdata);
|
||||
}
|
||||
$request = implode("\r\n", $headers)."\r\n\r\n".$this->postdata;
|
||||
return $request;
|
||||
}
|
||||
function getStatus() {
|
||||
return $this->status;
|
||||
}
|
||||
function getContent() {
|
||||
return $this->content;
|
||||
}
|
||||
function getHeaders() {
|
||||
return $this->headers;
|
||||
}
|
||||
function getHeader($header) {
|
||||
$header = strtolower($header);
|
||||
if (isset($this->headers[$header])) {
|
||||
return $this->headers[$header];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function getError() {
|
||||
return $this->errormsg;
|
||||
}
|
||||
function getCookies() {
|
||||
return $this->cookies;
|
||||
}
|
||||
function getRequestURL() {
|
||||
$url = 'http://'.$this->host;
|
||||
if ($this->port != 80) {
|
||||
$url .= ':'.$this->port;
|
||||
}
|
||||
$url .= $this->path;
|
||||
return $url;
|
||||
}
|
||||
// Setter methods
|
||||
function setUserAgent($string) {
|
||||
$this->user_agent = $string;
|
||||
}
|
||||
function setAuthorization($username, $password) {
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
}
|
||||
function setCookies($array) {
|
||||
$this->cookies = $array;
|
||||
}
|
||||
// Option setting methods
|
||||
function useGzip($boolean) {
|
||||
$this->use_gzip = $boolean;
|
||||
}
|
||||
function setPersistCookies($boolean) {
|
||||
$this->persist_cookies = $boolean;
|
||||
}
|
||||
function setPersistReferers($boolean) {
|
||||
$this->persist_referers = $boolean;
|
||||
}
|
||||
function setHandleRedirects($boolean) {
|
||||
$this->handle_redirects = $boolean;
|
||||
}
|
||||
function setMaxRedirects($num) {
|
||||
$this->max_redirects = $num;
|
||||
}
|
||||
function setHeadersOnly($boolean) {
|
||||
$this->headers_only = $boolean;
|
||||
}
|
||||
function setDebug($boolean) {
|
||||
$this->debug = $boolean;
|
||||
}
|
||||
// "Quick" static methods
|
||||
function quickGet($url) {
|
||||
$bits = parse_url($url);
|
||||
$host = $bits['host'];
|
||||
$port = isset($bits['port']) ? $bits['port'] : 80;
|
||||
$path = isset($bits['path']) ? $bits['path'] : '/';
|
||||
if (isset($bits['query'])) {
|
||||
$path .= '?'.$bits['query'];
|
||||
}
|
||||
$client = new HttpClient($host, $port);
|
||||
if (!$client->get($path)) {
|
||||
return false;
|
||||
} else {
|
||||
return $client->getContent();
|
||||
}
|
||||
}
|
||||
function quickPost($url, $data) {
|
||||
$bits = parse_url($url);
|
||||
$host = $bits['host'];
|
||||
$port = isset($bits['port']) ? $bits['port'] : 80;
|
||||
$path = isset($bits['path']) ? $bits['path'] : '/';
|
||||
$client = new HttpClient($host, $port);
|
||||
if (!$client->post($path, $data)) {
|
||||
return false;
|
||||
} else {
|
||||
return $client->getContent();
|
||||
}
|
||||
}
|
||||
function debug($msg, $object = false) {
|
||||
if ($this->debug) {
|
||||
print '<div style="border: 1px solid red; padding: 0.5em; margin: 0.5em;"><strong>HttpClient Debug:</strong> '.$msg;
|
||||
if ($object) {
|
||||
ob_start();
|
||||
print_r($object);
|
||||
$content = htmlentities(ob_get_contents());
|
||||
ob_end_clean();
|
||||
print '<pre>'.$content.'</pre>';
|
||||
}
|
||||
print '</div>';
|
||||
}
|
||||
}
|
||||
}
|
@ -1,783 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/xentral_autoloader.php';
|
||||
if (class_exists(Config::class)){
|
||||
$config = new Config();
|
||||
$updateHost = $config->updateHost ?: 'removed.upgrade.host';
|
||||
}else{
|
||||
$updateHost = 'removed.upgrade.host';
|
||||
}
|
||||
|
||||
$WAWISION['host']=$updateHost;
|
||||
$WAWISION['port']="443";
|
||||
|
||||
$myUpd = new UpgradeClient($WAWISION,$this->app);
|
||||
|
||||
|
||||
echo "STARTE UPDATE\n";
|
||||
echo "Im folgenden stehen die Dateien die geaendert wurden.\n
|
||||
Erscheinen keine Dateien sind Sie auf der neusten Version.\n";
|
||||
|
||||
$myUpd->Connect();
|
||||
//$myUpd->CheckCRT();
|
||||
$myUpd->CheckUpdate();
|
||||
$myUpd->CheckUpdateCustom();
|
||||
$myUpd->CheckUpdateModules();
|
||||
|
||||
|
||||
class UpgradeClient
|
||||
{
|
||||
var $localmd5sums;
|
||||
|
||||
function __construct($conf,&$app)
|
||||
{
|
||||
$this->conf = $conf;
|
||||
$this->app=&$app;
|
||||
}
|
||||
|
||||
|
||||
function Connect()
|
||||
{
|
||||
// check connection then stop
|
||||
|
||||
}
|
||||
|
||||
|
||||
function CheckCRT()
|
||||
{
|
||||
|
||||
$cert = shell_exec("openssl s_client -connect update.embedded-projects.net:443 < /dev/null 2>/dev/null | openssl x509 -in /dev/stdin");
|
||||
if($cert==$this->conf['cert']."\n") return 1;
|
||||
else {
|
||||
echo "wrong\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function CheckUpdate()
|
||||
{
|
||||
$parameter['version']=@$this->conf['version'];
|
||||
$result = $this->Request("md5list",$parameter);
|
||||
|
||||
if($result=="ERROR") { echo "Updates: ERROR FROM SERVER (Perhaps a wrong license?)\n"; return;}
|
||||
|
||||
$rows = explode(";",$result);
|
||||
|
||||
if(count($rows)>0)
|
||||
{
|
||||
foreach($rows as $value)
|
||||
{
|
||||
unset($single_row);
|
||||
$single_row = explode(":",$value);
|
||||
|
||||
if(count($single_row)>=2 && strlen($single_row[0])>3 && strlen($single_row[1])>3)
|
||||
{
|
||||
|
||||
$filename = $single_row[0];
|
||||
$file = __DIR__."/".$single_row[0];
|
||||
$md5sum = $single_row[1];
|
||||
|
||||
$parameter['file']=$filename;
|
||||
$parameter['md5sum']=$md5sum;
|
||||
|
||||
|
||||
if($file=="./upgradesystemclient.php")
|
||||
{
|
||||
|
||||
}
|
||||
else if(is_file($file))
|
||||
{
|
||||
// pruefe md5sum
|
||||
if(md5_file($file)!=$md5sum)
|
||||
{
|
||||
// wenn update dann UPD_
|
||||
echo "update <- $file\n";
|
||||
$result = $this->Request("getfile",$parameter);
|
||||
$output = (base64_decode($result));
|
||||
//$output = preg_replace('/[^(\x22-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."UPD", $output);
|
||||
/*
|
||||
$fp = fopen($file."UPD","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
// pruefsuemme neu berechnen wenn passt umbenennen und ins archiv
|
||||
echo md5_file($file."UPD");
|
||||
echo "-".$md5sum."\n";
|
||||
if(md5_file($file."UPD")==$md5sum)
|
||||
{
|
||||
echo "update ok $file\n";
|
||||
rename($file."UPD",$file);
|
||||
}
|
||||
}
|
||||
} else if($file!="") {
|
||||
echo "datei <- $file\n";
|
||||
// pruefe ob es verzeichnis gibt
|
||||
$verzeichnis = dirname($file);
|
||||
if(!is_dir($verzeichnis))
|
||||
{
|
||||
echo "verzeichnis <- $verzeichnis\n";
|
||||
mkdir($verzeichnis,0777,true);
|
||||
}
|
||||
$result = $this->Request("getfile",$parameter);
|
||||
$output = base64_decode($result);
|
||||
//$output = iconv("UTF-8","ISO-8859-1//IGNORE",$output);
|
||||
//$output = iconv("ISO-8859-1","UTF-8",$output);
|
||||
//$output = preg_replace('/[^(\x20-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."NEW", $output);
|
||||
/*$fp = fopen($file."NEW","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
if(md5_file($file."NEW")==$md5sum)
|
||||
{
|
||||
echo "datei ok $file\n";
|
||||
rename($file."NEW",$file);
|
||||
} else {
|
||||
// echo "datei XX $file local: ".md5_file($file."NEW")." remote: ".$md5sum."\n";
|
||||
|
||||
}
|
||||
} else { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//pruefe, update, lege verzeichnis an, lege datei an, loesche datei????
|
||||
|
||||
|
||||
|
||||
// download all files with UPD_ prefix
|
||||
|
||||
|
||||
// get md5 liste von server
|
||||
|
||||
// pruefe ob alle dateien passen, wenn ja dann alle updaten am schluss
|
||||
|
||||
// wenn nein fehler abbrechen und ganzen prozess nochmal starten
|
||||
|
||||
//echo $md5sums;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function CheckUpdateModules()
|
||||
{
|
||||
$parameter['version']=@$this->conf['version'];
|
||||
$result = $this->Request("md5listmodules",$parameter);
|
||||
|
||||
if($result=="ERROR") { echo "Modules: ERROR FROM SERVER (Perhaps a wrong license?)\n"; return;}
|
||||
|
||||
$rows = explode(";",$result);
|
||||
|
||||
if(count($rows)>0)
|
||||
{
|
||||
foreach($rows as $value)
|
||||
{
|
||||
unset($single_row);
|
||||
$single_row = explode(":",$value);
|
||||
|
||||
if(count($single_row)>=2 && strlen($single_row[0])>3 && strlen($single_row[1])>3)
|
||||
{
|
||||
$filename = $single_row[0];
|
||||
$file = dirname(__FILE__)."/".$single_row[0];
|
||||
$md5sum = $single_row[1];
|
||||
|
||||
$parameter['file']=$filename;
|
||||
$parameter['md5sum']=$md5sum;
|
||||
|
||||
if($file=="./upgradesystemclient.php")
|
||||
{
|
||||
|
||||
}
|
||||
else if(is_file($file))
|
||||
{
|
||||
// pruefe md5sum
|
||||
if(md5_file($file)!=$md5sum)
|
||||
{
|
||||
// wenn update dann UPD_
|
||||
echo "update (M) <- $file\n";
|
||||
$result = $this->Request("getfilemodules",$parameter);
|
||||
$output = (base64_decode($result));
|
||||
//$output = preg_replace('/[^(\x22-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."UPD", $output);
|
||||
/*
|
||||
$fp = fopen($file."UPD","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
// pruefsuemme neu berechnen wenn passt umbenennen und ins archiv
|
||||
echo md5_file($file."UPD");
|
||||
echo "-".$md5sum."\n";
|
||||
if(md5_file($file."UPD")==$md5sum)
|
||||
{
|
||||
echo "update (M) ok $file\n";
|
||||
rename($file."UPD",$file);
|
||||
}
|
||||
}
|
||||
} else if($file!="") {
|
||||
echo "datei (M) <- $file\n";
|
||||
// pruefe ob es verzeichnis gibt
|
||||
$verzeichnis = dirname($file);
|
||||
if(!is_dir($verzeichnis))
|
||||
{
|
||||
echo "verzeichnis (M) <- $verzeichnis\n";
|
||||
mkdir($verzeichnis,0777,true);
|
||||
}
|
||||
$result = $this->Request("getfilemodules",$parameter);
|
||||
$output = base64_decode($result);
|
||||
//$output = iconv("UTF-8","ISO-8859-1//IGNORE",$output);
|
||||
//$output = iconv("ISO-8859-1","UTF-8",$output);
|
||||
//$output = preg_replace('/[^(\x20-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."NEW", $output);
|
||||
/*$fp = fopen($file."NEW","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
if(md5_file($file."NEW")==$md5sum)
|
||||
{
|
||||
echo "datei (M) ok $file\n";
|
||||
rename($file."NEW",$file);
|
||||
} else {
|
||||
// echo "datei XX $file local: ".md5_file($file."NEW")." remote: ".$md5sum."\n";
|
||||
|
||||
}
|
||||
} else { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//pruefe, update, lege verzeichnis an, lege datei an, loesche datei????
|
||||
|
||||
|
||||
|
||||
// download all files with UPD_ prefix
|
||||
|
||||
|
||||
// get md5 liste von server
|
||||
|
||||
// pruefe ob alle dateien passen, wenn ja dann alle updaten am schluss
|
||||
|
||||
// wenn nein fehler abbrechen und ganzen prozess nochmal starten
|
||||
|
||||
//echo $md5sums;
|
||||
|
||||
|
||||
}
|
||||
|
||||
function CheckUpdateCustom()
|
||||
{
|
||||
$parameter['version']=@$this->conf['version'];
|
||||
$result = $this->Request("md5listcustom",$parameter);
|
||||
|
||||
if($result=="ERROR") { echo "Custom: ERROR FROM SERVER (Perhaps a wrong license?)\n"; return;}
|
||||
|
||||
$rows = explode(";",$result);
|
||||
|
||||
if(count($rows)>0)
|
||||
{
|
||||
foreach($rows as $value)
|
||||
{
|
||||
unset($single_row);
|
||||
$single_row = explode(":",$value);
|
||||
|
||||
if(count($single_row)>=2 && strlen($single_row[0])>3 && strlen($single_row[1])>3)
|
||||
{
|
||||
$filename = $single_row[0];
|
||||
$file = __DIR__."/".$single_row[0];
|
||||
$md5sum = $single_row[1];
|
||||
|
||||
$parameter['file']=$filename;
|
||||
$parameter['md5sum']=$md5sum;
|
||||
|
||||
if($file=="./upgradesystemclient.php")
|
||||
{
|
||||
|
||||
}
|
||||
else if(is_file($file))
|
||||
{
|
||||
// pruefe md5sum
|
||||
if(md5_file($file)!=$md5sum)
|
||||
{
|
||||
// wenn update dann UPD_
|
||||
echo "update (C) <- $file\n";
|
||||
$result = $this->Request("getfilecustom",$parameter);
|
||||
$output = (base64_decode($result));
|
||||
//$output = preg_replace('/[^(\x22-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."UPD", $output);
|
||||
/*
|
||||
$fp = fopen($file."UPD","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
// pruefsuemme neu berechnen wenn passt umbenennen und ins archiv
|
||||
echo md5_file($file."UPD");
|
||||
echo "-".$md5sum."\n";
|
||||
if(md5_file($file."UPD")==$md5sum)
|
||||
{
|
||||
echo "update (C) ok $file\n";
|
||||
rename($file."UPD",$file);
|
||||
}
|
||||
}
|
||||
} else if($file!="") {
|
||||
echo "datei (C) <- $file\n";
|
||||
// pruefe ob es verzeichnis gibt
|
||||
$verzeichnis = dirname($file);
|
||||
if(!is_dir($verzeichnis))
|
||||
{
|
||||
echo "verzeichnis (C) <- $verzeichnis\n";
|
||||
mkdir($verzeichnis,0777,true);
|
||||
}
|
||||
$result = $this->Request("getfilecustom",$parameter);
|
||||
$output = base64_decode($result);
|
||||
//$output = iconv("UTF-8","ISO-8859-1//IGNORE",$output);
|
||||
//$output = iconv("ISO-8859-1","UTF-8",$output);
|
||||
//$output = preg_replace('/[^(\x20-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."NEW", $output);
|
||||
/*$fp = fopen($file."NEW","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
if(md5_file($file."NEW")==$md5sum)
|
||||
{
|
||||
echo "datei (C) ok $file\n";
|
||||
rename($file."NEW",$file);
|
||||
} else {
|
||||
// echo "datei XX $file local: ".md5_file($file."NEW")." remote: ".$md5sum."\n";
|
||||
|
||||
}
|
||||
} else { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//pruefe, update, lege verzeichnis an, lege datei an, loesche datei????
|
||||
|
||||
|
||||
|
||||
// download all files with UPD_ prefix
|
||||
|
||||
|
||||
// get md5 liste von server
|
||||
|
||||
// pruefe ob alle dateien passen, wenn ja dann alle updaten am schluss
|
||||
|
||||
// wenn nein fehler abbrechen und ganzen prozess nochmal starten
|
||||
|
||||
//echo $md5sums;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function DownloadUpdate()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
function CheckDownloadedUpdate()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
function ExecuteUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
function Request($command,$parameter)
|
||||
{
|
||||
global $erp;
|
||||
$auth['serial']=$this->app->erp->Firmendaten("lizenz");//$this->conf['serial'];
|
||||
$auth['authkey']=$this->app->erp->Firmendaten("schluessel");//$this->conf['authkey'];
|
||||
|
||||
$auth = base64_encode(json_encode($auth));
|
||||
$parameter = base64_encode(json_encode($parameter));
|
||||
$client = new HttpClientUpgrade($this->conf['host'],$this->conf['port']);
|
||||
$client->post('/upgradesystem.php', array( "authjson" => $auth, "parameterjson"=>$parameter,"command"=>"$command" ));
|
||||
$pageContents = $client->getContent();
|
||||
return $pageContents;
|
||||
}
|
||||
|
||||
function dir_rekursiv($verzeichnis)
|
||||
{
|
||||
$handle = opendir($verzeichnis);
|
||||
|
||||
while ($datei = readdir($handle))
|
||||
{
|
||||
if ($datei != "." && $datei != "..")
|
||||
{
|
||||
if (is_dir($verzeichnis.$datei)) // Wenn Verzeichniseintrag ein Verzeichnis ist
|
||||
{
|
||||
// Erneuter Funktionsaufruf, um das aktuelle Verzeichnis auszulesen
|
||||
$this->dir_rekursiv($verzeichnis.$datei.'/');
|
||||
}
|
||||
else
|
||||
{
|
||||
// Wenn Verzeichnis-Eintrag eine Datei ist, diese ausgeben
|
||||
$this->localmd5sums[$verzeichnis.$datei] = md5_file($verzeichnis.$datei);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Version 0.9, 6th April 2003 - Simon Willison ( http://simon.incutio.com/ )
|
||||
Manual: http://scripts.incutio.com/httpclient/
|
||||
*/
|
||||
|
||||
class HttpClientUpgrade {
|
||||
// Request vars
|
||||
var $host;
|
||||
var $port;
|
||||
var $path;
|
||||
var $method;
|
||||
var $postdata = '';
|
||||
var $cookies = array();
|
||||
var $referer;
|
||||
var $accept = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,image/jpeg,image/gif,*/*';
|
||||
var $accept_encoding = 'gzip';
|
||||
var $accept_language = 'en-us';
|
||||
var $user_agent = 'Incutio HttpClientUpgrade v0.9';
|
||||
// Options
|
||||
var $timeout = 20;
|
||||
var $use_gzip = true;
|
||||
var $persist_cookies = true; // If true, received cookies are placed in the $this->cookies array ready for the next request
|
||||
// Note: This currently ignores the cookie path (and time) completely. Time is not important,
|
||||
// but path could possibly lead to security problems.
|
||||
var $persist_referers = true; // For each request, sends path of last request as referer
|
||||
var $debug = false;
|
||||
var $handle_redirects = true; // Auaomtically redirect if Location or URI header is found
|
||||
var $max_redirects = 5;
|
||||
var $headers_only = false; // If true, stops receiving once headers have been read.
|
||||
// Basic authorization variables
|
||||
var $username;
|
||||
var $password;
|
||||
// Response vars
|
||||
var $status;
|
||||
var $headers = array();
|
||||
var $content = '';
|
||||
var $errormsg;
|
||||
// Tracker variables
|
||||
var $redirect_count = 0;
|
||||
var $cookie_host = '';
|
||||
function __construct($host, $port=80) {
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
}
|
||||
function get($path, $data = false) {
|
||||
$this->path = $path;
|
||||
$this->method = 'GET';
|
||||
if ($data) {
|
||||
$this->path .= '?'.$this->buildQueryString($data);
|
||||
}
|
||||
return $this->doRequest();
|
||||
}
|
||||
function post($path, $data) {
|
||||
$this->path = $path;
|
||||
$this->method = 'POST';
|
||||
$this->postdata = $this->buildQueryString($data);
|
||||
return $this->doRequest();
|
||||
}
|
||||
function buildQueryString($data) {
|
||||
$querystring = '';
|
||||
if (is_array($data)) {
|
||||
// Change data in to postable data
|
||||
foreach ($data as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
foreach ($val as $val2) {
|
||||
$querystring .= urlencode($key).'='.urlencode($val2).'&';
|
||||
}
|
||||
} else {
|
||||
$querystring .= urlencode($key).'='.urlencode($val).'&';
|
||||
}
|
||||
}
|
||||
$querystring = substr($querystring, 0, -1); // Eliminate unnecessary &
|
||||
} else {
|
||||
$querystring = $data;
|
||||
}
|
||||
return $querystring;
|
||||
}
|
||||
function doRequest() {
|
||||
// Performs the actual HTTP request, returning true or false depending on outcome
|
||||
// check if port is available
|
||||
if(!fsockopen("ssl://".$this->host, $this->port, $errno, $errstr, $this->timeout) && $this->port==443)
|
||||
{
|
||||
$this->port=80;
|
||||
}
|
||||
|
||||
if($this->port==443)
|
||||
$url = "ssl://".$this->host;
|
||||
else
|
||||
$url = $this->host;
|
||||
|
||||
if (!$fp = @fsockopen($url, $this->port, $errno, $errstr, $this->timeout)) {
|
||||
// Set error message
|
||||
switch($errno) {
|
||||
case -3:
|
||||
$this->errormsg = 'Socket creation failed (-3)';
|
||||
case -4:
|
||||
$this->errormsg = 'DNS lookup failure (-4)';
|
||||
case -5:
|
||||
$this->errormsg = 'Connection refused or timed out (-5)';
|
||||
default:
|
||||
$this->errormsg = 'Connection failed ('.$errno.')';
|
||||
$this->errormsg .= ' '.$errstr;
|
||||
$this->debug($this->errormsg);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
stream_set_timeout($fp, $this->timeout);
|
||||
$request = $this->buildRequest();
|
||||
$this->debug('Request', $request);
|
||||
fwrite($fp, $request);
|
||||
// Reset all the variables that should not persist between requests
|
||||
$this->headers = array();
|
||||
$this->content = '';
|
||||
$this->errormsg = '';
|
||||
// Set a couple of flags
|
||||
$inHeaders = true;
|
||||
$atStart = true;
|
||||
// Now start reading back the response
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp, 4096);
|
||||
if ($atStart) {
|
||||
// Deal with first line of returned data
|
||||
$atStart = false;
|
||||
if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
|
||||
$this->errormsg = "Status code line invalid: ".htmlentities($line);
|
||||
$this->debug($this->errormsg);
|
||||
//return false;
|
||||
}
|
||||
$http_version = $m[1]; // not used
|
||||
$this->status = $m[2];
|
||||
$status_string = $m[3]; // not used
|
||||
$this->debug(trim($line));
|
||||
continue;
|
||||
}
|
||||
if ($inHeaders) {
|
||||
if (trim($line) == '') {
|
||||
$inHeaders = false;
|
||||
$this->debug('Received Headers', $this->headers);
|
||||
if ($this->headers_only) {
|
||||
break; // Skip the rest of the input
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) {
|
||||
// Skip to the next header
|
||||
continue;
|
||||
}
|
||||
$key = strtolower(trim($m[1]));
|
||||
$val = trim($m[2]);
|
||||
// Deal with the possibility of multiple headers of same name
|
||||
if (isset($this->headers[$key])) {
|
||||
if (is_array($this->headers[$key])) {
|
||||
$this->headers[$key][] = $val;
|
||||
} else {
|
||||
$this->headers[$key] = array($this->headers[$key], $val);
|
||||
}
|
||||
} else {
|
||||
$this->headers[$key] = $val;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// We're not in the headers, so append the line to the contents
|
||||
$this->content .= $line;
|
||||
}
|
||||
fclose($fp);
|
||||
// If data is compressed, uncompress it
|
||||
if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] == 'gzip') {
|
||||
$this->debug('Content is gzip encoded, unzipping it');
|
||||
$this->content = substr($this->content, 10); // See http://www.php.net/manual/en/function.gzencode.php
|
||||
$this->content = gzinflate($this->content);
|
||||
}
|
||||
// If $persist_cookies, deal with any cookies
|
||||
if ($this->persist_cookies && isset($this->headers['set-cookie']) && $this->host == $this->cookie_host) {
|
||||
$cookies = $this->headers['set-cookie'];
|
||||
if (!is_array($cookies)) {
|
||||
$cookies = array($cookies);
|
||||
}
|
||||
foreach ($cookies as $cookie) {
|
||||
if (preg_match('/([^=]+)=([^;]+);/', $cookie, $m)) {
|
||||
$this->cookies[$m[1]] = $m[2];
|
||||
}
|
||||
}
|
||||
// Record domain of cookies for security reasons
|
||||
$this->cookie_host = $this->host;
|
||||
}
|
||||
// If $persist_referers, set the referer ready for the next request
|
||||
if ($this->persist_referers) {
|
||||
$this->debug('Persisting referer: '.$this->getRequestURL());
|
||||
$this->referer = $this->getRequestURL();
|
||||
}
|
||||
// Finally, if handle_redirects and a redirect is sent, do that
|
||||
if ($this->handle_redirects) {
|
||||
if (++$this->redirect_count >= $this->max_redirects) {
|
||||
$this->errormsg = 'Number of redirects exceeded maximum ('.$this->max_redirects.')';
|
||||
$this->debug($this->errormsg);
|
||||
$this->redirect_count = 0;
|
||||
return false;
|
||||
}
|
||||
$location = isset($this->headers['location']) ? $this->headers['location'] : '';
|
||||
$uri = isset($this->headers['uri']) ? $this->headers['uri'] : '';
|
||||
if ($location || $uri) {
|
||||
$url = parse_url($location.$uri);
|
||||
// This will FAIL if redirect is to a different site
|
||||
return $this->get($url['path']);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function buildRequest() {
|
||||
$headers = array();
|
||||
$headers[] = "{$this->method} {$this->path} HTTP/1.0"; // Using 1.1 leads to all manner of problems, such as "chunked" encoding
|
||||
$headers[] = "Host: {$this->host}";
|
||||
$headers[] = "User-Agent: {$this->user_agent}";
|
||||
$headers[] = "Accept: {$this->accept}";
|
||||
if ($this->use_gzip) {
|
||||
$headers[] = "Accept-encoding: {$this->accept_encoding}";
|
||||
}
|
||||
$headers[] = "Accept-language: {$this->accept_language}";
|
||||
if ($this->referer) {
|
||||
$headers[] = "Referer: {$this->referer}";
|
||||
}
|
||||
// Cookies
|
||||
if ($this->cookies) {
|
||||
$cookie = 'Cookie: ';
|
||||
foreach ($this->cookies as $key => $value) {
|
||||
$cookie .= "$key=$value; ";
|
||||
}
|
||||
$headers[] = $cookie;
|
||||
}
|
||||
// Basic authentication
|
||||
if ($this->username && $this->password) {
|
||||
$headers[] = 'Authorization: BASIC '.base64_encode($this->username.':'.$this->password);
|
||||
}
|
||||
// If this is a POST, set the content type and length
|
||||
if ($this->postdata) {
|
||||
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
||||
$headers[] = 'Content-Length: '.strlen($this->postdata);
|
||||
}
|
||||
$request = implode("\r\n", $headers)."\r\n\r\n".$this->postdata;
|
||||
return $request;
|
||||
}
|
||||
function getStatus() {
|
||||
return $this->status;
|
||||
}
|
||||
function getContent() {
|
||||
return $this->content;
|
||||
}
|
||||
function getHeaders() {
|
||||
return $this->headers;
|
||||
}
|
||||
function getHeader($header) {
|
||||
$header = strtolower($header);
|
||||
if (isset($this->headers[$header])) {
|
||||
return $this->headers[$header];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function getError() {
|
||||
return $this->errormsg;
|
||||
}
|
||||
function getCookies() {
|
||||
return $this->cookies;
|
||||
}
|
||||
function getRequestURL() {
|
||||
$url = 'http://'.$this->host;
|
||||
if ($this->port != 80) {
|
||||
$url .= ':'.$this->port;
|
||||
}
|
||||
$url .= $this->path;
|
||||
return $url;
|
||||
}
|
||||
// Setter methods
|
||||
function setUserAgent($string) {
|
||||
$this->user_agent = $string;
|
||||
}
|
||||
function setAuthorization($username, $password) {
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
}
|
||||
function setCookies($array) {
|
||||
$this->cookies = $array;
|
||||
}
|
||||
// Option setting methods
|
||||
function useGzip($boolean) {
|
||||
$this->use_gzip = $boolean;
|
||||
}
|
||||
function setPersistCookies($boolean) {
|
||||
$this->persist_cookies = $boolean;
|
||||
}
|
||||
function setPersistReferers($boolean) {
|
||||
$this->persist_referers = $boolean;
|
||||
}
|
||||
function setHandleRedirects($boolean) {
|
||||
$this->handle_redirects = $boolean;
|
||||
}
|
||||
function setMaxRedirects($num) {
|
||||
$this->max_redirects = $num;
|
||||
}
|
||||
function setHeadersOnly($boolean) {
|
||||
$this->headers_only = $boolean;
|
||||
}
|
||||
function setDebug($boolean) {
|
||||
$this->debug = $boolean;
|
||||
}
|
||||
// "Quick" static methods
|
||||
function quickGet($url) {
|
||||
$bits = parse_url($url);
|
||||
$host = $bits['host'];
|
||||
$port = isset($bits['port']) ? $bits['port'] : 80;
|
||||
$path = isset($bits['path']) ? $bits['path'] : '/';
|
||||
if (isset($bits['query'])) {
|
||||
$path .= '?'.$bits['query'];
|
||||
}
|
||||
$client = new HttpClientUpgrade($host, $port);
|
||||
if (!$client->get($path)) {
|
||||
return false;
|
||||
} else {
|
||||
return $client->getContent();
|
||||
}
|
||||
}
|
||||
function quickPost($url, $data) {
|
||||
$bits = parse_url($url);
|
||||
$host = $bits['host'];
|
||||
$port = isset($bits['port']) ? $bits['port'] : 80;
|
||||
$path = isset($bits['path']) ? $bits['path'] : '/';
|
||||
$client = new HttpClientUpgrade($host, $port);
|
||||
if (!$client->post($path, $data)) {
|
||||
return false;
|
||||
} else {
|
||||
return $client->getContent();
|
||||
}
|
||||
}
|
||||
function debug($msg, $object = false) {
|
||||
if ($this->debug) {
|
||||
print '<div style="border: 1px solid red; padding: 0.5em; margin: 0.5em;"><strong>HttpClientUpgrade Debug:</strong> '.$msg;
|
||||
if ($object) {
|
||||
ob_start();
|
||||
print_r($object);
|
||||
$content = htmlentities(ob_get_contents());
|
||||
ob_end_clean();
|
||||
print '<pre>'.$content.'</pre>';
|
||||
}
|
||||
print '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,928 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/xentral_autoloader.php';
|
||||
if (class_exists(Config::class)){
|
||||
$config = new Config();
|
||||
$updateHost = $config->updateHost ?: 'removed.upgrade.host';
|
||||
}else{
|
||||
$updateHost = 'removed.upgrade.host';
|
||||
}
|
||||
define('XENTRAL_UPDATE_HOST', $updateHost);
|
||||
|
||||
$WAWISION['host']=XENTRAL_UPDATE_HOST;
|
||||
$WAWISION['port']="443";
|
||||
|
||||
$myUpd = new UpgradeClient($WAWISION,$this->app);
|
||||
|
||||
|
||||
$myUpd->Connect();
|
||||
if(isset($sendStats)) {
|
||||
}
|
||||
elseif(isset($buy)) {
|
||||
}
|
||||
elseif(isset($getBuyList)) {
|
||||
}
|
||||
elseif(isset($getBuyInfo)) {
|
||||
}
|
||||
elseif(isset($setBeta)) {
|
||||
}
|
||||
elseif(isset($setDevelopmentVersion)) {
|
||||
}
|
||||
elseif(isset($buyFromDemo)) {
|
||||
}
|
||||
elseif(isset($resetXentral)) {
|
||||
}
|
||||
elseif(isset($fiskalyCommand)) {
|
||||
}
|
||||
elseif(isset($createFiskalyClientFromClientId) && isset($tseId) && isset($organizationId)) {
|
||||
}
|
||||
elseif(isset($sma) && isset($sendSmaErrorMessage)) {
|
||||
}
|
||||
else{
|
||||
}
|
||||
if(!class_exists('Md5Dateien'))
|
||||
{
|
||||
class Md5Dateien
|
||||
{
|
||||
var $Dateien;
|
||||
function __construct($quellverzeichnis)
|
||||
{
|
||||
$this->getVerzeichnis($quellverzeichnis, '', 0, '');
|
||||
}
|
||||
|
||||
function getVerzeichnis($quellverzeichnis, $zielverzeichnis, $lvl, $relativ){
|
||||
//echo "Verzeichnis: ".$quellverzeichnis." ".$zielverzeichnis. "\r\n";
|
||||
|
||||
$quelllast = $quellverzeichnis;
|
||||
if($quellverzeichnis[strlen($quellverzeichnis) - 1] == '/')$quelllast = substr($quellverzeichnis, 0, strlen($quellverzeichnis) - 1);
|
||||
|
||||
$path_parts = pathinfo($quelllast);
|
||||
|
||||
$quelllast = $path_parts['basename'];
|
||||
|
||||
if(file_exists($quellverzeichnis))
|
||||
{
|
||||
if($quelllast != 'importer' || $lvl != 1){
|
||||
if ($handle = opendir($quellverzeichnis)) {
|
||||
while (false !== ($entry = readdir($handle))) {
|
||||
|
||||
if($entry != '.' && $entry != '..' && $entry != '.git' && $entry != '.svn' && $entry != 'main.conf.php' && $entry != 'user.inc.php' && $entry != 'user_db_version.php' && $entry != 'pygen')
|
||||
{
|
||||
if(is_dir($quellverzeichnis.'/'.$entry))
|
||||
{
|
||||
if(!($lvl == 1 && $entry == 'vorlagen' && strpos($quellverzeichnis,'www')))
|
||||
$this->getVerzeichnis($quellverzeichnis.(strrpos($quellverzeichnis,'/')!==strlen($quellverzeichnis)-1?'/':'').$entry,$zielverzeichnis .(strrpos($zielverzeichnis,'/')!==strlen($zielverzeichnis)-1?'/':'').$entry, $lvl + 1,$relativ.'/'.$entry);
|
||||
} else {
|
||||
if(!($lvl == 0 && ($entry == 'INSTALL' || $entry == 'LICENSE_LIST' || $entry == 'LICENSE' || $entry == 'README' || $entry == 'gitlog.txt')))
|
||||
{
|
||||
//$this->getFile($quellverzeichnis.(strrpos($quellverzeichnis,'/')!==strlen($quellverzeichnis)-1?'/':'').$entry,$zielverzeichnis .(strrpos($zielverzeichnis,'/')!==strlen($zielverzeichnis)-1?'/':'').$entry,$relativ.'/'.$entry);
|
||||
if(strtolower(substr($entry,-4)) == '.php')$this->Dateien[$relativ.'/'.$entry] = md5_file($quellverzeichnis.(strrpos($quellverzeichnis,'/')!==strlen($quellverzeichnis)-1?'/':'').$entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@closedir($handle);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UpgradeClient
|
||||
{
|
||||
var $localmd5sums;
|
||||
|
||||
/**
|
||||
* UpgradeClient constructor.
|
||||
*
|
||||
* @param Config $conf
|
||||
* @param ApplicationCore $app
|
||||
*/
|
||||
public function __construct($conf, $app)
|
||||
{
|
||||
$this->conf = $conf;
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
|
||||
function Connect()
|
||||
{
|
||||
// check connection then stop
|
||||
|
||||
}
|
||||
|
||||
|
||||
function CheckCRT()
|
||||
{
|
||||
$updateHost = XENTRAL_UPDATE_HOST;
|
||||
$cert = shell_exec("openssl s_client -connect {$updateHost}:443 < /dev/null 2>/dev/null | openssl x509 -in /dev/stdin");
|
||||
if($cert==$this->conf['cert']."\n") return 1;
|
||||
else {
|
||||
echo "wrong\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function CheckUpdate()
|
||||
{
|
||||
//$this->dir_rekursiv("./");
|
||||
//$parameter['md5sums'] = $this->localmd5sums;
|
||||
//shell_exec('find ./ -exec md5sum "{}" \;');
|
||||
$lines = null;
|
||||
$funktions_ind = null;
|
||||
$dateien = new Md5Dateien(__DIR__.'/');
|
||||
if(!empty($dateien->Dateien) && is_array($dateien->Dateien)) {
|
||||
foreach($dateien->Dateien as $k => $v) {
|
||||
if(
|
||||
strtolower(substr($k,-4)) === '.php'
|
||||
&& strpos($k, '_custom') !== false
|
||||
&& strpos($k,'/vendor/') === false
|
||||
) {
|
||||
$datei = __DIR__.$k;
|
||||
if(!file_exists($datei)) {
|
||||
continue;
|
||||
}
|
||||
$fh = fopen($datei, 'r');
|
||||
if(!$fh) {
|
||||
continue;
|
||||
}
|
||||
$f_ind = -1;
|
||||
if(isset($lines)) {
|
||||
unset($lines);
|
||||
}
|
||||
$i = -1;
|
||||
while(($line = fgets($fh)) !== false) {
|
||||
$i++;
|
||||
$lines[$i] = $line;
|
||||
if(isset($funktions_ind) && isset($funktions_ind[$k])) {
|
||||
foreach($funktions_ind[$k] as $k2 => $v2) {
|
||||
if($v2 + 5 >= $i) {
|
||||
$funktions[$k][$k2][] = $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(strpos($line, 'function') !== false) {
|
||||
$f_ind++;
|
||||
for($j = $i-5; $j <= $i; $j++) {
|
||||
if($j > -1) {
|
||||
$funktions[$k][$f_ind][] = $lines[$j];
|
||||
}
|
||||
}
|
||||
$funktions_ind[$k][$f_ind] = $i;
|
||||
}
|
||||
}
|
||||
fclose($fh);
|
||||
}
|
||||
}
|
||||
}
|
||||
$parameter['version'] = @$this->conf['version'];
|
||||
if(isset($funktions)) {
|
||||
$parameter['funktionen'] = $funktions;
|
||||
$this->Request("versionen", $parameter);
|
||||
}
|
||||
|
||||
if (is_file(__DIR__ . '/marketing_labels.txt')) {
|
||||
$parameter['marketing_labels'] = explode(',', (string)@file_get_contents(__DIR__ . '/marketing_labels.txt'));
|
||||
}
|
||||
$result = $this->Request("md5list",$parameter);
|
||||
|
||||
if($result==="ERROR") {
|
||||
echo "Updates: ERROR FROM SERVER (Perhaps a wrong license?)\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$rows = explode(";",$result);
|
||||
|
||||
if(count($rows)>0)
|
||||
{
|
||||
foreach($rows as $value)
|
||||
{
|
||||
unset($single_row);
|
||||
$single_row = explode(":",$value);
|
||||
|
||||
if(count($single_row)>=2 && strlen($single_row[0])>3 && strlen($single_row[1])>3)
|
||||
{
|
||||
|
||||
$filename = $single_row[0];
|
||||
$file = __DIR__."/".$single_row[0];
|
||||
$md5sum = $single_row[1];
|
||||
|
||||
$parameter['file']=$filename;
|
||||
$parameter['md5sum']=$md5sum;
|
||||
|
||||
|
||||
if($file==="./upgradesystemclient.php")
|
||||
{
|
||||
|
||||
}
|
||||
else if(is_file($file))
|
||||
{
|
||||
// pruefe md5sum
|
||||
if(md5_file($file)!=$md5sum)
|
||||
{
|
||||
// wenn update dann UPD_
|
||||
echo "update <- $file\n";
|
||||
$result = $this->Request("getfile",$parameter);
|
||||
$output = (base64_decode($result));
|
||||
//$output = preg_replace('/[^(\x22-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."UPD", $output);
|
||||
/*
|
||||
$fp = fopen($file."UPD","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
// pruefsuemme neu berechnen wenn passt umbenennen und ins archiv
|
||||
echo md5_file($file."UPD");
|
||||
echo "-".$md5sum."\n";
|
||||
if(md5_file($file."UPD")==$md5sum)
|
||||
{
|
||||
echo "update ok $file\n";
|
||||
rename($file."UPD",$file);
|
||||
}
|
||||
}
|
||||
} else if($file!="") {
|
||||
echo "datei <- $file\n";
|
||||
// pruefe ob es verzeichnis gibt
|
||||
$verzeichnis = dirname($file);
|
||||
if(!is_dir($verzeichnis))
|
||||
{
|
||||
echo "verzeichnis <- $verzeichnis\n";
|
||||
mkdir($verzeichnis,0777,true);
|
||||
}
|
||||
$result = $this->Request("getfile",$parameter);
|
||||
$output = base64_decode($result);
|
||||
//$output = iconv("UTF-8","ISO-8859-1//IGNORE",$output);
|
||||
//$output = iconv("ISO-8859-1","UTF-8",$output);
|
||||
//$output = preg_replace('/[^(\x20-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."NEW", $output);
|
||||
/*$fp = fopen($file."NEW","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
if(md5_file($file."NEW")==$md5sum)
|
||||
{
|
||||
echo "datei ok $file\n";
|
||||
rename($file."NEW",$file);
|
||||
} else {
|
||||
// echo "datei XX $file local: ".md5_file($file."NEW")." remote: ".$md5sum."\n";
|
||||
|
||||
}
|
||||
} else { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//pruefe, update, lege verzeichnis an, lege datei an, loesche datei????
|
||||
|
||||
|
||||
|
||||
// download all files with UPD_ prefix
|
||||
|
||||
|
||||
// get md5 liste von server
|
||||
|
||||
// pruefe ob alle dateien passen, wenn ja dann alle updaten am schluss
|
||||
|
||||
// wenn nein fehler abbrechen und ganzen prozess nochmal starten
|
||||
|
||||
//echo $md5sums;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function CheckUpdateModules()
|
||||
{
|
||||
$parameter['version']=@$this->conf['version'];
|
||||
$result = $this->Request("md5listmodules",$parameter);
|
||||
|
||||
if($result=="ERROR") { echo "Modules: ERROR FROM SERVER (Perhaps a wrong license?)\n"; return;}
|
||||
|
||||
$rows = explode(";",$result);
|
||||
|
||||
if(count($rows)>0)
|
||||
{
|
||||
foreach($rows as $value)
|
||||
{
|
||||
unset($single_row);
|
||||
$single_row = explode(":",$value);
|
||||
|
||||
if(count($single_row)>=2 && strlen($single_row[0])>3 && strlen($single_row[1])>3)
|
||||
{
|
||||
$filename = $single_row[0];
|
||||
$file = dirname(__FILE__)."/".$single_row[0];
|
||||
$md5sum = $single_row[1];
|
||||
|
||||
$parameter['file']=$filename;
|
||||
$parameter['md5sum']=$md5sum;
|
||||
|
||||
if($file=="./upgradesystemclient.php")
|
||||
{
|
||||
|
||||
}
|
||||
else if(is_file($file))
|
||||
{
|
||||
// pruefe md5sum
|
||||
if(md5_file($file)!=$md5sum)
|
||||
{
|
||||
// wenn update dann UPD_
|
||||
echo "update (M) <- $file\n";
|
||||
$result = $this->Request("getfilemodules",$parameter);
|
||||
$output = (base64_decode($result));
|
||||
//$output = preg_replace('/[^(\x22-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."UPD", $output);
|
||||
/*
|
||||
$fp = fopen($file."UPD","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
// pruefsuemme neu berechnen wenn passt umbenennen und ins archiv
|
||||
echo md5_file($file."UPD");
|
||||
echo "-".$md5sum."\n";
|
||||
if(md5_file($file."UPD")==$md5sum)
|
||||
{
|
||||
echo "update (M) ok $file\n";
|
||||
rename($file."UPD",$file);
|
||||
}
|
||||
}
|
||||
} else if($file!="") {
|
||||
echo "datei (M) <- $file\n";
|
||||
// pruefe ob es verzeichnis gibt
|
||||
$verzeichnis = dirname($file);
|
||||
if(!is_dir($verzeichnis))
|
||||
{
|
||||
echo "verzeichnis (M) <- $verzeichnis\n";
|
||||
mkdir($verzeichnis,0777,true);
|
||||
}
|
||||
$result = $this->Request("getfilemodules",$parameter);
|
||||
$output = base64_decode($result);
|
||||
//$output = iconv("UTF-8","ISO-8859-1//IGNORE",$output);
|
||||
//$output = iconv("ISO-8859-1","UTF-8",$output);
|
||||
//$output = preg_replace('/[^(\x20-\x7F)\x0A]*/','', $output);
|
||||
file_put_contents($file."NEW", $output);
|
||||
/*$fp = fopen($file."NEW","wb+");
|
||||
fwrite($fp,base64_decode($result));
|
||||
fclose($fp);
|
||||
*/
|
||||
if(md5_file($file."NEW")==$md5sum)
|
||||
{
|
||||
echo "datei (M) ok $file\n";
|
||||
rename($file."NEW",$file);
|
||||
} else {
|
||||
// echo "datei XX $file local: ".md5_file($file."NEW")." remote: ".$md5sum."\n";
|
||||
|
||||
}
|
||||
} else { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//pruefe, update, lege verzeichnis an, lege datei an, loesche datei????
|
||||
|
||||
|
||||
|
||||
// download all files with UPD_ prefix
|
||||
|
||||
|
||||
// get md5 liste von server
|
||||
|
||||
// pruefe ob alle dateien passen, wenn ja dann alle updaten am schluss
|
||||
|
||||
// wenn nein fehler abbrechen und ganzen prozess nochmal starten
|
||||
|
||||
//echo $md5sums;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function sendSetDevelopmentStatus($data)
|
||||
{
|
||||
$parameter['version'] = isset($this->conf['version']) ? $this->conf['version']: null;
|
||||
$parameter['data'] = $data;
|
||||
|
||||
return $this->Request('setdevelopmentversion', $parameter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function sendSetBetaStatus($data)
|
||||
{
|
||||
$parameter['version'] = isset($this->conf['version']) ? $this->conf['version']: null;
|
||||
$parameter['data'] = $data;
|
||||
|
||||
return $this->Request('setbeta', $parameter);
|
||||
}
|
||||
|
||||
|
||||
function CheckUpdateKey()
|
||||
{
|
||||
$parameter['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
|
||||
if(!empty($_SERVER['HTTP_HOST']) && (empty($parameter['SERVER_NAME']) || $parameter['SERVER_NAME'] === '_')) {
|
||||
$parameter['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
|
||||
}
|
||||
$parameter['phpversion'] = (String)phpversion();
|
||||
$parameter['mysqlversion'] = $this->app->DB->GetVersion();
|
||||
$parameter['version']=@$this->conf['version'];
|
||||
$result = $this->Request('md5listcustom',$parameter);
|
||||
|
||||
if($result==='ERROR') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$rows = explode(';',$result);
|
||||
|
||||
$return = false;
|
||||
|
||||
if(count($rows) <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($rows as $value) {
|
||||
unset($single_row);
|
||||
$single_row = explode(':',$value);
|
||||
|
||||
if(count($single_row)>=2 && strlen($single_row[0])>3 && strlen($single_row[1])>3) {
|
||||
$filename = $single_row[0];
|
||||
$file = __DIR__.'/'.$single_row[0];
|
||||
$md5sum = $single_row[1];
|
||||
|
||||
$parameter['file']=$filename;
|
||||
$parameter['md5sum']=$md5sum;
|
||||
|
||||
$fileOk = $filename === './key.php';
|
||||
if(!$fileOk && strpos($md5sum, 'DEL') === false) {
|
||||
if($filename === './www/themes/new/templates/loginslider.tpl') {
|
||||
$fileOk = true;
|
||||
}
|
||||
elseif(strpos($filename ,'./www/themes/new/templates/') === 0
|
||||
&& (substr($filename,-4) === '.jpg' || substr($filename,-5) === '.jpeg')
|
||||
&& strpos($filename, '/', 28) === false) {
|
||||
$fileOk = true;
|
||||
}
|
||||
}
|
||||
if(!$fileOk) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(is_file($file)) {
|
||||
|
||||
// pruefe md5sum
|
||||
if(md5_file($file)!=$md5sum) {
|
||||
// wenn update dann UPD_
|
||||
$result = $this->Request('getfilecustom',$parameter);
|
||||
$output = (base64_decode($result));
|
||||
file_put_contents($file.'UPD', $output);
|
||||
|
||||
if(md5_file($file.'UPD')==$md5sum && $result) {
|
||||
$return = rename($file.'UPD',$file);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$return = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// pruefe ob es verzeichnis gibt
|
||||
$verzeichnis = dirname($file);
|
||||
if(!is_dir($verzeichnis) && !mkdir($verzeichnis,0777,true) && !is_dir($verzeichnis)) {
|
||||
}
|
||||
$result = $this->Request('getfilecustom',$parameter);
|
||||
$output = base64_decode($result);
|
||||
file_put_contents($file.'NEW', $output);
|
||||
if(md5_file($file.'NEW')==$md5sum) {
|
||||
$return = rename($file.'NEW',$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
function DownloadUpdate()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
function CheckDownloadedUpdate()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
function ExecuteUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
function Request($command,$parameter)
|
||||
{
|
||||
global $erp;
|
||||
$auth['serial']=$this->app->erp->Firmendaten("lizenz");//$this->conf['serial'];
|
||||
$auth['authkey']=$this->app->erp->Firmendaten("schluessel");//$this->conf['authkey'];
|
||||
$auth['SERVER_NAME'] = (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] != '')?$_SERVER['SERVER_NAME']:(isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:'');
|
||||
$auth = base64_encode(json_encode($auth));
|
||||
$parameter = base64_encode(json_encode($parameter));
|
||||
$client = new HttpClientUpgrade($this->conf['host'],$this->conf['port']);
|
||||
$client->post('/upgradesystem.php', array( "authjson" => $auth, "parameterjson"=>$parameter,"command"=>"$command" ));
|
||||
$pageContents = $client->getContent();
|
||||
return $pageContents;
|
||||
}
|
||||
|
||||
function dir_rekursiv($verzeichnis)
|
||||
{
|
||||
$handle = opendir($verzeichnis);
|
||||
|
||||
while ($datei = readdir($handle))
|
||||
{
|
||||
if ($datei != "." && $datei != "..")
|
||||
{
|
||||
if (is_dir($verzeichnis.$datei)) // Wenn Verzeichniseintrag ein Verzeichnis ist
|
||||
{
|
||||
// Erneuter Funktionsaufruf, um das aktuelle Verzeichnis auszulesen
|
||||
$this->dir_rekursiv($verzeichnis.$datei.'/');
|
||||
}
|
||||
else
|
||||
{
|
||||
// Wenn Verzeichnis-Eintrag eine Datei ist, diese ausgeben
|
||||
$this->localmd5sums[$verzeichnis.$datei] = md5_file($verzeichnis.$datei);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Version 0.9, 6th April 2003 - Simon Willison ( http://simon.incutio.com/ )
|
||||
Manual: http://scripts.incutio.com/httpclient/
|
||||
*/
|
||||
|
||||
class HttpClientUpgrade {
|
||||
// Request vars
|
||||
var $host;
|
||||
var $port;
|
||||
var $path;
|
||||
var $method;
|
||||
var $postdata = '';
|
||||
var $cookies = array();
|
||||
var $referer;
|
||||
var $accept = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,image/jpeg,image/gif,*/*';
|
||||
var $accept_encoding = 'gzip';
|
||||
var $accept_language = 'en-us';
|
||||
var $user_agent = 'Incutio HttpClientUpgrade v0.9';
|
||||
// Options
|
||||
var $timeout = 20;
|
||||
var $use_gzip = true;
|
||||
var $persist_cookies = true; // If true, received cookies are placed in the $this->cookies array ready for the next request
|
||||
// Note: This currently ignores the cookie path (and time) completely. Time is not important,
|
||||
// but path could possibly lead to security problems.
|
||||
var $persist_referers = true; // For each request, sends path of last request as referer
|
||||
var $debug = false;
|
||||
var $handle_redirects = true; // Auaomtically redirect if Location or URI header is found
|
||||
var $max_redirects = 5;
|
||||
var $headers_only = false; // If true, stops receiving once headers have been read.
|
||||
// Basic authorization variables
|
||||
var $username;
|
||||
var $password;
|
||||
// Response vars
|
||||
var $status;
|
||||
var $headers = array();
|
||||
var $content = '';
|
||||
var $errormsg;
|
||||
// Tracker variables
|
||||
var $redirect_count = 0;
|
||||
var $cookie_host = '';
|
||||
function __construct($host, $port=80) {
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
}
|
||||
function get($path, $data = false) {
|
||||
$this->path = $path;
|
||||
$this->method = 'GET';
|
||||
if ($data) {
|
||||
$this->path .= '?'.$this->buildQueryString($data);
|
||||
}
|
||||
return $this->doRequest();
|
||||
}
|
||||
function post($path, $data) {
|
||||
$this->path = $path;
|
||||
$this->method = 'POST';
|
||||
$this->postdata = $this->buildQueryString($data);
|
||||
return $this->doRequest();
|
||||
}
|
||||
function buildQueryString($data) {
|
||||
$querystring = '';
|
||||
if (is_array($data)) {
|
||||
// Change data in to postable data
|
||||
foreach ($data as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
foreach ($val as $val2) {
|
||||
$querystring .= urlencode($key).'='.urlencode($val2).'&';
|
||||
}
|
||||
} else {
|
||||
$querystring .= urlencode($key).'='.urlencode($val).'&';
|
||||
}
|
||||
}
|
||||
$querystring = substr($querystring, 0, -1); // Eliminate unnecessary &
|
||||
} else {
|
||||
$querystring = $data;
|
||||
}
|
||||
return $querystring;
|
||||
}
|
||||
function doRequest() {
|
||||
// Performs the actual HTTP request, returning true or false depending on outcome
|
||||
// check if port is available
|
||||
if(!fsockopen("ssl://".$this->host, $this->port, $errno, $errstr, $this->timeout) && $this->port==443)
|
||||
{
|
||||
$this->port=80;
|
||||
}
|
||||
|
||||
if($this->port==443)
|
||||
$url = "ssl://".$this->host;
|
||||
else
|
||||
$url = $this->host;
|
||||
|
||||
if (!$fp = @fsockopen($url, $this->port, $errno, $errstr, $this->timeout)) {
|
||||
// Set error message
|
||||
switch($errno) {
|
||||
case -3:
|
||||
$this->errormsg = 'Socket creation failed (-3)';
|
||||
case -4:
|
||||
$this->errormsg = 'DNS lookup failure (-4)';
|
||||
case -5:
|
||||
$this->errormsg = 'Connection refused or timed out (-5)';
|
||||
default:
|
||||
$this->errormsg = 'Connection failed ('.$errno.')';
|
||||
$this->errormsg .= ' '.$errstr;
|
||||
$this->debug($this->errormsg);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
socket_set_timeout($fp, $this->timeout);
|
||||
$request = $this->buildRequest();
|
||||
$this->debug('Request', $request);
|
||||
fwrite($fp, $request);
|
||||
// Reset all the variables that should not persist between requests
|
||||
$this->headers = array();
|
||||
$this->content = '';
|
||||
$this->errormsg = '';
|
||||
// Set a couple of flags
|
||||
$inHeaders = true;
|
||||
$atStart = true;
|
||||
// Now start reading back the response
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp, 4096);
|
||||
if ($atStart) {
|
||||
// Deal with first line of returned data
|
||||
$atStart = false;
|
||||
if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
|
||||
$this->errormsg = "Status code line invalid: ".htmlentities($line);
|
||||
$this->debug($this->errormsg);
|
||||
//return false;
|
||||
}
|
||||
$http_version = $m[1]; // not used
|
||||
$this->status = $m[2];
|
||||
$status_string = $m[3]; // not used
|
||||
$this->debug(trim($line));
|
||||
continue;
|
||||
}
|
||||
if ($inHeaders) {
|
||||
if (trim($line) == '') {
|
||||
$inHeaders = false;
|
||||
$this->debug('Received Headers', $this->headers);
|
||||
if ($this->headers_only) {
|
||||
break; // Skip the rest of the input
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) {
|
||||
// Skip to the next header
|
||||
continue;
|
||||
}
|
||||
$key = strtolower(trim($m[1]));
|
||||
$val = trim($m[2]);
|
||||
// Deal with the possibility of multiple headers of same name
|
||||
if (isset($this->headers[$key])) {
|
||||
if (is_array($this->headers[$key])) {
|
||||
$this->headers[$key][] = $val;
|
||||
} else {
|
||||
$this->headers[$key] = array($this->headers[$key], $val);
|
||||
}
|
||||
} else {
|
||||
$this->headers[$key] = $val;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// We're not in the headers, so append the line to the contents
|
||||
$this->content .= $line;
|
||||
}
|
||||
fclose($fp);
|
||||
// If data is compressed, uncompress it
|
||||
if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] == 'gzip') {
|
||||
$this->debug('Content is gzip encoded, unzipping it');
|
||||
$this->content = substr($this->content, 10); // See http://www.php.net/manual/en/function.gzencode.php
|
||||
$this->content = gzinflate($this->content);
|
||||
}
|
||||
// If $persist_cookies, deal with any cookies
|
||||
if ($this->persist_cookies && isset($this->headers['set-cookie']) && $this->host == $this->cookie_host) {
|
||||
$cookies = $this->headers['set-cookie'];
|
||||
if (!is_array($cookies)) {
|
||||
$cookies = array($cookies);
|
||||
}
|
||||
foreach ($cookies as $cookie) {
|
||||
if (preg_match('/([^=]+)=([^;]+);/', $cookie, $m)) {
|
||||
$this->cookies[$m[1]] = $m[2];
|
||||
}
|
||||
}
|
||||
// Record domain of cookies for security reasons
|
||||
$this->cookie_host = $this->host;
|
||||
}
|
||||
// If $persist_referers, set the referer ready for the next request
|
||||
if ($this->persist_referers) {
|
||||
$this->debug('Persisting referer: '.$this->getRequestURL());
|
||||
$this->referer = $this->getRequestURL();
|
||||
}
|
||||
// Finally, if handle_redirects and a redirect is sent, do that
|
||||
if ($this->handle_redirects) {
|
||||
if (++$this->redirect_count >= $this->max_redirects) {
|
||||
$this->errormsg = 'Number of redirects exceeded maximum ('.$this->max_redirects.')';
|
||||
$this->debug($this->errormsg);
|
||||
$this->redirect_count = 0;
|
||||
return false;
|
||||
}
|
||||
$location = isset($this->headers['location']) ? $this->headers['location'] : '';
|
||||
$uri = isset($this->headers['uri']) ? $this->headers['uri'] : '';
|
||||
if ($location || $uri) {
|
||||
$url = parse_url($location.$uri);
|
||||
// This will FAIL if redirect is to a different site
|
||||
return $this->get($url['path']);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function buildRequest() {
|
||||
$headers = array();
|
||||
$headers[] = "{$this->method} {$this->path} HTTP/1.0"; // Using 1.1 leads to all manner of problems, such as "chunked" encoding
|
||||
$headers[] = "Host: {$this->host}";
|
||||
$headers[] = "User-Agent: {$this->user_agent}";
|
||||
$headers[] = "Accept: {$this->accept}";
|
||||
if ($this->use_gzip) {
|
||||
$headers[] = "Accept-encoding: {$this->accept_encoding}";
|
||||
}
|
||||
$headers[] = "Accept-language: {$this->accept_language}";
|
||||
if ($this->referer) {
|
||||
$headers[] = "Referer: {$this->referer}";
|
||||
}
|
||||
// Cookies
|
||||
if ($this->cookies) {
|
||||
$cookie = 'Cookie: ';
|
||||
foreach ($this->cookies as $key => $value) {
|
||||
$cookie .= "$key=$value; ";
|
||||
}
|
||||
$headers[] = $cookie;
|
||||
}
|
||||
// Basic authentication
|
||||
if ($this->username && $this->password) {
|
||||
$headers[] = 'Authorization: BASIC '.base64_encode($this->username.':'.$this->password);
|
||||
}
|
||||
// If this is a POST, set the content type and length
|
||||
if ($this->postdata) {
|
||||
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
||||
$headers[] = 'Content-Length: '.strlen($this->postdata);
|
||||
}
|
||||
$request = implode("\r\n", $headers)."\r\n\r\n".$this->postdata;
|
||||
return $request;
|
||||
}
|
||||
function getStatus() {
|
||||
return $this->status;
|
||||
}
|
||||
function getContent() {
|
||||
return $this->content;
|
||||
}
|
||||
function getHeaders() {
|
||||
return $this->headers;
|
||||
}
|
||||
function getHeader($header) {
|
||||
$header = strtolower($header);
|
||||
if (isset($this->headers[$header])) {
|
||||
return $this->headers[$header];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function getError() {
|
||||
return $this->errormsg;
|
||||
}
|
||||
function getCookies() {
|
||||
return $this->cookies;
|
||||
}
|
||||
function getRequestURL() {
|
||||
$url = 'http://'.$this->host;
|
||||
if ($this->port != 80) {
|
||||
$url .= ':'.$this->port;
|
||||
}
|
||||
$url .= $this->path;
|
||||
return $url;
|
||||
}
|
||||
// Setter methods
|
||||
function setUserAgent($string) {
|
||||
$this->user_agent = $string;
|
||||
}
|
||||
function setAuthorization($username, $password) {
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
}
|
||||
function setCookies($array) {
|
||||
$this->cookies = $array;
|
||||
}
|
||||
// Option setting methods
|
||||
function useGzip($boolean) {
|
||||
$this->use_gzip = $boolean;
|
||||
}
|
||||
function setPersistCookies($boolean) {
|
||||
$this->persist_cookies = $boolean;
|
||||
}
|
||||
function setPersistReferers($boolean) {
|
||||
$this->persist_referers = $boolean;
|
||||
}
|
||||
function setHandleRedirects($boolean) {
|
||||
$this->handle_redirects = $boolean;
|
||||
}
|
||||
function setMaxRedirects($num) {
|
||||
$this->max_redirects = $num;
|
||||
}
|
||||
function setHeadersOnly($boolean) {
|
||||
$this->headers_only = $boolean;
|
||||
}
|
||||
function setDebug($boolean) {
|
||||
$this->debug = $boolean;
|
||||
}
|
||||
// "Quick" static methods
|
||||
function quickGet($url) {
|
||||
$bits = parse_url($url);
|
||||
$host = $bits['host'];
|
||||
$port = isset($bits['port']) ? $bits['port'] : 80;
|
||||
$path = isset($bits['path']) ? $bits['path'] : '/';
|
||||
if (isset($bits['query'])) {
|
||||
$path .= '?'.$bits['query'];
|
||||
}
|
||||
$client = new HttpClientUpgrade($host, $port);
|
||||
if (!$client->get($path)) {
|
||||
return false;
|
||||
} else {
|
||||
return $client->getContent();
|
||||
}
|
||||
}
|
||||
function quickPost($url, $data) {
|
||||
$bits = parse_url($url);
|
||||
$host = $bits['host'];
|
||||
$port = isset($bits['port']) ? $bits['port'] : 80;
|
||||
$path = isset($bits['path']) ? $bits['path'] : '/';
|
||||
$client = new HttpClientUpgrade($host, $port);
|
||||
if (!$client->post($path, $data)) {
|
||||
return false;
|
||||
} else {
|
||||
return $client->getContent();
|
||||
}
|
||||
}
|
||||
function debug($msg, $object = false) {
|
||||
if ($this->debug) {
|
||||
print '<div style="border: 1px solid red; padding: 0.5em; margin: 0.5em;"><strong>HttpClientUpgrade Debug:</strong> '.$msg;
|
||||
if ($object) {
|
||||
ob_start();
|
||||
print_r($object);
|
||||
$content = htmlentities(ob_get_contents());
|
||||
ob_end_clean();
|
||||
print '<pre>'.$content.'</pre>';
|
||||
}
|
||||
print '</div>';
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -3017,7 +3017,7 @@ class Shopimporter_Shopware6 extends ShopimporterBase
|
||||
|
||||
$ordersToProcess = $this->getOrdersToProcess($this->getOrderSearchLimit());
|
||||
|
||||
return (!empty(count($ordersToProcess['data'])?count($ordersToProcess['data']):0);
|
||||
return (!empty(count($ordersToProcess['data'])?count($ordersToProcess['data']):0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,8 +90,6 @@ class Welcome
|
||||
$this->app->ActionHandler("mobileapps","WelcomeMobileApps");
|
||||
$this->app->ActionHandler("spooler","WelcomeSpooler");
|
||||
$this->app->ActionHandler("redirect","WelcomeRedirect");
|
||||
$this->app->ActionHandler("upgrade","WelcomeUpgrade");
|
||||
$this->app->ActionHandler("upgradedb","WelcomeUpgradeDB");
|
||||
$this->app->ActionHandler("startseite","WelcomeStartseite");
|
||||
|
||||
$this->app->ActionHandler("addnote","WelcomeAddNote");
|
||||
@ -886,8 +884,6 @@ $this->app->Tpl->Add('TODOFORUSER',"<tr><td width=\"90%\">".$tmp[$i]['aufgabe'].
|
||||
$this->app->Tpl->Parse('AUFGABENPOPUP','aufgaben_popup.tpl');
|
||||
// ENDE:Aufgabe-Bearbeiten-Popup
|
||||
|
||||
$this->XentralUpgradeFeed();
|
||||
|
||||
$this->app->erp->RunHook('welcome_start', 1 , $this);
|
||||
|
||||
// Xentral 20 database compatibility
|
||||
@ -1113,97 +1109,6 @@ $this->app->Tpl->Add('TODOFORUSER',"<tr><td width=\"90%\">".$tmp[$i]['aufgabe'].
|
||||
$this->app->erp->ExitWawi();
|
||||
}
|
||||
|
||||
protected function XentralUpgradeFeed($max=3)
|
||||
{
|
||||
if(!$this->app->Conf->WFoffline)
|
||||
{
|
||||
$version = $this->app->erp->Version();
|
||||
$revision = $this->app->erp->Revision();
|
||||
/*
|
||||
$tmp = explode('.',$revision);
|
||||
$branch = strtolower($version).'_'.$tmp[0].'.'.$tmp[1];
|
||||
|
||||
$BLOGURL = "https://{$this->app->Conf->updateHost}/wawision_2016.php?branch=".$branch;
|
||||
$CACHEFILE = $this->app->erp->GetTMP().md5($BLOGURL);
|
||||
$CACHEFILE2 = $this->app->erp->GetTMP().md5($BLOGURL).'2';
|
||||
if(!file_exists($CACHEFILE2))
|
||||
{
|
||||
if(file_exists($CACHEFILE)){
|
||||
@unlink($CACHEFILE);
|
||||
}
|
||||
}else{
|
||||
if(trim(file_get_contents($CACHEFILE2)) != $version.$revision){
|
||||
@unlink($CACHEFILE);
|
||||
}
|
||||
}
|
||||
$CACHETIME = 4; # hours
|
||||
|
||||
if(!file_exists($CACHEFILE) || ((time() - filemtime($CACHEFILE)) > 3600 * $CACHETIME)) {
|
||||
if($feed_contents = @file_get_contents($BLOGURL)) {
|
||||
$fp = fopen($CACHEFILE, 'w');
|
||||
fwrite($fp, $feed_contents);
|
||||
fclose($fp);
|
||||
@file_put_contents($CACHEFILE2, $version.$revision);
|
||||
}
|
||||
}
|
||||
$feed_contents = file_get_contents($CACHEFILE);
|
||||
|
||||
$xml = simplexml_load_string($feed_contents);
|
||||
$json = json_encode($xml);
|
||||
$array = json_decode($json,TRUE);
|
||||
$found = false;
|
||||
$version_revision = null;
|
||||
include dirname(dirname(__DIR__)) .'/version.php';
|
||||
if($version_revision != '') {
|
||||
$ra = explode('.', $version_revision);
|
||||
if(isset($ra[2]) && $ra[2] != '') {
|
||||
$itemsCount = isset($array['channel']['item'])?count($array['channel']['item']):0;
|
||||
for($i = 0; $i< $itemsCount; $i++) {
|
||||
if($found !== false) {
|
||||
unset($array['channel']['item'][$i]);
|
||||
}
|
||||
else{
|
||||
$rev = isset($array['channel']['item'][$i]['guid'])?(string)$array['channel']['item'][$i]['guid']:'';
|
||||
if($rev === '') {
|
||||
$rev = trim(trim($array['channel']['item'][$i]['title']),')');
|
||||
$rev = trim(substr($rev, strrpos($rev, '(')+4));
|
||||
}
|
||||
if($rev == $ra[2]) {
|
||||
$found = $i;
|
||||
unset($array['channel']['item'][$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!empty($array['channel']) && !empty($array['channel']['item']) && is_array($array['channel']['item'])) {
|
||||
$itemsCount = isset($array['channel']['item'])?count($array['channel']['item']):0;
|
||||
for($i = 0; $i < $itemsCount; $i++) {
|
||||
$this->app->Tpl->Add('WAIWISONFEEDS','<tr><td><b>'.$array['channel']['item'][$i]['title']
|
||||
.'</b></td></tr><tr><td style="font-size:7pt">'.$array['channel']['item'][$i]['description'].'</td></tr>');
|
||||
}
|
||||
}
|
||||
elseif($found !== false){
|
||||
$this->app->Tpl->Add('WAIWISONFEEDS','<tr><td><br><b>Ihre Version ist auf dem neusten Stand.</b></td></tr>');
|
||||
}
|
||||
$version = $this->app->erp->Version();
|
||||
if($version==='OSS') {
|
||||
$this->app->Tpl->Set('INFO', '<br>Sie verwenden die Open-Source Version.');
|
||||
$this->app->Tpl->Set('TESTBUTTON','<div class="btn">
|
||||
<a href="index.php?module=appstore&action=testen" class="button" target="_blank">14 Tage Business testen</a>
|
||||
</div>');
|
||||
}
|
||||
$this->app->Tpl->Set('RAND',md5(microtime(true)));
|
||||
if(!$this->app->erp->RechteVorhanden('welcome','changelog')) {
|
||||
$this->app->Tpl->Set('BEFORECHANGELOG', '<!--');
|
||||
$this->app->Tpl->Set('AFTERCHANGELOG', '-->');
|
||||
}
|
||||
$this->app->erp->RunHook('welcome_news');
|
||||
$this->app->Tpl->Parse('WELCOMENEWS','welcome_news.tpl');
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function WelcomeAddPinwand()
|
||||
{
|
||||
@ -1668,156 +1573,6 @@ $this->app->Tpl->Add('TODOFORUSER',"<tr><td width=\"90%\">".$tmp[$i]['aufgabe'].
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function WelcomeUpgrade()
|
||||
{
|
||||
$this->app->erp->MenuEintrag('index.php?module=welcome&action=start','zurück zur Startseite');
|
||||
$this->app->erp->Headlines('Update für Xentral');
|
||||
|
||||
$this->app->Tpl->Set('STARTBUTTON','<!--');
|
||||
$this->app->Tpl->Set('ENDEBUTTON','-->');
|
||||
|
||||
$lizenz = $this->app->erp->Firmendaten('lizenz');
|
||||
$schluessel = $this->app->erp->Firmendaten('schluessel');
|
||||
if($lizenz=='' || $schluessel=='')
|
||||
{
|
||||
if(is_file('../wawision.inc.php'))
|
||||
{
|
||||
include_once '../wawision.inc.php';
|
||||
$this->app->erp->FirmendatenSet('lizenz',$WAWISION['serial']);
|
||||
$this->app->erp->FirmendatenSet('schluessel',$WAWISION['authkey']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->app->erp->MenuEintrag('index.php?module=welcome&action=upgrade','Update');
|
||||
$this->XentralUpgradeFeed(5);
|
||||
$result = '';
|
||||
if($this->app->Secure->GetPOST('upgrade'))
|
||||
{
|
||||
ob_start();
|
||||
// dringend nacheinander, sonst wird das alte upgrade nur ausgefuehrt
|
||||
if(!is_dir('.svn'))
|
||||
{
|
||||
echo "new update system\r\n";
|
||||
include '../upgradesystemclient2_include.php';
|
||||
} else {
|
||||
echo "Update in Entwicklungsversion\r\n";
|
||||
}
|
||||
|
||||
$result .= "\r\n>>>>>>Bitte klicken Sie jetzt auf \"Weiter mit Schritt 2\"<<<<<<\r\n\r\n";
|
||||
$result .= ob_get_contents();
|
||||
$result .= "\r\n>>>>>>Bitte klicken Sie jetzt auf \"Weiter mit Schritt 2\"<<<<<<\r\n\r\n";
|
||||
ob_end_clean();
|
||||
|
||||
if(is_dir('.svn'))
|
||||
{
|
||||
$version_revision = 'SVN';
|
||||
} else {
|
||||
include '../version.php';
|
||||
}
|
||||
|
||||
$result .="\r\nIhre Version: $version_revision\r\n";
|
||||
|
||||
} else {
|
||||
$result .=">>>>>Bitte auf \"Dateien aktualisieren jetzt starten\" klicken<<<<<<\r\n";
|
||||
}
|
||||
|
||||
if($this->app->erp->Firmendaten('version')==''){
|
||||
$this->app->erp->FirmendatenSet('version', $this->app->erp->RevisionPlain());
|
||||
}
|
||||
|
||||
$doc_root = preg_replace("!{$_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']); # ex: /var/www
|
||||
$path = preg_replace("!^{$doc_root}!", '', __DIR__);
|
||||
|
||||
$this->app->Tpl->Add('TAB1',"<h2>Schritt 1 von 2: Dateien aktualisieren</h2><table width=\"100%\"><tr valign=\"top\"><td width=\"70%\"><form action=\"\" method=\"post\" class=\"updateForm\"><input type=\"hidden\" name=\"upgrade\" value=\"1\">
|
||||
<textarea rows=\"15\" cols=\"90\">$result</textarea>
|
||||
<br><input type=\"submit\" value=\"Dateien aktualisieren jetzt starten\" name=\"upgrade\">
|
||||
<input type=\"button\" value=\"Weiter mit Schritt 2\" onclick=\"window.location.href='index.php?module=welcome&action=upgradedb'\">
|
||||
</form></td><td>[WELCOMENEWS]</td></tr></table>");
|
||||
|
||||
$this->app->Tpl->Parse('PAGE','tabview.tpl');
|
||||
}
|
||||
|
||||
public function WelcomeUpgradeDB()
|
||||
{
|
||||
$this->app->erp->MenuEintrag('index.php?module=welcome&action=start','zurück zur Startseite');
|
||||
$this->app->erp->Headlines('Update für Xentral');
|
||||
|
||||
$lizenz = $this->app->erp->Firmendaten('lizenz');
|
||||
$schluessel = $this->app->erp->Firmendaten('schluessel');
|
||||
if($lizenz=='' || $schluessel=='')
|
||||
{
|
||||
if(is_file('../wawision.inc.php'))
|
||||
{
|
||||
include_once '../wawision.inc.php';
|
||||
$this->app->erp->FirmendatenSet('lizenz',$WAWISION['serial']);
|
||||
$this->app->erp->FirmendatenSet('schluessel',$WAWISION['authkey']);
|
||||
}
|
||||
}
|
||||
$this->app->erp->MenuEintrag('index.php?module=welcome&action=upgradedb','Update');
|
||||
$this->XentralUpgradeFeed(5);
|
||||
$result = '';
|
||||
if($this->app->Secure->GetPOST('upgradedb'))
|
||||
{
|
||||
ob_start();
|
||||
// include("upgradesystemclient.php");
|
||||
$result .="Starte DB Update\r\n";
|
||||
$this->app->erp->UpgradeDatabase();
|
||||
$this->app->erp->check_column_missing_run = true;
|
||||
$this->app->erp->UpgradeDatabase();
|
||||
|
||||
if((!empty($this->app->erp->check_column_missing)?count($this->app->erp->check_column_missing):0) > 0)
|
||||
{
|
||||
$result .= "\r\n**** INFORMATION DATENBANK ****\r\n";
|
||||
foreach($this->app->erp->check_column_missing as $tablename=>$columns)
|
||||
{
|
||||
$result .= "\r\n";
|
||||
foreach($columns as $key=>$columname) {
|
||||
$result .= $tablename . ':' . $columname . "\r\n";
|
||||
}
|
||||
}
|
||||
$result .= "\r\n**** INFORMATION DATENBANK ****\r\n\r\n";
|
||||
}
|
||||
if((!empty($this->app->erp->check_index_missing)?count($this->app->erp->check_index_missing):0) > 0)
|
||||
{
|
||||
$result .= "\r\n**** INFORMATION DATENBANK INDEXE ****\r\n";
|
||||
foreach($this->app->erp->check_index_missing as $tablename=>$columns)
|
||||
{
|
||||
$result .= "\r\n";
|
||||
foreach($columns as $key=>$columname) {
|
||||
$result .= $tablename . ":" . $columname . "\r\n";
|
||||
}
|
||||
}
|
||||
$result .= "\r\n**** INFORMATION DATENBANK INDEXE ****\r\n\r\n";
|
||||
}
|
||||
$result .="Fertig DB Update\r\n";
|
||||
$result .="\r\n\r\nDas Datenbank Update wurde durchgeführt\r\n";
|
||||
$result .="\r\n>>>>>Sie können nun mit Xentral weiterarbeiten.<<<<<<\r\n";
|
||||
$result .= ob_get_contents();
|
||||
ob_end_clean();
|
||||
} else {
|
||||
$result .="\r\n>>>>>Bitte auf \"Datenbank Anpassungen jetzt durchführen\" klicken<<<<<<\r\n";
|
||||
}
|
||||
|
||||
if($this->app->erp->Firmendaten('version')==''){
|
||||
$this->app->erp->FirmendatenSet('version', $this->app->erp->RevisionPlain());
|
||||
}
|
||||
|
||||
$doc_root = preg_replace("!{$_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']); # ex: /var/www
|
||||
$path = preg_replace("!^{$doc_root}!", '', __DIR__);
|
||||
|
||||
$this->app->Tpl->Add('TAB1',"<h2>Schritt 2 von 2: Datenbank anpassen</h2><table width=\"100%\"><tr valign=\"top\"><td width=\"70%\"><form action=\"\" method=\"post\" class=\"updateForm\"><input type=\"hidden\" name=\"upgrade\" value=\"1\">
|
||||
<textarea rows=\"15\" cols=\"90\">$result</textarea>
|
||||
<br><input type=\"submit\" value=\"Datenbank Anpassungen jetzt durchführen\" name=\"upgradedb\">
|
||||
<input type=\"button\" value=\"Zurück\" onclick=\"window.location.href='index.php?module=welcome&action=upgrade'\">
|
||||
<input type=\"button\" value=\"Abbrechen\" onclick=\"window.location.href='index.php'\">
|
||||
</form></td><td>[WELCOMENEWS]</td></tr></table>");
|
||||
|
||||
$this->app->Tpl->Parse('PAGE','tabview.tpl');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function Termine($date)
|
||||
{
|
||||
$userid = $this->app->User->GetID();
|
||||
|
5420
www/update.php
5420
www/update.php
File diff suppressed because it is too large
Load Diff
886
www/update.tpl
886
www/update.tpl
@ -1,886 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta name="viewport" content="initial-scale=1, user-scalable=no">
|
||||
<meta http-equiv="cache-control" content="max-age=0" />
|
||||
<meta http-equiv="cache-control" content="no-cache" />
|
||||
<meta http-equiv="expires" content="0" />
|
||||
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
|
||||
<meta http-equiv="pragma" content="no-cache" />
|
||||
<script type="text/javascript" src="./jquery-update.js"></script>
|
||||
<script type="text/javascript" src="./jquery-ui-update.js"></script>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<!--<meta name="viewport" content="width=1200, user-scalable=yes" />-->
|
||||
<title>OpenXE Update</title>
|
||||
<link rel="stylesheet" type="text/css" href="./jquery-ui.min.css">
|
||||
|
||||
|
||||
<style type="text/css">
|
||||
@font-face{
|
||||
font-family: 'Inter';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
src: url('./themes/new/fonts/Inter-Regular.woff2?v=3.13') format("woff2"),
|
||||
url('./themes/new/fonts/Inter-Regular.woff?v=3.13') format("woff");
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Inter';
|
||||
font-style: italic;
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
src: url('./themes/new/fonts/Inter-Italic.woff2?v=3.13') format("woff2"),
|
||||
url('./themes/new/fonts/Inter-Italic.woff?v=3.13') format("woff");
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Inter';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
font-display: swap;
|
||||
src: url('./themes/new/fonts/Inter-Bold.woff2?v=3.13') format("woff2"),
|
||||
url('../themes/new/fonts/Inter-Bold.woff?v=3.13') format("woff");
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Inter';
|
||||
font-style: italic;
|
||||
font-weight: 700;
|
||||
font-display: swap;
|
||||
src: url('./themes/new/fonts/Inter-BoldItalic.woff2?v=3.13') format("woff2"),
|
||||
url('./themes/new/fonts/Inter-BoldItalic.woff?v=3.13') format("woff");
|
||||
}
|
||||
|
||||
|
||||
html, body {
|
||||
height:100%;
|
||||
}
|
||||
|
||||
body{
|
||||
background:#ffffff;
|
||||
font-family: 'Inter', Arial, Helvetica, sans-serif;
|
||||
font-size: 8pt;
|
||||
color: var(--grey);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
line-height:1.4;
|
||||
height: 100vh;
|
||||
|
||||
SCROLLBAR-FACE-COLOR: #fff;
|
||||
SCROLLBAR-HIGHLIGHT-COLOR: #fff;
|
||||
SCROLLBAR-SHADOW-COLOR: #fff;
|
||||
SCROLLBAR-ARROW-COLOR: #d4d4d4;
|
||||
SCROLLBAR-BASE-COLOR: #d4d4d4;
|
||||
SCROLLBAR-DARKSHADOW-COLOR: #d4d4d4;
|
||||
SCROLLBAR-TRACK-COLOR: #fff;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color:#000;
|
||||
text-align:center;
|
||||
width:100%;
|
||||
font-size:2em;
|
||||
padding-top:10px;
|
||||
}
|
||||
|
||||
DIV#footer {
|
||||
height:32px; margin-top:-6px;
|
||||
width:100%;
|
||||
text-align:center; color: #c9c9cb;}
|
||||
DIV#footer ul {
|
||||
list-style-type:none;width:100%; text-align:center;
|
||||
margin: 8px 0 0 0;
|
||||
padding: 0;
|
||||
}
|
||||
DIV#footer ul li { color:rgb(73, 73, 73);font-weight:bold;display: inline;
|
||||
padding-right: 8px;
|
||||
list-style: none;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
DIV#footer ul li a{ color:rgb(73, 73, 73);font-weight:bold;ext-decoration: none;
|
||||
}
|
||||
#page_container
|
||||
{
|
||||
/*border: 0px solid rgb(166, 201, 226);
|
||||
border-right:8px solid rgb(1, 143, 163);
|
||||
border-left:8px solid rgb(1, 143, 163);*/
|
||||
background-color:white;
|
||||
min-height: calc(100vh - 230px);
|
||||
/*border-bottom:8px solid rgb(1, 143, 163);*/
|
||||
overflow:auto
|
||||
}
|
||||
input[type="button"] {
|
||||
cursor:pointer;
|
||||
}
|
||||
input[type="submit"] {
|
||||
cursor:pointer;
|
||||
}
|
||||
img.details {
|
||||
cursor:pointer;
|
||||
}
|
||||
.button {
|
||||
width: 300px;
|
||||
height: 25px;
|
||||
background: rgb(120, 185, 93);
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
border-radius: 3px;
|
||||
color: white !important;
|
||||
font-weight: bold;
|
||||
top: 20px;
|
||||
position: relative;
|
||||
text-decoration:none;
|
||||
}
|
||||
.button2 {
|
||||
width: 300px;
|
||||
height: 25px;
|
||||
/*background: rgb(1, 143, 163);*/
|
||||
text-align: center;
|
||||
border-radius: 3px;
|
||||
color: white !important;
|
||||
font-weight: bold;
|
||||
text-decoration:none;
|
||||
border:1px solid rgb(120, 185, 93) !important;
|
||||
margin-left:5px;
|
||||
background: rgb(120, 185, 93);
|
||||
}
|
||||
|
||||
|
||||
input:disabled {
|
||||
background: #dddddd;
|
||||
}
|
||||
</style>
|
||||
[CSSLINKS]
|
||||
|
||||
|
||||
[JAVASCRIPT]
|
||||
<script type="application/javascript">
|
||||
|
||||
var aktprozent = 0;
|
||||
var updateval = '';
|
||||
|
||||
|
||||
function openPermissionbox(data)
|
||||
{
|
||||
var html = '';
|
||||
if(typeof data.FolderError != 'undefined')
|
||||
{
|
||||
html += '<h3>In folgenden Ordnern fehlen Schreibrechte</h3>';
|
||||
$(data.FolderError).each(function(k,v)
|
||||
{
|
||||
html += v+'<br />';
|
||||
});
|
||||
}
|
||||
if(typeof data.FileError != 'undefined')
|
||||
{
|
||||
html += '<h3>In folgenden Dateien fehlen Schreibrechte</h3>';
|
||||
$(data.FileError).each(function(k,v)
|
||||
{
|
||||
html += v+'<br />';
|
||||
});
|
||||
}
|
||||
$('#permissionbox').dialog('open');
|
||||
$('#permissionboxcontent').html(html);
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#upgrade').prop('disabled',true);
|
||||
updateval = $('input#upgrade').val();
|
||||
$('input#upgrade').val('Suche nach Updates. Bitte warten');
|
||||
$.ajax({
|
||||
url: 'update.php?action=ajax&cmd=checkforupdate',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { version: '[AKTVERSION]'},
|
||||
fail : function( ) {
|
||||
$('#upgrade').prop('disabled',false);
|
||||
$('input#upgrade').val(updateval);
|
||||
},
|
||||
error : function() {
|
||||
$('#upgrade').prop('disabled',false);
|
||||
$('input#upgrade').val(updateval);
|
||||
},
|
||||
success: function(data) {
|
||||
if(typeof data != 'undefined' && data != null && typeof data.reload != 'undefined')
|
||||
{
|
||||
$('input#upgrade').val(updateval);
|
||||
window.location = window.location.href;
|
||||
}else{
|
||||
$('#upgrade').prop('disabled',false);
|
||||
$('input#upgrade').val(updateval);
|
||||
if(data !== null && typeof data.error != 'undefined' && data.error != '') {
|
||||
alert(data.error);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setInterval(function(){
|
||||
if(aktprozent > 0)
|
||||
{
|
||||
var pr = parseInt(aktprozent);
|
||||
if(pr > 0)
|
||||
{
|
||||
var modulo = pr % 10;
|
||||
if(modulo < 9)pr++;
|
||||
updateprogressbardbupgrade(pr);
|
||||
}
|
||||
}
|
||||
},1000);
|
||||
$('#permissionbox').dialog(
|
||||
{
|
||||
modal: true,
|
||||
autoOpen: false,
|
||||
minWidth: 940,
|
||||
title:'Dateirechte',
|
||||
buttons: {
|
||||
OK: function() {
|
||||
$(this).dialog('close');
|
||||
}
|
||||
},
|
||||
close: function(event, ui){
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
[DATATABLES]
|
||||
|
||||
[SPERRMELDUNG]
|
||||
|
||||
[AUTOCOMPLETE]
|
||||
|
||||
[JQUERY]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
[ADDITIONALJAVASCRIPT]
|
||||
<style>
|
||||
.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
|
||||
input.ui-autocomplete-input { background-color:#D5ECF2; }
|
||||
.ui-autocomplete { font-size: 8pt;z-index: 100000 !important ; }
|
||||
.ui-widget-header {border:0px;}
|
||||
.ui-dialog { z-index: 10000 !important ;}
|
||||
|
||||
[YUICSS]
|
||||
</style>
|
||||
</head>
|
||||
<body class="ex_highlight_row" [BODYSTYLE]>
|
||||
[SPERRMELDUNGNACHRICHT]
|
||||
<div class="container_6" style="height:100%;">
|
||||
|
||||
<div class="grid_6 bgstyle" style=" min-height: calc(100vh - 150px);">
|
||||
<table width="100%"><tr valign="top">
|
||||
[ICONBAR]
|
||||
<td>
|
||||
<style>
|
||||
.ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default {
|
||||
color:#fff;/*[TPLFIRMENFARBEHELL];*/
|
||||
background-color:[TPLFIRMENFARBEHELL];
|
||||
}
|
||||
|
||||
.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {
|
||||
border: 1px solid #53bed0;
|
||||
background:none;
|
||||
background-color: #E5E4E2;
|
||||
color: #53bed0;
|
||||
}
|
||||
|
||||
.ui-state-hover a,
|
||||
.ui-state-hover a:hover,
|
||||
.ui-state-hover a:link,
|
||||
.ui-state-hover a:visited {
|
||||
color: #53bed0;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.ui-state-hover,
|
||||
.ui-widget-content .ui-state-hover,
|
||||
.ui-widget-header .ui-state-hover,
|
||||
.ui-state-focus,
|
||||
.ui-widget-content .ui-state-focus,
|
||||
.ui-widget-header .ui-state-focus {
|
||||
border: 1px solid #448dae;
|
||||
font-weight: normal;
|
||||
color: #53bed0;
|
||||
}
|
||||
|
||||
|
||||
.ui-tabs-nav {
|
||||
background: [TPLFIRMENFARBEHELL];
|
||||
}
|
||||
|
||||
.ui-widget-content {
|
||||
border-top: 1px solid [TPLFIRMENFARBEHELL];
|
||||
border-left: 1px solid [TPLFIRMENFARBEHELL];
|
||||
border-right: 1px solid [TPLFIRMENFARBEHELL];
|
||||
}
|
||||
.ui-accordion {
|
||||
border-bottom: 1px solid [TPLFIRMENFARBEHELL];
|
||||
}
|
||||
|
||||
.ui-state-default, .ui-widget-header .ui-state-default {
|
||||
border: 0px solid none;
|
||||
}
|
||||
|
||||
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default {
|
||||
border: 0px solid [TPLFIRMENFARBEHELL];
|
||||
}
|
||||
|
||||
.ui-widget-content .ui-state-default a, .ui-widget-header .ui-state-default a, .ui-button-text {
|
||||
font-size:8pt;
|
||||
font-weight:bold;
|
||||
border: 0px;
|
||||
}
|
||||
|
||||
|
||||
.ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active {
|
||||
color:#53bed0;
|
||||
}
|
||||
|
||||
.ui-widget-content .ui-state-active a, .ui-widget-header .ui-state-active a {
|
||||
color:#53bed0;
|
||||
font-weight:bold;
|
||||
font-size:8pt;
|
||||
background-color:[TPLFIRMENFARBEHELL];
|
||||
border: 0px;
|
||||
}
|
||||
|
||||
ul.ui-tabs-nav {
|
||||
background: [TPLFIRMENFARBEHELL];
|
||||
padding:2px;
|
||||
}
|
||||
.ui-widget-header {
|
||||
background: [TPLFIRMENFARBEHELL];
|
||||
}
|
||||
.ui-button-icon-primary.ui-icon.ui-icon-closethick
|
||||
{
|
||||
background-color:[TPLFIRMENFARBEDUNKEL];
|
||||
color:white;
|
||||
}
|
||||
|
||||
|
||||
#toolbar {
|
||||
padding: 4px;
|
||||
display: inline-block;
|
||||
}
|
||||
/* support: IE7 */
|
||||
*+html #toolbar {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#wawilink
|
||||
{
|
||||
display:none;
|
||||
font-size:150%;
|
||||
text-align:center;
|
||||
|
||||
}
|
||||
|
||||
#downloadhinweis
|
||||
{
|
||||
display:none;
|
||||
font-size:150%;
|
||||
color:#000;
|
||||
}
|
||||
|
||||
#installhinweis
|
||||
{
|
||||
display:none;
|
||||
font-size:150%;
|
||||
color:#000;
|
||||
}
|
||||
|
||||
#upgradediv
|
||||
{
|
||||
display:none;
|
||||
}
|
||||
#dbhinweis
|
||||
{
|
||||
display:none;
|
||||
font-size:150%;
|
||||
color:#000;
|
||||
}
|
||||
|
||||
#wawilink a {
|
||||
color:#000;
|
||||
}
|
||||
|
||||
|
||||
@media screen and (max-width: 767px){
|
||||
#tabsul
|
||||
{
|
||||
float:left;
|
||||
display:block;
|
||||
width:70%;
|
||||
padding-left:0vw;
|
||||
min-width:55vw;
|
||||
}
|
||||
|
||||
#tabsul li a {
|
||||
width:100%;
|
||||
display:block;
|
||||
}
|
||||
|
||||
#tabsul li
|
||||
{
|
||||
display:none;
|
||||
}
|
||||
#tabsul li.menuaktiv
|
||||
{
|
||||
display:block;
|
||||
|
||||
width:100%;
|
||||
padding-top:0px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#tabsul li.opentab
|
||||
{
|
||||
width:98%;
|
||||
display:block;
|
||||
}
|
||||
|
||||
#tabsul li.opentab a
|
||||
{
|
||||
width:100%;
|
||||
display:block;
|
||||
background-color:#53bed0;
|
||||
}
|
||||
|
||||
#scroller2{
|
||||
|
||||
max-width:99vw !important;
|
||||
}
|
||||
|
||||
.navdirekt{
|
||||
min-width:70vw !important;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
<div id="scroller2" style="margin-top:3px; padding:0px; position:relative; height:53px;">
|
||||
|
||||
<h1>OpenXE Update</h1>
|
||||
</div>
|
||||
<div id="page_container">
|
||||
[PAGE]
|
||||
|
||||
<div id="progress" style="width:50%;top:100px;left:25%;position:relative;display:block;">
|
||||
<div id="downloadhinweis">Download:</div>
|
||||
<div id="progressbardownload"></div>
|
||||
<div id="installhinweis">Installieren:</div>
|
||||
<div id="progressbarupdate"></div>
|
||||
<div id="dbhinweis">Datenbank Update:</div>
|
||||
<div id="progressbardbupgrade"></div>
|
||||
<div id="wawilink"><a href="./index.php" class="button">Installation vollständig - Zurück zu OpenXE</a></div>
|
||||
<div id="upgradediv"><form id="upgradefrm" method="POST" action="index.php?module=welcome&action=upgradedb"><input type="hidden" name="upgradedb" value="1" /><input type="submit" style="display:none;" value=" "></form></div>
|
||||
</div>
|
||||
|
||||
|
||||
<script type="application/javascript">
|
||||
var aktversion = '[AKTVERSION]';
|
||||
var downloadversion = '[AKTVERSION]';
|
||||
var ioncubeversion = '[IONCUBEVERSION]';
|
||||
var phpversion = '[PHPVERSION]';
|
||||
var todownload = null;
|
||||
var tocopy = null;
|
||||
var anzcheck = 0;
|
||||
var runDownloaded = 0;
|
||||
|
||||
function versel()
|
||||
{
|
||||
downloadversion = $('#verssel').val();
|
||||
}
|
||||
|
||||
function upgrade()
|
||||
{
|
||||
if(aktversion && downloadversion)
|
||||
{
|
||||
var text = 'Wirklich updaten?';
|
||||
if(aktversion == downloadversion)
|
||||
{
|
||||
|
||||
}else{
|
||||
text = 'Wirklich auf neue Version upgraden?';
|
||||
}
|
||||
|
||||
if(confirm(text))
|
||||
{
|
||||
anzcheck = 0;
|
||||
check2();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function check2()
|
||||
{
|
||||
if(anzcheck > 10)
|
||||
{
|
||||
alert('Verbindungsproblem beim Updaten. Bitte nochmal das Update starten!');
|
||||
return;
|
||||
}
|
||||
$('#downloadhinweis').show();
|
||||
$('#installhinweis').show();
|
||||
$('#dbhinweis').show();
|
||||
anzcheck++;
|
||||
$( "#progressbardownload" ).progressbar({
|
||||
value: 0
|
||||
});
|
||||
$( "#progressbarupdate" ).progressbar({
|
||||
value: 0
|
||||
});
|
||||
$( "#progressbardbupgrade" ).progressbar({
|
||||
value: 0
|
||||
});
|
||||
aktprozent = 0;
|
||||
$.ajax({
|
||||
url: 'update.php?action=ajax&cmd=checkfiles2',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { version: downloadversion}})
|
||||
.done( function(data) {
|
||||
if(typeof data.error != 'undefined')
|
||||
{
|
||||
alert(data.error);
|
||||
return;
|
||||
}
|
||||
if(typeof data.FolderError != 'undefined' || typeof data.FileError != 'undefined')
|
||||
{
|
||||
openPermissionbox(data);
|
||||
return;
|
||||
}
|
||||
if(downloadversion != aktversion)
|
||||
{
|
||||
$.ajax({
|
||||
url: 'update.php?action=ajax&cmd=changeversion',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { version: downloadversion}})
|
||||
.done( function(data) {
|
||||
if(typeof data.version != 'undefined')
|
||||
{
|
||||
if(downloadversion == data.version)
|
||||
aktversion = data.version;
|
||||
check2();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof data.download != 'undefined')
|
||||
{
|
||||
todownload = data.download;
|
||||
|
||||
}else{
|
||||
todownload = null;
|
||||
}
|
||||
if(typeof data.copy != 'undefined')
|
||||
{
|
||||
tocopy = data.copy;
|
||||
|
||||
}else{
|
||||
tocopy = null;
|
||||
}
|
||||
if(todownload != null)
|
||||
{
|
||||
if(typeof todownload != 'undefined' && todownload > 0)
|
||||
{
|
||||
runDownloaded = 0;
|
||||
return download2(todownload);
|
||||
}
|
||||
}else {
|
||||
runDownloaded++;
|
||||
if(runDownloaded < 3) {
|
||||
return download2(1);
|
||||
}
|
||||
$( "#progressbardownload" ).progressbar({
|
||||
value: 100
|
||||
});
|
||||
}
|
||||
if(tocopy != null)
|
||||
{
|
||||
if(typeof tocopy != 'undefined' && tocopy > 0)
|
||||
{
|
||||
return copy2(tocopy);
|
||||
}else {
|
||||
copy2(0);
|
||||
}
|
||||
}else {
|
||||
copy2(0);
|
||||
}
|
||||
})
|
||||
.fail(function( jqXHR, textStatus, errorThrown ) {
|
||||
alert('Verbindungsproblem beim Updaten. Bitte nochmal das Update starten!');
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function download2(anzahl)
|
||||
{
|
||||
if(todownload == null)
|
||||
{
|
||||
$( "#progressbardownload" ).progressbar({
|
||||
value: 100
|
||||
});
|
||||
if(anzahl > 0)check2();
|
||||
if(anzahl == 0)copy2();
|
||||
}
|
||||
else if((typeof todownload == 'undefined' || todownload == 0) )
|
||||
{
|
||||
$( "#progressbardownload" ).progressbar({
|
||||
value: 100
|
||||
});
|
||||
check2();
|
||||
}else if((todownload == 0))
|
||||
{
|
||||
$( "#progressbardownload" ).progressbar({
|
||||
value: 100
|
||||
});
|
||||
check2();
|
||||
}else{
|
||||
var len = todownload;
|
||||
if(anzahl <= len)
|
||||
{
|
||||
$( "#progressbardownload" ).progressbar({
|
||||
value: false
|
||||
});
|
||||
}else if(anzahl > len){
|
||||
$( "#progressbardownload" ).progressbar({
|
||||
value: 100*((anzahl-len)/anzahl)
|
||||
});
|
||||
}
|
||||
if(len > 0)
|
||||
{
|
||||
var j = 0;
|
||||
for(j = 0; j < 250; j++) {
|
||||
$.ajax({
|
||||
url: 'update.php?action=ajax&cmd=downloadfiles2',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
async: false,
|
||||
data: {version: downloadversion}
|
||||
})
|
||||
.done(
|
||||
function (data) {
|
||||
if (typeof data.todownload !== undefined) {
|
||||
todownload = data.todownload;
|
||||
if (todownload === null) {
|
||||
len = 0;
|
||||
} else {
|
||||
len = todownload;
|
||||
runDownloaded = 0;
|
||||
}
|
||||
$("#progressbardownload").progressbar({
|
||||
value: 100 * ((anzahl - len) / anzahl)
|
||||
});
|
||||
}
|
||||
else {
|
||||
todownload = null;
|
||||
}
|
||||
})
|
||||
.fail(function (jqXHR, textStatus) {
|
||||
todownload = null;
|
||||
check2();
|
||||
});
|
||||
if(todownload === null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
check2();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function copy2(anzahl)
|
||||
{
|
||||
if((todownload == null) || (typeof todownload == 'undefined') || (todownload == 0))
|
||||
{
|
||||
if((tocopy == null) || (typeof tocopy == 'undefined') || (tocopy == 0))
|
||||
{
|
||||
$( "#progressbarupdate" ).progressbar({
|
||||
value: 100
|
||||
});
|
||||
upgradedb2(1);
|
||||
}
|
||||
else{
|
||||
var len = tocopy;
|
||||
if(anzahl <= len)
|
||||
{
|
||||
$( "#progressbarupdate" ).progressbar({
|
||||
value: false
|
||||
});
|
||||
}else if(anzahl > len){
|
||||
$( "#progressbarupdate" ).progressbar({
|
||||
value: 100*(len/anzahl)
|
||||
});
|
||||
}
|
||||
if(len > 0)
|
||||
{
|
||||
$.ajax({
|
||||
url: 'update.php?action=ajax&cmd=copyfiles2',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { version: downloadversion}})
|
||||
.done(function(data) {
|
||||
if(typeof data.tocopy != 'undefined')
|
||||
{
|
||||
tocopy = data.tocopy;
|
||||
if(tocopy === null)
|
||||
{
|
||||
len = 0;
|
||||
}else{
|
||||
len = tocopy;
|
||||
}
|
||||
$( "#progressbardownload" ).progressbar({
|
||||
value: 100*((anzahl-len)/anzahl)
|
||||
});
|
||||
copy2(anzahl);
|
||||
}
|
||||
})
|
||||
|
||||
.fail(function( jqXHR, textStatus, errorThrown ) {
|
||||
check2();
|
||||
});
|
||||
}
|
||||
}
|
||||
}else{
|
||||
check2();
|
||||
}
|
||||
}
|
||||
|
||||
function updateprogressbardbupgrade(prozent)
|
||||
{
|
||||
aktprozent = prozent;
|
||||
$( "#progressbardbupgrade" ).progressbar({
|
||||
value: prozent
|
||||
});
|
||||
}
|
||||
|
||||
var aktdb = null;
|
||||
var aktsubdb = null;
|
||||
function upgradedb2(nr)
|
||||
{
|
||||
if(anzcheck > 12 && nr == 0) {
|
||||
return;
|
||||
}
|
||||
if(todownload == null || typeof todownload == 'undefined' || todownload == 0)
|
||||
{
|
||||
if(tocopy == null || typeof tocopy == 'undefined' || tocopy == 0)
|
||||
{
|
||||
if(nr == 1) {
|
||||
anzcheck = 0;
|
||||
}
|
||||
if(nr < 1)
|
||||
{
|
||||
updateprogressbardbupgrade(1);
|
||||
}else{
|
||||
updateprogressbardbupgrade(8 * nr - 5);
|
||||
}
|
||||
aktdb = nr;
|
||||
$.ajax({
|
||||
url: 'update.php?action=ajax&cmd=upgradedb',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
version: downloadversion,
|
||||
nummer: (nr!=10 || aktsubdb == null)?nr:nr+'-'+aktsubdb
|
||||
}})
|
||||
.done( function(data) {
|
||||
if(typeof data.nr != 'undefined')
|
||||
{
|
||||
var nrar = (data.nr+'').split('-');
|
||||
nr = parseInt(nrar[ 0 ]);
|
||||
if(typeof nrar[ 1 ] != 'undefined') {
|
||||
aktsubdb = parseInt(nrar[ 1 ]);
|
||||
}
|
||||
else {
|
||||
aktsubdb = null;
|
||||
}
|
||||
if(nr > 11 || data.nr == null)
|
||||
{
|
||||
updateprogressbardbupgrade(100);
|
||||
|
||||
$('#wawilink').show();
|
||||
}else{
|
||||
updateprogressbardbupgrade(8 * nr);
|
||||
upgradedb2(data.nr);
|
||||
}
|
||||
}
|
||||
}).fail(function( jqXHR, textStatus, errorThrown ) {
|
||||
if(aktdb < 12)
|
||||
{
|
||||
if(aktdb == 10) {
|
||||
if(aktsubdb == null) {
|
||||
aktsubdb = 1;
|
||||
}
|
||||
else {
|
||||
aktsubdb++;
|
||||
if(aktsubdb > 100) {
|
||||
aktdb++;
|
||||
aktsubdb = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
aktdb++;
|
||||
aktsubdb = null;
|
||||
}
|
||||
upgradedb2(aktdb);
|
||||
}else {
|
||||
aktsubdb = null;
|
||||
$('#upgradediv').show();
|
||||
$('#upgradefrm').submit();
|
||||
}
|
||||
}
|
||||
);
|
||||
}else{
|
||||
check2();
|
||||
}
|
||||
}else{
|
||||
check2();
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
</div>
|
||||
</td></tr></table>
|
||||
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
<!-- end CONTENT -->
|
||||
|
||||
<!-- end RIGHT -->
|
||||
|
||||
<div id="footer" class="grid_6">
|
||||
© [YEAR] OpenXE project & Xentral ERP Software GmbH
|
||||
</div>
|
||||
<!-- end FOOTER -->
|
||||
<div class="clear"></div>
|
||||
|
||||
</div>
|
||||
|
||||
[JSSCRIPTS]
|
||||
|
||||
|
||||
[BODYENDE]
|
||||
<div id="permissionbox" style="display:none;">
|
||||
<div id="permissionboxcontent"></div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -1,121 +0,0 @@
|
||||
<center>
|
||||
<table border="0" celpadding="0" cellspacing="4" width="100%"
|
||||
height="100%" align="left">
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<form action="" id="frmlogin" method="post"><br>
|
||||
<table align="center">
|
||||
[MULTIDB]
|
||||
<tr>
|
||||
<td style="width:100%;text-align:center;"><input style="display:none;width:200px;" id="chtype" type="button" value="Login mit Username / PW" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><input type="hidden" name="isbarcode" id="isbarcode" value="0" /><input name="username" type="text" size="45" id="username" placeholder="Benutzer"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><input name="password" id="password" type="password" size="45" placeholder="Passwort"></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td align="center"><span id="loginmsg">[LOGINMSG]</span>
|
||||
<span style="color:red">[LOGINERRORMSG]</span></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td align="center">[STECHUHRDEVICE]</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td align="center"><input name="token" id="token" type="text" size="45" autocomplete="off" placeholder="optional OTP"><br></td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr>
|
||||
<td align="center"><br><br><input type="submit" value="anmelden"> <input type="reset"
|
||||
name="Submit" value="zurücksetzen"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<script type="text/javascript">
|
||||
var siv = null;
|
||||
document.getElementById("username").focus();
|
||||
$("#isbarcode").val('0');
|
||||
$(document).ready(function() {
|
||||
|
||||
$( "#username" ).focus();
|
||||
$( "#username" ).on('keydown',function( event ) {
|
||||
var which = event.which;
|
||||
if ( which == 13 ) {
|
||||
event.preventDefault();
|
||||
if($( "#username" ).val().indexOf("!!!") < 1)
|
||||
{
|
||||
$('#password').focus();
|
||||
}else{
|
||||
$('#frmlogin').submit();
|
||||
}
|
||||
} else {
|
||||
var iof = $( "#username" ).val().indexOf("!!!");
|
||||
if(iof > 0)
|
||||
{
|
||||
$('#password').focus();
|
||||
$('#username').val($( "#username" ).val().substring(0,iof));
|
||||
$("#isbarcode").val('1');
|
||||
}
|
||||
}
|
||||
});
|
||||
if(typeof(Storage) !== "undefined") {
|
||||
[RESETSTORAGE]
|
||||
var devicecode = localStorage.getItem("devicecode");
|
||||
if(devicecode)
|
||||
{
|
||||
$('#stechuhrdevice').each(function(){
|
||||
$('#token').hide();
|
||||
$('#password').hide();
|
||||
$('#username').hide();
|
||||
$('#loginmsg').hide();
|
||||
$('#chtype').show();
|
||||
$('#chtype').on('click',function()
|
||||
{
|
||||
$('#token').show();
|
||||
$('#password').show();
|
||||
$('#username').show();
|
||||
$('#loginmsg').show();
|
||||
$(this).hide();
|
||||
clearInterval(siv);
|
||||
});
|
||||
$('#code').val(devicecode);
|
||||
$('#stechuhrdevice').focus();
|
||||
$( "#stechuhrdevice" ).on('keydown',function( event ) {
|
||||
setTimeout(function(){
|
||||
if($('#stechuhrdevice').val().length > 205)
|
||||
setTimeout(function(){$('#frmlogin').submit();},100);
|
||||
}, 500);
|
||||
|
||||
});
|
||||
siv = setInterval(function(){$('#stechuhrdevice').focus(),200});
|
||||
});
|
||||
} else {
|
||||
$('#stechuhrdevice').hide();
|
||||
}
|
||||
} else {
|
||||
$('#stechuhrdevice').hide();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user