Example #1
0
    protected function _api($u = null)
    {
        $u = null === $u ? \webdof\wURI::getInstance() : $u;
        ini_set('display_errors', 0);
        $this->login();
        /*
         * ToDo:  set output formatter (defaults to jsonp)
         */
        $this->ob_compress();
        header("Content-Type: application/x-javascript; charset=UTF-8;");
        ob_start(function ($c) {
            $r = isset($this->data['data_out']) ? $this->data['data_out'] : new \stdclass();
            $r->type = isset($r->type) ? $r->type : 'print';
            $r->out = isset($r->out) ? $r->out : $c;
            $fnregex = "/^[A-Za-z0-9\$\\.-_\\({1}\\){1}]+\$/";
            $callback = isset($_REQUEST['callback']) && preg_match($fnregex, $_REQUEST['callback']) ? strip_tags($_REQUEST['callback']) : '';
            if ($callback === '') {
                $o = json_encode($r);
            } else {
                $r->callback = $callback;
                $o = $callback . '(' . json_encode($r) . ')';
            }
            return $o;
        });
        /* BEGIN extract phar (todo build/refactor API) */
        if (isset($_GET['EXTRA_EXTRACT_PHAR'])) {
            if (file_exists($this->data['CONFIGFILE']) && $this->data['config_new']['PACKAGE'] !== $this->data['config']['PACKAGE']) {
                \webdof\wResponse::status(409);
                $str = 'Error: Invalid installer package name';
                if (true === $this->debug) {
                    trigger_error($str, E_USER_ERROR);
                }
                die($str);
            }
            if (1 !== intval($this->data['INSTALLER_PHAR_AVAILABLE']) || intval(str_replace(array('"', "'"), array('', ''), $this->data['INSTALLER'])) !== 1 || !isset($this->data['PHAR_INCLUDE']) || !class_exists('\\Extract')) {
                \webdof\wResponse::status(400);
                $str = 'Error: Not in installer context';
                if (true === $this->debug) {
                    trigger_error($str, E_USER_ERROR);
                }
                die($str);
            }
            if (true !== $this->isLoggedIn()) {
                \webdof\wResponse::status(401);
                die('Invalid credentials, try to install via <a href="{___$$URL_INSTALLER_HTMLPAGE$$___}">{___$$URL_INSTALLER_HTMLPAGE$$___}</a>!');
            }
            try {
                $userInfo = posix_getpwuid(fileowner(__FILE__));
                $this->data['config']['DIR_PACKAGE'] = $userInfo['dir'] . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
                chmod($this->data['config']['DIR_PACKAGE'], 0755);
                if (!is_dir($this->data['config']['DIR_PACKAGE']) || !is_writable($this->data['config']['DIR_PACKAGE'])) {
                    $this->data['config']['DIR_PACKAGE'] = $userInfo['dir'] . DIRECTORY_SEPARATOR;
                    chmod($this->data['config']['DIR_PACKAGE'], 0755);
                }
                if (!is_dir($this->data['config']['DIR_PACKAGE']) || !is_writable($this->data['config']['DIR_PACKAGE'])) {
                    $this->data['config']['DIR_PACKAGE'] = $this->data['DIR'];
                }
            } catch (\Exception $e) {
                $str = 'Warning: Cannot get home dir';
                if (true === $this->debug) {
                    trigger_error($str, E_USER_WARNING);
                }
                $this->data['config']['DIR_PACKAGE'] = $this->data['DIR'];
            }
            if (isset($_REQUEST['DIR_PACKAGE']) && is_dir($_REQUEST['DIR_PACKAGE'])) {
                chmod($_REQUEST['DIR_PACKAGE'], 0755);
                $this->data['config']['DIR_PACKAGE'] = $_REQUEST['DIR_PACKAGE'];
            }
            if (!is_dir($this->data['config']['DIR_PACKAGE']) || !is_writable($this->data['config']['DIR_PACKAGE'])) {
                $this->data['config']['DIR_PACKAGE'] = $this->data['DIR'];
            }
            if (isset($_REQUEST['DIR_WWW']) && is_dir($_REQUEST['DIR_WWW'])) {
                chmod($_REQUEST['DIR_WWW'], 0755);
                $this->data['config']['DIRS']['www'] = $_REQUEST['DIR_WWW'];
            }
            if (!is_dir($this->data['config']['DIRS']['www']) || !is_writable($this->data['config']['DIRS']['www'])) {
                $this->data['config']['DIRS']['www'] = $this->data['DIR'] . 'www' . DIRECTORY_SEPARATOR;
            }
            $this->data['CONFIGFILE'] = $this->data['config']['DIR_PACKAGE'] . 'config.frdl.php';
            if (isset($_REQUEST['test']) && 'response' === $_REQUEST['test']) {
                \webdof\wResponse::status(200);
                $this->data['data_out']->code = 200;
                $this->data['data_out']->extra = true;
                $this->data['data_out']->out = 'OK';
                $this->data['data_out']->changed = json_encode($this->data['config']) !== json_encode($this->data['config_new']);
                $this->data['data_out']->config = new \stdclass();
                $this->data['data_out']->config_new = new \stdclass();
                $this->data['data_out']->config->PACKAGE = $this->data['config']['PACKAGE'];
                $this->data['data_out']->config_new->PACKAGE = $this->data['config_new']['PACKAGE'];
                $this->data['data_out']->config->VERSION = $this->data['config']['VERSION'];
                $this->data['data_out']->config_new->VERSION = $this->data['config_new']['VERSION'];
                $this->data['data_out']->config->INSTALLED = $this->data['config']['INSTALLED'];
                $this->data['data_out']->config_new->INSTALLED = $this->data['config_new']['INSTALLED'];
                $this->data['data_out']->config->REGISTERED = $this->data['config']['REGISTERED'];
                $this->data['data_out']->config_new->REGISTERED = $this->data['config_new']['REGISTERED'];
                $this->data['data_out']->config->UNAME = $this->data['config']['UNAME'];
                $this->data['data_out']->config_new->UNAME = $this->data['config_new']['UNAME'];
                $this->data['data_out']->config->UID = $this->data['config']['UID'];
                $this->data['data_out']->config_new->UID = $this->data['config_new']['UID'];
                $this->data['data_out']->config->DIR_PACKAGE = $this->data['config']['DIR_PACKAGE'];
                $this->data['data_out']->config_new->DIR_PACKAGE = $this->data['config_new']['DIR_PACKAGE'];
                $wwwdir = is_dir($this->data['config']['DIRS']['www']) ? $this->data['config']['DIRS']['www'] : $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR;
                $this->data['data_out']->config->DIR_WWW = $wwwdir;
                $this->data['data_out']->config_new->DIR_WWW = $wwwdir;
                die('OK');
            }
            $EXTRA =& $this->data['config']['EXTRA'];
            mkdir($this->data['config']['DIR_PACKAGE'], 0755, true);
            try {
                \Extract::from($this->data['PHAR_INCLUDE'])->to($this->data['config']['DIR_PACKAGE'], function (\Entry $entry) use(&$EXTRA) {
                    if (false == strpos(basename($entry->getName()), '.') && (true == \webdof\valFormats::is(basename($entry->getName()), 'md5', true) || true == \webdof\valFormats::is(basename($entry->getName()), 'sha1', true))) {
                        return;
                    }
                    if ('config.frdl.php' == basename($entry->getName()) || 'config.php' == basename($entry->getName())) {
                        return;
                    }
                    //  if(true == $EXTRA['extra']['pragmamx']['main'] ){
                    if ('.htaccess' === basename($entry->getName())) {
                        return;
                    }
                    if ('index.php' === basename($entry->getName())) {
                        return;
                    }
                    //   }
                });
            } catch (\Exception $e) {
                //\webdof\wResponse::status(409);
                //$str = $this->data['PHAR_INCLUDE'] .' -> '.$this->data['DIR'].' ('.__LINE__.') - ' .$e->getMessage();
                //if(true === $this->debug)trigger_error($str, E_USER_ERROR);
                //die($str);
            }
            if (file_exists($this->data['config']['DIR_PACKAGE'] . 'composer.json')) {
                /*
                			 	   		 $.WebfanDesktop.Registry.Programs[\'frdl-webfan\'].config.loc.api_url="'.$this->data['config']['URL_API_ORIGINAL'].'";
                */
                $this->data['data_out']->js = trim(preg_replace("/\\s+|\n/", " ", 'try{
			 			$(\'#window_\' + \'frdl-webfan\').find(\'#wd-li-frdl-webfan-installPHAR\').find(\'u\').html(\'Update\');
			 			$.WebfanDesktop.Registry.Programs[\'frdl-webfan\'].formConfig();
			 		
			 			}catch(err){console.error(err);}			 			
			 			'));
                if ('' === $this->data['config_new']['ADMIN_PWD']) {
                    $this->data['config_new']['ADMIN_PWD'] = $this->data['config']['ADMIN_PWD'];
                }
                if ($this->data['config_new']['ADMIN_PWD'] !== $this->data['config']['ADMIN_PWD']) {
                    $this->data['data_out']->js .= ' 
					     		alert("Attention: Password has changed (' . trim($_POST['pwd'], '"\' ') . ')!");
							 ';
                }
                if ('' === $this->data['config_new']['PIN']) {
                    $this->data['config_new']['PIN'] = $this->data['config']['PIN'];
                }
                if ($this->data['config_new']['PIN'] !== $this->data['config']['PIN']) {
                    $this->data['data_out']->js .= ' 
					     		alert("Attention: PIN has changed (' . $this->aSess['PIN'] . ')!");
							 ';
                }
                $this->data['config']['VERSION'] = $this->data['config_new']['VERSION'];
                $this->data['config']['DOWNLOADUPDATETIME'] = $this->data['config_new']['DOWNLOADTIME'];
                $this->data['config']['UPDATETIME'] = time();
                $this->data['config']['ADMIN_PWD'] = $this->aSess['ADMIN_PWD'];
                $this->data['config']['PIN'] = $this->aSess['PIN'];
                if (0 === intval($this->data['config']['UID']) && 0 !== intval($this->data['config_new']['UID'])) {
                    $this->data['config']['UID'] = $this->data['config_new']['UID'];
                }
                if ('' === $this->data['config']['UNAME'] && '' !== $this->data['config_new']['UNAME']) {
                    $this->data['config']['UNAME'] = $this->data['config_new']['UNAME'];
                }
                $this->data['config']['DIRS'] = array_merge(isset($this->data['config']['DIRS']) && is_array($this->data['config']['DIRS']) ? $this->data['config']['DIRS'] : array(), array('psr-0' => null, 'psr-4' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR, 'apps' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR, 'components' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR, 'batch' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'batch' . DIRECTORY_SEPARATOR, 'cache' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR, 'config' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR, 'data.norm' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'data.norm' . DIRECTORY_SEPARATOR, 'data.storage' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'data.storage' . DIRECTORY_SEPARATOR, 'packages' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR, 'repositories' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'repositories' . DIRECTORY_SEPARATOR, 'servers' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'servers' . DIRECTORY_SEPARATOR, 'share' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'share' . DIRECTORY_SEPARATOR, 'tmp' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR, 'vendor' => $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR, 'www' => is_dir($this->data['config']['DIRS']['www']) && is_writable($this->data['config']['DIRS']['www']) ? $this->data['config']['DIRS']['www'] : $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR, 'files' => isset($_REQUEST['EXTRA_DIR']) && is_dir($_REQUEST['EXTRA_DIR']) ? $_REQUEST['EXTRA_DIR'] : (is_dir($this->homedir() . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR) ? $this->homedir() . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR : $this->data['config']['DIR_PACKAGE'] . '.ApplicationComposer' . DIRECTORY_SEPARATOR . '.files' . DIRECTORY_SEPARATOR)));
                $files = array();
                $this->data['config']['FILES'] = array_merge(isset($this->data['config']['FILES']) && is_array($this->data['config']['FILES']) ? $this->data['config']['FILES'] : array(), array('composer' => $this->data['config']['DIR_PACKAGE'] . 'composer.json', 'config' => $this->data['CONFIGFILE'], 'database-schema' => $this->data['config']['DIRS']['config'] . 'database-schema.dat', 'boot.batch' => $this->data['config']['DIRS']['batch'] . '.boot.bat'));
                $config = $this->data['config'];
                if (true === $EXTRA['extra']['pragmamx']['main']) {
                    $config['URL'] .= 'setup.php';
                }
                if (!isset($this->data['config']['autoupdate'])) {
                    $this->data['config']['autoupdate'] = true;
                }
                $php = "<?php\n\t\t\t \t\t\t/*\n\t\t\t \t\t\t  - Do not edit this file manually! \n\t\t\t \t\t\t  Application Composer - Config\n\t\t\t \t\t\t  Download: {___\${$URL_INSTALLER_HTMLPAGE}\${$___}}\n\t\t\t \t\t\t  \n\t\t\t \t\t\t*/\n\t\t\t \t\t\t    if(isset(\$this) &&\n\t\t\t \t\t\t     (  get_class(\$this) === '\\" . get_class($this) . "' \n\t\t\t \t\t\t     || is_subclass_of(\$this, '\\frdl\\ApplicationComposer\\Command\\CMD')  \n\t\t\t \t\t\t     || get_class(\$this) === '" . get_class($this) . "' \n\t\t\t \t\t\t     || is_subclass_of(\$this, 'frdl\\ApplicationComposer\\Command\\CMD')  \n\t\t\t \t\t\t     || is_subclass_of(\$this, 'frdl\\xGlobal\fexe')  \n\t\t\t \t\t\t     )\n\t\t\t \t\t\t     ){\n\t\t\t \t\t\t     \t \$this->data['config'] = " . var_export($config, true) . ";\t\t\n\t\t\t \t\t\t     \t\n                         \t    ";
                $php .= "\n\n\n/*\n* If you have PragmaMx installed, its db-config will be used instead!\n*/\n\$pmxconfigfile=__DIR__.DIRECTORY_SEPARATOR. 'config.php';\nif(true === \$this->data['config']['EXTRA']['extra']['pragmamx']['main'] && file_exists( \$pmxconfigfile)  ){\n\ttry{\n\t  ob_start();\n\t\t@include \$pmxconfigfile;\n\t\tif(isset(\$dbtype))\$this->data['config']['db-driver']=strtolower(\$dbtype);\n\t\tif(isset(\$dbhost))\$this->data['config']['db-host']=\$dbhost;\n\t\tif(isset(\$dbuname))\$this->data['config']['db-user']=\$dbuname;\n\t\tif(isset(\$dbpass))\$this->data['config']['db-pwd']=\$dbpass;\n\t\tif(isset(\$dbname))\$this->data['config']['db-dbname']=\$dbname;\n\t\tif(isset(\$prefix))\$this->data['config']['db-pfx']=\$prefix;\n\t  ob_end_clean();\t\t\t\n\t}catch(\\Exception \$e){\n\t\t\n\t}\n\n}\n\nif(!isset(\$this->data['config']['db-driver']))\$this->data['config']['db-driver']='';\nif(!isset(\$this->data['config']['db-host']))\$this->data['config']['db-host']='';\nif(!isset(\$this->data['config']['db-user']))\$this->data['config']['db-user']='';\nif(!isset(\$this->data['config']['db-pwd']))\$this->data['config']['db-pwd']='';\nif(!isset(\$this->data['config']['db-dbname']))\$this->data['config']['db-dbname']='';\nif(!isset(\$this->data['config']['db-pfx']))\$this->data['config']['db-pfx']='';\n\n\n";
                $php .= "}";
                file_put_contents($this->data['CONFIGFILE'], $php);
                /*
                if(dirname(realpath($this->data['DIR']))!==dirname(realpath($this->data['config']['DIR_PACKAGE']))){
                	$this->copy_dir($this->data['DIR'], $this->data['config']['DIR_PACKAGE'], true);
                	rmdir($this->data['DIR'].'.ApplicationComposer'.DIRECTORY_SEPARATOR);
                	
                }
                */
                $msg = '';
                $EXTRA_DIR = '' !== $_REQUEST['DIR_WWW'] && is_dir($_REQUEST['DIR_WWW']) ? rtrim($_REQUEST['DIR_WWW'], '/ ') : $this->data['config']['DIRS']['www'];
                mkdir($EXTRA_DIR, 0755, true);
                if ('yes' === $_REQUEST['INSTALL_UPDATE_PMX']) {
                    $tok = 'http://download.pragmamx.org/pmx/';
                    if ($tok === substr($_REQUEST['INSTALL_UPDATE_PMX_URL'], 0, strlen($tok))) {
                        $zipcontents = file_get_contents($_REQUEST['INSTALL_UPDATE_PMX_URL']);
                        if (false === $zipcontents) {
                            $msg .= 'Download of PragmaMx failed!';
                        } else {
                            $zipfilename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . '~tmp.pragmamxdownload.zip';
                            file_put_contents($zipfilename, $zipcontents);
                            $Zip = new \frdl\webfan\Compress\zip\wUnzip($zipfilename, $EXTRA_DIR);
                            $r = $Zip->unzip();
                            $msg .= 'PragmaMx extracted.';
                            unlink($zipfilename);
                            $zipcontents = file_get_contents('https://github.com/frdlweb/flow4pmx/archive/master.zip');
                            if (false === $zipcontents) {
                                $msg .= 'Download of flow4pmx failed!';
                            } else {
                                $zipfilename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . '~tmp.flow4pmx.zip';
                                file_put_contents($zipfilename, $zipcontents);
                                $Zip = new \frdl\webfan\Compress\zip\wUnzip($zipfilename, $EXTRA_DIR);
                                $r = $Zip->unzip();
                                $this->copy_dir($EXTRA_DIR . 'flow4pmx-master' . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . ltrim($EXTRA_DIR, '/ '), true);
                                rmdir($EXTRA_DIR . 'flow4pmx-master' . DIRECTORY_SEPARATOR);
                                $msg .= 'flow4pmx extracted.';
                                unlink($zipfilename);
                            }
                        }
                    }
                }
                /* eo install/update pmx */
                if ('yes' === $_REQUEST['INSTALL_UPDATE_WP']) {
                    $tok = 'https://wordpress.org/';
                    if ($tok === substr($_REQUEST['INSTALL_UPDATE_WP_URL'], 0, strlen($tok))) {
                        $zipcontents = file_get_contents($_REQUEST['INSTALL_UPDATE_WP_URL']);
                        if (false === $zipcontents) {
                            $msg .= 'Download of Wordpress failed!';
                        } else {
                            $zipfilename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . '~tmp.wordpressdownload.zip';
                            file_put_contents($zipfilename, $zipcontents);
                            $Zip = new \frdl\webfan\Compress\zip\wUnzip($zipfilename, $this->data['DIR']);
                            $r = $Zip->unzip();
                            /* rename(ltrim($this->data['DIR'], '/ ').'wordpress',trim($this->data['DIR'], '/ ')); */
                            $this->copy_dir($EXTRA_DIR . 'wordpress' . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . ltrim($EXTRA_DIR, '/ '), true);
                            rmdir($this->data['DIR'] . 'wordpress' . DIRECTORY_SEPARATOR);
                            $msg .= 'Wordpress extracted.';
                            unlink($zipfilename);
                        }
                    }
                }
                try {
                    $flowfile = $this->data['DIR'] . 'js' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'flow.js';
                    file_put_contents($flowfile, file_get_contents('http://api.webfan.de/api-d/4/js-api/library.js?skipcache=' . mt_rand(100000, 999999999999999)));
                    chmod($flowfile, 0755);
                } catch (\Exception $e) {
                    //	\webdof\wResponse::status(409);
                    //		$str = $this->data['PHAR_INCLUDE'] .' -> '.$this->data['DIR'].' - ('.__LINE__.') ' .$e->getMessage();
                    //		if(true === $this->debug)trigger_error($str, E_USER_ERROR);
                    //	die($str);
                }
                unset($Zip, $r, $tok, $zipcontents, $zipfilename);
                $DIR_PACKAGE = rtrim(realpath($this->data['config']['DIR_PACKAGE']), '/ ') . DIRECTORY_SEPARATOR;
                $VERSION = $this->data['config']['VERSION'];
                $SERVERCODE = <<<PHP
<?php
/**
*  Generated by frdl/webfan
*  This file should NOT be edited manually!
*  
*  @role:      server
*  @app:       frdl/webfan
*  @version:   {$VERSION}
*  @project:   @root  
*  @dir:       {$DIR_PACKAGE}
*
*/
namespace frdlweb\\webfan\\server;
\$dir = '{$DIR_PACKAGE}';
chdir(\$dir);
require \$dir.'.ApplicationComposer'. DIRECTORY_SEPARATOR .  'bootstrap.php';
require \$dir.'.ApplicationComposer'. DIRECTORY_SEPARATOR .  'apps' . DIRECTORY_SEPARATOR . 'webfan.fexe.php';


PHP;
                foreach (array(DIRECTORY_SEPARATOR . ltrim($this->data['DIR'], '/ ') . '~index.php', DIRECTORY_SEPARATOR . ltrim($this->data['DIR'], '/ ') . 'api.php', DIRECTORY_SEPARATOR . ltrim($this->data['DIR'], '/ ') . 'app.php', DIRECTORY_SEPARATOR . ltrim($this->data['DIR'], '/ ') . 'setup.php') as $serverFile) {
                    file_put_contents($serverFile, $SERVERCODE);
                }
                if (!file_exists(DIRECTORY_SEPARATOR . ltrim($this->data['DIR'], '/ ') . 'index.php')) {
                    copy('~index.php', DIRECTORY_SEPARATOR . ltrim($this->data['DIR'], '/ ') . 'index.php');
                }
                if (isset($_REQUEST['u'])) {
                    unlink($this->data['PHAR_INCLUDE']);
                    $this->data['data_out']->js .= ' $.WebfanDesktop.Registry.Programs[\'frdl-webfan\'].config.EXTRA_INSTALLER = null;	';
                }
                $config['URL'] = str_replace('setup.phpsetup.php', 'setup.php', $config['URL']);
                $this->data['data_out']->js .= '
			                	$(\'#window_main_postbox-ttt-all\').wdPostbox(\'deleteMessage\', \'install-frdl-webfan-installer-' . $this->data['config_new']['VERSION'] . '\',  \'update\', false);	 	   	
					 	   	
					 	   	
					 	   	alert(\'' . $msg . '\\nPlease set up the configuration next...\');
			 		    	window.location = "' . $config['URL'] . '";
			 		    	';
                $this->writeToConfigFile();
                \webdof\wResponse::status(201);
                die('Extracted');
            } else {
                $str = 'Error extracting php archive (' . __LINE__ . ') ';
                \webdof\wResponse::status(409);
                if (true === $this->debug) {
                    trigger_error($str, E_USER_ERROR);
                }
                die($str);
            }
        } elseif (isset($_REQUEST[self::CMD])) {
            return $this->_api_request_cmd($_REQUEST[self::CMD]);
        }
        \webdof\wResponse::status(404);
        die('Unexpected end of api.request');
    }
Example #2
0
    /**  <div data-frdl-desktop-widget="widget://example.com/webfan/marketplace"></div>
    * 
    * @param string $html : result reference
    * @param string $component (example: 'vendor/component')
    * @param boolean $preferLocal : if true search for the widget installed locally, if false use 
    * 
    * @return $this : methodchain
    */
    public function html($component, $Type = null, $options = array('preferLocal' => true, 'forceLibraryJSInvocation' => true, 'URL_DEFAULT' => null, 'components_dir' => null, 'components_url' => null))
    {
        $types = $this->types();
        if (!is_string($options['components_dir']) || !is_dir($options['components_dir'])) {
            $options['components_dir'] = $this->components_dir;
        }
        if (!is_string($options['components_url'])) {
            $options['components_url'] = $this->components_url;
        }
        if (!is_string($options['URL_DEFAULT'])) {
            $options['URL_DEFAULT'] = self::URL_DEFAULT;
        }
        if (true !== $options['preferLocal'] && false !== $options['preferLocal']) {
            $u = \webdof\wURI::getInstance();
            $options['preferLocal'] = 'install.phar' === $u->getU()->file || 'install.php' === $u->getU()->file ? false : true;
        }
        $get = $this->q('html', $Type);
        if (is_callable($get)) {
            return call_user_func_array($get, array($component, $options));
        }
        return false;
        $preferLocal = (bool) $preferLocal;
        if (true === $options['preferLocal'] && is_dir($options['components_dir'] . str_replace('/', DIRECTORY_SEPARATOR, $component))) {
            $url = $options['components_url'];
            $url = str_replace('widget://', 'http://', $url) . $component;
        } else {
            $url = $options['URL_DEFAULT'] . $component;
        }
        $JSInvocation = false === $options['forceLibraryJSInvocation'] ? '' : <<<SCRIPTtag

<script>(function(){if('undefined'===typeof frdl && 0===document.querySelectorAll('script[src*="api.webfan.de\\/api-d\\/4\\/js-api\\/library.js"]').length && 0===document.querySelectorAll('script[src*="flow.js"]').length){var h=document.getElementsByTagName("head",document)[0];var s=document.createElement('script');s.setAttribute('async','true');s.setAttribute('src','http://api.webfan.de/api-d/4/js-api/library.js');h.insertBefore(s,h.firstChild);}}());</script>          

SCRIPTtag;
        $html = <<<WEBAPP

<div data-frdl-component="{$url}"></div>{$JSInvocation}

WEBAPP;
        return $html;
    }
Example #3
0
 protected function __todo(\webdof\wURI $u = null)
 {
     $u = null === $u ? \webdof\wURI::getInstance() : $u;
     $this->login();
     ini_set('display_errors', isset($this->aSess['isAdmin']) ? $this->aSess['isAdmin'] : 0);
     ob_start(function ($content) {
         $parseHeaders = function ($serverVars = NULL) {
             if (!is_array($serverVars)) {
                 $serverVars = $_SERVER;
             }
             $headers = array();
             foreach ($_SERVER as $key => $value) {
                 if (substr($key, 0, 5) == "HTTP_") {
                     $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))));
                     $headers[$key] = $value;
                     if ($key == 'If-None-Match') {
                         $ifNoneMatch = $headers['If-None-Match'];
                         if (substr($ifNoneMatch, 0, 1) != '"') {
                             $ifNoneMatch = NULL;
                         }
                     }
                     if ($key == 'If-Modified-Since') {
                         $ifModifiedSince = $headers['If-Modified-Since'];
                     }
                 }
             }
             return $headers;
         };
         $headers = $parseHeaders($_SERVER);
         if (isset($headers['X-Requested-With']) && 'XMLHttpRequest' === $headers['X-Requested-With']) {
             preg_match("/<body>(.*)<\\/body>/s", $content, $matches);
             //for cache GET:
             $_GET['_______X-Requested-With'] = 'XMLHttpRequest';
             if (isset($matches[1])) {
                 $content = (isset($documentTitle) ? '<meta name="document.title" content="' . strip_tags($documentTitle) . '" />' : '') . $matches[1];
             }
         }
         if (preg_match("/<\\/html>(?<rest>.*)/s", $content, $matches)) {
             if (isset($matches['rest'])) {
                 $content = str_replace('</html>' . $matches['test'], $matches['test'] . '</html>', $content);
             }
         }
         if (preg_match("/(?<start>.*)<\\!DOCTYPE html>/s", $content, $matches)) {
             if (isset($matches['start'])) {
                 $content = str_replace($matches['start'] . '<!DOCTYPE html>', '<!DOCTYPE html>' . $matches['start'], $content);
             }
         }
         return $content;
     });
     $this->modul = '404';
     $_u = parse_url($this->data['config']['URL']);
     $uri = substr($u->getU()->classic['path'], strlen($_u['path']), strlen($u->getU()->classic['path']));
     $_u = explode('/', $uri);
     if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . $_u[1] . DIRECTORY_SEPARATOR . self::APPFILE)) {
         $this->modul = $_u[1];
     }
     $this->process_modul($this->modul);
     return $this;
 }
