We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5430
    • 247 Posts
    Trying to create resources via a remote script file (on the same server). Keep getting "permission_denied" as my reply when attempting to use the resource/create processor. I'm quite sure I have no idea how to provide the proper permissions from a remote file so this is a plea for help. I have the following in place at the top of my file:

    require_once '/path/to/www/config.core.php';
    require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
    require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
    $modx = new modX();
    $modx->initialize('mgr');
    $modx->initialize('web');
    
    $login = $modx->runProcessor('security/login', array(
        'username' => 'myusername', /*$username*/
        'password' => 'mypassword' /*$password */
    ));
    


    The user I'm using for security/login has full permissions in all contexts. What more do I need to do here to be able to run resource/create and resource/update with full permissions?

    This question has been answered by claytonk. See the first response.

      • 4172
      • 5,888 Posts
      call processors thrue connectors, like done here:

      https://github.com/Jako/ImagePlus/blob/master/assets/components/imageplus/connector.php#L31

      or simpler, use a snippet, which you place on a resource with an 'empty'-template and use that resource as your connector.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 5430
        • 247 Posts
        I don't think I'm grasping this. There is no active manager session, and no ajax request for the connector to process (sorry if that wasn't clear). This file is being sent POST data from a third party publishing service. I can submit that POST data to a snippet running in a resource, but this doesn't get me the permissions to run the processor I need. I'm not understanding how using a connector will grant me the permissions I need, am I missing something?

        I can do all this without the processor by creating a new modResource object, but I'd like to know how to do this with using runProcessor.
          • 5430
          • 247 Posts
          define('MODX_API_MODE', true);
          require dirname(dirname(__FILE__)).'/index.php';
          


          Seems like that was what I was missing. Got it working. Thanks.
            • 5430
            • 247 Posts
            ...or not. Sigh.

            So I can access this PHP file via a browser, without being logged in to the manager, and it works just fine (resource is created, all is good). When I try to POST to the same file from my 3rd party service I get a "permission_denied" message and a message indicating the session failed ("There was an error retrieving or creating session id: f52ua7bh465n2qll4hg441e8o6").

            What am I missing here? Please pardon the ignorance, this is the first time I've attempted running something like this outside of MODX.

            I may just go ahead and do this via newObject, but it seems like I'm probably very close and just missing something obvious.

            Here's what I have for my connection:

            define('MODX_API_MODE', true);
            require dirname(dirname(__FILE__)).'/index.php';
            $modx->getService('error','error.modError');
            $modx->setLogLevel(modX::LOG_LEVEL_INFO);
             
            $login = $modx->runProcessor('security/login', array('username' => 'claytonk', 'password' => '316.creative'));
            if ($login->isError()) {
                $modx->log(modX::LOG_LEVEL_ERROR, $response->getMessage());
                return;
            }
            
            $modx->initialize('mgr');
            
              • 4172
              • 5,888 Posts
              you can just create a login-page with the login-snippet-call
              Then login at a first step and do your stuff in a second step.

              This is working fine for me, to download protected stuff (static resources in this case):
              https://github.com/Bruno17/migxBackupRestore/blob/master/core/components/migxbackuprestore/elements/snippets/mbrclientinstallerwidget.snippet.php#L63

              no need for any controllers. They are just MODX-resources in this case.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
              • discuss.answer
                • 5430
                • 247 Posts
                Thanks Bruno, but I think I'm going to be better off simply building the resource as a newObject. It works, and most of the stuff I wanted from runProcessor (like auto menuindex assignment, etc.) I can do programmatically. Thanks for the input.