示例#1
0
 /**
  * This function is used to create archives .
  * zip
  *
  * @return boolean
  */
 public function create_zip()
 {
     $files = 0;
     $offset = 0;
     $central = "";
     if (!empty($this->options['sfx'])) {
         if ($fp = @fopen($this->options['sfx'], "rb")) {
             $temp = fread($fp, filesize($this->options['sfx']));
             fclose($fp);
             $this->add_data($temp);
             $offset += strlen($temp);
             unset($temp);
         } else {
             $this->error[] = "Could not open sfx module from {$this->options['sfx']}.";
         }
     }
     $pwd = getcwd();
     chdir($this->options['basedir']);
     foreach ($this->files as $current) {
         if ($current['name'] == $this->options['name']) {
             continue;
         }
         $timedate = explode(" ", date("Y n j G i s", $current['stat'][9]));
         $timedate = $timedate[0] - 1980 << 25 | $timedate[1] << 21 | $timedate[2] << 16 | $timedate[3] << 11 | $timedate[4] << 5 | $timedate[5];
         $block = pack("VvvvV", 0x4034b50, 0xa, 0x0, isset($current['method']) || $this->options['method'] == 0 ? 0x0 : 0x8, $timedate);
         if ($current['stat'][7] == 0 && $current['type'] == 5) {
             $block .= pack("VVVvv", 0x0, 0x0, 0x0, strlen($current['name2']) + 1, 0x0);
             $block .= $current['name2'] . "/";
             $this->add_data($block);
             $central .= pack("VvvvvVVVVvvvvvVV", 0x2014b50, 0x14, $this->options['method'] == 0 ? 0x0 : 0xa, 0x0, isset($current['method']) || $this->options['method'] == 0 ? 0x0 : 0x8, $timedate, 0x0, 0x0, 0x0, strlen($current['name2']) + 1, 0x0, 0x0, 0x0, 0x0, $current['type'] == 5 ? 0x10 : 0x0, $offset);
             $central .= $current['name2'] . "/";
             $files++;
             $offset += 31 + strlen($current['name2']);
         } elseif ($current['stat'][7] == 0) {
             $block .= pack("VVVvv", 0x0, 0x0, 0x0, strlen($current['name2']), 0x0);
             $block .= $current['name2'];
             $this->add_data($block);
             $central .= pack("VvvvvVVVVvvvvvVV", 0x2014b50, 0x14, $this->options['method'] == 0 ? 0x0 : 0xa, 0x0, isset($current['method']) || $this->options['method'] == 0 ? 0x0 : 0x8, $timedate, 0x0, 0x0, 0x0, strlen($current['name2']), 0x0, 0x0, 0x0, 0x0, $current['type'] == 5 ? 0x10 : 0x0, $offset);
             $central .= $current['name2'];
             $files++;
             $offset += 30 + strlen($current['name2']);
         } elseif ($fp = @fopen($current['name'], "rb")) {
             $temp = fread($fp, $current['stat'][7]);
             fclose($fp);
             $crc32 = G::encryptCrc32($temp);
             if (!isset($current['method']) && $this->options['method'] == 1) {
                 $temp = gzcompress($temp, $this->options['level']);
                 $size = strlen($temp) - 6;
                 $temp = substr($temp, 2, $size);
             } else {
                 $size = strlen($temp);
             }
             $block .= pack("VVVvv", $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0);
             $block .= $current['name2'];
             $this->add_data($block);
             $this->add_data($temp);
             unset($temp);
             $central .= pack("VvvvvVVVVvvvvvVV", 0x2014b50, 0x14, $this->options['method'] == 0 ? 0x0 : 0xa, 0x0, isset($current['method']) || $this->options['method'] == 0 ? 0x0 : 0x8, $timedate, $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0, 0x0, 0x0, 0x0, 0x0, $offset);
             $central .= $current['name2'];
             $files++;
             $offset += 30 + strlen($current['name2']) + $size;
         } else {
             $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
         }
     }
     $this->add_data($central);
     $this->add_data(pack("VvvvvVVv", 0x6054b50, 0x0, 0x0, $files, $files, strlen($central), $offset, !empty($this->options['comment']) ? strlen($this->options['comment']) : 0x0));
     if (!empty($this->options['comment'])) {
         $this->add_data($this->options['comment']);
     }
     chdir($pwd);
     return 1;
 }