Example #4
0
File: A.php Project: frdl/webfan
 /**
  * todo...
  * 
  */
 protected function apply_fm_flow()
 {
     $args = func_get_args();
     $THIS =& $this;
     $SELF =& $this;
     \webfan\App::God()->{'$'}('?session_started', function ($startIf = true) use($THIS, $SELF) {
         $r = false;
         if (php_sapi_name() !== 'cli') {
             if (version_compare(phpversion(), '5.4.0', '>=')) {
                 $r = session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE;
             } else {
                 $r = '' === session_id() ? FALSE : TRUE;
             }
         }
         if (true === $startIf && false === $r) {
             if (!session_start()) {
                 if (isset($THIS) && isset($THIS->debug) && true === $THIS->debug) {
                     trigger_error('Cannot start session in ' . basename(__FILE__) . ' ' . __LINE__, E_USER_WARNING);
                 }
             }
         }
         return $r;
     });
     $func_jsonP = function ($str) use($THIS, $SELF) {
         $r = isset($THIS) && isset($THIS->data['data_out']) ? $THIS->data['data_out'] : new \stdclass();
         $r->type = 'print';
         $r->out = $str;
         $fnregex = "/^[A-Za-z0-9\$\\.-_\\({1}\\){1}]+\$/";
         $callback = isset($_REQUEST['callback']) && preg_match($fnregex, $_REQUEST['callback']) ? strip_tags($_REQUEST['callback']) : '';
         if ($callback === '') {
             $o = json_encode($r);
         } else {
             $r->callback = $callback;
             $o = $callback . '(' . json_encode($r) . ')';
         }
         return $o;
     };
     /**
      * http://php.net/manual/en/function.apache-request-headers.php#116645
      */
     \webfan\App::God()->{'$'}('?request_headers', function () {
         if (function_exists('apache_request_headers')) {
             return apache_request_headers();
         }
         foreach ($_SERVER as $K => $V) {
             $a = explode('_', $K);
             if (array_shift($a) === 'HTTP') {
                 array_walk($a, function (&$v) {
                     $v = ucfirst(strtolower($v));
                 });
                 $retval[join('-', $a)] = $V;
             }
         }
         return $retval;
     });
     \webfan\App::God()->{'$'}('$.sem.parse', function ($sem) use($THIS, $SELF) {
         $str = $SELF::TPL_SERVER_ROUTE;
         foreach ($sem as $k => $v) {
             $s = is_array($v) ? implode(',', $v) : $v;
             $str = str_replace('{$' . $k . '}', $s, $str);
         }
         return $str;
     })->{'$'}('$.sem.unparse', function (&$sem, $route) use($THIS, $SELF) {
         $seg = explode('.', $route);
         $sem['cmd'] = array_shift($seg);
         $sem['responseformat'] = array_shift($seg);
         $sem['modul'] = array_shift($seg);
         $sem['responsebuffers'] = explode(',', array_shift($seg));
         $sem['.nodes'] = $seg;
         return $THIS;
     })->{'$'}('$.sem->getFomatterMethod', function ($format) {
         if ('jsonp' !== $format && 'json' !== $format) {
             return false;
         }
         return '$.sem.format->' . $format;
     })->{'$'}('$.sem.format->json', $func_jsonP)->{'$'}('$.sem.format->jsonp', $func_jsonP)->{'$'}('$.sem.get->mime', function ($format = null, $file = null, $apply = true, $default = '') use($THIS, $SELF) {
         $file = null === $file || !is_string($file) ? \webdof\wURI::getInstance()->getU()->file : $file;
         if (true === $apply) {
             $THIS->format = $default;
         }
         $mime_types = array('' => array('text/html'), 'frdl' => array('application/frdl-bin'), 'jpg' => array('image/jpeg'), 'jpeg' => array('image/jpeg'), 'jpe' => array('image/jpeg'), 'gif' => array('image/gif'), 'png' => array('image/png'), 'bmp' => array('image/bmp'), 'flv' => array('video/x-flv'), 'js' => array('application/x-javascript'), 'json' => array('application/json'), 'jsonp' => array('application/x-javascript'), 'tiff' => array('image/tiff'), 'css' => array('text/css'), 'xml' => array('application/xml'), 'doc' => array('application/msword'), 'docx' => array('application/msword'), 'xls' => array('application/vnd.ms-excel'), 'xlm' => array('application/vnd.ms-excel'), 'xld' => array('application/vnd.ms-excel'), 'xla' => array('application/vnd.ms-excel'), 'xlc' => array('application/vnd.ms-excel'), 'xlw' => array('application/vnd.ms-excel'), 'xll' => array('application/vnd.ms-excel'), 'ppt' => array('application/vnd.ms-powerpoint'), 'pps' => array('application/vnd.ms-powerpoint'), 'rtf' => array('application/rtf'), 'pdf' => array('application/pdf'), 'html' => array('text/html'), 'htm' => array('text/html'), 'php' => array('text/html'), 'txt' => array('text/plain'), 'mpeg' => array('video/mpeg'), 'mpg' => array('video/mpeg'), 'mpe' => array('video/mpeg'), 'mp3' => array('audio/mpeg3'), 'wav' => array('audio/wav'), 'aiff' => array('audio/aiff'), 'aif' => array('audio/aiff'), 'avi' => array('video/msvideo'), 'wmv' => array('video/x-ms-wmv'), 'mov' => array('video/quicktime'), 'zip' => array('application/zip'), 'tar' => array('application/x-tar'), 'swf' => array('application/x-shockwave-flash'), 'odt' => array('application/vnd.oasis.opendocument.text'), 'ott' => array('application/vnd.oasis.opendocument.text-template'), 'oth' => array('application/vnd.oasis.opendocument.text-web'), 'odm' => array('application/vnd.oasis.opendocument.text-master'), 'odg' => array('application/vnd.oasis.opendocument.graphics'), 'otg' => array('application/vnd.oasis.opendocument.graphics-template'), 'odp' => array('application/vnd.oasis.opendocument.presentation'), 'otp' => array('application/vnd.oasis.opendocument.presentation-template'), 'ods' => array('application/vnd.oasis.opendocument.spreadsheet'), 'ots' => array('application/vnd.oasis.opendocument.spreadsheet-template'), 'odc' => array('application/vnd.oasis.opendocument.chart'), 'odf' => array('application/vnd.oasis.opendocument.formula'), 'odb' => array('application/vnd.oasis.opendocument.database'), 'odi' => array('application/vnd.oasis.opendocument.image'), 'oxt' => array('application/vnd.openofficeorg.extension'), 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document'), 'docm' => array('application/vnd.ms-word.document.macroEnabled.12'), 'dotx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.template'), 'dotm' => array('application/vnd.ms-word.template.macroEnabled.12'), 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'), 'xlsm' => array('application/vnd.ms-excel.sheet.macroEnabled.12'), 'xltx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.template'), 'xltm' => array('application/vnd.ms-excel.template.macroEnabled.12'), 'xlsb' => array('application/vnd.ms-excel.sheet.binary.macroEnabled.12'), 'xlam' => array('application/vnd.ms-excel.addin.macroEnabled.12'), 'pptx' => array('application/vnd.openxmlformats-officedocument.presentationml.presentation'), 'pptm' => array('application/vnd.ms-powerpoint.presentation.macroEnabled.12'), 'ppsx' => array('application/vnd.openxmlformats-officedocument.presentationml.slideshow'), 'ppsm' => array('application/vnd.ms-powerpoint.slideshow.macroEnabled.12'), 'potx' => array('application/vnd.openxmlformats-officedocument.presentationml.template'), 'potm' => array('application/vnd.ms-powerpoint.template.macroEnabled.12'), 'ppam' => array('application/vnd.ms-powerpoint.addin.macroEnabled.12'), 'sldx' => array('application/vnd.openxmlformats-officedocument.presentationml.slide'), 'sldm' => array('application/vnd.ms-powerpoint.slide.macroEnabled.12'), 'thmx' => array('application/vnd.ms-officetheme'), 'onetoc' => array('application/onenote'), 'onetoc2' => array('application/onenote'), 'onetmp' => array('application/onenote'), 'onepkg' => array('application/onenote'), 'po' => array("Content-Type: text/plain; charset=UTF-8;", "Content-Transfer-Encoding: 8bit\n"), 'key' => array('application/pkcs8'), 'crt' => array('application/x-x509-ca-cert'), 'cer' => array('pkix-cert'), 'crl' => array('application/x-pkcs7-crl'), 'pfx' => array('application/x-pkcs12'), 'bin' => array("Content-Type: application/octet-stream", "Content-Transfer-Encoding: binary\n"), 'dat' => array("Content-Type: application/octet-stream", "Content-Transfer-Encoding: binary\n", 'Content-Disposition:attachment; filename="' . $file . '"'));
         $fnFromatFromHeaders = function () use($mime_types) {
             /**
              * 
              * @todo
              * 
              */
             return false;
             $headers = \webfan\App::God()->{'?request_headers'}();
             if (isset($headers['Accept'])) {
                 $accepts = explode(',', $headers['Accept']);
                 if (count($accepts) === 1) {
                     $_ = explode('/', $accepts[0]);
                     $_ = explode(';', $_[1]);
                     $_ = explode('+', $_[0]);
                     if ('*' !== $_s[0]) {
                         return isset($mime_types[$_s[0]]) ? $_s[0] : false;
                     }
                 }
             }
             return false;
         };
         if (null === $format || false === $format || !isset($mime_types[$format])) {
             $fromHeaders = $fnFromatFromHeaders();
             $_e = explode('.', $file);
             $_e = array_reverse($_e);
             $extension = count($_e) > 1 ? $_e[0] : '';
             if ('?' === $format) {
                 $format = $extension;
                 if (!isset($mime_types[$format]) && false !== $fromHeaders) {
                     $format = $fromHeaders;
                 }
             } elseif ('?:extension' === $format) {
                 $format = $extension;
             } elseif ('?:headers' === $format) {
                 $format = $fromHeaders;
             }
         }
         if (null !== $format && false !== $format) {
             if (true === $apply) {
                 $THIS->format = $format;
             }
             return isset($mime_types[$format]) ? $mime_types[$format] : false;
         } else {
             return $mime_types;
         }
     });
     return $this;
 }
