$f = $APPL['isAPI'].'/'. $APPL['api']. '.php'; $f = WGParseFile($f); if (!$f) FatalError("Invalid API name"); if (!$f['F']) FatalError("API file not found `".$f['f']."`"); $APPL['bin'] = $f; WGRequirePHP($f['f']); } if ($APPL['executor']) { $f = WGParseFile($APPL['executor'],true); if (!$f) FatalError("Invalid executor file name"); if (!$f['F'] and !$f['D']) FatalError("Executor not found `".print_r($APPL['executor'],true)."`"); $APPL['bin'] = $f; if ($f['F']) { if ($f['extension']=='php') { WGRequirePHP($f['f']); } else if ($f['extension']=='json') { $js=@file_get_contents($f); $js=json_decode($f,true); if (!is_array($js)) FatalError("Invalid executor json `".$APPL['executor']."`"); Window($f['filename']); $WEBGUI['win']=array_merge($WEBGUI['win'],$js); $js=null; unset($js['hdc']); endWin(); } else FatalError("Unknown executor type `".$APPL['executor']."`"); } else if ($f['D']) execApp($f['w'],$JSON['t']); } if (is_array($ini['db']) && !$DBH) dbclose($DBH); retGUI(); }
function execApp($ex,$action=AJ_SHELL) { global $CMD; global $OUTJSON; global $APPL; global $DBH; global $JSON; global $WEBGUI; global $WGData; if (!is_array($ex)) $ex = WGParseFile($ex); if ($ex===false) FatalError("Invalid file"); if (!$ex['D']) FatalError("E5 Invalid application"); $lang=$_SESSION['WGLang'] ? $_SESSION['WGLang'] : '_D_'; $rvar = array( 'FILE' => $ex['w'], 'PATH' => pathinfo($ex['w'],PATHINFO_DIRNAME), 'URL' => @$JSON['url']) ; if ($ex['D']) $rvar['APPPATH']=rtrim($ex['w'],'/').'/'; else $rvar['APPPATH']=rtrim($rvar['PATH'],'/').'/'; $mf = json_decode( @file_get_contents($ex['f'].'/manifest.json') , true); if (!is_array($mf)) FatalError("Invalid Manifest"); $x = $ex['f'].'/lang'; if (file_exists($x) and is_dir($x)) { list($y)=explode('-',$lang,2); foreach(array($lang,$y,'_D_') as $kf) { $y = $x . '/'. $kf.'.json'; if (file_exists($y)) { $x = @file_get_contents($y); $x = json_decode($x,true); if (!is_array($x)) FatalError("Can't load lang `$kf`"); $rvar=array_merge($rvar,$x); $x=null; break; } } } $WEBGUI['rvar']=$rvar; $x = $ex['f'].'/'.$mf['ico']; if (file_exists($x)) $x=$ex['w'].'/'.$mf['ico']; else $x=null; //--form endWin(); Window( $mf['title'], $x, $mf['w'] ? $mf['w'] : 320 , $mf['h'] ? $mf['h'] : 240 ) ; if (@$mf['autoResize']) WGAutoResizeWin(); if (isset($mf['winType'])) { if (is_numeric($mf['winType'])) $WEBGUI['win']['winType']=$mf['winType']; else { if ($mf['winType']=='nosize') $WEBGUI['win']['winType'] = WIN_NOSIZE; if ($mf['winType']=='dialog') $WEBGUI['win']['winType'] = WIN_DIALOG; if ($mf['winType']=='normal') $WEBGUI['win']['winType'] = WIN_NORMAL; if ($mf['winType']=='popup') $WEBGUI['win']['winType'] = WIN_POPUP; } } if (isset($mf['pox'])) { if (!is_numeric($mf['pox'])) { if ($mf['pox']=='center') $mf['pox']=POX_CENTER; else if ($mf['pox']=='rev') $mf['pox']=POX_RB; else $mf['pox']=POX_NORMAL; } setWindowPox( $mf['pox'], isset($mf['x']) ? $mf['x'] : false, isset($mf['y']) ? $mf['y'] : false) ; } if ($action == AJ_SHELL or $action == AJ_DIALOG) { $hdc=WGSNew($ex['w'], isset($mf['name']) ? $mf['name'] : false); $APPL['hdc']=$hdc; $APPL['asNew']=true; $APPL['url']=$ex['w']; } else $hdc=$APPL['hdc']; setWindowContext($hdc,$mf['name'] ? $mf['name'] : false,$ex['w']); $WEBGUI['win']['data'] = WGSLoad($hdc,$ex['w'],isset($mf['name']) ? $mf['name'] : false); if (is_array($rvar) and ($action==AJ_SHELL or $action==AJ_DIALOG)) { if (isset($rvar['win']) and is_array($rvar['win'])) $WEBGUI['win']['winLang'] = $rvar['win']; if (file_exists($ex['f'].'/style.css')) WGWinCss($ex['w'].'/style.css',$rvar); if (isset($rvar['_title'])) $WEBGUI['win']['title'] = $rvar['_title']; } $f = $ex['f'].'/event.php'; if (file_exists($f)) { WGRequirePHP($f,$rvar); $fn=false; if ($action==AJ_POST) { $fn='form_'.@$JSON['frm'].'_post'; if (!function_exists($fn)) $fn='form_'.$APPL['act'].'_post'; $WEBGUI['win']['data'][$APPL['act']]=$JSON['par']; } if ($action==AJ_WINAJAX) $fn='ajax_'.$APPL['api']; if ($action==AJ_EVENT) $fn='event_'.$APPL['api']; if (($action==AJ_SHELL || $action==AJ_DIALOG) && $APPL['act']!='') $fn='load_'.$APPL['act']; if (($action==AJ_SHELL || $action==AJ_DIALOG) && $APPL['act']=='') $fn='winMain'; if ($fn and function_exists($fn)) { if (isset($WEBGUI['form']) and isset($JSON['frm']) and $JSON['frm']!='') { if (!isset($WEBGUI['form'][ $JSON['frm'] ])) FatalError("Unknown form `".$JSON['frm']."`"); $formData=$JSON['par']; $err = WGFormCheck($WEBGUI['form'][ $JSON['frm'] ], $formData); if ($err) { foreach($WEBGUI['form'][ $JSON['frm']]['obj'] as $t0) { if ($t0['n']==$err) { FatalError( isset($t0['par']['err']) ? $t0['par']['err'] : "Invalid value for `".$t0['c']."`"); } } FatalError("Invalid value for `$err`"); } WGDestroyCaptcha($WEBGUI['form'][ $JSON['frm'] ]); } else { $formData=@$JSON['par']; } $pr=$fn(@$JSON['par'],$formData); if ($action==AJ_POST and $pr) $OUTJSON['postReply']=$pr; if ($action==AJ_WINAJAX and $pr) $OUTJSON['ajaxReturn'] = $pr; } } $formFile=$ex['f'].'/form.conf'; if (file_exists($formFile)) { $X = @file_get_contents($formFile); if ($X===false) FatalError("Can't read form.conf"); $X = WGReplacer($X,$rvar); $WEBGUI['form'] = WGFormParser($X,$action); $X=null; $formFile=true; } else $formFile=false; if ($action == AJ_SHELL || $action == AJ_DIALOG) { $f = $ex['f'].'/app.js'; if (file_exists($f)) winJS( @file_get_contents($f) ); $f = $ex['f'].'/data.json'; if (file_exists($f)) { $WEBGUI['win']['data'] = json_decode(@file_get_contents($f),true); if (!is_array($WEBGUI['win']['data'])) FatalError("Invalid `data.json` structure/syntax"); } $f = $ex['f'].'/layout.php'; if (file_exists($f)) WGRequirePHP($f,$rvar); if (isset($WEBGUI['form'])) { foreach($WEBGUI['form'] as $X) WGFormActivity($X); $X=null; } $f = $ex['f'].'/app.ejs'; if (file_exists($f)) { $f = @file_get_contents($f); if ($f===false) FatalError("Can't load EJS"); $f = WGReplacer($f,$rvar); $f=explode("\n",$f); WGParseEJSTag($f); } else { $f = $ex['f'].'/event.json'; if (file_exists($f)) { $js=@file_get_contents($f); $js=json_decode($js,true); if (!is_array($js)) FatalError("Can't load application.\nBad JSON sctructure in event.json"); $WEBGUI['win']['event']=$js; $js=null; } } if (function_exists('layout_create')) layout_create(); } endWin(); }
function form_running_post($rawData,$data) { global $ini; global $DBERROR; global $DBH; global $WEBGUI; if (@$ini['webgui']['cansetup']!='webgui') FatalError("Setup Bloccato"); $path = $_SERVER['DOCUMENT_ROOT'].$WEBGUI['rvar']['APPPATH']; $DBERROR=catchDBError; if ($data['dbp1']!=$data['dbp2']) return LocalError("Le password del database non coincidono."); if ($data['rp1']!=$data['rp2']) return LocalError("Le password di root non coincidono."); $x = $_SERVER['DOCUMENT_ROOT'].'/etc/InstallHash'; if (file_exists($x)) { $x = @file_get_contents($x); if ($x===false) FatalError("Non riesco a leggere `InstallHash`"); list($a,$b)=@explode(' ',$x,2); $x = $a.' '.$data['root'].':'.$data['rp1']; $x = md5($x); $b=strtolower($b); if ($b!=$x) return LocalError("La login e la password di root non coincidono con quelle precedentemente segnalate nel file `InstallHash`\nRimuovere il file oppure usare le credenziali corrette."); } $ini['db'] = array( 'mysql'=> ($data['mysql'] ? $data['mysql'] : '127.0.0.1') , 'db' => $data['db'], 'dblog'=> $data['dbl'], 'dbpas'=> $data['dbp1']) ; $ini['db']['ok'] = true; dbopen($DBH); if ($ini['db']['ok']==false) return LocalError("Errore accesso database: {$ini['db']['err']}"); unset($ini['db']['ok']); unset($ini['db']['err']); if (!isset($ini['webgui'])) $ini['webgui']=array(); $ini['webgui']['title'] = $data['title']; unset($ini['webgui']['autoexec']); if (isset($ini['webgui']['install-autoexec'])) { $ini['webgui']['autoexec']=$ini['webgui']['install-autoexec']; unset($ini['webgui']['install-autoexec']); } unset($ini['allowdir']); $a = array( 'etc', 'etc/conf.d', 'etc/desktop.json', 'etc/start.json', 'etc/mime.json', 'etc/mimehome.json', 'etc/server.php', 'tmp', 'var/cache', 'var/cache/font.json', 'var/cache/font.css', 'home', 'usr', 'bin/app/grp', 'bin/usr', 'bin/dlg', 'bin/dll', 'bin/font', 'bin/mod', 'bin/php', 'bin/theme', 'bin/wgx', 'bin/mime', 'bin/mime/ico') ; foreach($a as $b) { $c=$_SERVER['DOCUMENT_ROOT'].'/'.$b; if (@file_exists($c) and @chmod($c,0770)==false ) return LocalError("Non riesco ad impostare i permessi su $b"); } $dh=@opendir($path.'etc'); if ($dh===false) FatalError("Non trovo la directory skel file di installazione {$path}etc"); while($f=readdir($dh)) { if (is_dir( $path.'etc/'.$f ) or $f[0]=='.') continue; $dt = @file_get_contents($path.'etc/'.$f); if ($dt===false) return LocalError("Non riesco a leggere `$f`"); if (@file_put_contents( $_SERVER['DOCUMENT_ROOT'].'/etc/'.$f , $dt ) == false ) return LocalError("No riesco a copiare: $f"); } closedir($dh); $dh=@opendir($path.'setup'); if ($dh===false) FatalError("Non trovo la directory skel file di installazione {$path}setup"); $lst=array(); while($f=readdir($dh)) { $tf=$path.'setup/'.$f; if (is_dir( $tf ) or $f[0]=='.') continue; if (preg_match('/\.sql$/',$f)!=0) { $a = intval($f); $lst[$a]=@file_get_contents($tf); if ($lst[$a]===false) return LocalError("Non riesco a leggere `$tf`"); } } closedir($dh); ksort($lst); $ini['db']['ok']=true; $ini['db']['err']=''; foreach($lst as $db) { dbquery($DBH,$db); if ($ini['db']['ok']==false) return LocalError("Errore Query SQL: ".$ini['db']['err']); } $x=WGCreateUser($data['root'],$data['rp1'],'root',array('root' => true)); if ($x==false) LocalError("Non riesco a creare l'utente root."); unset($ini['db']['ok']); unset($ini['db']['err']); unset($ini['logon']); unset($ini['auth']); if ($data['accesmode']==1) { $ini['auth'] = array( 'realm' => $data['title']!='' ? $data['title'] : 'WebGui8') ; } if ($data['accesmode']==2) { $ini['logon']=array('enabled'=>1); } $t0 = str_pad($data['debug'],4,'0'); $ini['debug'] = array( 'debug' => $t0[0], 'log' => $t0[1], 'showid'=> $t0[2], 'args' => $t0[3]) ; $ini['webgui']['cookie'] = $data['cookie']!=0 ? '1' : '0'; $fs =$path.'setup/server.conf'; if (file_exists($fs)) { $i = @parse_ini_file($fs,true); if ($i===false) return LoaclError("Non riesco a leggere correttamente il file di installazione `$fs`"); foreach($i as $k => $st) { if (!isset($ini[$k])) $ini[$k]=array(); foreach($st as $k1 => $v1) { $ini[$k][$k1]=$v1; } } } $fs=$path.'setup/install.php'; if (file_exists($fs)) WGRequirePHP($fs,$data); unset($ini['webgui']['cansetup']); $i=';) <'.'? exit; ?'.'>'; $i.="\n"; foreach($ini as $k => $li) { $i.="[{$k}]\n"; foreach($li as $vk => $vv) { if (!is_numeric($vv)) $vv='"'.addcslashes($vv,"\t\r\n\\\"`'").'"'; $i.="{$vk}={$vv}\n"; } $i.="\n"; } $fs=$_SERVER['DOCUMENT_ROOT'].'/etc/server.php'; if ( file_put_contents($fs,$i)==false) return LocalError("Non riesco a scrivere su `$fs`"); EWGCacheFont(); WGSetActivity('setup'); }