示例#2
0
 public function encryptCrc32($string)
 {
     if (!class_exists('G')) {
         $realdocuroot = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']);
         $docuroot = explode('/', $realdocuroot);
         array_pop($docuroot);
         $pathhome = implode('/', $docuroot) . '/';
         array_pop($docuroot);
         $pathTrunk = implode('/', $docuroot) . '/';
         require_once $pathTrunk . 'gulliver/system/class.g.php';
     }
     return G::encryptCrc32($string);
 }
示例#3
0
 /**
  * If the primary key is not <code>null</code>, return the hashcode of the
  * primary key.  Otherwise calls <code>Object.hashCode()</code>.
  *
  * @return     int Hashcode
  */
 public function hashCode()
 {
     if (!class_exists('G')) {
         $realdocuroot = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']);
         $docuroot = explode('/', $realdocuroot);
         array_pop($docuroot);
         $pathhome = implode('/', $docuroot) . '/';
         array_pop($docuroot);
         $pathTrunk = implode('/', $docuroot) . '/';
         require_once $pathTrunk . 'gulliver/system/class.g.php';
     }
     $ok = $this->getPrimaryKey();
     if ($ok === null) {
         return G::encryptCrc32(serialize($this));
     }
     return G::encryptCrc32(serialize($ok));
     // serialize because it could be an array ("ComboKey")
 }
