2012-03-29 16:42:09 -04:00
< ? php
2012-10-18 11:32:36 -04:00
2018-02-01 13:06:32 +00:00
use ProcessMaker\Util\Common ;
2017-08-14 16:13:46 -04:00
use ProcessMaker\Core\System ;
2017-08-23 15:39:12 -04:00
2018-02-01 13:06:32 +00:00
use Illuminate\Database\QueryException ;
use Illuminate\Support\Facades\DB ;
2017-08-14 16:51:17 -04:00
global $translation ;
2017-08-14 16:13:46 -04:00
2017-08-14 16:51:17 -04:00
include PATH_LANGUAGECONT . " translation. " . SYS_LANG ;
2012-03-29 16:42:09 -04:00
2017-08-23 15:39:12 -04:00
class InstallerModule extends Controller
2012-04-12 17:50:43 -04:00
{
2018-06-13 12:00:06 -04:00
const PHP_VERSION_MINIMUM_SUPPORTED = '5.6' ;
const PHP_VERSION_NOT_SUPPORTED = '7.2' ;
2012-10-18 11:32:36 -04:00
public $path_config ;
public $path_languages ;
public $path_plugins ;
public $path_xmlforms ;
public $path_shared ;
public $path_sep ;
2013-04-26 17:01:09 -04:00
public $systemName ;
2012-10-18 11:32:36 -04:00
public $link ; #resource for database connection
2018-02-01 13:06:32 +00:00
/**
* Default name for connection
*
* @ var string
*/
const CONNECTION_INSTALL = 'install' ;
const CONNECTION_TEST_INSTALL = 'testInstall' ;
2012-10-18 11:32:36 -04:00
2018-02-01 13:06:32 +00:00
/**
* Constructor
* We defined the paths for the installer
*/
2017-12-04 13:25:35 +00:00
public function __construct ()
2012-10-18 11:32:36 -04:00
{
$this -> path_config = PATH_CORE . 'config/' ;
$this -> path_languages = PATH_CORE . 'content/languages/' ;
$this -> path_plugins = PATH_CORE . 'plugins/' ;
$this -> path_xmlforms = PATH_CORE . 'xmlform/' ;
$this -> path_public = PATH_HOME . 'public_html/index.html' ;
$this -> path_shared = PATH_TRUNK . 'shared/' ;
$this -> path_sep = PATH_SEP ;
2013-04-26 17:01:09 -04:00
$this -> systemName = '' ;
2015-01-31 15:56:34 -04:00
//$this->path_documents = ;
$this -> path_translations = PATH_CORE . 'js/labels/' ;
$this -> path_translationsMafe = PATH_HOME . 'public_html/translations/' ;
2012-03-29 16:42:09 -04:00
}
2017-12-04 13:25:35 +00:00
public function index ( $httpData )
2012-10-18 11:32:36 -04:00
{
2017-05-31 12:11:58 -04:00
if ( file_exists ( FILE_PATHS_INSTALLED )) {
$this -> setJSVar ( 'messageError' , G :: LoadTranslation ( 'ID_PROCESSMAKER_ALREADY_INSTALLED' ));
$this -> includeExtJS ( 'installer/stopInstall' );
$this -> setView ( 'installer/mainStopInstall' );
G :: RenderPage ( 'publish' , 'extJs' );
return ;
}
2015-02-19 17:54:54 -04:00
if (( strtoupper ( substr ( PHP_OS , 0 , 3 )) == 'WIN' ) && ( file_exists ( $this -> path_shared . 'partner.info' ))) {
2017-05-31 12:11:58 -04:00
$this -> setJSVar ( 'messageError' , G :: LoadTranslation ( 'ID_NO_INSTALL' ));
$this -> includeExtJS ( 'installer/stopInstall' );
$this -> setView ( 'installer/mainStopInstall' );
G :: RenderPage ( 'publish' , 'extJs' );
2013-08-30 10:32:17 -04:00
return ;
}
2017-12-04 13:25:35 +00:00
$licenseContent = file_get_contents ( PATH_TRUNK . 'LICENSE.txt' );
2012-10-18 11:32:36 -04:00
2017-12-04 13:25:35 +00:00
$this -> includeExtJS ( 'installer/CardLayout' , false );
$this -> includeExtJS ( 'installer/Wizard' , false );
$this -> includeExtJS ( 'installer/Header' , false );
$this -> includeExtJS ( 'installer/Card' , false );
2012-10-18 11:32:36 -04:00
2017-12-04 13:25:35 +00:00
$this -> includeExtJS ( 'installer/installer_cards' );
$this -> includeExtJS ( 'installer/main' , false );
2012-10-18 11:32:36 -04:00
2017-12-04 13:25:35 +00:00
$this -> setJSVar ( 'licenseTxt' , $licenseContent );
2012-10-18 11:32:36 -04:00
2017-12-04 13:25:35 +00:00
$this -> setJSVar ( 'path_config' , $this -> path_config );
$this -> setJSVar ( 'path_languages' , $this -> path_languages );
$this -> setJSVar ( 'path_plugins' , $this -> path_plugins );
$this -> setJSVar ( 'path_xmlforms' , $this -> path_xmlforms );
$this -> setJSVar ( 'path_public' , $this -> path_public );
$this -> setJSVar ( 'path_shared' , $this -> path_shared );
$this -> setJSVar ( 'path_sep' , $this -> path_sep );
$this -> setJSVar ( 'path_translations' , $this -> path_translations );
$this -> setJSVar ( 'path_translationsMafe' , $this -> path_translationsMafe );
2012-10-18 11:32:36 -04:00
2017-12-04 13:25:35 +00:00
$this -> setView ( 'installer/main' );
2012-10-18 11:32:36 -04:00
2017-12-04 13:25:35 +00:00
G :: RenderPage ( 'publish' , 'extJs' );
2012-03-29 16:42:09 -04:00
}
2017-08-05 12:35:14 -04:00
/**
* This function can be create a new workspace
* The user need permission PM_SETUP_ADVANCE for this action
* @ return void
2017-12-04 13:25:35 +00:00
*/
public function newSite ()
2012-10-18 11:32:36 -04:00
{
2017-08-05 12:35:14 -04:00
if ( ! $this -> pmIsInstalled ()) {
$textStep1 = G :: LoadTranslation ( 'ID_PROCESSMAKER_REQUIREMENTS_DESCRIPTION_STEP4_1' );
$textStep2 = G :: LoadTranslation ( 'ID_PROCESSMAKER_REQUIREMENTS_DESCRIPTION_STEP5' );
$this -> includeExtJS ( 'installer/CardLayout' , false );
$this -> includeExtJS ( 'installer/Wizard' , false );
$this -> includeExtJS ( 'installer/Header' , false );
$this -> includeExtJS ( 'installer/Card' , false );
$this -> includeExtJS ( 'installer/newSite' , false );
$this -> setJSVar ( 'textStep1' , $textStep1 );
$this -> setJSVar ( 'textStep2' , $textStep2 );
$this -> setJSVar ( 'DB_ADAPTER' , DB_ADAPTER );
$aux = explode ( ':' , DB_HOST );
$this -> setJSVar ( 'DB_HOST' , $aux [ 0 ]);
2019-08-21 10:22:17 -04:00
$this -> setJSVar ( 'DB_PORT' , isset ( $aux [ 1 ]) ? $aux [ 1 ] : '3306' );
2017-08-05 12:35:14 -04:00
$this -> setJSVar ( 'DB_NAME' , 'workflow' );
$this -> setJSVar ( 'DB_USER' , '' );
$this -> setJSVar ( 'DB_PASS' , '' );
$this -> setJSVar ( 'pathConfig' , PATH_CORE . 'config' . PATH_SEP );
$this -> setJSVar ( 'pathLanguages' , PATH_LANGUAGECONT );
$this -> setJSVar ( 'pathPlugins' , PATH_PLUGINS );
$this -> setJSVar ( 'pathXmlforms' , PATH_XMLFORM );
$this -> setJSVar ( 'pathShared' , PATH_DATA );
$this -> setView ( 'installer/newSite' );
2012-10-18 11:32:36 -04:00
2017-08-05 12:35:14 -04:00
G :: RenderPage ( 'publish' , 'extJs' );
} else {
$this -> displayError ();
}
2012-03-29 16:42:09 -04:00
}
2018-02-01 13:06:32 +00:00
/**
* Set config connection
*
* @ param string $nameConnection name Connection
* @ param string $host
* @ param string $user
* @ param string $pass
* @ param string $database
* @ param int $port
* @ param array $options
*
* @ throws Exception
*/
public static function setNewConnection ( $nameConnection , $host , $user , $pass , $database , $port , $options = [])
{
try {
if ( empty ( $port )) {
$dbHost = explode ( ':' , $host );
$port = 3306 ;
if ( count ( $dbHost ) > 1 ) {
$port = $dbHost [ 1 ];
}
$host = $dbHost [ 0 ];
}
config ([ 'database.connections.' . $nameConnection => [
'driver' => 'mysql' ,
'host' => $host ,
'port' => $port ,
'database' => $database ,
'username' => $user ,
'password' => $pass ,
'unix_socket' => '' ,
'charset' => 'utf8' ,
'collation' => 'utf8_unicode_ci' ,
'prefix' => '' ,
'strict' => false ,
'engine' => 'InnoDB' ,
'options' => $options
]]);
DB :: connection ( $nameConnection ) -> getPdo ();
} catch ( Exception $e ) {
throw new Exception ( G :: LoadTranslation ( 'ID_MYSQL_CREDENTIALS_WRONG' ));
}
}
/**
* Get system information for review the requirements to install ProcessMaker
*
* @ return object
*/
2017-12-04 13:25:35 +00:00
public function getSystemInfo ()
2012-10-18 11:32:36 -04:00
{
2017-12-04 13:25:35 +00:00
$this -> setResponseType ( 'json' );
2012-10-18 11:32:36 -04:00
// PHP info and verification
$phpVer = phpversion ();
2017-12-04 13:25:35 +00:00
preg_match ( '/[0-9\.]+/' , $phpVer , $match );
$phpVerNum = ( float ) $match [ 0 ];
2012-10-18 11:32:36 -04:00
$info = new stdclass ();
$info -> php = new stdclass ();
$info -> mysql = new stdclass ();
$info -> openssl = new stdclass ();
$info -> curl = new stdclass ();
$info -> dom = new stdclass ();
$info -> gd = new stdclass ();
$info -> multibyte = new stdclass ();
$info -> soap = new stdclass ();
$info -> ldap = new stdclass ();
2014-10-29 11:56:51 -04:00
$info -> mcrypt = new stdclass ();
2012-10-18 11:32:36 -04:00
$info -> memory = new stdclass ();
2017-12-04 13:25:35 +00:00
$info -> php -> version = $phpVer ;
2018-06-13 12:00:06 -04:00
$info -> php -> result = (
version_compare ( phpversion (), self :: PHP_VERSION_MINIMUM_SUPPORTED , '>=' ) &&
version_compare ( phpversion (), self :: PHP_VERSION_NOT_SUPPORTED , '<' )) ? true : false ;
2012-10-18 11:32:36 -04:00
// MYSQL info and verification
$info -> mysql -> result = false ;
2017-12-04 13:25:35 +00:00
if ( function_exists ( 'mysqli_query' )) {
$mysqlVer = mysqli_get_client_info ();
preg_match ( '/[0-9\.]+/' , $mysqlVer , $match );
$mysqlNum = ( float ) $match [ 0 ];
2012-10-18 11:32:36 -04:00
$info -> mysql -> version = 'Client API version ' . $mysqlVer ;
2017-12-04 13:25:35 +00:00
$info -> mysql -> result = $mysqlNum >= 5.0 ;
2012-10-18 11:32:36 -04:00
}
2012-03-29 16:42:09 -04:00
2012-10-18 11:32:36 -04:00
// OpenSSL info
$info -> openssl -> result = false ;
2013-03-11 10:23:59 -04:00
$info -> openssl -> version = G :: LoadTranslation ( 'ID_NOT_ENABLED' );
2017-12-04 13:25:35 +00:00
if ( function_exists ( 'openssl_open' )) {
2012-10-18 11:32:36 -04:00
$info -> openssl -> result = true ;
2013-03-11 10:23:59 -04:00
$info -> openssl -> version = G :: LoadTranslation ( 'ID_ENABLED' );
2012-10-18 11:32:36 -04:00
}
2012-03-29 16:42:09 -04:00
2012-10-18 11:32:36 -04:00
// Curl info
$info -> curl -> result = false ;
2013-03-11 10:23:59 -04:00
$info -> curl -> version = G :: LoadTranslation ( 'ID_NOT_ENABLED' );
2017-12-04 13:25:35 +00:00
if ( function_exists ( 'curl_version' )) {
2012-10-18 11:32:36 -04:00
$info -> curl -> result = true ;
$version = curl_version ();
$info -> curl -> version = 'cURL ' . $version [ 'version' ];
$info -> openssl -> version = $version [ 'ssl_version' ];
}
2012-03-29 16:42:09 -04:00
2012-10-18 11:32:36 -04:00
// DOMDocument info
$info -> dom -> result = false ;
2013-03-11 10:23:59 -04:00
$info -> dom -> version = G :: LoadTranslation ( 'ID_NOT_ENABLED' );
2017-12-04 13:25:35 +00:00
if ( class_exists ( 'DOMDocument' )) {
2012-10-18 11:32:36 -04:00
$info -> dom -> result = true ;
2013-03-11 10:23:59 -04:00
$info -> dom -> version = G :: LoadTranslation ( 'ID_ENABLED' );
2012-10-18 11:32:36 -04:00
}
2012-03-29 16:42:09 -04:00
2012-10-18 11:32:36 -04:00
// GD info
$info -> gd -> result = false ;
2013-03-11 10:23:59 -04:00
$info -> gd -> version = G :: LoadTranslation ( 'ID_NOT_ENABLED' );
2017-12-04 13:25:35 +00:00
if ( function_exists ( 'gd_info' )) {
2012-10-18 11:32:36 -04:00
$info -> gd -> result = true ;
$gdinfo = gd_info ();
$info -> gd -> version = $gdinfo [ 'GD Version' ];
}
2012-03-29 16:42:09 -04:00
2012-10-18 11:32:36 -04:00
// Multibyte info
$info -> multibyte -> result = false ;
2013-03-11 10:23:59 -04:00
$info -> multibyte -> version = G :: LoadTranslation ( 'ID_NOT_ENABLED' );
2017-12-04 13:25:35 +00:00
if ( function_exists ( 'mb_check_encoding' )) {
2012-10-18 11:32:36 -04:00
$info -> multibyte -> result = true ;
2013-03-11 10:23:59 -04:00
$info -> multibyte -> version = G :: LoadTranslation ( 'ID_ENABLED' );
2012-10-18 11:32:36 -04:00
}
2012-03-29 16:42:09 -04:00
2012-10-18 11:32:36 -04:00
// soap info
$info -> soap -> result = false ;
2013-03-11 10:23:59 -04:00
$info -> soap -> version = G :: LoadTranslation ( 'ID_NOT_ENABLED' );
2017-12-04 13:25:35 +00:00
if ( class_exists ( 'SoapClient' )) {
2012-10-18 11:32:36 -04:00
$info -> soap -> result = true ;
2013-03-11 10:23:59 -04:00
$info -> soap -> version = G :: LoadTranslation ( 'ID_ENABLED' );
2012-10-18 11:32:36 -04:00
}
2012-03-29 16:42:09 -04:00
2014-10-17 14:30:28 -04:00
//mcrypt info
2017-12-04 13:25:35 +00:00
$info -> mcrypt -> result = extension_loaded ( 'mcrypt' );
$info -> mcrypt -> version = $info -> mcrypt -> result ? G :: LoadTranslation ( 'ID_ENABLED' ) : G :: LoadTranslation ( 'ID_NOT_ENABLED' );
2014-10-17 14:30:28 -04:00
2012-10-18 11:32:36 -04:00
// ldap info
$info -> ldap -> result = false ;
2013-03-11 10:23:59 -04:00
$info -> ldap -> version = G :: LoadTranslation ( 'ID_NOT_ENABLED' );
2017-12-04 13:25:35 +00:00
if ( function_exists ( 'ldap_connect' )) {
2012-10-18 11:32:36 -04:00
$info -> ldap -> result = true ;
2013-03-11 10:23:59 -04:00
$info -> ldap -> version = G :: LoadTranslation ( 'ID_ENABLED' );
2012-10-18 11:32:36 -04:00
}
2012-09-26 12:56:24 -04:00
2012-10-18 11:32:36 -04:00
// memory limit verification
2017-12-04 13:25:35 +00:00
$memory = ( int ) ini_get ( 'memory_limit' );
2019-07-10 08:43:16 -04:00
$info -> memory -> version = changeAbbreviationOfDirectives ( ini_get ( 'memory_limit' ));
2017-12-04 13:25:35 +00:00
$info -> memory -> result = $memory > 255 ;
2012-09-26 12:56:24 -04:00
2012-10-18 11:32:36 -04:00
return $info ;
2012-04-26 13:21:41 -04:00
}
2012-03-29 16:42:09 -04:00
2017-12-04 13:25:35 +00:00
public function is_dir_writable ( $path )
2012-10-18 11:32:36 -04:00
{
2017-12-04 13:25:35 +00:00
return G :: is_writable_r ( $path );
2012-04-26 13:21:41 -04:00
}
2012-03-29 16:42:09 -04:00
2017-12-04 13:25:35 +00:00
public function getPermissionInfo ()
2012-10-18 11:32:36 -04:00
{
2017-12-04 13:25:35 +00:00
$this -> setResponseType ( 'json' );
2012-10-18 11:32:36 -04:00
$info = new StdClass ();
$info -> success = true ;
2018-02-01 13:06:32 +00:00
$noWritableFiles = [];
2017-12-04 13:25:35 +00:00
$noWritable = G :: LoadTranslation ( 'ID_INDEX_NOT_WRITEABLE' );
$writable = G :: LoadTranslation ( 'ID_WRITEABLE' );
2012-10-18 11:32:36 -04:00
// pathConfig
2013-01-30 17:32:49 -04:00
$info -> pathConfig = new stdclass ();
2017-12-04 13:25:35 +00:00
$info -> pathConfig -> message = $noWritable ;
$info -> pathConfig -> result = G :: is_writable_r ( $_REQUEST [ 'pathConfig' ], $noWritableFiles );
2012-10-18 11:32:36 -04:00
if ( $info -> pathConfig -> result ) {
2017-12-04 13:25:35 +00:00
$info -> pathConfig -> message = $writable ;
2012-10-18 11:32:36 -04:00
} else {
$info -> success = false ;
}
2012-03-29 16:42:09 -04:00
2013-01-30 17:32:49 -04:00
$info -> pathLanguages = new stdclass ();
2017-12-04 13:25:35 +00:00
$info -> pathLanguages -> message = $noWritable ;
$info -> pathLanguages -> result = G :: is_writable_r ( $_REQUEST [ 'pathLanguages' ], $noWritableFiles );
2012-10-18 11:32:36 -04:00
if ( $info -> pathLanguages -> result ) {
2017-12-04 13:25:35 +00:00
$info -> pathLanguages -> message = $writable ;
2012-10-18 11:32:36 -04:00
} else {
$info -> success = false ;
}
2012-03-29 16:42:09 -04:00
2013-01-30 17:32:49 -04:00
$info -> pathPlugins = new stdclass ();
2017-12-04 13:25:35 +00:00
$info -> pathPlugins -> message = $noWritable ;
$info -> pathPlugins -> result = G :: is_writable_r ( $_REQUEST [ 'pathPlugins' ], $noWritableFiles );
2012-10-18 11:32:36 -04:00
if ( $info -> pathPlugins -> result ) {
2017-12-04 13:25:35 +00:00
$info -> pathPlugins -> message = $writable ;
2012-10-18 11:32:36 -04:00
} else {
$info -> success = false ;
}
2012-03-29 16:42:09 -04:00
2013-01-30 17:32:49 -04:00
$info -> pathXmlforms = new stdclass ();
2017-12-04 13:25:35 +00:00
$info -> pathXmlforms -> message = $noWritable ;
$info -> pathXmlforms -> result = G :: is_writable_r ( $_REQUEST [ 'pathXmlforms' ], $noWritableFiles );
2012-10-18 11:32:36 -04:00
if ( $info -> pathXmlforms -> result ) {
2017-12-04 13:25:35 +00:00
$info -> pathXmlforms -> message = $writable ;
2012-10-18 11:32:36 -04:00
} else {
2015-01-31 15:56:34 -04:00
$info -> success = false ;
}
$info -> pathTranslations = new stdclass ();
$info -> pathTranslations -> message = G :: LoadTranslation ( 'ID_TRANSLATION_NOT_WRITEABLE' );
2017-12-04 13:25:35 +00:00
$info -> pathTranslations -> result = G :: is_writable_r ( $_REQUEST [ 'pathTranslations' ], $noWritableFiles );
2015-01-31 15:56:34 -04:00
if ( $info -> pathTranslations -> result ) {
2017-12-04 13:25:35 +00:00
$info -> pathTranslations -> message = $writable ;
2015-01-31 15:56:34 -04:00
} else {
$info -> success = false ;
}
$info -> pathTranslationsMafe = new stdclass ();
$info -> pathTranslationsMafe -> message = G :: LoadTranslation ( 'ID_MAFE_TRANSLATION_NOT_WRITEABLE' );
2017-12-04 13:25:35 +00:00
$info -> pathTranslationsMafe -> result = G :: is_writable_r ( $_REQUEST [ 'pathTranslationsMafe' ], $noWritableFiles );
2015-01-31 15:56:34 -04:00
if ( $info -> pathTranslationsMafe -> result ) {
2017-12-04 13:25:35 +00:00
$info -> pathTranslationsMafe -> message = $writable ;
2015-01-31 15:56:34 -04:00
} else {
2012-10-18 11:32:36 -04:00
$info -> success = false ;
}
2012-03-29 16:42:09 -04:00
2013-04-15 14:05:52 -04:00
$info -> pathPublic = new stdclass ();
2013-01-30 17:32:49 -04:00
$info -> pathShared = new stdclass ();
2017-12-04 13:25:35 +00:00
$info -> pathPublic -> message = $noWritable ;
$info -> pathPublic -> result = G :: is_writable_r ( $_REQUEST [ 'pathPublic' ], $noWritableFiles );
2012-10-18 11:32:36 -04:00
if ( $info -> pathPublic -> result ) {
2017-12-04 13:25:35 +00:00
$info -> pathShared -> message = $writable ;
2012-10-18 11:32:36 -04:00
} else {
$info -> success = false ;
2012-03-29 16:42:09 -04:00
}
2012-04-26 13:21:41 -04:00
2017-12-04 13:25:35 +00:00
$info -> pathShared -> message = $noWritable ;
$info -> pathShared -> result = G :: is_writable_r ( $_REQUEST [ 'pathShared' ], $noWritableFiles );
2012-10-18 11:32:36 -04:00
if ( $info -> pathShared -> result ) {
2017-12-04 13:25:35 +00:00
$info -> pathShared -> message = $writable ;
2012-10-18 11:32:36 -04:00
} else {
2017-07-28 11:33:56 -04:00
//Verify and create the shared path
2017-12-04 13:25:35 +00:00
G :: verifyPath ( $_REQUEST [ 'pathShared' ], true );
$info -> pathShared -> result = G :: is_writable_r ( $_REQUEST [ 'pathShared' ], $noWritableFiles );
2012-10-18 11:32:36 -04:00
if ( $info -> pathShared -> result ) {
2017-12-04 13:25:35 +00:00
$info -> pathShared -> message = $writable ;
2017-07-28 11:33:56 -04:00
$info -> success = $this -> verifySharedFrameworkPaths ( $_REQUEST [ 'pathShared' ]);
2012-10-18 11:32:36 -04:00
} else {
$info -> success = false ;
}
}
2015-11-26 20:11:58 -04:00
2015-05-11 16:36:07 -04:00
$filter = new InputFilter ();
$pathShared = $filter -> validateInput ( $_REQUEST [ 'pathShared' ], 'path' );
2012-09-26 12:56:24 -04:00
2012-10-18 11:32:36 -04:00
if ( $info -> pathShared -> result ) {
2017-12-04 13:25:35 +00:00
$aux = pathinfo ( $_REQUEST [ 'pathLogFile' ]);
G :: verifyPath ( $aux [ 'dirname' ], true );
if ( is_dir ( $aux [ 'dirname' ])) {
if ( ! file_exists ( $_REQUEST [ 'pathLogFile' ])) {
@ file_put_contents ( $_REQUEST [ 'pathLogFile' ], '' );
@ chmod ( $pathShared , 0770 );
2012-10-18 11:32:36 -04:00
}
}
}
2012-04-26 13:21:41 -04:00
2013-01-30 17:32:49 -04:00
$info -> pathLogFile = new stdclass ();
2013-03-11 10:23:59 -04:00
$info -> pathLogFile -> message = G :: LoadTranslation ( 'ID_CREATE_LOG_INSTALLATION' );
2017-12-04 13:25:35 +00:00
$info -> pathLogFile -> result = file_exists ( $_REQUEST [ 'pathLogFile' ]);
2012-04-26 13:21:41 -04:00
2012-10-18 11:32:36 -04:00
if ( $info -> pathLogFile -> result ) {
2014-09-22 09:58:50 -04:00
$info -> pathLogFile -> message = G :: LoadTranslation ( 'ID_INSTALLATION_FILE_LOG' );
2012-10-18 11:32:36 -04:00
}
2012-03-29 16:42:09 -04:00
2017-12-04 13:25:35 +00:00
$info -> notify = $info -> success ? G :: LoadTranslation ( 'ID_SUCCESS_DIRECTORIES_WRITABLE' ) : G :: LoadTranslation ( 'ID_DIRECTORIES_NOT_WRITABLE' );
2012-03-29 16:42:09 -04:00
2012-10-18 11:32:36 -04:00
$info -> noWritableFiles = $noWritableFiles ;
2012-03-29 16:42:09 -04:00
2012-10-18 11:32:36 -04:00
return $info ;
2012-03-29 16:42:09 -04:00
}
2012-04-10 16:49:09 -04:00
2017-12-04 13:25:35 +00:00
/**
* Test db connection
*
* @ return StdClass
*/
public function testConnection ()
2012-10-18 11:32:36 -04:00
{
2017-12-04 13:25:35 +00:00
$this -> setResponseType ( 'json' );
$info = new StdClass ();
try {
2019-08-21 10:22:17 -04:00
$info = $this -> testMySQLConnection ();
2017-12-04 13:25:35 +00:00
} catch ( Exception $e ) {
$info -> result = false ;
$info -> message = G :: LoadTranslation ( 'DBCONNECTIONS_MSGA' );
2012-10-18 11:32:36 -04:00
}
2017-12-04 13:25:35 +00:00
return $info ;
2012-03-29 16:42:09 -04:00
}
2012-10-18 11:32:36 -04:00
/**
* log the queries and other information to install . log ,
* the install . log files should be placed in shared / logs
* for that reason we are using the $_REQUEST of pathShared
*/
2018-02-01 13:06:32 +00:00
private function installLog ( $text )
2012-10-18 11:32:36 -04:00
{
//if this function is called outside the createWorkspace, just returns and do nothing
2017-12-04 13:25:35 +00:00
if ( ! isset ( $_REQUEST [ 'pathShared' ])) {
2012-10-18 11:32:36 -04:00
return ;
}
2017-12-04 13:25:35 +00:00
//log file is in shared/logs
$pathShared = trim ( $_REQUEST [ 'pathShared' ]);
2018-02-01 13:06:32 +00:00
if ( substr ( $pathShared , - 1 ) !== '/' ) {
2012-10-18 11:32:36 -04:00
$pathShared .= '/' ;
}
2017-12-04 13:25:35 +00:00
$pathSharedLog = $pathShared . 'log/' ;
2013-04-22 17:01:26 -04:00
G :: verifyPath ( $pathSharedLog , true );
$logFile = $pathSharedLog . 'install.log' ;
2012-10-18 11:32:36 -04:00
2017-12-04 13:25:35 +00:00
if ( ! is_file ( $logFile )) {
G :: mk_dir ( dirname ( $pathShared ));
$fpt = fopen ( $logFile , 'w' );
2012-10-18 11:32:36 -04:00
if ( $fpt !== null ) {
2017-12-04 13:25:35 +00:00
fwrite ( $fpt , sprintf ( " %s %s \n " , date ( 'Y:m:d H:i:s' ), '----- ' . G :: LoadTranslation ( 'ID_STARTING_LOG_FILE' ) . ' ------' ));
fclose ( $fpt );
2012-10-18 11:32:36 -04:00
} else {
2018-02-01 13:06:32 +00:00
throw new Exception ( G :: LoadTranslation ( 'ID_FILE_NOT_WRITEABLE' , SYS_LANG , [ $logFile ]));
2012-10-18 11:32:36 -04:00
return $false ;
}
}
2015-11-26 20:11:58 -04:00
2015-05-11 16:36:07 -04:00
$filter = new InputFilter ();
$logFile = $filter -> validateInput ( $logFile , 'path' );
2015-11-26 20:11:58 -04:00
2017-12-04 13:25:35 +00:00
$fpt = fopen ( $logFile , 'a' );
fwrite ( $fpt , sprintf ( " %s %s \n " , date ( 'Y:m:d H:i:s' ), trim ( $text )));
fclose ( $fpt );
2012-10-18 11:32:36 -04:00
return true ;
2012-03-29 16:42:09 -04:00
}
2012-10-18 11:32:36 -04:00
/**
* function to create a workspace
2019-08-21 10:22:17 -04:00
* in fact this function is calling appropriate functions for mysql
2017-08-05 12:35:14 -04:00
* need permission PM_SETUP_ADVANCE for this action
2017-12-04 13:25:35 +00:00
* @ return stdClass information create a workspace .
2012-10-18 11:32:36 -04:00
*/
2017-12-04 13:25:35 +00:00
public function createWorkspace ()
2012-10-18 11:32:36 -04:00
{
2017-08-05 12:35:14 -04:00
if ( ! $this -> pmIsInstalled ()) {
$pathSharedPartner = trim ( $_REQUEST [ 'pathShared' ]);
if ( file_exists ( trim ( $pathSharedPartner , PATH_SEP ) . PATH_SEP . 'partner.info' )) {
$this -> systemName = $this -> getSystemName ( $pathSharedPartner );
2017-12-04 13:25:35 +00:00
$_REQUEST [ 'PARTNER_FLAG' ] = true ;
2017-08-05 12:35:14 -04:00
}
$this -> setResponseType ( 'json' );
2017-12-04 13:25:35 +00:00
$info = new StdClass ();
try {
2019-08-21 10:22:17 -04:00
$info = $this -> createMySQLWorkspace ();
2017-12-04 13:25:35 +00:00
} catch ( Exception $e ) {
$info -> result = false ;
$info -> message = G :: LoadTranslation ( 'DBCONNECTIONS_MSGA' );
2017-08-05 12:35:14 -04:00
}
return $info ;
2012-10-18 11:32:36 -04:00
} else {
2017-08-05 12:35:14 -04:00
$this -> displayError ();
2012-10-18 11:32:36 -04:00
}
2017-08-05 12:35:14 -04:00
}
2012-10-18 11:32:36 -04:00
2017-08-05 12:35:14 -04:00
/**
* We check if processMaker is not installed
*
* @ return boolean
2017-12-04 13:25:35 +00:00
*/
private function pmIsInstalled ()
{
2017-08-05 12:35:14 -04:00
return file_exists ( FILE_PATHS_INSTALLED );
}
/**
* Display an error when processMaker is already installed
*
* @ return void
*/
2017-12-04 13:25:35 +00:00
private function displayError ()
{
2017-08-05 12:35:14 -04:00
$this -> setJSVar ( 'messageError' , G :: LoadTranslation ( 'ID_PROCESSMAKER_ALREADY_INSTALLED' ));
$this -> includeExtJS ( 'installer/stopInstall' );
$this -> setView ( 'installer/mainStopInstall' );
G :: RenderPage ( 'publish' , 'extJs' );
2012-03-29 16:42:09 -04:00
}
2012-10-18 11:32:36 -04:00
2017-12-04 13:25:35 +00:00
public function forceTogenerateTranslationsFiles ( $url )
2012-10-18 11:32:36 -04:00
{
$ch = curl_init ();
2018-10-19 17:01:49 -04:00
curl_setopt ( $ch , CURLOPT_URL , G :: browserCacheFilesUrl ( System :: getServerProtocolHost () . " /js/ext/translation.en.js?r= " . rand ( 1 , 10000 )));
2013-04-26 16:34:48 -04:00
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt ( $ch , CURLOPT_FRESH_CONNECT , 1 );
curl_setopt ( $ch , CURLOPT_TIMEOUT , 60 );
curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT , 20 );
curl_exec ( $ch );
curl_close ( $ch );
2012-09-26 12:56:24 -04:00
}
2012-03-29 16:42:09 -04:00
2012-10-18 11:32:36 -04:00
/**
* query_sql_file send many statements to server
*
* @ param string $file
* @ param string $connection
* @ return array $report
*/
2017-12-04 13:25:35 +00:00
public function mysqlFileQuery ( $file )
2012-10-18 11:32:36 -04:00
{
2017-12-04 13:25:35 +00:00
if ( ! is_file ( $file )) {
2018-02-01 13:06:32 +00:00
throw new Exception ( G :: LoadTranslation ( 'ID_SQL_FILE_INVALID' , SYS_LANG , [ $file ]));
2012-10-18 11:32:36 -04:00
return $false ;
}
2018-02-01 13:06:32 +00:00
$this -> installLog ( G :: LoadTranslation ( 'ID_PROCESING' , SYS_LANG , [ $file ]));
2017-12-04 13:25:35 +00:00
$startTime = microtime ( true );
//New Update, to support more complex queries
2012-03-29 16:42:09 -04:00
2017-12-04 13:25:35 +00:00
$lines = file ( $file );
2012-10-18 11:32:36 -04:00
$previous = null ;
2018-02-01 13:06:32 +00:00
DB :: connection ( self :: CONNECTION_INSTALL )
-> statement ( " SET NAMES 'utf8' " );
2012-10-18 11:32:36 -04:00
foreach ( $lines as $j => $line ) {
2017-12-04 13:25:35 +00:00
$line = trim ( $line ); // Remove comments from the script
2012-04-23 18:13:06 -04:00
2018-02-01 13:06:32 +00:00
if ( strpos ( $line , '--' ) === 0 ) {
$line = substr ( $line , 0 , strpos ( $line , '--' ));
2012-10-18 11:32:36 -04:00
}
2012-04-23 18:13:06 -04:00
2017-12-04 13:25:35 +00:00
if ( empty ( $line )) {
2012-10-18 11:32:36 -04:00
continue ;
}
2012-09-26 12:56:24 -04:00
2018-02-01 13:06:32 +00:00
if ( strpos ( $line , '#' ) === 0 ) {
$line = substr ( $line , 0 , strpos ( $line , '#' ));
2012-10-18 11:32:36 -04:00
}
2012-09-26 12:56:24 -04:00
2017-12-04 13:25:35 +00:00
if ( empty ( $line )) {
2012-10-18 11:32:36 -04:00
continue ;
}
2012-09-26 12:56:24 -04:00
2012-10-18 11:32:36 -04:00
// Concatenate the previous line, if any, with the current
if ( $previous ) {
2018-02-01 13:06:32 +00:00
$line = $previous . ' ' . $line ;
2012-10-18 11:32:36 -04:00
}
$previous = null ;
2012-09-26 12:56:24 -04:00
2012-10-18 11:32:36 -04:00
// If the current line doesnt end with ; then put this line together
// with the next one, thus supporting multi-line statements.
2018-02-01 13:06:32 +00:00
if ( strrpos ( $line , ';' ) !== strlen ( $line ) - 1 ) {
2012-10-18 11:32:36 -04:00
$previous = $line ;
continue ;
}
2012-09-26 12:56:24 -04:00
2018-02-01 13:06:32 +00:00
$line = substr ( $line , 0 , strrpos ( $line , ';' ));
DB :: connection ( self :: CONNECTION_INSTALL )
-> statement ( $line );
2012-10-18 11:32:36 -04:00
}
2012-09-26 12:56:24 -04:00
2017-12-04 13:25:35 +00:00
$endTime = microtime ( true );
2018-02-01 13:06:32 +00:00
$this -> installLog ( G :: LoadTranslation ( 'ID_FILE_PROCESSED' , SYS_LANG , [ basename ( $file ), $endTime - $startTime ]));
2012-10-18 11:32:36 -04:00
return true ;
}
2012-04-23 18:13:06 -04:00
2012-10-18 11:32:36 -04:00
/**
* set Grant Privileges for MySQL
*
* @ param string $psUser
* @ param string $psPassword
* @ param string $psDatabase
2018-02-01 13:06:32 +00:00
* @ param string $host
*
* @ throws Exception
2012-10-18 11:32:36 -04:00
*/
2018-02-01 13:06:32 +00:00
private function setGrantPrivilegesMySQL ( $psUser , $psPassword , $psDatabase , $host )
2012-10-18 11:32:36 -04:00
{
2018-02-01 13:06:32 +00:00
try {
$host = $host === 'localhost' || $host === '127.0.0.1' ? 'localhost' : '%' ;
2014-09-25 15:33:21 -04:00
2018-02-01 13:06:32 +00:00
$query = " GRANT ALL PRIVILEGES ON ` $psDatabase `.* TO $psUser @' $host ' IDENTIFIED BY ' $psPassword ' WITH GRANT OPTION " ;
DB :: connection ( self :: CONNECTION_INSTALL )
-> statement ( $query );
2017-12-04 13:25:35 +00:00
2018-02-01 13:06:32 +00:00
$this -> installLog ( $query );
} catch ( QueryException $e ) {
$this -> installLog ( G :: LoadTranslation ( 'ID_MYSQL_ERROR' , SYS_LANG , [ $e -> getMessage ()]));
throw new Exception ( $e -> getMessage ());
2017-12-04 13:25:35 +00:00
}
2012-10-18 11:32:36 -04:00
}
2012-04-26 13:21:41 -04:00
2018-02-01 13:06:32 +00:00
/**
* Create a workspace in a MySQL database
*
* @ return StdClass object
*/
2017-12-04 13:25:35 +00:00
public function createMySQLWorkspace ()
{
2015-03-25 11:25:00 -04:00
$filter = new InputFilter ();
2017-12-04 13:25:35 +00:00
ini_set ( 'max_execution_time' , '0' );
2013-01-30 17:32:49 -04:00
$info = new StdClass ();
2012-10-18 11:32:36 -04:00
$info -> result = false ;
$info -> message = '' ;
$info -> canRedirect = true ;
2017-12-04 13:25:35 +00:00
$db_hostname = trim ( $_REQUEST [ 'db_hostname' ]);
$db_port = trim ( $_REQUEST [ 'db_port' ]);
2015-03-25 11:25:00 -04:00
$db_port = $filter -> validateInput ( $db_port );
2017-12-04 13:25:35 +00:00
$db_username = trim ( $_REQUEST [ 'db_username' ]);
2015-03-25 11:25:00 -04:00
$db_username = $filter -> validateInput ( $db_username );
2016-12-20 12:35:10 -04:00
$db_password = urlencode ( trim ( $_REQUEST [ 'db_password' ]));
$db_password = urldecode ( $filter -> validateInput ( $db_password ));
2017-12-04 13:25:35 +00:00
$wf = trim ( $_REQUEST [ 'wfDatabase' ]);
$workspace = trim ( $_REQUEST [ 'workspace' ]);
$pathShared = trim ( $_REQUEST [ 'pathShared' ]);
$adminPassword = trim ( $_REQUEST [ 'adminPassword' ]);
2015-03-25 11:25:00 -04:00
$adminPassword = $filter -> validateInput ( $adminPassword );
2017-12-04 13:25:35 +00:00
$adminUsername = trim ( $_REQUEST [ 'adminUsername' ]);
2015-03-25 11:25:00 -04:00
$adminUsername = $filter -> validateInput ( $adminUsername );
2018-02-01 13:06:32 +00:00
$deleteDB = $_REQUEST [ 'deleteDB' ] === 'true' ;
$userLogged = isset ( $_REQUEST [ 'userLogged' ]) ? $_REQUEST [ 'userLogged' ] === 'true' : false ;
2015-03-25 11:25:00 -04:00
$userLogged = $filter -> validateInput ( $userLogged );
2012-10-18 11:32:36 -04:00
2018-02-01 13:06:32 +00:00
if ( substr ( $pathShared , - 1 ) !== '/' ) {
2012-10-18 11:32:36 -04:00
$pathShared .= '/' ;
}
2017-12-04 13:25:35 +00:00
$this -> installLog ( '-------------------------------------------' );
2018-02-01 13:06:32 +00:00
$this -> installLog ( G :: LoadTranslation ( 'ID_CREATING_WORKSPACE' , SYS_LANG , [ $workspace ]));
2012-10-18 11:32:36 -04:00
try {
2018-02-01 13:06:32 +00:00
self :: setNewConnection ( self :: CONNECTION_TEST_INSTALL , $db_hostname , $db_username , $db_password , '' , $db_port );
2012-10-18 11:32:36 -04:00
$db_host = ( $db_port != '' && $db_port != 3306 ) ? $db_hostname . ':' . $db_port : $db_hostname ;
2017-12-04 13:25:35 +00:00
2018-02-01 13:06:32 +00:00
$this -> installLog ( G :: LoadTranslation ( 'ID_CONNECT_TO_SERVER' , SYS_LANG , [ $db_hostname , $db_port , $db_username ]));
2012-10-18 11:32:36 -04:00
if ( $deleteDB ) {
2018-02-01 13:06:32 +00:00
$query = sprintf ( 'DROP DATABASE IF EXISTS %s' , $wf );
DB :: connection ( self :: CONNECTION_TEST_INSTALL ) -> statement ( $query );
2012-10-18 11:32:36 -04:00
}
2018-02-01 13:06:32 +00:00
// CREATE databases wf_workflow
DB :: connection ( self :: CONNECTION_TEST_INSTALL )
2018-05-10 10:40:05 -04:00
-> statement ( " CREATE DATABASE IF NOT EXISTS $wf DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci " );
2018-02-01 13:06:32 +00:00
self :: setNewConnection ( self :: CONNECTION_INSTALL , $db_hostname , $db_username , $db_password , $wf , $db_port );
2012-10-18 11:32:36 -04:00
// CREATE users and GRANT Privileges
2017-12-04 13:25:35 +00:00
$wf_workspace = $wf ;
2016-11-04 17:10:36 -04:00
$wfGrantUser = uniqid ( 'wf_' );
2014-05-07 11:18:09 -04:00
if ( ! $userLogged ) {
2017-12-04 13:25:35 +00:00
$wfPass = G :: generate_password ( 15 );
$this -> setGrantPrivilegesMySQL ( $wfGrantUser , $wfPass , $wf , $db_hostname );
2014-05-07 11:18:09 -04:00
} else {
$wfPass = $db_password ;
$wf = $db_username ;
2016-11-04 17:10:36 -04:00
$wfGrantUser = $db_username ;
2014-05-07 11:18:09 -04:00
}
2012-10-18 11:32:36 -04:00
// Generate the db.php file and folders
2018-02-01 13:06:32 +00:00
$path_site = $pathShared . '/sites/' . $workspace . '/' ;
2015-11-26 20:11:58 -04:00
2017-12-04 13:25:35 +00:00
@ mkdir ( $path_site , 0777 , true );
2018-02-01 13:06:32 +00:00
@ mkdir ( $path_site . 'files/' , 0777 , true );
@ mkdir ( $path_site . 'mailTemplates/' , 0777 , true );
@ mkdir ( $path_site . 'public/' , 0777 , true );
@ mkdir ( $path_site . 'reports/' , 0777 , true );
@ mkdir ( $path_site . 'xmlForms' , 0777 , true );
2012-10-18 11:32:36 -04:00
2015-11-26 20:11:58 -04:00
$db_file = $path_site . 'db.php' ;
2012-10-18 11:32:36 -04:00
$dbText = " <?php \n " ;
2017-12-04 13:25:35 +00:00
$dbText .= sprintf ( " // Processmaker configuration \n " );
$dbText .= sprintf ( " define ('DB_ADAPTER', '%s' ); \n " , 'mysql' );
$dbText .= sprintf ( " define ('DB_HOST', '%s' ); \n " , $db_host );
$dbText .= sprintf ( " define ('DB_NAME', '%s' ); \n " , $wf_workspace );
$dbText .= sprintf ( " define ('DB_USER', '%s' ); \n " , $wfGrantUser );
$dbText .= sprintf ( " define ('DB_PASS', '%s' ); \n " , $wfPass );
$dbText .= sprintf ( " define ('DB_RBAC_HOST', '%s' ); \n " , $db_host );
$dbText .= sprintf ( " define ('DB_RBAC_NAME', '%s' ); \n " , $wf_workspace );
$dbText .= sprintf ( " define ('DB_RBAC_USER', '%s' ); \n " , $wfGrantUser );
$dbText .= sprintf ( " define ('DB_RBAC_PASS', '%s' ); \n " , $wfPass );
$dbText .= sprintf ( " define ('DB_REPORT_HOST', '%s' ); \n " , $db_host );
$dbText .= sprintf ( " define ('DB_REPORT_NAME', '%s' ); \n " , $wf_workspace );
$dbText .= sprintf ( " define ('DB_REPORT_USER', '%s' ); \n " , $wfGrantUser );
$dbText .= sprintf ( " define ('DB_REPORT_PASS', '%s' ); \n " , $wfPass );
2014-09-25 15:33:21 -04:00
2013-03-25 17:29:43 -04:00
if ( defined ( 'PARTNER_FLAG' ) || isset ( $_REQUEST [ 'PARTNER_FLAG' ])) {
2013-04-26 11:45:03 -04:00
$dbText .= " \n " ;
2018-02-01 13:06:32 +00:00
$dbText .= " define ('PARTNER_FLAG', " . ( defined ( 'PARTNER_FLAG' ) ? PARTNER_FLAG : isset ( $_REQUEST [ 'PARTNER_FLAG' ]) ? $_REQUEST [ 'PARTNER_FLAG' ] : 'false' ) . " ); \n " ;
if ( ! empty ( $this -> systemName )) {
2013-05-08 12:33:48 -04:00
$dbText .= " define ('SYSTEM_NAME', ' " . $this -> systemName . " '); \n " ;
2013-04-26 11:45:03 -04:00
}
2013-03-19 10:12:35 -04:00
}
2012-10-18 11:32:36 -04:00
2018-02-01 13:06:32 +00:00
$this -> installLog ( G :: LoadTranslation ( 'ID_CREATING' , SYS_LANG , [ $db_file ]));
2017-12-04 13:25:35 +00:00
file_put_contents ( $db_file , $dbText );
2012-10-18 11:32:36 -04:00
2015-12-04 16:43:45 -04:00
/*----------------------------------********---------------------------------*/
2015-12-07 09:32:02 -04:00
//Generate the env.ini file
$envIniFile = $path_site . 'env.ini' ;
$content = 'system_utc_time_zone = 1' . " \n " ;
$this -> installLog ( G :: LoadTranslation ( 'ID_CREATING' , SYS_LANG , [ $envIniFile ]));
file_put_contents ( $envIniFile , $content );
2015-12-04 16:43:45 -04:00
/*----------------------------------********---------------------------------*/
2015-11-26 20:11:58 -04:00
//Generate the databases.php file
2012-10-18 11:32:36 -04:00
$databases_file = $path_site . 'databases.php' ;
2017-12-04 13:25:35 +00:00
$dbData = sprintf ( " \$ dbAdapter = '%s'; \n " , 'mysql' );
$dbData .= sprintf ( " \$ dbHost = '%s'; \n " , $db_host );
$dbData .= sprintf ( " \$ dbName = '%s'; \n " , $wf_workspace );
$dbData .= sprintf ( " \$ dbUser = '%s'; \n " , $wf );
$dbData .= sprintf ( " \$ dbPass = '%s'; \n " , $wfPass );
$dbData .= sprintf ( " \$ dbRbacHost = '%s'; \n " , $db_host );
$dbData .= sprintf ( " \$ dbRbacName = '%s'; \n " , $wf_workspace );
$dbData .= sprintf ( " \$ dbRbacUser = '%s'; \n " , $wf );
$dbData .= sprintf ( " \$ dbRbacPass = '%s'; \n " , $wfPass );
$dbData .= sprintf ( " \$ dbReportHost = '%s'; \n " , $db_host );
$dbData .= sprintf ( " \$ dbReportName = '%s'; \n " , $wf_workspace );
$dbData .= sprintf ( " \$ dbReportUser = '%s'; \n " , $wf );
$dbData .= sprintf ( " \$ dbReportPass = '%s'; \n " , $wfPass );
$databasesText = str_replace ( '{dbData}' , $dbData , @ file_get_contents ( PATH_HOME . 'engine/templates/installer/databases.tpl' ));
$this -> installLog ( G :: LoadTranslation ( 'ID_CREATING' , SYS_LANG , array ( $databases_file )));
file_put_contents ( $databases_file , $databasesText );
2012-10-18 11:32:36 -04:00
2017-12-04 13:25:35 +00:00
$this -> mysqlFileQuery ( PATH_RBAC_HOME . 'engine/data/mysql/schema.sql' );
$this -> mysqlFileQuery ( PATH_RBAC_HOME . 'engine/data/mysql/insert.sql' );
$this -> mysqlFileQuery ( PATH_HOME . 'engine/data/mysql/schema.sql' );
$this -> mysqlFileQuery ( PATH_HOME . 'engine/data/mysql/insert.sql' );
2015-11-26 20:11:58 -04:00
2015-03-05 15:39:58 -04:00
2013-04-15 14:05:52 -04:00
if ( defined ( 'PARTNER_FLAG' ) || isset ( $_REQUEST [ 'PARTNER_FLAG' ])) {
$this -> setPartner ();
}
2012-10-18 11:32:36 -04:00
// Create the triggers
2017-12-04 13:25:35 +00:00
if ( file_exists ( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationInsert.sql' ) &&
file_exists ( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationUpdate.sql' ) &&
file_exists ( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql' ) &&
file_exists ( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql' ) &&
2018-08-15 15:05:23 -04:00
file_exists ( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerSubApplicationInsert.sql' ) &&
2017-12-04 13:25:35 +00:00
file_exists ( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql' )) {
2018-08-15 15:05:23 -04:00
DB :: connection ( self :: CONNECTION_INSTALL ) -> unprepared ( file_get_contents ( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationInsert.sql' ));
DB :: connection ( self :: CONNECTION_INSTALL ) -> unprepared ( file_get_contents ( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationUpdate.sql' ));
DB :: connection ( self :: CONNECTION_INSTALL ) -> unprepared ( file_get_contents ( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql' ));
DB :: connection ( self :: CONNECTION_INSTALL ) -> unprepared ( file_get_contents ( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql' ));
DB :: connection ( self :: CONNECTION_INSTALL ) -> unprepared ( file_get_contents ( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerSubApplicationInsert.sql' ));
DB :: connection ( self :: CONNECTION_INSTALL ) -> unprepared ( file_get_contents ( PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql' ));
2018-02-01 13:06:32 +00:00
DB :: connection ( self :: CONNECTION_INSTALL )
-> table ( 'CONFIGURATION' )
-> insert ([
'CFG_UID' => 'APP_CACHE_VIEW_ENGINE' ,
'CFG_VALUE' => serialize ([ 'LANG' => 'en' , 'STATUS' => 'active' ])
]);
DB :: connection ( self :: CONNECTION_INSTALL )
-> table ( 'EMAIL_SERVER' )
-> insert ([
'MESS_UID' => Common :: generateUID (),
'MESS_ENGINE' => 'MAIL'
]);
2012-10-18 11:32:36 -04:00
}
// Change admin user
2018-02-01 13:06:32 +00:00
DB :: connection ( self :: CONNECTION_INSTALL )
-> table ( 'USERS' )
-> where ( 'USR_UID' , '00000000000000000000000000000001' )
-> update ([
'USR_USERNAME' => $adminUsername ,
'USR_LASTNAME' => $adminUsername ,
2018-05-09 14:56:16 -04:00
'USR_PASSWORD' => G :: encryptHash ( $adminPassword )
2018-02-01 13:06:32 +00:00
]);
DB :: connection ( self :: CONNECTION_INSTALL )
-> table ( 'RBAC_USERS' )
-> where ( 'USR_UID' , '00000000000000000000000000000001' )
-> update ([
'USR_USERNAME' => $adminUsername ,
'USR_LASTNAME' => $adminUsername ,
2018-05-09 14:56:16 -04:00
'USR_PASSWORD' => G :: encryptHash ( $adminPassword )
2018-02-01 13:06:32 +00:00
]);
2012-10-18 11:32:36 -04:00
// Write the paths_installed.php file (contains all the information configured so far)
2017-12-04 13:25:35 +00:00
if ( ! file_exists ( FILE_PATHS_INSTALLED )) {
$sh = G :: encryptOld ( filemtime ( PATH_GULLIVER . '/class.g.php' ));
2018-02-01 13:06:32 +00:00
$h = G :: encrypt ( $db_host . $sh . $db_username . $sh . $db_password , $sh );
2012-10-18 11:32:36 -04:00
$dbText = " <?php \n " ;
2017-12-04 13:25:35 +00:00
$dbText .= sprintf ( " define('PATH_DATA', '%s'); \n " , $pathShared );
$dbText .= sprintf ( " define('PATH_C', '%s'); \n " , $pathShared . 'compiled/' );
$dbText .= sprintf ( " define('HASH_INSTALLATION', '%s'); \n " , $h );
$dbText .= sprintf ( " define('SYSTEM_HASH', '%s'); \n " , $sh );
2018-02-01 13:06:32 +00:00
$this -> installLog ( G :: LoadTranslation ( 'ID_CREATING' , SYS_LANG , [ FILE_PATHS_INSTALLED ]));
2017-12-04 13:25:35 +00:00
file_put_contents ( FILE_PATHS_INSTALLED , $dbText );
2012-10-18 11:32:36 -04:00
}
2018-08-15 15:05:23 -04:00
// for new env conf handling
2012-10-18 11:32:36 -04:00
$envFile = PATH_CONFIG . 'env.ini' ;
// getting configuration from env.ini
2017-12-04 13:25:35 +00:00
$sysConf = System :: getSystemConfiguration ( $envFile );
2012-10-18 11:32:36 -04:00
2013-04-17 11:43:20 -04:00
$langUri = 'en' ;
if ( isset ( $sysConf [ 'default_lang' ])) {
$langUri = $sysConf [ 'default_lang' ];
}
2013-05-14 18:19:47 -04:00
$skinUri = 'neoclassic' ;
2013-04-17 11:43:20 -04:00
if ( isset ( $sysConf [ 'default_skin' ])) {
$skinUri = $sysConf [ 'default_skin' ];
}
$updatedConf [ 'default_lang' ] = $langUri ;
$updatedConf [ 'default_skin' ] = $skinUri ;
2017-12-04 13:25:35 +00:00
$info -> uri = PATH_SEP . 'sys' . $_REQUEST [ 'workspace' ] . PATH_SEP . $langUri . PATH_SEP . $skinUri . PATH_SEP . 'login' . PATH_SEP . 'login' ;
2013-04-17 11:43:20 -04:00
2014-05-13 17:15:44 -04:00
//register PMDesigner Client
2018-02-01 13:06:32 +00:00
$http = G :: is_https () ? 'https' : 'http' ;
$host = $_SERVER [ 'SERVER_NAME' ] . ( $_SERVER [ 'SERVER_PORT' ] !== '80' ? ':' . $_SERVER [ 'SERVER_PORT' ] : '' );
2014-05-13 17:15:44 -04:00
$endpoint = sprintf (
'%s://%s/sys%s/%s/%s/oauth2/grant' ,
$http ,
$host ,
2014-06-10 11:48:18 -04:00
$workspace ,
2014-05-13 17:15:44 -04:00
$langUri ,
$skinUri
);
// inserting the outh_client
2018-02-01 13:06:32 +00:00
DB :: connection ( self :: CONNECTION_INSTALL )
-> table ( 'OAUTH_CLIENTS' )
-> insert ([
'CLIENT_ID' => 'x-pm-local-client' ,
'CLIENT_SECRET' => '179ad45c6ce2cb97cf1029e212046e81' ,
'CLIENT_NAME' => 'PM Web Designer' ,
'CLIENT_DESCRIPTION' => 'ProcessMaker Web Designer App' ,
'CLIENT_WEBSITE' => 'www.processmaker.com' ,
'REDIRECT_URI' => $endpoint ,
'USR_UID' => '00000000000000000000000000000001'
]);
2018-05-15 09:46:58 -04:00
if ( ! empty ( config ( 'oauthClients.mobile.clientId' ))) {
DB :: connection ( self :: CONNECTION_INSTALL )
-> table ( 'OAUTH_CLIENTS' )
-> insert ([
'CLIENT_ID' => config ( 'oauthClients.mobile.clientId' ),
'CLIENT_SECRET' => config ( 'oauthClients.mobile.clientSecret' ),
'CLIENT_NAME' => config ( 'oauthClients.mobile.clientName' ),
'CLIENT_DESCRIPTION' => config ( 'oauthClients.mobile.clientDescription' ),
'CLIENT_WEBSITE' => config ( 'oauthClients.mobile.clientWebsite' ),
'REDIRECT_URI' => $endpoint ,
'USR_UID' => '00000000000000000000000000000001'
]);
}
2014-05-13 17:15:44 -04:00
2013-04-22 17:01:26 -04:00
$indexFileUpdated = true ;
2013-04-15 13:46:13 -04:00
if ( defined ( 'PARTNER_FLAG' ) || isset ( $_REQUEST [ 'PARTNER_FLAG' ])) {
2013-05-07 12:00:44 -04:00
$this -> buildParternExtras ( $adminUsername , $adminPassword , $_REQUEST [ 'workspace' ], $langUri , $skinUri );
2013-04-17 10:25:32 -04:00
} else {
2013-04-17 11:43:20 -04:00
try {
2017-12-04 13:25:35 +00:00
G :: update_php_ini ( $envFile , $updatedConf );
2013-04-17 11:43:20 -04:00
} catch ( Exception $e ) {
$info -> result = false ;
2018-02-01 13:06:32 +00:00
$info -> message = G :: LoadTranslation ( 'ID_PROCESSMAKER_WRITE_CONFIG_INDEX' , SYS_LANG , [ $envFile ]);
2013-04-17 11:43:20 -04:00
$info -> message .= G :: LoadTranslation ( 'ID_PROCESSMAKER_UI_NOT_INSTALL' );
2018-02-01 13:06:32 +00:00
$this -> installLog ( G :: LoadTranslation ( 'ID_INSTALL_BUT_ERROR' , SYS_LANG , [ 'env.ini' ]));
2013-04-17 11:43:20 -04:00
return $info ;
}
2013-04-17 10:25:32 -04:00
try {
// update the main index file
2018-02-01 13:06:32 +00:00
$indexFileUpdated = System :: updateIndexFile ([ 'lang' => 'en' , 'skin' => $updatedConf [ 'default_skin' ]]);
2013-04-17 10:25:32 -04:00
} catch ( Exception $e ) {
$info -> result = false ;
2018-02-01 13:06:32 +00:00
$info -> message = G :: LoadTranslation ( 'ID_PROCESSMAKER_WRITE_CONFIG_INDEX' , SYS_LANG , [ PATH_HTML . " index.html. " ]);
2013-04-17 10:25:32 -04:00
$info -> message .= G :: LoadTranslation ( 'ID_PROCESSMAKER_UI_NOT_INSTALL' );
2018-02-01 13:06:32 +00:00
$this -> installLog ( G :: LoadTranslation ( 'ID_INSTALL_BUT_ERROR' , SYS_LANG , [ 'index.html' ]));
2013-04-17 10:25:32 -04:00
return $info ;
}
2013-04-15 13:46:13 -04:00
}
2015-01-15 17:01:37 -04:00
2018-02-01 13:06:32 +00:00
$this -> installLog ( G :: LoadTranslation ( 'ID_INDEX_FILE_UPDATED' , SYS_LANG , [ $indexFileUpdated , $sysConf [ 'default_lang' ], $sysConf [ 'default_skin' ]]));
2017-12-04 13:25:35 +00:00
$this -> installLog ( G :: LoadTranslation ( 'ID_INSTALL_SUCESS' ));
2012-10-18 11:32:36 -04:00
$info -> result = true ;
2013-03-11 10:23:59 -04:00
$info -> message = G :: LoadTranslation ( 'ID_INSTALL_SUCESS' );
2018-02-01 13:06:32 +00:00
$info -> messageFinish = G :: LoadTranslation ( 'ID_PROCESSMAKER_SUCCESS_INSTALLED' , SYS_LANG , [ $workspace ]);
2012-10-18 11:32:36 -04:00
} catch ( Exception $e ) {
$info -> canRedirect = false ;
$info -> result = false ;
$info -> message = $e -> getMessage ();
}
return $info ;
2012-03-29 16:42:09 -04:00
}
2012-10-18 11:32:36 -04:00
2017-12-04 13:25:35 +00:00
public function getSystemName ( $siteShared )
2013-04-26 11:45:03 -04:00
{
2013-04-26 17:16:00 -04:00
$systemName = '' ;
2017-12-04 13:25:35 +00:00
if ( substr ( $siteShared , - 1 ) != '/' ) {
2013-04-26 15:15:28 -04:00
$siteShared .= '/' ;
2013-04-26 11:45:03 -04:00
}
2013-04-26 16:36:32 -04:00
2013-04-26 15:15:28 -04:00
if ( file_exists ( $siteShared . 'partner.info' )) {
$dataInfo = parse_ini_file ( $siteShared . 'partner.info' );
2013-04-26 12:00:12 -04:00
if ( isset ( $dataInfo [ 'system_name' ])) {
$systemName = trim ( $dataInfo [ 'system_name' ]);
2013-04-26 11:45:03 -04:00
}
}
return $systemName ;
}
2018-02-01 13:06:32 +00:00
/**
* Get the Database engines list
*
* @ return object
*/
2017-12-04 13:25:35 +00:00
public function getEngines ()
2012-10-18 11:32:36 -04:00
{
2017-12-04 13:25:35 +00:00
$this -> setResponseType ( 'json' );
2018-02-01 13:06:32 +00:00
$engines = [];
2017-12-04 13:25:35 +00:00
if ( function_exists ( 'mysqli_query' )) {
2012-10-18 11:32:36 -04:00
$engine = new stdclass ();
$engine -> id = 'mysql' ;
$engine -> label = 'MySQL' ;
$engines [] = $engine ;
}
return $engines ;
}
2012-03-29 16:42:09 -04:00
2017-12-04 13:25:35 +00:00
public function checkDatabases ()
2012-10-18 11:32:36 -04:00
{
2015-03-16 12:03:45 -04:00
$filter = new InputFilter ();
2017-12-04 13:25:35 +00:00
$this -> setResponseType ( 'json' );
2012-10-18 11:32:36 -04:00
$info = new stdclass ();
2017-12-04 13:25:35 +00:00
$db_hostname = $filter -> validateInput ( $_REQUEST [ 'db_hostname' ]);
$db_username = $filter -> validateInput ( $_REQUEST [ 'db_username' ]);
$db_password = urlencode ( $_REQUEST [ 'db_password' ]);
$db_password = urldecode ( $filter -> validateInput ( $db_password ));
$db_port = $filter -> validateInput ( $_REQUEST [ 'db_port' ]);
switch ( $_REQUEST [ 'db_engine' ]) {
case 'mysql' :
$wfDatabase = $filter -> validateInput ( $_REQUEST [ 'wfDatabase' ], 'nosql' );
2018-02-01 13:06:32 +00:00
self :: setNewConnection ( self :: CONNECTION_TEST_INSTALL , $db_hostname , $db_username , $db_password , '' , $db_port );
$response = DB :: connection ( self :: CONNECTION_TEST_INSTALL )
-> select ( " show databases like ' $wfDatabase ' " );
$info -> wfDatabaseExists = count ( $response ) > 0 ;
2017-12-04 13:25:35 +00:00
break ;
case 'sqlsrv' :
$arguments = array ( " UID " => $db_username , " PWD " => $db_password );
$link = @ sqlsrv_connect ( $db_hostname , $arguments );
$wfDatabase = $filter -> validateInput ( $_REQUEST [ 'wfDatabase' ], 'nosql' );
$query = " select * from sys.databases where name = '%s' " ;
$query = $filter -> preventSqlInjection ( $query , array ( $wfDatabase ));
$dataSet = @ sqlsrv_query ( $link , $query );
$info -> wfDatabaseExists = ( @ sqlsrv_num_rows ( $dataSet ) > 0 );
break ;
default :
break ;
2012-10-18 11:32:36 -04:00
}
2012-03-29 16:42:09 -04:00
2013-03-11 10:23:59 -04:00
$info -> errMessage = G :: LoadTranslation ( 'ID_DATABASE_EXISTS_OVERWRITE' );
2012-03-29 16:42:09 -04:00
2012-10-18 11:32:36 -04:00
return $info ;
2012-03-29 16:42:09 -04:00
}
2012-10-18 11:32:36 -04:00
/**
* Privates functions section , non callable by http request
*/
2017-12-04 13:25:35 +00:00
private function testMySQLConnection ()
2012-10-18 11:32:36 -04:00
{
2018-02-01 13:06:32 +00:00
try {
$filter = new InputFilter ();
$info = new StdClass ();
$info -> result = false ;
$info -> message = '' ;
if ( ! function_exists ( 'mysqli_connect' )) {
$info -> message = G :: LoadTranslation ( 'ID_PHP_MYSQLI_NOT_INSTALL' );
return $info ;
}
$dataRequest = $_REQUEST ;
$db_hostname = $filter -> validateInput ( $dataRequest [ 'db_hostname' ]);
$db_port = $filter -> validateInput ( $dataRequest [ 'db_port' ]);
$db_username = $filter -> validateInput ( $dataRequest [ 'db_username' ]);
$db_password = urlencode ( $dataRequest [ 'db_password' ]);
$db_password = urldecode ( $filter -> validateInput ( $db_password ));
$fp = @ fsockopen ( $db_hostname , $db_port , $errno , $errstr , 30 );
if ( ! $fp ) {
$info -> message .= G :: LoadTranslation ( 'ID_CONNECTION_ERROR' , SYS_LANG , [ " $errstr ( $errno ) " ]);
return $info ;
}
2012-03-29 16:42:09 -04:00
2018-02-01 13:06:32 +00:00
$db_username = $filter -> validateInput ( $db_username , 'nosql' );
$db_hostname = $filter -> validateInput ( $db_hostname , 'nosql' );
2015-11-26 20:11:58 -04:00
2018-02-01 13:06:32 +00:00
self :: setNewConnection ( self :: CONNECTION_TEST_INSTALL , $db_hostname , $db_username , $db_password , '' , $db_port );
$query = " SELECT * FROM `information_schema`.`USER_PRIVILEGES` where (GRANTEE = \" ' $db_username '@' $db_hostname ' \" OR GRANTEE = \" ' $db_username '@'%%' \" ) " ;
$response = DB :: connection ( self :: CONNECTION_TEST_INSTALL ) -> select ( $query );
if ( ! is_array ( $response )) {
$info -> message .= G :: LoadTranslation ( 'ID_CONNECTION_ERROR_PRIVILEGE' , SYS_LANG , [ $db_username ]);
return $info ;
}
$info -> message .= G :: LoadTranslation ( 'ID_MYSQL_SUCCESS_CONNECT' );
$info -> result = true ;
} catch ( Exception $e ) {
$info -> result = false ;
$info -> message = G :: LoadTranslation ( 'ID_MYSQL_CREDENTIALS_WRONG' );
2012-10-18 11:32:36 -04:00
}
return $info ;
2012-03-29 16:42:09 -04:00
}
2018-02-01 13:06:32 +00:00
/**
* This function define the partner behaviour when the PARTNER_FLAG is defined
* Execute to change of skin
*
* @ return void
*/
private function setPartner ()
2013-04-15 14:05:52 -04:00
{
if ( defined ( 'PARTNER_FLAG' ) || isset ( $_REQUEST [ 'PARTNER_FLAG' ])) {
// Execute sql for partner
$pathMysqlPartner = PATH_CORE . 'data' . PATH_SEP . 'partner' . PATH_SEP . 'mysql' . PATH_SEP ;
if ( G :: verifyPath ( $pathMysqlPartner )) {
$filesSlq = glob ( $pathMysqlPartner . '*.sql' );
foreach ( $filesSlq as $value ) {
$this -> mysqlFileQuery ( $value );
}
}
// Execute to change of skin
$pathSkinPartner = PATH_CORE . 'data' . PATH_SEP . 'partner' . PATH_SEP . 'skin' . PATH_SEP ;
if ( G :: verifyPath ( $pathSkinPartner )) {
$fileTar = glob ( $pathSkinPartner . '*.tar' );
foreach ( $fileTar as $value ) {
$dataFile = pathinfo ( $value );
$nameSkinTmp = $dataFile [ 'filename' ];
2017-02-15 16:26:02 +00:00
2017-12-04 13:25:35 +00:00
$tar = new Archive_Tar ( $value );
2013-04-15 14:05:52 -04:00
$pathSkinTmp = $pathSkinPartner . 'tmp' . PATH_SEP ;
G :: rm_dir ( $pathSkinTmp );
G :: verifyPath ( $pathSkinTmp , true );
2017-12-04 13:25:35 +00:00
chmod ( $pathSkinTmp , 0777 );
2013-04-15 14:05:52 -04:00
$tar -> extract ( $pathSkinTmp );
$pathSkinName = $pathSkinTmp . $nameSkinTmp . PATH_SEP ;
2017-12-04 13:25:35 +00:00
chmod ( $pathSkinName , 0777 );
2013-04-15 14:05:52 -04:00
G :: verifyPath ( PATH_CORE . 'skinEngine' . PATH_SEP . 'tmp' , true );
$skinClassic = PATH_CORE . 'skinEngine' . PATH_SEP . 'tmp' . PATH_SEP ;
if ( is_dir ( $pathSkinName )) {
$this -> copyFile ( $pathSkinName , $skinClassic );
}
G :: rm_dir ( PATH_CORE . 'skinEngine' . PATH_SEP . 'base' );
rename ( PATH_CORE . 'skinEngine' . PATH_SEP . 'tmp' , PATH_CORE . 'skinEngine' . PATH_SEP . 'base' );
G :: rm_dir ( PATH_CORE . 'skinEngine' . PATH_SEP . 'tmp' );
break ;
}
}
}
}
2018-02-01 13:06:32 +00:00
/**
* Copy a directory or file
*
* @ param string $fromDir
* @ param string $toDir
* @ param integer $chmod
*
* @ return void
*/
2017-12-04 13:25:35 +00:00
public function copyFile ( $fromDir , $toDir , $chmod = 0777 )
2013-04-15 14:05:52 -04:00
{
2018-02-01 13:06:32 +00:00
$errors = [];
$messages = [];
2013-04-15 14:05:52 -04:00
2017-12-04 13:25:35 +00:00
if ( ! is_writable ( $toDir )) {
$errors [] = 'target ' . $toDir . ' is not writable' ;
2013-04-15 14:05:52 -04:00
}
if ( ! is_dir ( $toDir )) {
2017-12-04 13:25:35 +00:00
$errors [] = 'target ' . $toDir . ' is not a directory' ;
2013-04-15 14:05:52 -04:00
}
if ( ! is_dir ( $fromDir )) {
2017-12-04 13:25:35 +00:00
$errors [] = 'source ' . $fromDir . ' is not a directory' ;
2013-04-15 14:05:52 -04:00
}
if ( ! empty ( $errors )) {
return false ;
}
2017-12-04 13:25:35 +00:00
$exceptions = array ( '.' , '..' );
2013-04-15 14:05:52 -04:00
$handle = opendir ( $fromDir );
2017-12-04 13:25:35 +00:00
while ( false !== ( $item = readdir ( $handle ))) {
if ( ! in_array ( $item , $exceptions )) {
$from = str_replace ( '//' , '/' , $fromDir . '/' . $item );
$to = str_replace ( '//' , '/' , $toDir . '/' . $item );
2013-04-15 14:05:52 -04:00
if ( is_file ( $from )) {
2017-12-04 13:25:35 +00:00
if ( @ copy ( $from , $to )) {
chmod ( $to , $chmod );
touch ( $to , filemtime ( $from ));
2013-04-15 14:05:52 -04:00
}
}
if ( is_dir ( $from )) {
if ( @ mkdir ( $to )) {
2017-12-04 13:25:35 +00:00
chmod ( $to , $chmod );
2013-04-15 14:05:52 -04:00
}
2017-12-04 13:25:35 +00:00
$this -> copyFile ( $from , $to , $chmod );
2013-04-15 14:05:52 -04:00
}
}
}
closedir ( $handle );
}
2018-02-01 13:06:32 +00:00
/**
* Define build Pattern Extras related to :
* Upload translation . po file
* Upload skin file
* Upload plugin file
* Active plugins to enterprise
*
* @ param string $username
* @ param string $password
* @ param string $workspace
* @ param string $lang
* @ param string $skinName
*
* @ return void
*/
private function buildParternExtras ( $username , $password , $workspace , $lang , $skinName )
2013-04-15 13:46:13 -04:00
{
2015-03-25 11:25:00 -04:00
$filter = new InputFilter ();
2013-04-15 13:46:13 -04:00
ini_set ( 'max_execution_time' , '0' );
ini_set ( 'memory_limit' , '256M' );
2013-04-22 15:04:13 -04:00
$serv = 'http://' ;
2018-02-01 13:06:32 +00:00
if ( isset ( $_SERVER [ 'HTTPS' ]) && ! empty ( trim ( $_SERVER [ 'HTTPS' ]))) {
2013-04-22 15:04:13 -04:00
$serv = 'https://' ;
}
$serv .= $_SERVER [ 'SERVER_NAME' ];
2018-02-01 13:06:32 +00:00
if ( isset ( $_SERVER [ 'SERVER_PORT' ]) && ! empty ( trim ( $_SERVER [ 'SERVER_PORT' ]))) {
2013-04-22 15:04:13 -04:00
$serv .= ':' . $_SERVER [ 'SERVER_PORT' ];
}
2013-04-15 13:46:13 -04:00
// create session
2017-12-04 13:25:35 +00:00
$cookiefile = sys_get_temp_dir () . PATH_SEP . 'curl-session' ;
2013-04-15 13:46:13 -04:00
$fp = fopen ( $cookiefile , " w " );
fclose ( $fp );
2013-04-16 06:35:57 -04:00
chmod ( $cookiefile , 0777 );
2013-04-15 13:46:13 -04:00
$user = urlencode ( $username );
2015-03-25 11:25:00 -04:00
$user = $filter -> validateInput ( $user );
2013-04-15 13:46:13 -04:00
$pass = urlencode ( $password );
2015-03-25 11:25:00 -04:00
$pass = $filter -> validateInput ( $pass );
2013-04-15 13:46:13 -04:00
$lang = urlencode ( $lang );
2015-03-25 11:25:00 -04:00
$lang = $filter -> validateInput ( $lang );
2013-04-17 10:06:51 -04:00
2013-04-15 13:46:13 -04:00
$ch = curl_init ();
2013-04-17 10:06:51 -04:00
2013-04-15 13:46:13 -04:00
// set URL and other appropriate options
2013-05-07 16:08:07 -04:00
curl_setopt ( $ch , CURLOPT_URL , " $serv /sys { $workspace } / { $lang } / { $skinName } /login/authentication " );
2013-04-15 13:46:13 -04:00
curl_setopt ( $ch , CURLOPT_HEADER , 0 );
curl_setopt ( $ch , CURLOPT_COOKIEFILE , $cookiefile );
curl_setopt ( $ch , CURLOPT_COOKIEJAR , $cookiefile );
curl_setopt ( $ch , CURLOPT_FOLLOWLOCATION , false );
curl_setopt ( $ch , CURLOPT_POST , true );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
curl_setopt ( $ch , CURLOPT_POSTFIELDS , " form[USR_USERNAME]= $user &form[USR_PASSWORD]= $pass &form[USER_LANG]= $lang " );
2013-04-16 06:35:57 -04:00
curl_setopt ( $ch , CURLOPT_TIMEOUT , 90 );
2013-04-17 10:06:51 -04:00
2013-04-15 13:46:13 -04:00
$output = curl_exec ( $ch );
curl_close ( $ch );
2013-05-07 17:20:16 -04:00
/**
* Upload translation . po file
*/
$ch = curl_init ();
2018-02-01 13:06:32 +00:00
$postData = [];
2013-05-07 17:20:16 -04:00
// File to upload/post
2017-12-04 13:25:35 +00:00
$postData [ 'form[LANGUAGE_FILENAME]' ] = " @ " . PATH_CORE . " content/translations/processmaker. $lang .po " ;
2013-05-07 17:20:16 -04:00
curl_setopt ( $ch , CURLOPT_URL , " $serv /sys { $workspace } / { $lang } / { $skinName } /setup/languages_Import " );
curl_setopt ( $ch , CURLOPT_HEADER , 0 );
curl_setopt ( $ch , CURLOPT_VERBOSE , 0 );
curl_setopt ( $ch , CURLOPT_COOKIEFILE , $cookiefile );
curl_setopt ( $ch , CURLOPT_COOKIEJAR , $cookiefile );
curl_setopt ( $ch , CURLOPT_FOLLOWLOCATION , false );
curl_setopt ( $ch , CURLOPT_POST , true );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
curl_setopt ( $ch , CURLOPT_POSTFIELDS , $postData );
curl_setopt ( $ch , CURLOPT_TIMEOUT , 90 );
$output = curl_exec ( $ch );
curl_close ( $ch );
2013-04-26 16:34:48 -04:00
/**
2013-04-17 10:06:51 -04:00
* Upload skin file
2013-04-15 13:46:13 -04:00
*/
$ch = curl_init ();
2018-02-01 13:06:32 +00:00
$postData = [];
2013-04-15 13:46:13 -04:00
2017-12-04 13:25:35 +00:00
$skins = glob ( PATH_CORE . " data/partner/*.tar " );
2013-04-17 10:06:51 -04:00
if ( count ( $skins ) > 0 ) {
$skin = $skins [ 0 ];
$postData [ 'overwrite_files' ] = " on " ;
$postData [ 'workspace' ] = " global " ;
$postData [ 'option' ] = " standardupload " ;
$postData [ 'action' ] = " importSkin " ;
2013-04-16 06:36:33 -04:00
// File to upload/post
2017-12-04 13:25:35 +00:00
$postData [ 'uploadedFile' ] = " @ " . $skin ;
2013-04-17 10:06:51 -04:00
2013-05-07 16:08:07 -04:00
curl_setopt ( $ch , CURLOPT_URL , " $serv /sys { $workspace } / { $lang } / { $skinName } /setup/skin_Ajax " );
2013-04-16 06:35:57 -04:00
curl_setopt ( $ch , CURLOPT_HEADER , 0 );
2013-04-15 13:46:13 -04:00
curl_setopt ( $ch , CURLOPT_VERBOSE , 0 );
curl_setopt ( $ch , CURLOPT_COOKIEFILE , $cookiefile );
curl_setopt ( $ch , CURLOPT_COOKIEJAR , $cookiefile );
2013-04-16 06:35:57 -04:00
curl_setopt ( $ch , CURLOPT_FOLLOWLOCATION , false );
2013-04-15 13:46:13 -04:00
curl_setopt ( $ch , CURLOPT_POST , true );
2013-04-16 06:35:57 -04:00
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
2013-04-15 13:46:13 -04:00
curl_setopt ( $ch , CURLOPT_POSTFIELDS , $postData );
2013-04-17 10:25:32 -04:00
curl_setopt ( $ch , CURLOPT_TIMEOUT , 90 );
2013-04-15 13:46:13 -04:00
2013-04-16 06:36:33 -04:00
$output = curl_exec ( $ch );
2013-04-15 13:46:13 -04:00
curl_close ( $ch );
2013-04-17 10:06:51 -04:00
}
2013-04-15 13:46:13 -04:00
2013-04-17 10:25:32 -04:00
/**
2013-04-17 10:06:51 -04:00
* Upload plugin file
*/
2013-04-17 10:25:32 -04:00
2013-04-16 06:35:57 -04:00
$ch = curl_init ();
2018-02-01 13:06:32 +00:00
$postData = [];
2013-04-17 10:06:51 -04:00
// resolv the plugin name
2017-12-04 13:25:35 +00:00
$plugins = glob ( PATH_CORE . " plugins/*.tar " );
2013-04-17 10:06:51 -04:00
if ( count ( $plugins ) > 0 ) {
$pluginName = $plugins [ 0 ];
2013-04-16 06:35:57 -04:00
2013-04-16 06:36:33 -04:00
// File to upload/post
2013-04-17 10:06:51 -04:00
$postData [ 'form[PLUGIN_FILENAME]' ] = " @ { $pluginName } " ;
2013-05-07 16:08:07 -04:00
curl_setopt ( $ch , CURLOPT_URL , " $serv /sys { $workspace } / { $lang } / { $skinName } /setup/pluginsImportFile " );
2013-04-16 06:35:57 -04:00
curl_setopt ( $ch , CURLOPT_HEADER , 0 );
curl_setopt ( $ch , CURLOPT_VERBOSE , 0 );
curl_setopt ( $ch , CURLOPT_COOKIEFILE , $cookiefile );
curl_setopt ( $ch , CURLOPT_COOKIEJAR , $cookiefile );
curl_setopt ( $ch , CURLOPT_FOLLOWLOCATION , false );
curl_setopt ( $ch , CURLOPT_POST , true );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
curl_setopt ( $ch , CURLOPT_POSTFIELDS , $postData );
2013-04-17 10:06:51 -04:00
curl_setopt ( $ch , CURLOPT_TIMEOUT , 90 );
$output = curl_exec ( $ch );
2013-04-16 06:35:57 -04:00
curl_close ( $ch );
}
2013-07-23 11:27:30 -04:00
2013-07-23 14:26:17 -04:00
/**
* Active plugins to enterprise
*/
2013-07-24 10:32:12 -04:00
if ( ! defined ( " PATH_PM_ENTERPRISE " )) {
define ( " PATH_PM_ENTERPRISE " , PATH_CORE . " /plugins/enterprise/ " );
}
set_include_path ( PATH_PM_ENTERPRISE . PATH_SEPARATOR . get_include_path ());
2017-12-04 13:25:35 +00:00
require_once ( 'classes/model/AddonsManager.php' );
2013-07-24 10:32:12 -04:00
2017-12-04 13:25:35 +00:00
$plugins = glob ( PATH_CORE . " plugins/*.php " );
2013-07-23 11:27:30 -04:00
foreach ( $plugins as $value ) {
2013-07-23 12:25:55 -04:00
$dataPlugin = pathinfo ( $value );
$namePlugin = $dataPlugin [ 'filename' ];
2018-02-01 13:06:32 +00:00
if ( $value !== 'enterprise' ) {
2017-12-04 13:25:35 +00:00
$db_hostname = trim ( $_REQUEST [ 'db_hostname' ]);
2015-03-25 11:25:00 -04:00
$db_hostname = $filter -> validateInput ( $db_hostname );
2017-12-04 13:25:35 +00:00
$db_port = trim ( $_REQUEST [ 'db_port' ]);
2015-03-25 11:25:00 -04:00
$db_port = $filter -> validateInput ( $db_port );
2017-12-04 13:25:35 +00:00
$db_username = trim ( $_REQUEST [ 'db_username' ]);
2015-03-25 11:25:00 -04:00
$db_username = $filter -> validateInput ( $db_username );
2016-12-20 12:35:10 -04:00
$db_password = urlencode ( trim ( $_REQUEST [ 'db_password' ]));
$db_password = urldecode ( $filter -> validateInput ( $db_password ));
2017-12-04 13:25:35 +00:00
$wf = trim ( $_REQUEST [ 'wfDatabase' ]);
2015-05-05 09:55:39 -04:00
$wf = $filter -> validateInput ( $wf );
2013-07-24 12:32:08 -04:00
2013-07-26 09:22:58 -04:00
$db_host = ( $db_port != '' && $db_port != 3306 ) ? $db_hostname . ':' . $db_port : $db_hostname ;
2015-11-26 20:11:58 -04:00
2018-02-01 13:06:32 +00:00
$row = DB :: connection ( self :: CONNECTION_INSTALL )
-> table ( 'ADDONS_MANAGER' )
-> select ( 'STORE_ID' )
-> where ( 'ADDON_NAME' , $namePlugin )
-> toArray ();
if ( $row ) {
2013-07-23 14:29:55 -04:00
$ch = curl_init ();
2018-02-01 13:06:32 +00:00
$postData = [];
2013-07-23 14:29:55 -04:00
$postData [ 'action' ] = " enable " ;
2017-12-04 13:25:35 +00:00
$postData [ 'addon' ] = $namePlugin ;
$postData [ 'store' ] = $row [ 'STORE_ID' ];
2013-07-23 14:29:55 -04:00
curl_setopt ( $ch , CURLOPT_URL , " $serv /sys { $workspace } / { $lang } / { $skinName } /enterprise/addonsStoreAction " );
curl_setopt ( $ch , CURLOPT_HEADER , 0 );
curl_setopt ( $ch , CURLOPT_VERBOSE , 0 );
curl_setopt ( $ch , CURLOPT_COOKIEFILE , $cookiefile );
curl_setopt ( $ch , CURLOPT_COOKIEJAR , $cookiefile );
curl_setopt ( $ch , CURLOPT_FOLLOWLOCATION , false );
curl_setopt ( $ch , CURLOPT_POST , true );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
curl_setopt ( $ch , CURLOPT_POSTFIELDS , $postData );
curl_setopt ( $ch , CURLOPT_TIMEOUT , 90 );
$output = curl_exec ( $ch );
curl_close ( $ch );
}
2013-07-23 11:36:51 -04:00
}
2013-07-23 11:27:30 -04:00
}
2013-04-15 13:46:13 -04:00
}
2017-07-28 11:33:56 -04:00
/**
* Verify / create framework shared directory structure
*
*/
private function verifySharedFrameworkPaths ( $sharedPath )
{
$paths = [
2017-08-07 13:02:26 -04:00
$sharedPath . 'framework' => 0770 ,
$sharedPath . 'framework' . DIRECTORY_SEPARATOR . 'cache' => 0770 ,
2017-07-28 11:33:56 -04:00
];
foreach ( $paths as $path => $permission ) {
if ( ! file_exists ( $path )) {
G :: mk_dir ( $path , $permission );
}
if ( ! file_exists ( $path )) {
return false ;
}
}
return true ;
}
2012-10-18 11:32:36 -04:00
}