Example #5
0
File: fexe.php Project: frdl/webfan
 protected final function default_route(\webdof\wURI $u = null)
 {
     $u = null === $u ? \webdof\wURI::getInstance() : $u;
     $inc_files = get_included_files();
     array_walk($inc_files, function (&$file, $num) {
         $file = basename($file);
     }, $this);
     $_file = (isset($this->data['config']['DIR_PACKAGE']) ? $this->data['config']['DIR_PACKAGE'] : getcwd() . DIRECTORY_SEPARATOR) . $u->getU()->file;
     if (in_array(self::URI_DIR_API, $u->getU()->dirs) || in_array('api.php', $inc_files) || 'api.php' === $u->getU()->file || 'frdl.jsonp' === $u->getU()->file || 'api' === $u->getU()->file || 'jsonp' === $u->getU()->file_ext || 'json' === $u->getU()->file_ext || 'xml' === $u->getU()->file_ext || 'dat' === $u->getU()->file_ext || 'bin' === $u->getU()->file_ext || 'api' === $u->getU()->file_ext) {
         $this->route = self::SERVER_API;
     } elseif ('/' === $u->getU()->req_uri || basename(__FILE__) === $u->getU()->file || 'install.phar' === $u->getU()->file || 'install.php' === $u->getU()->file || substr($u->getU()->location, 0, strlen($this->data['config']['URL'])) === $this->data['config']['URL']) {
         $this->route = self::SERVER_PAGE;
     } elseif (file_exists($_file) && is_file($_file)) {
         $this->route = self::SERVER_HTML;
     } else {
         $this->route = self::SERVER_404;
     }
     return $this;
 }