示例#4
0
    /**
     * This function updates to the files
     *
     *
     * @name upgrade
     *
     * param
     * @return array
     */
    public function upgrade ()
    {
        //get special files
        $sListFile = '';
        $sCheckListFile = '';
        $sPatchVersionFile = '';
        $sPoFile = '';
        $sSchemaFile = '';
        $sSchemaRBACFile = '';
        foreach ($this->sFilesList->files as $sFile) {
            if (basename( $sFile ) == 'schema.xml') {
                if (strpos( $sFile, '/rbac/engine/' ) === false) {
                    $sOldSchema = '';
                    $sSchemaFile = $sFile;
                } else {
                    $sOldSchemaRBAC = '';
                    $sSchemaRBACFile = $sFile;
                }
            }

            //files.lst
            if (basename( $sFile ) == 'files.lst') {
                $this->sUpgradeFileList = $sFile;
            }

            //files.lst
            if (basename( $sFile ) == 'patch.version.txt') {
                $sPatchVersionFile = $sFile;
            }

            //files.rev.txt
            if (substr( basename( $sFile ), 0, 6 ) == 'files.' && substr( basename( $sFile ), - 4 ) == '.txt') {
                $sCheckListFile = $sFile;
            }

            //po files
            $sExtension = substr( $sFile, strrpos( $sFile, '.' ) + 1, strlen( $sFile ) );
            if ($sExtension == 'po') {
                $sPoFile = $sFile;
            }
        }

        $pmVersion = explode( '-', self::getVersion() );
        array_shift( $pmVersion );
        $patchVersion = explode( '-', $this->sRevision );

        if ($sPatchVersionFile != '' && file_exists( $sPatchVersionFile )) {
            $this->sRevision = file_get_contents( $sPatchVersionFile );
            $patchVersion = explode( '-', $this->sRevision );
        }

        if (! file_exists( PATH_DATA . 'log' . PATH_SEP )) {
            G::mk_dir( PATH_DATA . 'log' . PATH_SEP );
        }

        //empty query log
        $sqlLog = PATH_DATA . 'log' . PATH_SEP . "query.log";
        $fp = fopen( $sqlLog, "w+" );
        fwrite( $fp, "" );
        fclose( $fp );

        $aEnvironmentsUpdated = array ();
        $aEnvironmentsDiff = array ();
        $aErrors = array ();

        //now will verify each folder and file has permissions to write and add files.
        if ($this->sUpgradeFileList != '') {
            $bCopySchema = true;
            $oFile = fopen( $this->sUpgradeFileList, 'r' );
            while ($sLine = trim( fgets( $oFile ) )) {
                $sLine = substr( $sLine, 1 );
                $aAux = explode( PATH_SEP, $sLine );
                array_shift( $aAux );
                $sFilePath = implode( PATH_SEP, $aAux );
                $targetFileName = PATH_TRUNK . $sFilePath;
                if (! is_dir( $this->sPath . 'processmaker' . PATH_SEP . $sFilePath )) {
                    //if we are updating or deleting a file
                    if (file_exists( $this->sPath . 'processmaker' . PATH_SEP . $sFilePath )) {
                        if (file_exists( $targetFileName )) {
                            if (! is_writable( $targetFileName )) {
                                throw (new Exception( "File $targetFileName is not writable." ));
                            }
                        } else {
                            //verify parent folder, and ask if that folder is writable
                            $auxDir = explode( '/', $targetFileName );
                            array_pop( $auxDir );
                            $parentDir = implode( '/', $auxDir );
                            if (! is_dir( $parentDir )) {
                                //throw (new Exception("File $parentDir is an invalid directory."));
                                G::mk_dir( $parentDir );
                            }
                            if (! is_writable( $parentDir )) {
                                throw (new Exception( "Directory $parentDir is not writable." ));
                            }
                        }
                    } else {
                        //delete unused files
                        if (file_exists( $targetFileName ) && ! is_writable( $targetFileName )) {
                            throw (new Exception( "File $targetFileName is not writable." ));
                        }
                    }
                } else {
                    $dirName = PATH_TRUNK . $sFilePath;
                    if ($dirName[strlen( $dirName ) - 1] == '/') {
                        $dirName = substr( $dirName, 0, strlen( $dirName ) - 1 );
                    }
                    $auxDir = explode( '/', $dirName );
                    array_pop( $auxDir );
                    $parentDir = implode( '/', $auxDir );
                    if (file_exists( $dirName )) {
                        if (is_writable( $dirName )) {
                            //print "e. ok $dirName <br>";
                        } else {
                            throw (new Exception( "$dirName  is not writable" ));
                        }
                    } else {
                        if (is_writable( $parentDir )) {
                            mkdir( $dirName, 0777 );
                        } else {
                            throw (new Exception( "$dirName does not exist and parent folder $parentDir is not writable" ));
                        }
                    }
                }
            }
        }

        //processing list file files.lst
        if ($this->sUpgradeFileList != '') {
            $bCopySchema = true;
            $oFile = fopen( $this->sUpgradeFileList, 'r' );
            while ($sLine = trim( fgets( $oFile ) )) {
                $action = substr( $sLine, 0, 1 );
                $sLine = substr( $sLine, 1 );
                $aAux = explode( PATH_SEP, $sLine );
                array_shift( $aAux );
                $sFilePath = implode( PATH_SEP, $aAux );
                $targetFileName = PATH_TRUNK . $sFilePath;
                if (strtoupper( $action ) != 'D') {
                    if (! is_dir( $this->sPath . 'processmaker' . PATH_SEP . $sFilePath )) {
                        if (file_exists( $this->sPath . 'processmaker' . PATH_SEP . $sFilePath )) {
                            if (strpos( $sFilePath, 'schema.xml' ) !== false && $bCopySchema) {
                                $bCopySchema = false;
                                $sOldSchema = str_replace( 'schema.xml', 'schema_' . date( 'Ymd' ) . '.xml', PATH_TRUNK . $sFilePath );
                                $this->pm_copy( PATH_TRUNK . $sFilePath, $sOldSchema );
                            }
                            if (file_exists( $targetFileName )) {
                                if (is_writable( $targetFileName )) {
                                    $this->pm_copy( $this->sPath . 'processmaker' . PATH_SEP . $sFilePath, $targetFileName );
                                    @chmod( $targetFileName, 0666 );
                                } else {
                                    throw (new Exception( "Failed to open file: Permission denied in $targetFileName." ));
                                }
                            } else {
                                $this->pm_copy( $this->sPath . 'processmaker' . PATH_SEP . $sFilePath, $targetFileName );
                                @chmod( $targetFileName, 0666 );
                            }
                        } else {
                            //delete unused files
                            if (file_exists( $targetFileName )) {
                                @unlink( $targetFileName );
                            }
                        }
                    } else {
                        if (! file_exists( PATH_TRUNK . $sFilePath )) {
                            mkdir( PATH_TRUNK . $sFilePath, 0777 );
                        }
                    }
                } elseif (file_exists( PATH_TRUNK . $sFilePath ) && $sFilePath != 'workflow/engine/gulliver') {
                    @unlink( PATH_TRUNK . $sFilePath );
                }
            }
        }

        //end files copied.
        $missedFiles = '';
        $distinctFiles = '';
        $missed = 0;
        $distinct = 0;
        //checking files of this installation server with the files in Repository Code.
        if ($sCheckListFile != '') {
            $fp = fopen( $sCheckListFile, 'r' );
            while (! feof( $fp )) {
                $line = explode( ' ', fgets( $fp ) );
                if (count( $line ) == 3) {
                    $file = PATH_TRUNK . trim( $line[2] );
                    if (is_readable( $file )) {
                        $size = sprintf( "%07d", filesize( $file ) );
                        $checksum = sprintf( "%010u", G::encryptCrc32( file_get_contents( $file ) ) );
                        if (! ($line[0] == $size && $line[1] == $checksum) && substr( $file, - 4 ) != '.xml') {
                            $distinctFiles .= $file . "\n";
                            $distinct ++;
                        }
                    } else {
                        $missedFiles .= $file . "\n";
                        $missed ++;
                    }
                }
            }
            fclose( $fp );
        }

        if ($missed > 0) {
            $aErrors[] = "Warning: there are $missed missed files. ";
        }
        $aErrors[] = $missedFiles;

        if ($distinct > 0) {
            $aErrors[] = "Warning: there are $distinct files with differences. ";
            $aErrors[] = $distinctFiles;
        }

        //now include the files and classes needed for upgrade databases, dont move this files, because we
        //are getting the last files in this point.  Even the files was in the patch we will take the new ones.
        include PATH_METHODS . PATH_SEP . 'setup' . PATH_SEP . 'upgrade_RBAC.php';
        G::LoadClass( 'languages' );
        G::LoadSystem( 'database_mysql' );

        $bForceXml = true;
        $bParseSchema = true;
        $bParseSchemaRBAC = true;
        $oDirectory = dir( PATH_DB );

        //count db.php files ( workspaces )
        $aWorkspaces = array ();
        while (($sObject = $oDirectory->read())) {
            if (is_dir( PATH_DB . $sObject ) && substr( $sObject, 0, 1 ) != '.' && file_exists( PATH_DB . $sObject . PATH_SEP . 'db.php' )) {
                $aWorkspaces[] = $sObject;
            }
        }
        $aUpgradeData = array ();
        $aUpgradeData['workspaces'] = $aWorkspaces;
        $aUpgradeData['wsQuantity'] = count( $aWorkspaces );
        $aUpgradeData['sPoFile'] = $sPoFile;
        $aUpgradeData['bForceXmlPoFile'] = true;
        $aUpgradeData['sSchemaFile'] = $sSchemaFile;
        $aUpgradeData['sSchemaRBACFile'] = $sSchemaRBACFile;

        file_put_contents( PATH_DATA . 'log' . PATH_SEP . "upgrade.data.bin", serialize( $aUpgradeData ) );

        $sSchemaFile = '';
        $sPoFile = '';
        $sSchemaRBACFile = '';

        $oDirectory = dir( PATH_DB );
        while (($sObject = $oDirectory->read())) {
            if (is_dir( PATH_DB . $sObject ) && substr( $sObject, 0, 1 ) != '.') {
                if (file_exists( PATH_DB . $sObject . PATH_SEP . 'db.php' )) {
                    eval( $this->getDatabaseCredentials( PATH_DB . $sObject . PATH_SEP . 'db.php' ) );
                }
                $aEnvironmentsUpdated[] = $sObject;
                $aEnvironmentsDiff[] = $sObject;
            }
        }
        $oDirectory->close();
        @unlink( PATH_CORE . 'config/_databases_.php' );

        //clean up smarty directory
        $oDirectory = dir( PATH_SMARTY_C );
        while ($sFilename = $oDirectory->read()) {
            if (($sFilename != '.') && ($sFilename != '..')) {
                @unlink( PATH_SMARTY_C . PATH_SEP . $sFilename );
            }
        }

        G::LoadSystem('inputfilter');
        $filter = new InputFilter();

        //clean up xmlform folders
        $sDir = PATH_C . 'xmlform';
        $sDir = $filter->xssFilterHard($sDir, 'path');
        if (file_exists( $sDir ) && is_dir( $sDir )) {
            $oDirectory = dir( $sDir );
            while ($sObjectName = $oDirectory->read()) {
                if (($sObjectName != '.') && ($sObjectName != '..')) {
                    if (is_dir( $sDir . PATH_SEP . $sObjectName )) {
                        G::rm_dir( $sDir . PATH_SEP . $sObjectName );
                    }
                }
            }
            $oDirectory->close();
        }

        //changing the PM_VERSION according the patch file name
        $oFile = fopen( PATH_METHODS . 'login/version-pmos.php', 'w+' );
        if (isset( $this->sRevision ) && $this->sRevision != '') {
            fwrite( $oFile, "<?php\n  define ( 'PM_VERSION' , str_replace ( ' ','',  '1.6-" . $this->sRevision . "' ));\n?>" );
        } else {
            fwrite( $oFile, "<?php\n  define ( 'PM_VERSION' , str_replace ( ' ','',  'unknow' ));\n?>" );
        }
        fclose( $oFile );
        $ver = explode( "-", $this->sRevision );
        $this->aErrors = $aErrors;
        $this->aWorkspaces = $aWorkspaces;

        return $ver;
    }
