[795] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /**************************************************************************\ |
---|
| 4 | * eGroupWare * |
---|
| 5 | * http://www.egroupware.org * |
---|
| 6 | * -------------------------------------------- * |
---|
| 7 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 8 | * under the terms of the GNU General Public License as published by the * |
---|
| 9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 10 | * option) any later version. * |
---|
| 11 | \**************************************************************************/ |
---|
| 12 | |
---|
| 13 | require_once 'common.inc.php'; |
---|
| 14 | require_once 'engine/config.egw.inc.php'; |
---|
| 15 | |
---|
| 16 | /** |
---|
| 17 | * @package Workflow |
---|
| 18 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 19 | * @author Sidnei Augusto Drovetto Jr. - drovetto@gmail.com |
---|
| 20 | */ |
---|
| 21 | class external_bridge |
---|
| 22 | { |
---|
| 23 | /** |
---|
| 24 | * @var string $siteAddress the address of the site |
---|
| 25 | * @access public |
---|
| 26 | */ |
---|
| 27 | var $siteAddress; |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | * @var object $acl access rights object |
---|
| 31 | * @access public |
---|
| 32 | */ |
---|
| 33 | var $acl; |
---|
| 34 | /** |
---|
| 35 | * @var object $db |
---|
| 36 | * @access public |
---|
| 37 | */ |
---|
| 38 | var $db; |
---|
| 39 | /** |
---|
| 40 | * @var array $public_functions |
---|
| 41 | * @access public |
---|
| 42 | */ |
---|
| 43 | var $public_functions = array( |
---|
| 44 | 'render' => True |
---|
| 45 | ); |
---|
| 46 | /** |
---|
| 47 | * External bridge |
---|
| 48 | * @access public |
---|
| 49 | * @return void |
---|
| 50 | */ |
---|
| 51 | function external_bridge() |
---|
| 52 | { |
---|
[3167] | 53 | $this->db = Factory::getInstance('WorkflowObjects')->getDBGalaxia(); |
---|
| 54 | $this->acl = &Factory::getInstance('so_adminaccess', Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID); |
---|
[795] | 55 | } |
---|
| 56 | /** |
---|
| 57 | * load Data |
---|
| 58 | * @access public |
---|
| 59 | * @return void |
---|
| 60 | */ |
---|
| 61 | function loadData($site) |
---|
| 62 | { |
---|
| 63 | /* define the dynamic values that can be used in the login process */ |
---|
| 64 | $tmpUser = ""; |
---|
| 65 | $tmpOrg = ""; |
---|
| 66 | |
---|
| 67 | $tmpUser = $GLOBALS['phpgw_info']['user']['account_lid']; |
---|
| 68 | $tmpOrg = explode(",ou=", $GLOBALS['phpgw_info']['user']['account_dn']); |
---|
| 69 | $tmpOrg = explode(",", $tmpOrg[1]); |
---|
| 70 | $tmpOrg = $tmpOrg[0]; |
---|
| 71 | |
---|
| 72 | $replace = array( |
---|
| 73 | '%user%' => $tmpUser, |
---|
| 74 | '%organization%' => $tmpOrg, |
---|
| 75 | '%password%' => $GLOBALS['phpgw_info']['user']['passwd']); |
---|
| 76 | |
---|
| 77 | /* select the required form values for submission */ |
---|
| 78 | $result = $this->db->query("SELECT address, post FROM egw_wf_external_application WHERE (external_application_id = {$site})"); |
---|
| 79 | $row = $result->fetchRow(DB_FETCHMODE_ASSOC); |
---|
| 80 | if (!$row) |
---|
| 81 | die(""); |
---|
| 82 | |
---|
| 83 | $dataTmp = str_replace("\r", "", $row['post']); |
---|
| 84 | $dataTmp = explode("\n", $dataTmp); |
---|
| 85 | |
---|
| 86 | $this->siteAddress = $row['address']; |
---|
| 87 | |
---|
| 88 | $data = array(); |
---|
| 89 | foreach ($dataTmp as $aux) |
---|
| 90 | { |
---|
| 91 | list($varName,$value) = explode("=", $aux, 2); |
---|
| 92 | $data["$varName"] = $value; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | /* replace the tags with the actual values */ |
---|
| 96 | foreach ($data as $key => $value) |
---|
| 97 | foreach ($replace as $before => $after) |
---|
| 98 | $data[$key] = str_replace($before, $after, $data[$key]); |
---|
| 99 | |
---|
| 100 | /* load the data */ |
---|
| 101 | $output = array(); |
---|
| 102 | foreach ($data as $key => $value) |
---|
| 103 | $output[] = array( |
---|
| 104 | "name" => $key, |
---|
| 105 | "value" => $value); |
---|
| 106 | |
---|
| 107 | return $output; |
---|
| 108 | } |
---|
| 109 | /** |
---|
| 110 | * External bridge |
---|
| 111 | * @access public |
---|
| 112 | * @return void |
---|
| 113 | */ |
---|
| 114 | function render() |
---|
| 115 | { |
---|
| 116 | if (($GLOBALS['phpgw_info']['server']['use_https'] > 0) && ($_SERVER['HTTPS'] != 'on')) |
---|
| 117 | { |
---|
| 118 | header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
---|
| 119 | exit; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | /* validate the var and avoid SQL injection */ |
---|
| 123 | $site = $_REQUEST['site']; |
---|
| 124 | |
---|
| 125 | $redirect = false; |
---|
| 126 | if (!is_numeric($site)) |
---|
| 127 | $redirect = true; |
---|
| 128 | else |
---|
| 129 | { |
---|
| 130 | /* check if the user has the permission to access the requested site */ |
---|
| 131 | $site = (int) $site; |
---|
| 132 | if (!$this->acl->checkUserGroupAccessToResource('APX', $GLOBALS['phpgw_info']['user']['account_id'], $site)) |
---|
| 133 | $redirect = true; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | /* in case of any error, send the user to the frontpage */ |
---|
| 137 | if ($redirect) |
---|
| 138 | { |
---|
| 139 | header("Location: index.php"); |
---|
| 140 | exit; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | /* generates the form */ |
---|
| 144 | $generatedForm = ''; |
---|
| 145 | $loginData = $this->loadData($site); |
---|
| 146 | foreach ($loginData as $formData) |
---|
| 147 | $generatedForm .= "<input type=\"hidden\" name=\"" . $formData['name'] . "\" id=\"" . $formData['name'] . "\" value=\"" . $formData['value'] . "\">"; |
---|
| 148 | $generatedForm = 'document.write(\'' . $generatedForm . '\');'; |
---|
| 149 | |
---|
| 150 | /* encode the form before submission */ |
---|
| 151 | $encodedForm = ''; |
---|
| 152 | for ($i = 0; $i < strlen($generatedForm); $i++) |
---|
| 153 | $encodedForm .= '%' . bin2hex($generatedForm[$i]); |
---|
| 154 | $encodedForm = '<script type="text/javascript">eval(unescape(\'' . $encodedForm . '\'))</script>'; |
---|
| 155 | |
---|
| 156 | /* assign variables to the template */ |
---|
[3167] | 157 | $smarty = Factory::getInstance('workflow_smarty', false); |
---|
[795] | 158 | $smarty->assign('encodedForm', $encodedForm); |
---|
| 159 | $smarty->assign('siteAddress', $this->siteAddress); |
---|
| 160 | $smarty->display('external_bridge.tpl'); |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | ?> |
---|