Files
luos/workflow/engine/controllers/designer.php

236 lines
9.0 KiB
PHP
Raw Normal View History

<?php
/**
* Designer Controller
*
* @inherits Controller
* @access public
*/
class Designer extends Controller
{
protected $clientId = 'x-pm-local-client';
public function __construct ()
{
}
/**
* Index Action
*
* @param string $httpData (opional)
*/
public function index($httpData)
{
$proUid = isset($httpData->prj_uid) ? $httpData->prj_uid : '';
$appUid = isset($httpData->app_uid) ? $httpData->app_uid : '';
$proReadOnly = isset($httpData->prj_readonly) ? $httpData->prj_readonly : 'false';
$client = $this->getClientCredentials();
if (isset($httpData->tracker_designer) && $httpData->tracker_designer == 1) {
2017-05-22 13:27:38 -04:00
try {
2017-05-23 15:00:57 -04:00
if (!isset($_SESSION['CASE']) && !isset($_SESSION['PIN'])) {
2017-05-23 12:19:36 -04:00
throw (new \Exception(
\G::LoadTranslation('ID_CASE_NOT_EXISTS') . "\n" . \G::LoadTranslation('ID_PIN_INVALID')
));
}
\ProcessMaker\BusinessModel\Light\Tracker::authentication($_SESSION['CASE'], $_SESSION['PIN']);
2017-05-22 13:27:38 -04:00
} catch (\Exception $e) {
2017-05-23 12:19:36 -04:00
Bootstrap::registerMonolog('CaseTracker', 400, $e->getMessage(), [], SYS_SYS, 'processmaker.log');
\G::header('Location: /errors/error403.php');
2017-05-22 13:27:38 -04:00
die();
}
$client["tracker_designer"] = 1;
}
$authCode = $this->getAuthorizationCode($client);
$debug = false; //System::isDebugMode();
$loader = Maveriks\Util\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 \OAuth2\Request(array(), $request, array(), array(), array(), $server, null, $headers);
$oauthServer = new \ProcessMaker\Services\OAuth2\Server();
$response = $oauthServer->postToken($request, true);
$clientToken = $response->getParameters();
$clientToken["client_id"] = $client['CLIENT_ID'];
$clientToken["client_secret"] = $client['CLIENT_SECRET'];
2015-03-24 17:42:13 -04:00
$consolidated = 0;
$enterprise = 0;
$distribution = 0;
/*----------------------------------********---------------------------------*/
2015-03-24 17:42:13 -04:00
$licensedFeatures = & PMLicensedFeatures::getSingleton();
if ($licensedFeatures->verifyfeature('7TTeDBQeWRoZTZKYjh4eFpYUlRDUUEyVERPU3FxellWank=')) {
$consolidated = 1;
}
$enterprise = 1;
if ($licensedFeatures->verifyfeature("Jb0N3dSZHVhZ1JNOEFZaElqdm15Y050Wmh5S0FEVEI0ckQ=")) {
$distribution = 1;
}
/*----------------------------------********---------------------------------*/
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);
$this->setVar('enterprise', $enterprise);
$this->setVar('prj_readonly', $proReadOnly);
$this->setVar('credentials', base64_encode(json_encode($clientToken)));
$this->setVar('isDebugMode', $debug);
$this->setVar("distribution", $distribution);
$this->setVar("SYS_SYS", SYS_SYS);
$this->setVar("SYS_LANG", SYS_LANG);
$this->setVar("SYS_SKIN", SYS_SKIN);
HOR-433 "(WSSO Plugin) Cuando se ingresa al proceso, se..." SOLVED Issue: (WSSO Plugin) Cuando se ingresa al proceso, se puede verificar que no se puede recuperar la data del mismo Cause: Se esta usando el mismo VirtualHost para clientes WEB y REST Solution: Se realizo la implementacion de la nueva directiva "server_hostname_requests_frontend" del "env.ini"; esto para el caso en que se requiera del "feature SSO", tomar nota de lo siguiente: - Habilitar el modulo "mod_headers" de apache (httpd.conf) - Tener configurado un VirtualHost normal para ProcessMaker (pmos.conf) - Para el "feature SSO" se debera crear un 2do VirtualHost con toda la configuracion necesaria para el mismo (pmos.conf), por lo que todos los usuarios que requieran este feature, deberan usar este para acceder por browser - Crear un 3er VirtualHost para las solicitudes del front-end (DESIGNER), en donde se agregara lo siguiente (pmos.conf): <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Headers "Content-Type,Depth,User-Agent,X-File-Size,X-Requested-With,If-Modified-Since,X-File-Name,Cache-Control,Authorization" Header set Access-Control-Allow-Methods "OPTIONS,GET,POST,PUT,DELETE" </IfModule> De tal forma que quedara asi: <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Headers "Content-Type,Depth,User-Agent,X-File-Size,X-Requested-With,If-Modified-Since,X-File-Name,Cache-Control,Authorization" Header set Access-Control-Allow-Methods "OPTIONS,GET,POST,PUT,DELETE" </IfModule> <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^.*/(.*)$ app.php [QSA,L,NC] </IfModule> - Agregar lo siguiente al archivo "/path/to/processmaker/shared/sites/your-workspace/env.ini" server_hostname_requests_frontend = "{your_server_hostname_requests_frontend}" Donde: - your_server_hostname_requests_frontend, es el nombre del servidor configurado para el front-end (3er VirtualHost), ejemplo: server_hostname_requests_frontend = "192.168.40.72:3017" - Tambien se puede hacer la configuracion en el archivo "/path/to/processmaker/workflow/engine/config/env.ini", considerar que esto afectara a todos lo workspaces creados Note: Todo el desarrollo se lo hizo en un server Windows-Server-2012-R2 con Apache-2.4
2016-03-17 08:45:23 -04:00
$this->setVar('HTTP_SERVER_HOSTNAME', System::getHttpServerHostnameRequestsFrontEnd());
if ($debug) {
if (! file_exists(PATH_HTML . "lib-dev/pmUI/build.cache")) {
throw new RuntimeException("Development JS Files were are not generated!.\nPlease execute: \$>rake pmBuildDebug in pmUI project");
}
if (! file_exists(PATH_HTML . "lib-dev/mafe/build.cache")) {
throw new RuntimeException("Development JS Files were are not generated!.\nPlease execute: \$>rake pmBuildDebug in MichelangeloFE project");
}
$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;
}
}
$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));
$this->setVar('designerCacheFile', file(PATH_HTML . "lib-dev/mafe/applications.cache", FILE_IGNORE_NEW_LINES));
$this->setVar('mafeJsFiles', $mafeJsFiles);
$this->setVar('mafeCssFiles', $mafeCssFiles);
} else {
$buildhashFile = PATH_HTML . "lib/buildhash";
if (! file_exists($buildhashFile)) {
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-04-14 12:35:47 -04:00
$translationMafe = "/translations/translationsMafe.js";
$this->setVar('translationMafe', $translationMafe);
if (!file_exists(PATH_HTML . "translations" . PATH_SEP. 'translationsMafe' . ".js")) {
$translation = new Translation();
$translation->generateFileTranslationMafe();
}
2015-09-25 19:55:26 -04:00
$this->setVar('sys_skin', SYS_SKIN);
2014-04-14 12:35:47 -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();
if ($user->checkPermission($row['USER_ID'], 'PM_FACTORY') || $proReadOnly == 'true') {
$this->setView('designer/index');
} else {
2016-03-24 10:38:18 -04:00
G::header('Location: /errors/error403.php');
die();
}
}
2016-11-25 13:06:25 -05:00
//plugin set source path
$sourceCss = array();
$sourceJs = array();
$pluginRegistry = &PMPluginRegistry::getSingleton();
$srcPath = $pluginRegistry->getDesignerSourcePath();
foreach ($srcPath as $key => $value) {
$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);
$this->render();
}
protected function getClientCredentials()
{
$oauthQuery = new ProcessMaker\Services\OAuth2\PmPdo($this->getDsn());
return $oauthQuery->getClientDetails($this->clientId);
}
protected function getAuthorizationCode($client)
{
\ProcessMaker\Services\OAuth2\Server::setDatabaseSource($this->getDsn());
\ProcessMaker\Services\OAuth2\Server::setPmClientId($client['CLIENT_ID']);
$oauthServer = new \ProcessMaker\Services\OAuth2\Server();
if (isset($client["tracker_designer"]) && $client["tracker_designer"] == 1) {
$_SESSION["USER_LOGGED"] = "00000000000000000000000000000001";
}
$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);
$code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40);
if (isset($client["tracker_designer"]) && $client["tracker_designer"] == 1) {
unset($_SESSION["USER_LOGGED"]);
}
return $code;
}
private function getDsn()
{
list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, '');
$port = empty($port) ? '' : ";port=$port";
$dsn = DB_ADAPTER.':host='.$host.';dbname='.DB_NAME.$port;
return array('dsn' => $dsn, 'username' => DB_USER, 'password' => DB_PASS);
}
}