2013-11-06 10:10:36 -04:00
|
|
|
<?php
|
|
|
|
|
|
2017-08-14 16:13:46 -04:00
|
|
|
use ProcessMaker\Core\System;
|
2017-08-01 12:16:06 -04:00
|
|
|
use ProcessMaker\Plugins\PluginRegistry;
|
|
|
|
|
|
2013-11-06 10:10:36 -04:00
|
|
|
/**
|
|
|
|
|
* Designer Controller
|
|
|
|
|
*
|
|
|
|
|
* @inherits Controller
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
|
|
|
|
|
2017-08-04 16:49:29 -04:00
|
|
|
use Maveriks\Util\ClassLoader;
|
2019-02-27 19:48:45 -04:00
|
|
|
use OAuth2\Request;
|
|
|
|
|
use ProcessMaker\BusinessModel\InputDocument;
|
|
|
|
|
use ProcessMaker\BusinessModel\Light\Tracker;
|
|
|
|
|
use ProcessMaker\Services\OAuth2\Server;
|
2017-08-04 16:49:29 -04:00
|
|
|
|
2013-11-06 10:10:36 -04:00
|
|
|
class Designer extends Controller
|
|
|
|
|
{
|
2013-12-06 13:33:50 -04:00
|
|
|
protected $clientId = 'x-pm-local-client';
|
|
|
|
|
|
2017-08-04 16:49:29 -04:00
|
|
|
public function __construct()
|
2013-11-06 10:10:36 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Index Action
|
|
|
|
|
*
|
|
|
|
|
* @param string $httpData (opional)
|
2019-02-27 19:48:45 -04:00
|
|
|
*
|
|
|
|
|
* @see Controller->call()
|
2013-11-06 10:10:36 -04:00
|
|
|
*/
|
|
|
|
|
public function index($httpData)
|
|
|
|
|
{
|
2018-11-27 15:59:01 -04:00
|
|
|
global $RBAC;
|
2014-03-06 17:41:39 -04:00
|
|
|
$proUid = isset($httpData->prj_uid) ? $httpData->prj_uid : '';
|
2014-05-21 15:58:45 -04:00
|
|
|
$appUid = isset($httpData->app_uid) ? $httpData->app_uid : '';
|
|
|
|
|
$proReadOnly = isset($httpData->prj_readonly) ? $httpData->prj_readonly : 'false';
|
2015-05-08 11:24:26 -04:00
|
|
|
|
2017-08-04 16:49:29 -04:00
|
|
|
$clientToken = $this->getCredentials($httpData);
|
2014-07-09 10:43:51 -04:00
|
|
|
$debug = false; //System::isDebugMode();
|
2015-03-24 17:42:13 -04:00
|
|
|
$consolidated = 0;
|
2015-05-08 15:41:43 -04:00
|
|
|
$enterprise = 0;
|
2015-06-01 16:14:39 -04:00
|
|
|
$distribution = 0;
|
|
|
|
|
|
2019-08-29 12:09:04 -04:00
|
|
|
$usrUid = (isset($RBAC->userObj)) ? $RBAC->userObj->getUsrUid() : '';
|
|
|
|
|
|
2018-11-27 15:59:01 -04:00
|
|
|
$userProperties = UsersPropertiesPeer::retrieveByPk($usrUid);
|
|
|
|
|
|
2015-03-25 22:30:02 -04:00
|
|
|
/*----------------------------------********---------------------------------*/
|
2017-12-04 13:25:35 +00:00
|
|
|
$licensedFeatures = PMLicensedFeatures::getSingleton();
|
2015-03-24 17:42:13 -04:00
|
|
|
if ($licensedFeatures->verifyfeature('7TTeDBQeWRoZTZKYjh4eFpYUlRDUUEyVERPU3FxellWank=')) {
|
|
|
|
|
$consolidated = 1;
|
|
|
|
|
}
|
2015-06-01 16:14:39 -04:00
|
|
|
$enterprise = 1;
|
|
|
|
|
|
|
|
|
|
if ($licensedFeatures->verifyfeature("Jb0N3dSZHVhZ1JNOEFZaElqdm15Y050Wmh5S0FEVEI0ckQ=")) {
|
|
|
|
|
$distribution = 1;
|
|
|
|
|
}
|
2015-03-25 22:30:02 -04:00
|
|
|
/*----------------------------------********---------------------------------*/
|
2015-03-24 17:42:13 -04:00
|
|
|
|
2016-03-02 18:17:46 +00:00
|
|
|
$this->setVar('prj_uid', htmlspecialchars($proUid));
|
|
|
|
|
$this->setVar('app_uid', htmlspecialchars($appUid));
|
2015-03-24 17:42:13 -04:00
|
|
|
$this->setVar('consolidated', $consolidated);
|
2015-05-08 15:41:43 -04:00
|
|
|
$this->setVar('enterprise', $enterprise);
|
2014-05-21 15:58:45 -04:00
|
|
|
$this->setVar('prj_readonly', $proReadOnly);
|
2014-06-16 18:05:04 -04:00
|
|
|
$this->setVar('credentials', base64_encode(json_encode($clientToken)));
|
2014-07-09 10:43:51 -04:00
|
|
|
$this->setVar('isDebugMode', $debug);
|
2015-06-01 16:14:39 -04:00
|
|
|
$this->setVar("distribution", $distribution);
|
2017-10-10 12:33:25 -04:00
|
|
|
$this->setVar("SYS_SYS", config("system.workspace"));
|
2015-11-13 11:46:18 -04:00
|
|
|
$this->setVar("SYS_LANG", SYS_LANG);
|
|
|
|
|
$this->setVar("SYS_SKIN", SYS_SKIN);
|
2017-08-14 16:13:46 -04:00
|
|
|
$this->setVar('HTTP_SERVER_HOSTNAME', System::getHttpServerHostnameRequestsFrontEnd());
|
2019-08-29 12:09:04 -04:00
|
|
|
isset($userProperties) ? $this->setVar('PMDYNAFORM_FIRST_TIME',
|
|
|
|
|
$userProperties->getPmdynaformFirstTime()) : $this->setVar('PMDYNAFORM_FIRST_TIME', '0');
|
2019-02-27 19:48:45 -04:00
|
|
|
$inpuDocument = new InputDocument();
|
|
|
|
|
$this->setVar('maxFileSizeInformation', G::json_encode($inpuDocument->getMaxFileSize()));
|
2015-11-13 11:46:18 -04:00
|
|
|
|
2014-07-09 10:43:51 -04:00
|
|
|
if ($debug) {
|
2017-08-04 16:49:29 -04:00
|
|
|
if (!file_exists(PATH_HTML . "lib-dev/pmUI/build.cache")) {
|
2014-02-28 09:37:29 -04:00
|
|
|
throw new RuntimeException("Development JS Files were are not generated!.\nPlease execute: \$>rake pmBuildDebug in pmUI project");
|
2014-02-06 18:55:34 -04:00
|
|
|
}
|
2017-08-04 16:49:29 -04:00
|
|
|
if (!file_exists(PATH_HTML . "lib-dev/mafe/build.cache")) {
|
2014-02-28 09:37:29 -04:00
|
|
|
throw new RuntimeException("Development JS Files were are not generated!.\nPlease execute: \$>rake pmBuildDebug in MichelangeloFE project");
|
2014-02-06 18:10:55 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-18 18:03:10 -04:00
|
|
|
$mafeFiles = file(PATH_HTML . "lib-dev/mafe/build.cache", FILE_IGNORE_NEW_LINES);
|
|
|
|
|
$mafeCssFiles = array();
|
|
|
|
|
$mafeJsFiles = array();
|
|
|
|
|
|
|
|
|
|
foreach ($mafeFiles as $file) {
|
|
|
|
|
if (substr($file, -3) == ".js") {
|
|
|
|
|
$mafeJsFiles[] = $file;
|
|
|
|
|
} else {
|
|
|
|
|
$mafeCssFiles[] = $file;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-06 18:55:34 -04:00
|
|
|
$this->setVar('pmuiJsCacheFile', file(PATH_HTML . "lib-dev/pmUI/build.cache", FILE_IGNORE_NEW_LINES));
|
|
|
|
|
$this->setVar('pmuiCssCacheFile', file(PATH_HTML . "lib-dev/pmUI/css.cache", FILE_IGNORE_NEW_LINES));
|
|
|
|
|
|
2019-08-29 12:09:04 -04:00
|
|
|
$this->setVar('designerCacheFile',
|
|
|
|
|
file(PATH_HTML . "lib-dev/mafe/applications.cache", FILE_IGNORE_NEW_LINES));
|
2014-02-18 18:03:10 -04:00
|
|
|
$this->setVar('mafeJsFiles', $mafeJsFiles);
|
|
|
|
|
$this->setVar('mafeCssFiles', $mafeCssFiles);
|
2014-03-12 13:08:01 -04:00
|
|
|
} else {
|
|
|
|
|
$buildhashFile = PATH_HTML . "lib/buildhash";
|
2017-08-04 16:49:29 -04:00
|
|
|
if (!file_exists($buildhashFile)) {
|
2014-03-12 13:08:01 -04:00
|
|
|
throw new RuntimeException("CSS and JS Files were are not generated!.\nPlease review install process");
|
|
|
|
|
}
|
|
|
|
|
$buildhash = file_get_contents($buildhashFile);
|
|
|
|
|
$this->setVar('buildhash', $buildhash);
|
2014-02-06 18:10:55 -04:00
|
|
|
}
|
|
|
|
|
|
2014-04-14 12:35:47 -04:00
|
|
|
$translationMafe = "/translations/translationsMafe.js";
|
|
|
|
|
$this->setVar('translationMafe', $translationMafe);
|
2017-08-04 16:49:29 -04:00
|
|
|
if (!file_exists(PATH_HTML . "translations" . PATH_SEP . 'translationsMafe' . ".js")) {
|
2014-04-14 12:35:47 -04:00
|
|
|
$translation = new Translation();
|
|
|
|
|
$translation->generateFileTranslationMafe();
|
|
|
|
|
}
|
2015-12-03 17:05:28 -04:00
|
|
|
|
2015-09-25 19:55:26 -04:00
|
|
|
$this->setVar('sys_skin', SYS_SKIN);
|
2014-04-14 12:35:47 -04:00
|
|
|
|
2015-12-03 17:05:28 -04:00
|
|
|
//Verify user
|
|
|
|
|
$criteria = new Criteria('workflow');
|
|
|
|
|
|
|
|
|
|
$criteria->addSelectColumn(OauthAccessTokensPeer::ACCESS_TOKEN);
|
|
|
|
|
$criteria->addSelectColumn(OauthAccessTokensPeer::USER_ID);
|
|
|
|
|
$criteria->add(OauthAccessTokensPeer::ACCESS_TOKEN, $clientToken['access_token'], Criteria::EQUAL);
|
|
|
|
|
$rsCriteria = OauthAccessTokensPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
if ($rsCriteria->next()) {
|
|
|
|
|
$row = $rsCriteria->getRow();
|
|
|
|
|
|
|
|
|
|
$user = new \ProcessMaker\BusinessModel\User();
|
|
|
|
|
|
2016-01-26 14:59:12 -04:00
|
|
|
if ($user->checkPermission($row['USER_ID'], 'PM_FACTORY') || $proReadOnly == 'true') {
|
2015-12-03 17:05:28 -04:00
|
|
|
$this->setView('designer/index');
|
|
|
|
|
} else {
|
2016-03-24 10:38:18 -04:00
|
|
|
G::header('Location: /errors/error403.php');
|
|
|
|
|
die();
|
2015-12-03 17:05:28 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-25 13:06:25 -05:00
|
|
|
//plugin set source path
|
|
|
|
|
$sourceCss = array();
|
|
|
|
|
$sourceJs = array();
|
|
|
|
|
|
2017-08-01 12:16:06 -04:00
|
|
|
$pluginRegistry = PluginRegistry::loadSingleton();
|
2016-11-25 13:06:25 -05:00
|
|
|
$srcPath = $pluginRegistry->getDesignerSourcePath();
|
|
|
|
|
|
2017-08-01 12:16:06 -04:00
|
|
|
foreach ($srcPath as $value) {
|
2016-11-25 13:06:25 -05:00
|
|
|
$ext = pathinfo($value->pathFile, PATHINFO_EXTENSION);
|
|
|
|
|
if ($ext === "css") {
|
|
|
|
|
$sourceCss[] = $value->pathFile;
|
|
|
|
|
}
|
|
|
|
|
if ($ext === "js") {
|
|
|
|
|
$sourceJs[] = $value->pathFile;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->setVar('sourceCss', $sourceCss);
|
|
|
|
|
$this->setVar('sourceJs', $sourceJs);
|
|
|
|
|
|
2013-11-06 10:10:36 -04:00
|
|
|
$this->render();
|
|
|
|
|
}
|
2013-12-06 13:33:50 -04:00
|
|
|
|
|
|
|
|
protected function getClientCredentials()
|
|
|
|
|
{
|
2014-04-02 16:51:28 -04:00
|
|
|
$oauthQuery = new ProcessMaker\Services\OAuth2\PmPdo($this->getDsn());
|
2013-12-06 13:33:50 -04:00
|
|
|
return $oauthQuery->getClientDetails($this->clientId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getAuthorizationCode($client)
|
|
|
|
|
{
|
2017-08-04 16:49:29 -04:00
|
|
|
Server::setDatabaseSource($this->getDsn());
|
|
|
|
|
Server::setPmClientId($client['CLIENT_ID']);
|
2013-12-06 13:33:50 -04:00
|
|
|
|
2017-08-04 16:49:29 -04:00
|
|
|
$oauthServer = new Server();
|
2015-05-06 16:28:05 -04:00
|
|
|
|
2015-05-08 11:24:26 -04:00
|
|
|
if (isset($client["tracker_designer"]) && $client["tracker_designer"] == 1) {
|
2015-05-06 16:28:05 -04:00
|
|
|
$_SESSION["USER_LOGGED"] = "00000000000000000000000000000001";
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 13:33:50 -04:00
|
|
|
$userId = $_SESSION['USER_LOGGED'];
|
|
|
|
|
$authorize = true;
|
|
|
|
|
$_GET = array_merge($_GET, array(
|
|
|
|
|
'response_type' => 'code',
|
|
|
|
|
'client_id' => $client['CLIENT_ID'],
|
|
|
|
|
'scope' => implode(' ', $oauthServer->getScope())
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$response = $oauthServer->postAuthorize($authorize, $userId, true);
|
2017-08-04 16:49:29 -04:00
|
|
|
$code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=') + 5, 40);
|
2013-12-06 13:33:50 -04:00
|
|
|
|
2015-05-08 11:24:26 -04:00
|
|
|
if (isset($client["tracker_designer"]) && $client["tracker_designer"] == 1) {
|
|
|
|
|
unset($_SESSION["USER_LOGGED"]);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 13:33:50 -04:00
|
|
|
return $code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getDsn()
|
|
|
|
|
{
|
|
|
|
|
list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, '');
|
|
|
|
|
$port = empty($port) ? '' : ";port=$port";
|
2017-08-04 16:49:29 -04:00
|
|
|
$dsn = DB_ADAPTER . ':host=' . $host . ';dbname=' . DB_NAME . $port;
|
2013-12-06 13:33:50 -04:00
|
|
|
|
|
|
|
|
return array('dsn' => $dsn, 'username' => DB_USER, 'password' => DB_PASS);
|
|
|
|
|
}
|
2017-08-04 16:49:29 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return credentials oauth2
|
|
|
|
|
*
|
|
|
|
|
* @param object $httpData
|
|
|
|
|
* @return array credentials
|
|
|
|
|
*/
|
|
|
|
|
public function getCredentials($httpData = null)
|
|
|
|
|
{
|
|
|
|
|
$client = $this->getClientCredentials();
|
|
|
|
|
|
|
|
|
|
if (!empty($httpData->tracker_designer) && $httpData->tracker_designer == 1) {
|
|
|
|
|
try {
|
|
|
|
|
if (!isset($_SESSION['CASE']) && !isset($_SESSION['PIN'])) {
|
|
|
|
|
throw (new \Exception(
|
|
|
|
|
\G::LoadTranslation('ID_CASE_NOT_EXISTS') . "\n" . \G::LoadTranslation('ID_PIN_INVALID')
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
Tracker::authentication($_SESSION['CASE'], $_SESSION['PIN']);
|
|
|
|
|
} catch (\Exception $e) {
|
2017-10-10 12:33:25 -04:00
|
|
|
Bootstrap::registerMonolog('CaseTracker', 400, $e->getMessage(), [], config("system.workspace"), 'processmaker.log');
|
2017-08-04 16:49:29 -04:00
|
|
|
\G::header('Location: /errors/error403.php');
|
|
|
|
|
die();
|
|
|
|
|
}
|
|
|
|
|
$client["tracker_designer"] = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$authCode = $this->getAuthorizationCode($client);
|
|
|
|
|
|
|
|
|
|
$loader = ClassLoader::getInstance();
|
|
|
|
|
$loader->add(PATH_TRUNK . 'vendor/bshaffer/oauth2-server-php/src/', "OAuth2");
|
|
|
|
|
|
|
|
|
|
$request = array(
|
|
|
|
|
'grant_type' => 'authorization_code',
|
|
|
|
|
'code' => $authCode
|
|
|
|
|
);
|
|
|
|
|
$server = array(
|
|
|
|
|
'REQUEST_METHOD' => 'POST'
|
|
|
|
|
);
|
|
|
|
|
$headers = array(
|
|
|
|
|
"PHP_AUTH_USER" => $client['CLIENT_ID'],
|
|
|
|
|
"PHP_AUTH_PW" => $client['CLIENT_SECRET'],
|
|
|
|
|
"Content-Type" => "multipart/form-data;",
|
|
|
|
|
"Authorization" => "Basic " . base64_encode($client['CLIENT_ID'] . ":" . $client['CLIENT_SECRET'])
|
|
|
|
|
);
|
|
|
|
|
$request = new Request(array(), $request, array(), array(), array(), $server, null, $headers);
|
|
|
|
|
$oauthServer = new Server();
|
|
|
|
|
$response = $oauthServer->postToken($request, true);
|
|
|
|
|
$clientToken = $response->getParameters();
|
|
|
|
|
$clientToken["client_id"] = $client['CLIENT_ID'];
|
|
|
|
|
$clientToken["client_secret"] = $client['CLIENT_SECRET'];
|
|
|
|
|
|
|
|
|
|
return $clientToken;
|
|
|
|
|
}
|
2013-11-06 10:10:36 -04:00
|
|
|
}
|