Um beim Versand von Versandbestätigungen (Trackingmails) an Ihre Kunden mehr Flexibilität zu bieten,
kann der Versand sowohl pro Projekt als auch pro Versandart aktiviert werden.
Einstellungen in einer einzelnen Versandart stechen die aus dem Projekt.
Es empfiehlt sich daher, die Einstellungen gemäß der eigenen Anforderungen zu überprüfen.
Für jede Versandart, für die Versandbestätigungen per E-Mail an die Kunden gesendet werden sollen,
ist die Einstellung in der Versandart zu setzen.
Eine genaue Erläuterung über das aktuelle Verhalten findet sich
hier
';
}
}
elseif(count($resulta) == 1) {
$resu = reset($resulta);
//foreach($resulta as $resu)
//{
$versa = explode(':',$resu,2);
if($returnfirst) {
$return['version'] = $versa[0];
return $return;
}
$this->app->Tpl->Set('AKTVERSION', $versa[0]);
$ret .= '';
//}
}else{
if($ioncube_loader_version !== '' && !$masterkey1erlaubt && !$masterkey2erlaubt && !$masterkey3erlaubt)
{
$message = 'Die Ioncubeversion ist zu alt';
$ret .= $message;
}else{
$message = 'Ioncube nicht verfügbar';
$ret .= $message;
}
if($returnfirst) {
return ['error' => $message, 'version' => ''];
}
}
if($php73Warning && count($resulta) > 0) {
$ret .= ' '.'
Fehler: Ihre PHP-Version '
. $phpversion
. ' ist nicht kompatibel mit xentral 21.1 (Es wird mindestens PHP 7.3 benötigt)
';
}
}
else{
$this->errormsg = substr($result, 6);
if($returnfirst) {
return ['error'=>$this->errormsg,'version'=>''];
}
return $result;
}
return $ret;
}
function CheckMd5()
{
$parameter['version']=@$this->conf['version'];
$parameter['withsize'] = 1;
return $this->Request('md5list',$parameter);
}
function CopyFile($files, $maxtime = 10)
{
$parameter['versionname']=@$this->conf['versionname'];
$startzeit = microtime(true);
if(empty($files)) {
return array('tocopy'=>null);
}
foreach($files as $k => $file) {
$file = json_decode(json_encode($file),true);
if(isset($file['typ'])) {
switch($file['typ']) {
case 'getfile':
case 'getfilecustom':
case 'getfilemodules':
break;
default:
$file['typ'] = '';
break;
}
}
else {
$file['typ'] = '';
}
if(!isset($file['file']) || !isset($file['md5sum']) || !$file['file'] || $file['typ'] === '') {
unset($files[$k]);
}
else{
$parameter['file']=$file['file'];
$parameter['md5sum']=$file['md5sum'];
$ffile = $file['file'];
$_file = dirname(__DIR__).'/download/'.$ffile;
$_fileto = dirname(__DIR__).'/'.$ffile;
$ffa = explode('/',$ffile);
$_f = '';
$cffa = count($ffa)-1;
for($i = 0; $i < $cffa; $i++) {
$_f .= $ffa[$i];
if(is_file(dirname(__DIR__).'/'.$_f)) {
$this->removeEmptyFile(dirname(__DIR__).'/'.$_f);
}
if(!is_dir(dirname(__DIR__).'/'.$_f) &&
!@mkdir(dirname(__DIR__).'/'.$_f) &&
!is_dir(dirname(__DIR__).'/'.$_f)
) {
continue;
}
$_f .= '/';
}
if(file_exists($_file)) {
if(substr($file['md5sum'],0,3)=== 'DEL') {
if($this->CheckVersandZahlungsweise($_file)) {
@unlink($_file);
}
}
elseif(md5_file($_file)==$file['md5sum']) {
if(is_dir($_fileto) && is_file($_file)){
$this->removeEmptyFolder($_fileto);
}
if(@copy($_file,$_fileto)) {
if(md5_file($_fileto)==$file['md5sum']){
unset($files[$k]);
}
}
}
}
if(substr($file['md5sum'],0,3)=== 'DEL') {
unset($files[$k]);
}
}
if($maxtime > 0 && microtime(true) - $startzeit > $maxtime) {
break;
}
}
if(empty($files)) {
return array('tocopy'=>null);
}
foreach($files as $k => $file) {
$data[] = $file;
}
return array('tocopy'=>$data);
}
function CheckVersandZahlungsweise($datei){
if(strpos($datei, 'versandart') !== false) {
$dateia = pathinfo($datei);
$versandart = $dateia['filename'];
if(strpos($versandart, 'versandarten_')) {
$versandart = str_replace('versandarten_', '', $versandart);
}
if($this->app->DB->Select(
"SELECT id
FROM versandarten
WHERE modul = '".$this->app->DB->real_escape_string($versandart)."' AND ifnull(geloescht,0) = 0 AND aktiv = 1
LIMIT 1"
)) {
return false;
}
return true;
}
if(strpos($datei, 'zahlungsweise') !== false) {
$dateia = pathinfo($datei);
$zahlungsweise = $dateia['filename'];
if($this->app->DB->Select(
"SELECT id
FROM `zahlungsweisen`
WHERE modul = '".$this->app->DB->real_escape_string($zahlungsweise)."' AND ifnull(geloescht,0) = 0 AND aktiv = 1
LIMIT 1"
)) {
return false;
}
return true;
}
if(strpos($datei, 'cronjobs') !== false) {
$dateia = pathinfo($datei);
$cronjob = $dateia['filename'];
if($this->app->DB->Select(
"SELECT id
FROM `prozessstarter`
WHERE parameter = '".$this->app->DB->real_escape_string($cronjob)."' AND aktiv = 1
LIMIT 1"
)) {
return false;
}
}
return true;
}
function ChangeVersion()
{
$parameter['version']=@$this->conf['version'];
$parameter['versionname']=@$this->conf['versionname'];
if($parameter['versionname'] && $parameter['versionname'] != $parameter['version']) {
$changeversion = $this->Request('changeversion',$parameter);
}
return $changeversion;
}
function removeEmptyFile($file) {
if(is_file($file) && filesize($file) === 0) {
@unlink($file);
}
}
function removeEmptyFolder($folder)
{
if(empty($folder) || !is_dir($folder)){
return;
}
if(!($handle = opendir($folder))) {
return;
}
while (false !== ($entry = readdir($handle))) {
if($entry !== '.' && $entry !== '..') {
closedir($handle);
return;
}
}
closedir($handle);
rmdir($folder);
}
function DownloadFile($files, $maxtime = 15, $echo = false)
{
$startzeit = microtime(true);
$parameter['version']=@$this->conf['version'];
$parameter['versionname']=@$this->conf['versionname'];
$parameter['version']=@$this->conf['version'];
$parameter['versionname']=@$this->conf['versionname'];
if($parameter['versionname'] && $parameter['versionname'] != $parameter['version']) {
$changeversion = $this->Request('changeversion',$parameter);
}
if(empty($files)) {
return array('todownload'=>null);
}
$countFiles = count($files);
$batches = [];
$batch = [];
$keyToBatch = [];
foreach($files as $k => $file) {
$file = json_decode(json_encode($file), true);
if(isset($file['typ'])){
switch ($file['typ']) {
case 'getfile':
case 'getfilecustom':
case 'getfilemodules':
break;
default:
$file['typ'] = '';
break;
}
}else{
$file['typ'] = '';
}
if(!isset($file['file']) || !isset($file['md5sum']) || !$file['file'] || $file['typ'] === ''){
$files[$k]['error'] = $file['file'];
unset($files[$k]);
}else{
if(substr($file['md5sum'], 0, 3) === 'DEL'){
continue;
}
$parameter['file'] = $file['file'];
$parameter['md5sum'] = $file['md5sum'];
$ffile = $file['file'];
$_file = dirname(__DIR__) . '/download/' . $ffile;
$ffa = explode('/', $ffile);
$_f = '';
for ($i = 0; $i < count($ffa) - 1; $i++) {
$_f .= $ffa[$i];
if(is_file(dirname(__DIR__) . '/download/' . $_f)){
@unlink(dirname(__DIR__) . '/download/' . $_f);
}
if(!is_dir(dirname(__DIR__) . '/download/' . $_f) &&
!@mkdir(dirname(__DIR__) . '/download/' . $_f) &&
!is_dir(dirname(__DIR__) . '/download/' . $_f)){
continue;
}
$_f .= '/';
}
}
switch($file['typ']) {
case 'getfile':
$batch[] = $k;
$keyToBatch[$k] = count($batches);
if(count($batch) >= 10) {
$batches[] = $batch;
$batch = [];
}
break;
}
}
if(!empty($batch)) {
$batches[] = $batch;
}
foreach($files as $k => $file) {
$file = json_decode(json_encode($file),true);
if(isset($file['typ'])) {
switch($file['typ']) {
case 'getfile':
case 'getfilecustom':
case 'getfilemodules':
break;
default:
$file['typ'] = '';
break;
}
}
else {
$file['typ'] = '';
}
if(!isset($file['file']) || !isset($file['md5sum']) || !$file['file'] || $file['typ'] === '') {
$files[$k]['error'] = $file['file'];
unset($files[$k]);
}
else{
if(substr($file['md5sum'],0,3) === 'DEL') {
continue;
}
$parameter['file']=$file['file'];
$parameter['md5sum']=$file['md5sum'];
$ffile = $file['file'];
$_file = dirname(__DIR__).'/download/'.$ffile;
$ffa = explode('/',$ffile);
$_f = '';
for($i = 0; $i < count($ffa)-1; $i++) {
$_f .= $ffa[$i];
if(is_file(dirname(__DIR__).'/download/'.$_f)) {
@unlink(dirname(__DIR__).'/download/'.$_f);
}
if(!is_dir(dirname(__DIR__).'/download/'.$_f) &&
!@mkdir(dirname(__DIR__).'/download/'.$_f) &&
!is_dir(dirname(__DIR__).'/download/'.$_f)) {
continue;
}
$_f .= '/';
}
if($echo) {
echo "\rDownload Files: ".($k < $countFiles?$k+1:$countFiles).' / '.$countFiles."... ";
}
if(isset($keyToBatch[$k]) && isset($batches[$keyToBatch[$k]])) {
$batch = $batches[$keyToBatch[$k]];
if(count($batch) > 1) {
$parameter2 = $parameter;
$parameter2['parameters'] = [];
foreach ($batch as $key2) {
$file2 = $files[$key2];
$parameter2['parameters'][] = $parameter;
$parameter2['parameters'][count($parameter2['parameters']) - 1]['file'] = $file2['file'];
$parameter2['parameters'][count($parameter2['parameters']) - 1]['md5sum'] = $file2['md5sum'];
}
$result2 = explode('|', $this->Request('getfiles', $parameter2));
if(count($result2) === count($batch)) {
foreach ($batch as $bachKey => $key2) {
$file2 = $files[$key2];
if(
@file_put_contents(dirname(__DIR__).'/download/'.$file2['file'], @base64_decode($result2[$bachKey]))
) {
if(dirname(__DIR__).'/download/'.$file2['file'] === $file2['md5sum']){
unset($files[$key2]);
}
}
}
}
unset($result2);
}
unset($batches[$keyToBatch[$k]]);
}
if(is_file($_file) && md5_file($_file)==$file['md5sum']) {
unset($files[$k]);
continue;
}
$result = $this->Request($file['typ'],$parameter);
$output = @base64_decode($result);
if(strlen($output) > 0 && is_dir($_file)) {
$this->removeEmptyFolder($_file);
}
if(@file_put_contents($_file, $output)) {
if(md5_file($_file)==$file['md5sum']) {
unset($files[$k]);
}
else {
$files[$k]['error'] = 'md5 failed';
}
}
else{
$files[$k]['error'] = 'file_put_contents ' .$_file. ' failed '.$file['typ'].' ' .json_encode($parameter);
}
}
if($maxtime > 0 && microtime(true) - $startzeit > $maxtime) {
break;
}
}
if(empty($files)) {
return array('todownload'=>null);
}
foreach($files as $k => $file) {
if(substr($file['md5sum'],0,3) !== 'DEL'){
$data[] = $file;
}
}
return array('todownload'=>$data);
}
/**
* @return int[]|string|string[]
*/
public function downloadZips()
{
@clearstatcache();
if(!function_exists('system')) {
return ['zip' => 'system not found'];
}
$this->app->erp->setMaintainance(true);
$parameter['version']=@$this->conf['version'];
$parameter['versionname']=@$this->conf['versionname'];
if($parameter['versionname'] !== 'ent_masterkey4_20.3') {
return ['zip' => 'not ent_masterkey4_20.3'];
}
$parameter['withsize'] = 1;
if(!is_dir(dirname(__DIR__).'/download/')) {
if(!@mkdir(dirname(__DIR__).'/download/') && !is_dir(dirname(__DIR__).'/download/')) {
$this->app->erp->setMaintainance(false);
return 'ERROR: Downloadverzeichnis konnte nicht erstellt werden';
}
}
$ret = ['zip' => 0];
foreach([
'ent_masterkey4_20.3_4_wo_userdata.zip' => '',
'ent_masterkey4_20.3_4_vendor.zip' => '/vendor',
'ent_masterkey4_20.3_4_www.zip' => '/zip',
] as $file => $subfolder
) {
$parameter['file'] = $file;
if(file_put_contents(
dirname(__DIR__) . '/download/' . $file,
$this->Request('getversionzip', $parameter)
)) {
if(
!is_dir(dirname(__DIR__).'/download' . $subfolder)
&& !@mkdir(dirname(__DIR__).'/download/' . $subfolder)
&& !is_dir(dirname(__DIR__).'/download/' . $subfolder)
) {
continue;
}
system(
'cd '.dirname(__DIR__).'/download'
.' && unzip '.$file.' -d '
.dirname(__DIR__).'/download'.$subfolder
);
unlink(dirname(__DIR__).'/download/' . $subfolder);
$ret['zip']++;
}
else {
$ret['zip_error'][] = 'coudl not save '.$file;
}
}
return $ret;
}
/**
* @param bool $updatefiles
*
* @return array|mixed|string
*/
public function CheckFiles($updatefiles = false)
{
@clearstatcache();
$this->app->erp->setMaintainance(true);
$parameter['version']=@$this->conf['version'];
$parameter['versionname']=@$this->conf['versionname'];
$parameter['withsize'] = 1;
if(!is_dir(dirname(__DIR__).'/download/')) {
if(!@mkdir(dirname(__DIR__).'/download/') && !is_dir(dirname(__DIR__).'/download/')) {
$this->app->erp->setMaintainance(false);
return 'ERROR: Downloadverzeichnis konnte nicht erstellt werden';
}
}
$tmpfile = md5(microtime(true));
if(!($fh = fopen(dirname(__DIR__).'/download/'.$tmpfile,'w'))) {
$this->app->erp->setMaintainance(false);
return 'ERROR: Downloadverzeichnis hat keine Schreibrechte';
}
fclose($fh);
$eigenguser = fileowner(dirname(__DIR__).'/download/'.$tmpfile);
$eigengroup = filegroup(dirname(__DIR__).'/download/'.$tmpfile);
@unlink(dirname(__DIR__).'/download/'.$tmpfile);
$_result = $this->Request('md5list', $parameter);
$maxRetries = 5;
while(empty($_result) && $maxRetries > 0) {
$maxRetries--;
usleep(2000000);
$_result = $this->Request('md5list', $parameter);
}
if(isset($this->errormsg) && $this->errormsg) {
$this->app->erp->setMaintainance(false);
return 'ERROR: '.$this->errormsg;
}
if($_result==='ERROR') {
$this->app->erp->setMaintainance(false);
return 'ERROR FROM SERVER (Perhaps a wrong license?)';
}
$_result2 = '';
$_result3 = '';
if(!$updatefiles){
$_result2 = $this->Request('md5listmodules', $parameter);
if(empty($_result2) && (!empty($this->http_code) && strpos($this->http_code,'5') === 0)){
usleep(1000000);
$_result2 = $this->Request('md5listmodules', $parameter);
}
if($_result2 === 'ERROR'){
$this->app->erp->setMaintainance(false);
return "ERROR FROM SERVER (Perhaps a wrong license?)";
}
$_result3 = $this->Request('md5listcustom', $parameter);
if(empty($_result3)){
usleep(2000000);
$_result3 = $this->Request('md5listcustom', $parameter);
}
if($_result3 === 'ERROR'){
$this->app->erp->setMaintainance(false);
return "ERROR FROM SERVER (Perhaps a wrong license?)";
}
}
$result = '';
$result2 = '';
$result3 = '';
$resulta = explode(';',$_result);
$resulta2 = explode(';',$_result2);
$resulta3 = explode(';',$_result3);
unset($_result, $_result2, $_result3);
if($resulta3) {
foreach($resulta3 as $r) {
if($r)
{
$result3.= 'getfilecustom:'.$r.';';
$ra = explode(':',$r);
$dats[] = $ra[0];
}
}
unset($resulta3);
}
if($resulta2){
foreach($resulta2 as $r) {
if($r) {
$ra = explode(':',$r);
if(!isset($dats) || !in_array($ra[0], $dats)) {
$result2.= 'getfilemodules:'.$r.';';
$dats[] = $ra[0];
}
}
}
unset($resulta2);
}
if($resulta) {
foreach($resulta as $r) {
if($r) {
$ra = explode(':',$r);
if(!isset($dats) || !in_array($ra[0], $dats)) {
$result.= 'getfile:'.$r.';';
}
}
}
unset($resulta);
}
$result .= $result2.$result3;
unset($result2, $result3, $dats);
//$rows = explode(";",$result);
$rows = explode(';',$result);
$res['result'] = $result;
$res['parameter'] = $parameter;
$downloadind = 0;
$copyind = 0;
if(count($rows)>0) {
foreach($rows as $value) {
unset($single_row);
$single_row = explode(':',$value);
if(!(count($single_row)>=3 && strlen($single_row[0])>4 && strlen($single_row[2])>3)) {
continue;
}
$typ = $single_row[0];
$file = $single_row[1];
$file_lokal = dirname(__DIR__).'/'.($file);
$md5sum = $single_row[2];
$size = isset($single_row[3])?$single_row[3]:false;
$parameter['file']=$file;
$parameter['md5sum']=$md5sum;
if($file==='./upgradesystemclient.php') {
continue;
}
if(
(!$updatefiles && ($file==="./www/update.php" ||
$file==="./www/update.tpl" ||
$file==="./www/updatelogin.tpl" ||
$file === './www/jquery-update.js' ||
$file === './www/jquery-ui-update.js' ||
$file === 'jquery-ui.min.css'))
|| ($updatefiles && ($file!=="./www/update.php" &&
$file!=="./www/update.tpl" &&
$file!=="./www/updatelogin.tpl" &&
$file !== './www/jquery-update.js' &&
$file !== './www/jquery-ui-update.js' &&
$file !== 'jquery-ui.min.css'))
){
continue;
}
$bla[] = $file_lokal;
if(is_file($file_lokal)){
if(substr($md5sum,0,3) === 'DEL'){
if($this->CheckVersandZahlungsweise($file_lokal)) {
@unlink($file_lokal);
}
continue;
}
if(md5_file($file_lokal)==$md5sum){
continue;
}
$fileowner = fileowner($file_lokal);
$filegroup = filegroup($file_lokal);
$perms = fileperms($file_lokal);
$o = ($perms & 0x0080);
$g = ($perms & 0x0010);
$a = ($perms & 0x0002);
// pruefe ob datei angelegt werden kann, wenn das passt ist eh alles gut
if(touch(dirname(__DIR__).'/download/chkrights') && file_exists(dirname(__DIR__).'/download/chkrights')) {
@unlink(dirname(__DIR__).'/download/chkrights');
}
else if($eigenguser && $eigengroup){
if($fileowner != $eigenguser){
if($filegroup != $eigengroup){
if(!$a){
return array('error'=>'ERROR Fehlende Schreibrechte in '.$file_lokal);
}
}
else{
if(!$g) {
return array('error'=>'ERROR Fehlende Schreibrechte in '.$file_lokal);
}
}
}
else {
if(!$o) {
return array('error'=>'ERROR Fehlende Schreibrechte in '.$file_lokal);
}
}
}
$bla[] = array(
'fileowner'=>$fileowner,
'filegroup'=>$filegroup,
'perms'=>$perms,
'o'=>$o,
'g'=>$g,
'a'=>$a,
);
if(is_file(dirname(__DIR__).'/download/'.$file)){
if(md5_file(dirname(__DIR__).'/download/'.$file)!=$md5sum){
$res['download'][$downloadind] = array('typ'=>$typ,'file'=>$file,'md5sum'=>$md5sum,'size'=>$size);
$downloadexists[$typ][$file] = $downloadind;
$downloadind++;
}
else{
$res['copy'][$copyind] = array('typ'=>$typ,'file'=>$file,'md5sum'=>$md5sum,'size'=>$size);
$copyexists[$typ][$file] = $copyind;
$copyind++;
}
}
else{
$res['download'][$downloadind] = array('typ'=>$typ,'file'=>$file,'md5sum'=>$md5sum,'size'=>$size);
$downloadexists[$typ][$file] = $downloadind;
$downloadind++;
}
}
else if($file!='') {
if(substr($md5sum,0,3) === 'DEL') {
continue;
}
if(is_file(dirname(__DIR__).'/download/'.$file)) {
if(md5_file(dirname(__DIR__).'/download/'.$file)!=$md5sum) {
$fileowner = fileowner(dirname(__DIR__).'/download/'.ltrim($file,'.'));
$filegroup = filegroup(dirname(__DIR__).'/download/'.ltrim($file,'.'));
$perms = fileperms(dirname(__DIR__).'/download/'.ltrim($file,'.'));
$o = ($perms & 0x0080);
$g = ($perms & 0x0010);
$a = ($perms & 0x0002);
// pruefe ob datei angelegt werden kann, wenn das passt ist eh alles gut
if(touch(dirname(__DIR__).'/download/chkrights')) {
unlink(dirname(__DIR__).'/download/chkrights');
}
else if($eigenguser && $eigengroup) {
if($fileowner != $eigenguser) {
if($filegroup != $eigengroup) {
if(!$a) {
return array('error'=>'ERROR Fehlende Schreibrechte im Downloadordner');
}
}
else{
if(!$g) {
return array('error'=>'ERROR Fehlende Schreibrechte im Downloadordner');
}
}
}
else{
if(!$o) {
return array('error'=>'ERROR Fehlende Schreibrechte im Downloadordner');
}
}
}
$res['download'][$downloadind] = array('typ'=>$typ,'file'=>$file,'md5sum'=>$md5sum,'size'=>$size);
$downloadexists[$typ][$file] = $downloadind;
$downloadind++;
}
else{
$res['copy'][$copyind] = array('typ'=>$typ,'file'=>$file,'md5sum'=>$md5sum,'size'=>$size);
$copyexists[$typ][$file] = $copyind;
$copyind++;
}
}
else {
$res['download'][$downloadind] = array('typ'=>$typ,'file'=>$file,'md5sum'=>$md5sum,'size'=>$size);
$downloadexists[$typ][$file] = $downloadind;
$downloadind++;
}
}
}
}
if(!empty($res['download']) && count($res['download']) > 0) {
foreach($res['download'] as $key => $val) {
if(isset($val['md5sum']) && substr($val['md5sum'],0,3) === 'DEL') {
unset($res['download'][$key]);
}
}
}
return $this->CheckRights($res, $eigenguser, $eigengroup);
}
protected function CheckFileFolder($file, $eigenguser, $eigengroup)
{
if(is_file($file)) {
if($handle = @fopen($file,'a+')) {
fclose($handle);
return false;
}
$fileowner = fileowner($file);
if($fileowner !== $eigenguser) {
if(@chown($file,$eigenguser) && ($handle = @fopen($file,'a+'))) {
fclose($handle);
return false;
}
}
$perms = fileperms($file);
$filegroup = filegroup($file);
if($fileowner === $eigenguser) {
if(@chmod($file, $perms | 0600)) {
return false;
}
}
if($filegroup === $eigengroup) {
if(@chmod($file, $perms | 0060)) {
return false;
}
}
if(@chown($file,$perms | 0006)) {
return false;
}
return true;
}
if(!is_dir($file)) {
return false;
}
if(is_file($file.'/chkrights')) {
@unlink($file.'/chkrights');
}
if(!is_file($file.'/chkrights') && @touch($file.'/chkrights')){
if(is_file($file.'/chkrights')){
@unlink($file . '/chkrights');
return false;
}
return true;
}
$fileowner = fileowner($file);
if($fileowner !== $eigenguser) {
if(chown($file,$eigenguser) && @touch($file.'/chkrights')) {
@unlink($file.'/chkrights');
return false;
}
}
$perms = fileperms($file);
$filegroup = filegroup($file);
if($fileowner === $eigenguser) {
if(@chmod($file, $perms | 0700) && @touch($file.'/chkrights')) {
@unlink($file.'/chkrights');
return false;
}
}
if($filegroup === $eigengroup) {
if(@chmod($file, $perms | 0070) && @touch($file.'/chkrights')) {
@unlink($file.'/chkrights');
return false;
}
}
if(@chown($file,$perms | 0007) && @touch($file.'/chkrights')) {
@unlink($file.'/chkrights');
return false;
}
return true;
}
protected function CheckRights($res, $eigenguser, $eigengroup)
{
$foldertocheck = [];
if(!empty($res['download'])) {
foreach($res['download'] as $k => $v) {
$file = ltrim(ltrim($v['file'],'.'),'/');
if($file === '.') {
continue;
}
if($this->CheckFileFolder(dirname(__DIR__).'/'.$file, $eigenguser, $eigengroup)) {
$res['FileError'][] = dirname(__DIR__).'/'.$file;
}
if($this->CheckFileFolder(dirname(__DIR__).'/download/'.$file, $eigenguser, $eigengroup)) {
$res['FileError'][] = dirname(__DIR__).'/download/'.$file;
}
$dfile = dirname($file);
if($dfile === '.') {
$folder = dirname(__DIR__);
}
else{
$folder = dirname(__DIR__) . '/' . $dfile;
}
$foldertocheck[substr_count($folder,'/')][$folder] = true;
if($dfile === '.') {
$folder = dirname(__DIR__). '/download';
}
else{
$folder = dirname(__DIR__) . '/download/' . $dfile;
}
$foldertocheck[substr_count($folder,'/')][$folder] = true;
}
}
if(!empty($res['copy'])) {
foreach($res['copy'] as $k => $v) {
$file = ltrim(ltrim($v['file'],'.'),'/');
if($file === '.') {
continue;
}
if($this->CheckFileFolder(dirname(__DIR__).'/'.$file, $eigenguser, $eigengroup)) {
$res['FileError'][] = dirname(__DIR__).'/'.$file;
}
$dfile = dirname($file);
if($dfile === '.') {
$folder = dirname(__DIR__);
}
else {
$folder = dirname(__DIR__) . '/' . $dfile;
}
$foldertocheck[substr_count($folder,'/')][$folder] = true;
}
}
if(!empty($foldertocheck)) {
foreach($foldertocheck as $lvl => $folderarr) {
foreach($folderarr as $k => $v) {
if($this->CheckFileFolder($k, $eigenguser, $eigengroup)) {
$res['FolderError'][] = $k;
}
}
}
}
return $res;
}
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];
if(substr($md5sum,0,3) === 'DEL')continue;
$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);
}
}
}
}
}
}
function CheckUpdateModules()
{
//$this->dir_rekursiv("./");
//$parameter['md5sums'] = $this->localmd5sums;
//shell_exec('find ./ -exec md5sum "{}" \;');
$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];
if(substr($md5sum,0,3) === 'DEL') {
continue;
}
$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);
}
}
}
}
}
}
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(substr($md5sum,0,3) === 'DEL') {
continue;
}
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);
}
}
}
}
}
}
function DownloadUpdate()
{
}
function CheckDownloadedUpdate()
{
}
function ExecuteUpdate()
{
}
function Request($command,$parameter)
{
$erp = $this->erp;
$auth['serial']=trim($erp->Firmendaten('lizenz'));//$this->conf['serial'];
$auth['authkey']=trim($erp->Firmendaten('schluessel'));//$this->conf['authkey'];
if(empty($auth['serial']) || empty($auth['authkey']))
{
$this->errormsg = 'Bitte tragen Sie die Lizenzdaten in den Grundeinstellungen ein.';
return '';
}
if(!empty($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] !== '') {
$auth['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
}
elseif(!empty($_SERVER['HTTP_HOST'])) {
$auth['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
}
else {
$auth['SERVER_NAME'] = '';
}
$auth = base64_encode(json_encode($auth));
$parameter = base64_encode(json_encode($parameter));
$client = new UpdateHttpClient($this->conf['host'],$this->conf['port']);
$client->post('/upgradesystem.php', [
'authjson' => $auth,
'parameterjson'=>$parameter,
'command'=>(String)$command ,
'withdel' => 1
]
);
$pageContents = $client->getContent();
if(!empty($client->errormsg)){
$this->errormsg = $client->errormsg;
}
$this->http_code = (string)$client->getStatus();
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 UpdateHttpClient {
// 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)';
$this->errormsg .= ' '.$errstr;
$this->debug($this->errormsg);
break;
case -4:
$this->errormsg = 'DNS lookup failure (-4)';
$this->errormsg .= ' '.$errstr;
$this->debug($this->errormsg);
break;
case -5:
$this->errormsg = 'Connection refused or timed out (-5)';
$this->errormsg .= ' '.$errstr;
$this->debug($this->errormsg);
break;
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 = 'Verbindung konnte nicht aufgebaut werden. Bitte wenden Sie sich an Ihre IT. Eventuell sind SSL-Zertifikate nicht vorhanden bzw. abgelaufen';
$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];
}
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 UpdateHttpClient($host, $port);
if (!$client->get($path)) {
return false;
}
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 UpdateHttpClient($host, $port);
if (!$client->post($path, $data)) {
return false;
}
return $client->getContent();
}
function debug($msg, $object = false) {
if ($this->debug) {
print '