Ejemplo n.º 1
0
 public static function commitToggleEntMode($entityManager, $fullUrl)
 {
     // Obtain Lock File
     $mutex = fopen("/var/www/html/lock/.lock", "w");
     if (!$mutex) {
         return array('mutex' => 'lock file failure');
     }
     // Try To Obtain Permission
     $trial = 0;
     while (!flock($mutex, LOCK_EX)) {
         echo "\r\nRetrying\r\n";
         sleep(1);
         $trial++;
         if ($trial >= 50) {
             // Clean-Up
             fclose($mutex);
             return array('mutex' => 'unable to get control permission');
         }
     }
     //global $sequence;
     //$sequence ++;
     //echo "\r\n<<<<<<<<<< commitRemove " . $sequence . " === ";
     // Succeed To Get Control
     try {
         $result = SitesXMLManager::_commitToggleEntMode($entityManager, $fullUrl);
     } catch (Exception $e) {
         echo $e->getMessage() . "\r\n\r\n";
         echo $e->getTraceAsString();
     }
     $entityManager->flush();
     // Clean-Up Anyway
     flock($mutex, LOCK_UN);
     fclose($mutex);
     //echo "commitToggleEntMode " . $sequence . " >>>>>>>>>>>\r\n";
     return $result;
 }
Ejemplo n.º 2
0
    $url = $app->request->params('url');
    $business = $_SESSION['user_business'];
    if ($url == NULL) {
        die(json_encode(array('error' => 'insufficient parameters')));
    }
    if ($business == NULL) {
        die(json_encode(array('error' => 'invalid session')));
    }
    // match with current business
    // Permission Check!
    // Parse for domain & res
    $parts = explode('/', $url, 2);
    $domain = trim($parts[0]);
    $res = isset($parts[1]) && strlen(trim($parts[1])) > 0 ? trim('/' . $parts[1]) : NULL;
    $obj = NULL;
    if ($res == NULL) {
        // domain only
        $obj = $entityManager->getRepository('WhitelistEntry')->findOneBy(array('domain' => $domain, 'business' => $business));
    } else {
        // domain + res
        $obj = $entityManager->getRepository('WhitelistEntryRes')->findOneBy(array('domain' => $domain, 'res' => $res, 'business' => $business));
    }
    // If No Record (with suitable business) Retrieved & Not a Browser Team Account --> FAIL
    if ($business != "Browser Team" && $obj == NULL) {
        die(json_encode(array('error' => 'not authorized to delete entries of another business')));
    }
    // Commit Remove
    $result = SitesXMLManager::commitRemove($entityManager, $url);
    echo json_encode($result);
});
$app->run();