Пример #1
0
</div>

</body>

<script type="text/javascript" src="<?php 
echo getPathToStaticResource('/script/wz_tooltip.js');
?>
"></script>

<?php 
if (isset($_REQUEST["footerScripts"])) {
    foreach ($_REQUEST["footerScripts"] as $script) {
        print $script . "\n";
    }
}
?>

</html>

<?php 
$peak = memory_get_peak_usage();
workbenchLog(LOG_INFO, "MemoryUsageCheck", array("measure.memory.peak" => $peak . "byte"));
if (WorkbenchContext::isEstablished() && $peak / toBytes(ini_get("memory_limit")) > 0.7) {
    WorkbenchContext::get()->clearCache();
    workbenchLog(LOG_INFO, "MemoryUsageCacheClear", array("measure.memory.cache_clear" => 1));
}
if (isset($GLOBALS['REDIS'])) {
    redis()->close();
}
//USAGE: debug($showSuperVars = true, $showSoap = true, $customName = null, $customValue = null)
debug(true, true, null, null);
Пример #2
0
 private function processLogin($username, $password, $serverUrl, $sessionId, $actionJump)
 {
     if ($username && $password && $sessionId) {
         $this->addError('Provide only username and password OR session id, but not all three.');
         return;
     }
     //block connections to localhost
     if (stripos($serverUrl, 'localhost')) {
         if (isset($GLOBALS['internal']['localhostLoginError'])) {
             $this->addError($GLOBALS['internal']['localhostLoginError']);
         } else {
             $this->addError("Must not connect to 'localhost'");
         }
         return;
     }
     if (WorkbenchContext::isEstablished()) {
         // cache clearing shouldn't be needed since we're releasing on the next line,
         // but doing it just in case someone puts a cache key outside the WbCtx scope
         WorkbenchContext::get()->clearCache();
         WorkbenchContext::get()->release();
     }
     // TODO: clean up this hackiness due to in-progress context refactoring...
     $savedOauthConfig = isset($_SESSION['oauth']) ? $_SESSION['oauth'] : null;
     session_unset();
     session_destroy();
     session_start();
     session_regenerate_id();
     $_SESSION['oauth'] = $savedOauthConfig;
     $overriddenClientId = isset($_REQUEST["clientId"]) ? $_REQUEST["clientId"] : null;
     if ($username && $password && !$sessionId) {
         if ($this->oauthRequired) {
             throw new WorkbenchHandledException("OAuth login is required");
         }
         $orgId = isset($_REQUEST["orgId"]) ? $_REQUEST["orgId"] : WorkbenchConfig::get()->value("loginScopeHeader_organizationId");
         $portalId = isset($_REQUEST["portalId"]) ? $_REQUEST["portalId"] : WorkbenchConfig::get()->value("loginScopeHeader_portalId");
         WorkbenchContext::establish(ConnectionConfiguration::fromUrl($serverUrl, null, $overriddenClientId));
         try {
             WorkbenchContext::get()->login($username, $password, $orgId, $portalId);
         } catch (Exception $e) {
             WorkbenchContext::get()->release();
             $this->addError($e->getMessage());
             return;
         }
     } else {
         if ($sessionId && $serverUrl && !($username && $password)) {
             $serverUrlHost = parse_url($serverUrl, PHP_URL_HOST);
             $loginHosts = array("login.salesforce.com", "test.salesforce.com", "prerellogin.pre.salesforce.com");
             if (in_array($serverUrlHost, $loginHosts)) {
                 $this->addError('Must not connect to login server (www, login, test, or prerellogin) if providing a session id. ' . 'Choose your specific Salesforce instance on the QuickSelect menu when using a session id; ' . 'otherwise, provide a username and password and choose the appropriate a login server.');
                 return;
             }
             WorkbenchContext::establish(ConnectionConfiguration::fromUrl($serverUrl, $sessionId, $overriddenClientId));
             WorkbenchContext::get()->setIsUiSessionLikelySet(true);
         } else {
             $this->addError('Invalid login parameters.');
             return;
         }
     }
     // todo: put in WbCtx?
     if (stripos(WorkbenchContext::get()->getHost(), 'localhost')) {
         if (isset($GLOBALS['internal']['localhostLoginRedirectError'])) {
             $this->addError($GLOBALS['internal']['localhostLoginRedirectError']);
         } else {
             $this->addError("Must not connect to 'localhost'");
         }
         return;
     }
     if (isset($_POST['termsAccepted'])) {
         WorkbenchContext::get()->agreeToTerms();
     }
     // test the connection and prime the UserInfo cache
     // exceptions will be caught by top-level handler
     $userInfo = WorkbenchContext::get()->getUserInfo();
     // do org id whitelist/blacklisting
     $orgId15 = substr($userInfo->organizationId, 0, 15);
     $orgIdWhiteList = array_map('trim', explode(",", WorkbenchConfig::get()->value("orgIdWhiteList")));
     $orgIdBlackList = array_map('trim', explode(",", WorkbenchConfig::get()->value("orgIdBlackList")));
     $isAllowed = true;
     foreach ($orgIdWhiteList as $allowedOrgId) {
         if ($allowedOrgId === "") {
             continue;
         } else {
             if ($orgId15 === substr($allowedOrgId, 0, 15)) {
                 $isAllowed = true;
                 break;
             } else {
                 // there is something on the whitelist that's not us
                 // disallow and keep looking until we find our org id
                 $isAllowed = false;
             }
         }
     }
     foreach ($orgIdBlackList as $disallowedOrgId) {
         if ($orgId15 === substr($disallowedOrgId, 0, 15)) {
             $isAllowed = false;
             break;
         }
     }
     if (!$isAllowed) {
         throw new WorkbenchAuthenticationException("Requests for organization {$orgId15} are not allowed");
     }
     if (isset($_REQUEST['autoLogin'])) {
         $actionJump .= (strpos($actionJump, "?") > -1 ? "&" : "?") . "autoLogin=1";
         if (isset($_REQUEST['skipVC'])) {
             $actionJump .= "&skipVC=1";
         }
         if (isset($_GET['clientId'])) {
             $_SESSION['tempClientId'] = $_GET['clientId'];
         }
     }
     header("Location: {$actionJump}");
 }
