Ejemplo n.º 1
0
function doSomething()
{
    $resource = createResource();
    try {
        $result = useResource($resource);
        return $result;
    } catch (Exception $e) {
        log($e->getMessage());
        throw $e;
    } catch (Exception2 $e) {
        log($e->getMessage());
        throw $e;
    } catch (Exception3 $e) {
        log($e->getMessage());
        throw $e;
    } catch (Exception4 $e) {
        log($e->getMessage());
        throw $e;
    } catch (Exception5 $e) {
        log($e->getMessage());
        throw $e;
    } finally {
        releaseResource($resource);
    }
}
function copyResourceToTarget(&$resource, $modx, $from, $target)
{
    $babelTV = getBabelTV($modx);
    $id = $resource->get('id');
    $parent = $resource->get('parent');
    if ($parent !== 0) {
        $parent_in_target = getIdResourceInTarget($parent, $modx, $target);
    } else {
        $parent_in_target = 0;
    }
    $modx->log(modX::LOG_LEVEL_ERROR, '[[INFO]] resource: ' . $id . ', parent: ' . $parent . ', parent_in_target: ' . $parent_in_target);
    if (!empty($parent_in_target) || $parent_in_target === 0) {
        $modx->log(modX::LOG_LEVEL_ERROR, '[[COPY]] resource: ' . $id);
        $tvs = $resource->getMany('TemplateVars');
        $resource_tvs = array();
        foreach ($tvs as $tv) {
            $resource_tvs[$tv->get('name')] = $tv->getValue($id);
            //$tv->renderOutput($id);
        }
        $resource_tvs['babelLanguageLinks'] = $babelTV->getValue($id);
        $options = $resource->toArray();
        $options['parent'] = $parent_in_target;
        $options['context_key'] = $target['context_key'];
        $options['pagetitle'] = $options['pagetitle'] . $target['mark'];
        $new_id = createResource($options, $resource_tvs, $modx);
        $modx->log(modX::LOG_LEVEL_ERROR, '[[BABEL]] resource: ' . $resource_tvs['babelLanguageLinks']);
        $babelArr = babelTVtoArray($resource_tvs['babelLanguageLinks']);
        $babelArr[$from['context_key']] = $id;
        $babelArr[$target['context_key']] = $new_id;
        $babelStr = arrayToBabelTV($babelArr);
        $babelTV->setValue($id, $babelStr);
        $babelTV->setValue($new_id, $babelStr);
        $babelTV->save();
    } else {
        $modx->log(modX::LOG_LEVEL_ERROR, '[[COPY PARENT]] of resource: ' . $id . '(parent: ' . $parent . ')');
        if ($parent !== 0) {
            copyResourceToTarget($modx->getObject('modResource', $parent), $modx, $from, $target);
        }
        copyResourceToTarget(&$resource, $modx, $from, $target);
    }
}
             if ($resource['set_as_home'] == 1) {
                 unset($resource['set_as_home']);
                 $resource['id'] = $siteStart;
                 $resId = updateResource($resource);
                 if ($resId !== false) {
                     $resourceMap[$resource['pagetitle']] = $resId;
                 }
             } else {
                 $resId = createResource($resource);
                 if ($resId !== false) {
                     $resourceMap[$resource['pagetitle']] = $resId;
                 }
             }
         }
     } else {
         $resId = createResource($resource);
         if ($resId !== false) {
             $resourceMap[$resource['pagetitle']] = $resId;
         }
     }
 }
 foreach ($toRemove as $pageTitle => $resource) {
     unset($resourceMap[$pageTitle]);
     if ($resource == $siteStart) {
         continue;
     }
     /** @var modResource $modResource */
     $modResource = $modx->getObject('modResource', $resource);
     if ($modResource) {
         $modx->updateCollection('modResource', array('parent' => 0), array('parent' => $resource));
         $modResource->remove();
for each user it would take a couple of thousand guesses to get a match if you
tried to brute force create every possible activationKey for the time around
when the attackers account was created.
*/
$activationCode = md5(microtime() . $username);
// create the actual account
$encryptedPassword = createPassword($username, $password);
if (!createAccount($username, $encryptedPassword, $fullname, $domain, $email, $activationCode)) {
    // oops ... got an error creating the account
    $error = $error . "Error while creating account.";
    header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/createaccount.php?username={$username}&fullname={$fullname}&email={$email}&email2={$email2}&error=" . urlencode($error));
    exit;
}
// create a default resource
$defaultAOR = $username . '@' . $domain;
if (!createResource($username, $defaultAOR, 'N', '', '')) {
    // oops ... got an error creating the default resource
    $error = $error . "Error while creating account (default resource).";
    header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/createaccount.php?username={$username}&fullname={$fullname}&email={$email}&email2={$email2}&error=" . urlencode($error));
    exit;
}
// email the activation notice
// create activation link
$link = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/activateaccount.php?user={$username}&code={$activationCode}";
// subject
$subject = "{$provider} Activation Notice";
// message
$message = '
<html>
<head>
  <title>' . $provider . ' Activation Notice</title>
Ejemplo n.º 5
0
$aor = $_POST['aor'];
// check that if forwarding is Yes, then a forward address must be provided
// in this case we need to check forwardType against "Yes" rather than "Y since
// the value comes from the previous form rather than that database (which only
// stores 1 char)
if ($_POST['forwardType'] == "Yes" && empty($_POST['forward'])) {
    header($bounceURL . "If forwarding is turned on, a forwarding address must be provided.");
    exit;
}
$forwardType = $_POST['forwardType'];
$forward = $_POST['forward'];
$voicemail = $_POST['voicemail'];
// TODO: add code to validate that the forwarding address and voicemail
// address are valid SIP URI's
// save the resource to the database
if (createResource($username, $aor, $forwardType, $forward, $voicemail)) {
    // new resource added successfully
    $title = "New Resource Added";
    $heading = "New Resource Added";
    $msg = "Successfully added the new resource <em>{$aor}.</em>";
} else {
    $title = "Error While Adding Resource";
    $heading = "Error While Adding Resource";
    $msg = "An error occurred while attempting to add this resource.  Please contact an administrator.";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!--
System:  Repro
File:    savenewresource.php