示例#5
0
 /**
  * Returns a hash code value for the object.
  */
 public function hashCode()
 {
     if (!class_exists('G')) {
         $realdocuroot = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']);
         $docuroot = explode('/', $realdocuroot);
         array_pop($docuroot);
         $pathhome = implode('/', $docuroot) . '/';
         array_pop($docuroot);
         $pathTrunk = implode('/', $docuroot) . '/';
         require_once $pathTrunk . 'gulliver/system/class.g.php';
     }
     $h = G::encryptCrc32(serialize($this->value)) ^ G::encryptCrc32($this->comparison);
     if ($this->table !== null) {
         $h ^= G::encryptCrc32($this->table);
     }
     if ($this->column !== null) {
         $h ^= G::encryptCrc32($this->column);
     }
     foreach ($this->clauses as $clause) {
         // TODO: i KNOW there is a php incompatibility with the following line
         // but i dont remember what it is, someone care to look it up and
         // replace it if it doesnt bother us?
         // $clause->appendPsTo($sb='',$params=array());
         $sb = '';
         $params = array();
         $clause->appendPsTo($sb, $params);
         $h ^= G::encryptCrc32(serialize(array($sb, $params)));
         unset($sb, $params);
     }
     return $h;
 }
示例#6
0
 /**
  * Create a new DB connection object and connect to the specified
  * database
  *
  * @param mixed $dsn "data source name", see the self::parseDSN
  * method for a description of the dsn format.  Can also be
  * specified as an array of the format returned by DB::parseDSN().
  * @param int $flags Connection flags (e.g. PERSISTENT).
  *
  * @return Connection Newly created DB connection object
  * @throws SQLException
  * @see self::parseDSN()
  */
 public static function getConnection($dsn, $flags = 0)
 {
     if (is_array($dsn)) {
         $dsninfo = $dsn;
     } else {
         $dsninfo = self::parseDSN($dsn);
     }
     // gather any flags from the DSN
     if (isset($dsninfo['persistent']) && !empty($dsninfo['persistent'])) {
         $flags |= Creole::PERSISTENT;
     }
     if (isset($dsninfo['compat_assoc_lower']) && !empty($dsninfo['compat_assoc_lower'])) {
         $flags |= Creole::COMPAT_ASSOC_LOWER;
     }
     if (isset($dsninfo['compat_rtrim_string']) && !empty($dsninfo['compat_rtrim_string'])) {
         $flags |= Creole::COMPAT_RTRIM_STRING;
     }
     if (isset($dsninfo['compat_all']) && !empty($dsninfo['compat_all'])) {
         $flags |= Creole::COMPAT_ALL;
     }
     if ($flags & Creole::NO_ASSOC_LOWER) {
         trigger_error("The Creole::NO_ASSOC_LOWER flag has been deprecated, and is now the default behavior. Use Creole::COMPAT_ASSOC_LOWER to lowercase resulset keys.", E_USER_WARNING);
     }
     if (!class_exists('G')) {
         $realdocuroot = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']);
         $docuroot = explode('/', $realdocuroot);
         array_pop($docuroot);
         $pathhome = implode('/', $docuroot) . '/';
         array_pop($docuroot);
         $pathTrunk = implode('/', $docuroot) . '/';
         require_once $pathTrunk . 'gulliver/system/class.g.php';
     }
     // sort $dsninfo by keys so the serialized result is always the same
     // for identical connection parameters, no matter what their order is
     ksort($dsninfo);
     $connectionMapKey = G::encryptCrc32(serialize($dsninfo + array('compat_flags' => $flags & Creole::COMPAT_ALL)));
     // see if we already have a connection with these parameters cached
     if (isset(self::$connectionMap[$connectionMapKey]) && $dsninfo['phptype'] !== 'dbarray') {
         // persistent connections will be used if a non-persistent one was requested and is available
         // but a persistent connection will be created if a non-persistent one is present
         // TODO: impliment auto close of non persistent and replacing the
         // non persistent with the persistent object so as we dont have
         // both links open for no reason
         if (isset(self::$connectionMap[$connectionMapKey][1])) {
             // is persistent
             // a persistent connection with these parameters is already there,
             // so we return it, no matter what was specified as persistent flag
             $con = self::$connectionMap[$connectionMapKey][1];
         } else {
             // we don't have a persistent connection, and since the persistent
             // flag wasn't set either, we just return the non-persistent connection
             $con = self::$connectionMap[$connectionMapKey][0];
         }
         // if we're here, a non-persistent connection was already there, but
         // the user wants a persistent one, so it will be created
         if ($con->isConnected()) {
             return $con;
         }
     }
     // support "catchall" drivers which will themselves handle the details of connecting
     // using the proper RDBMS driver.
     if (isset(self::$driverMap['*'])) {
         $type = '*';
     } else {
         $type = $dsninfo['phptype'];
         if (!isset(self::$driverMap[$type])) {
             throw new SQLException("No driver has been registered to handle connection type: {$type}");
         }
     }
     // may need to make this more complex if we add support
     // for 'dbsyntax'
     $clazz = self::import(self::$driverMap[$type]);
     $obj = new $clazz();
     if (!$obj instanceof Connection) {
         throw new SQLException("Class does not implement creole.Connection interface: {$clazz}");
     }
     try {
         $obj->connect($dsninfo, $flags);
     } catch (SQLException $sqle) {
         $sqle->setUserInfo(isset($dsninfo["username"]) ? $dsninfo["username"] : "");
         throw $sqle;
     }
     $persistent = ($flags & Creole::PERSISTENT) === Creole::PERSISTENT;
     return self::$connectionMap[$connectionMapKey][(int) $persistent] = $obj;
 }