Пример #3
0
    httpError("403.4 SSL Required", "Secure connection to Workbench and Salesforce required");
    //TODO: what do we want to do here?
}
//kick user back to login page for any page that requires a session and one isn't established
$myPage = getMyPage();
if (!isLoggedIn() && $myPage->requiresSfdcSession) {
    session_unset();
    session_destroy();
    header('Location: login.php');
    exit;
}
if (!$myPage->isReadOnly && isReadOnlyMode()) {
    throw new WorkbenchHandledException("This page is not accessible in read-only mode");
}
if (WorkbenchContext::isEstablished() && !$myPage->isReadOnly && $_SERVER['REQUEST_METHOD'] == 'POST') {
    validateCsrfToken();
}
if (WorkbenchContext::isEstablished() && isset($_POST['termsAccepted'])) {
    WorkbenchContext::get()->agreeToTerms();
}
if (isLoggedIn()) {
    // todo: should this be in the ctx?
    if (!in_array(basename($_SERVER['PHP_SELF'], ".php"), array("login", "logout")) && isset($_SESSION['lastRequestTime'])) {
        $idleTime = microtime(true) - $_SESSION['lastRequestTime'];
        if ($idleTime > WorkbenchConfig::get()->value("sessionIdleMinutes") * 60) {
            // ping SFDC to check if session is still alive
            WorkbenchContext::get()->getPartnerConnection()->getServerTimestamp();
        }
    }
    $_SESSION['lastRequestTime'] = microtime(true);
}
Пример #4
0
function debug($showSuperVars = true, $showSoap = true, $customName = null, $customValue = null)
{
    if (WorkbenchConfig::get()->value("debug") == true) {
        print "<script>\n            function toggleDebugSection(title, sectionId) {\n                var section = document.getElementById(sectionId);\n                if (section.style.display == 'inline') {\n                    section.style.display = 'none';\n                    title.childNodes[0].nodeValue = title.childNodes[0].nodeValue.replace('-','+');\n                } else {\n                    title.childNodes[0].nodeValue = title.childNodes[0].nodeValue.replace('+','-');\n                    section.style.display = 'inline';\n                }\n            }\n            </script>";
        print "<div style='text-align: left;'><h1>Debug Mode</h1>";
        if ($customValue) {
            if ($customName) {
                print "<h2>{$customName}</h2>\n";
            } else {
                print "<h2>CUSTOM</h2>\n";
            }
            var_dump($customValue);
            print "<hr/>";
        }
        if ($showSuperVars) {
            print "<h2 onclick=\"toggleDebugSection(this,'container_globals')\" class=\"debugHeader\">+ SUPERGLOBAL VARIABLES</h2>\n";
            print "<div id='container_globals' class='debugContainer'>";
            print "<strong onclick=\"toggleDebugSection(this,'container_globals_cookie')\" class=\"debugHeader\">+ SERVER SUPERGLOBAL VARIABLE</strong>\n";
            print "<div id='container_globals_cookie' class='debugContainer'>";
            print htmlspecialchars(var_export($_SERVER, true), ENT_QUOTES);
            print "<hr/>";
            print "</div>";
            print "<strong onclick=\"toggleDebugSection(this,'container_globals_cookie')\" class=\"debugHeader\">+ COOKIE SUPERGLOBAL VARIABLE</strong>\n";
            print "<div id='container_globals_cookie' class='debugContainer'>";
            print htmlspecialchars(var_export($_COOKIE, true), ENT_QUOTES);
            print "<hr/>";
            print "</div>";
            print "<strong onclick=\"toggleDebugSection(this,'container_globals_session')\" class=\"debugHeader\">+ SESSION SUPERGLOBAL VARIABLE</strong>\n";
            print "<div id='container_globals_session' class='debugContainer'>";
            print htmlspecialchars(var_export($_SESSION, true), ENT_QUOTES);
            print "<hr/>";
            print "</div>";
            print "<strong onclick=\"toggleDebugSection(this,'container_globals_post')\" class=\"debugHeader\">+ POST SUPERGLOBAL VARIABLE</strong>\n";
            print "<div id='container_globals_post' class='debugContainer'>";
            print htmlspecialchars(var_export($_POST, true), ENT_QUOTES);
            print "<hr/>";
            print "</div>";
            print "<strong onclick=\"toggleDebugSection(this,'container_globals_get')\" class=\"debugHeader\">+ GET SUPERGLOBAL VARIABLE</strong>\n";
            print "<div id='container_globals_get' class='debugContainer'>";
            print htmlspecialchars(var_export($_GET, true), ENT_QUOTES);
            print "<hr/>";
            print "</div>";
            print "<strong onclick=\"toggleDebugSection(this,'container_globals_files')\" class=\"debugHeader\">+ FILES SUPERGLOBAL VARIABLE</strong>\n";
            print "<div id='container_globals_files' class='debugContainer'>";
            print htmlspecialchars(var_export($_FILES, true), ENT_QUOTES);
            print "<hr/>";
            print "</div>";
            print "<strong onclick=\"toggleDebugSection(this,'container_globals_env')\" class=\"debugHeader\">+ ENVIRONMENT SUPERGLOBAL VARIABLE</strong>\n";
            print "<div id='container_globals_env' class='debugContainer'>";
            print htmlspecialchars(var_export($_ENV, true), ENT_QUOTES);
            print "<hr/>";
            print "</div>";
            print "</div>";
        }
        // todo: contextify
        if ($showSoap && WorkbenchContext::isEstablished() && WorkbenchContext::get()->getPartnerConnection()->getLastRequestHeaders()) {
            try {
                print "<h2 onclick=\"toggleDebugSection(this,'partner_soap_container')\" class=\"debugHeader\">+ PARTNER SOAP MESSAGES</h2>\n";
                print "<div id='partner_soap_container'  class='debugContainer'>";
                print "<strong>LAST REQUEST HEADER</strong>\n";
                print htmlspecialchars(WorkbenchContext::get()->getPartnerConnection()->getLastRequestHeaders(), ENT_QUOTES);
                print "<hr/>";
                print "<strong>LAST REQUEST</strong>\n";
                print htmlspecialchars(prettyPrintXml(WorkbenchContext::get()->getPartnerConnection()->getLastRequest()), ENT_QUOTES);
                print "<hr/>";
                print "<strong>LAST RESPONSE HEADER</strong>\n";
                print htmlspecialchars(WorkbenchContext::get()->getPartnerConnection()->getLastResponseHeaders(), ENT_QUOTES);
                print "<hr/>";
                print "<strong>LAST RESPONSE</strong>\n";
                print htmlspecialchars(prettyPrintXml(WorkbenchContext::get()->getPartnerConnection()->getLastResponse()), ENT_QUOTES);
                print "<hr/>";
                print "</div>";
            } catch (Exception $e) {
                print "<strong>SOAP Error</strong>\n";
                print_r($e);
            }
        }
        if ($showSoap && WorkbenchContext::isEstablished() && WorkbenchContext::get()->getMetadataConnection()->getLastRequestHeaders()) {
            try {
                print "<h2 onclick=\"toggleDebugSection(this,'metadata_soap_container')\" class=\"debugHeader\">+ METADATA SOAP MESSAGES</h2>\n";
                print "<div id='metadata_soap_container' class='debugContainer'>";
                print "<strong>LAST REQUEST HEADER</strong>\n";
                print htmlspecialchars(WorkbenchContext::get()->getMetadataConnection()->getLastRequestHeaders(), ENT_QUOTES);
                print "<hr/>";
                print "<strong>LAST REQUEST</strong>\n";
                print htmlspecialchars(prettyPrintXml(WorkbenchContext::get()->getMetadataConnection()->getLastRequest()), ENT_QUOTES);
                print "<hr/>";
                print "<strong>LAST RESPONSE HEADER</strong>\n";
                print htmlspecialchars(WorkbenchContext::get()->getMetadataConnection()->getLastResponseHeaders(), ENT_QUOTES);
                print "<hr/>";
                print "<strong>LAST RESPONSE</strong>\n";
                print htmlspecialchars(prettyPrintXml(WorkbenchContext::get()->getMetadataConnection()->getLastResponse()), ENT_QUOTES);
                print "<hr/>";
                print "</div>";
            } catch (Exception $e) {
                print "<strong>SOAP Error</strong>\n";
                print_r($e);
            }
        }
        if ($showSoap && WorkbenchContext::isEstablished() && WorkbenchContext::get()->getApexConnection()->getLastRequestHeaders()) {
            try {
                print "<h2 onclick=\"toggleDebugSection(this,'apex_soap_container')\" class=\"debugHeader\">+ APEX SOAP MESSAGES</h2>\n";
                print "<div id='apex_soap_container' class='debugContainer'>";
                print "<strong>LAST REQUEST HEADER</strong>\n";
                print htmlspecialchars(WorkbenchContext::get()->getApexConnection()->getLastRequestHeaders(), ENT_QUOTES);
                print "<hr/>";
                print "<strong>LAST REQUEST</strong>\n";
                print htmlspecialchars(prettyPrintXml(WorkbenchContext::get()->getApexConnection()->getLastRequest()), ENT_QUOTES);
                print "<hr/>";
                print "<strong>LAST RESPONSE HEADER</strong>\n";
                print htmlspecialchars(WorkbenchContext::get()->getApexConnection()->getLastResponseHeaders(), ENT_QUOTES);
                print "<hr/>";
                print "<strong>LAST RESPONSE</strong>\n";
                print htmlspecialchars(prettyPrintXml(WorkbenchContext::get()->getApexConnection()->getLastResponse()), ENT_QUOTES);
                print "<hr/>";
                print "</div>";
            } catch (Exception $e) {
                print "<strong>SOAP Error</strong>\n";
                htmlspecialchars(print_r($e));
            }
        }
        // TODO: move into WbCtx
        if (isset($_SESSION['restDebugLog']) && $_SESSION['restDebugLog'] != "") {
            print "<h2 onclick=\"toggleDebugSection(this,'rest_debug_container')\" class=\"debugHeader\">+ REST/BULK API LOGS</h2>\n";
            print "<div id='rest_debug_container' class='debugContainer'>";
            print "<pre>" . $_SESSION['restDebugLog'] . "</pre>";
            print "<hr/>";
            print "</div>";
            $_SESSION['restDebugLog'] = null;
        }
        print "</div>";
    }
}
Пример #5
0
<?php

require_once "context/WorkbenchContext.php";
require_once "util/PhpReverseProxy.php";
require_once "session.php";
if (!WorkbenchContext::isEstablished()) {
    httpError("401 Unauthorized", "CometD Proxy only available if Workbench Context has been established.");
    exit;
}
// dereference session-based vars so we can close the session before entering the proxy
// this will allow concurrent long requests on the same session to work better
$host = WorkbenchContext::get()->getHost();
$apiVersion = WorkbenchContext::get()->getApiVersion();
$forceSSL = WorkbenchContext::get()->isSecure();
$sessionId = WorkbenchContext::get()->getSessionId();
session_write_close();
$proxy = new PhpReverseProxy();
$proxy->headers[] = "Authorization: OAuth {$sessionId}";
$proxy->host = $host;
$proxy->forceSSL = $forceSSL;
$proxy->forward_path = "/cometd/{$apiVersion}";
$proxy->cookie_whitelist = array("sfdc-stream", "BAYEUX_BROWSER");
$proxy->proxy_settings = getProxySettings();
$proxy->is_forward_path_static = true;
$proxy->connect();
$proxy->output();
Пример #6
0
}
print "Workbench " . ($GLOBALS["WORKBENCH_VERSION"] != "trunk" ? $GLOBALS["WORKBENCH_VERSION"] : "") . "<br/>\n";
?>
</div>

</body>

<script type="text/javascript" src="<?php 
echo getPathToStaticResource('/script/wz_tooltip.js');
?>
"></script>

<?php 
if (isset($_REQUEST["footerScripts"])) {
    foreach ($_REQUEST["footerScripts"] as $script) {
        print $script . "\n";
    }
}
?>

</html>

<?php 
if (WorkbenchContext::isEstablished() && memory_get_peak_usage() / toBytes(ini_get("memory_limit")) > 0.7) {
    WorkbenchContext::get()->clearCache();
}
if (isset($GLOBALS['REDIS'])) {
    redis()->close();
}
//USAGE: debug($showSuperVars = true, $showSoap = true, $customName = null, $customValue = null)
debug(true, true, null, null);