Example #1
0
$uri = $_SERVER["REQUEST_URI"];
// on ôte le prefix même que rewritebase.
$uri = substr($uri, strlen($base));
// on nettoie l'url.
if (false !== ($pos = strpos($uri, '?'))) {
    $uri = substr($uri, 0, $pos);
}
$uri = rawurldecode($uri);
// exécution du routage.
$routeInfo = $dispatcher->dispatch($httpMethod, $uri);
switch ($routeInfo[0]) {
    case Dispatcher::NOT_FOUND:
        $body = not_found();
        break;
    case Dispatcher::METHOD_NOT_ALLOWED:
        $body = not_allowed($routeInfo[1]);
        break;
    case Dispatcher::FOUND:
        $handler = $routeInfo[1];
        $args = $routeInfo[2];
        try {
            $body = call_user_func_array($handler, $args);
        } catch (Exception $e) {
            $body = server_error($e);
        }
        break;
}
header("Content-Type: text/html; charset=utf-8");
header("Content-Length: " . strlen($body));
echo $body;
// les pages
Example #2
0
/**
 * @throws EasySCP_Exception_Database
 * @param int $edit_id
 * @return bool
 */
function check_fwd_data($edit_id)
{
    $sql = EasySCP_Registry::get('Db');
    $add_mode = $edit_id === true;
    // unset errors
    $ed_error = '_off_';
    $err = '';
    $_text = '';
    $_type = $_POST['type'];
    $dmn_props = get_domain_default_props($_SESSION['user_id']);
    if ($add_mode) {
        $query = "\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM (\n\t\t\t\tSELECT\n\t\t\t\t\t'0' AS `alias_id`,\n\t\t\t\t\t`domain`.`domain_name` AS `domain_name`\n\t\t\t\tFROM\n\t\t\t\t\t`domain`\n\t\t\t\tWHERE\n\t\t\t\t\t`domain_id` = ?\n\t\t\t\tUNION\n\t\t\t\tSELECT\n\t\t\t\t\t`domain_aliasses`.`alias_id`,\n\t\t\t\t\t`domain_aliasses`.`alias_name`\n\t\t\t\tFROM\n\t\t\t\t\t`domain_aliasses`\n\t\t\t\tWHERE\n\t\t\t\t\t`domain_aliasses`.`domain_id` = ?\n\t\t\t) AS `tbl`\n\t\t\tWHERE\n\t\t\t\tIFNULL(`tbl`.`alias_id`, 0) = ?\n\t\t";
        $res = exec_query($sql, $query, array($dmn_props['domain_id'], $dmn_props['domain_id'], $_POST['alias_id']));
        if ($res->recordCount() <= 0) {
            not_allowed();
        }
        $data = $res->fetchRow();
        $record_domain = $data['domain_name'];
        // if no alias is selected, ID is 0 else the real alias_id
        $alias_id = $data['alias_id'];
        $_dns = $data['domain_name'];
    } else {
        $sql_query = "\n\t\t\t\tSELECT\n\t\t\t\t\td.id,\n\t\t\t\t\td.easyscp_domain_id,\n\t\t\t\t\td.easyscp_domain_alias_id,\n\t\t\t\t\td.name\n\t\t\t\tFROM\n\t\t\t\t\tpowerdns.domains d,\n\t\t\t\t\tpowerdns.records r\n\t\t\t\tWHERE\n\t\t\t\t\tr.id = :record_id\n\t\t\t\tAND\n\t\t\t\t\tr.domain_id = d.id;\n\t\t";
        $sql_param = array('record_id' => $edit_id);
        DB::prepare($sql_query);
        $stmt = DB::execute($sql_param);
        if ($stmt->rowCount() <= 0) {
            not_allowed();
        }
        $data = $stmt->fetch();
        $record_domain = $data['name'];
        $alias_id = $data['easyscp_domain_alias_id'];
        $_dns = $data['name'];
        $domain_id = $data['id'];
    }
    if (!validate_NAME(array('name' => $_POST['dns_name'], 'domain' => $record_domain), $err)) {
        $ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
    }
    $_ttl = null;
    $_dns_srv_prio = null;
    switch ($_POST['type']) {
        case 'CNAME':
            if (!validate_CNAME($_POST, $err)) {
                $ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
            }
            $_text = $_POST['dns_cname'];
            $_dns = $_POST['dns_name'];
            break;
        case 'A':
            if (!validate_A($_POST, $err)) {
                $ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
            }
            if (!check_CNAME_conflict($_POST['dns_name'] . '.' . $record_domain, $err)) {
                $ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
            }
            $_text = $_POST['dns_A_address'];
            $_dns = $_POST['dns_name'];
            $_ttl = '7200';
            break;
        case 'AAAA':
            if (!validate_AAAA($_POST, $err)) {
                $ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
            }
            if (!check_CNAME_conflict($_POST['dns_name'] . '.' . $record_domain, $err)) {
                $ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
            }
            $_text = $_POST['dns_AAAA_address'];
            $_dns = $_POST['dns_name'];
            break;
        case 'SRV':
            if (!validate_SRV($_POST, $err, $_dns, $_text)) {
                $ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
            }
            break;
        case 'MX':
            if (!validate_MX($_POST, $err, $_dns_srv_prio, $_text)) {
                $ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
            } else {
                // $_dns = $record_domain . '.';
                $_dns = $record_domain;
            }
            break;
        case 'NS':
            if (!validate_NS($_POST, $err)) {
                $ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
            }
            $_text = $_POST['dns_ns'];
            $_ttl = '28800';
            break;
        case 'SOA':
            $_ttl = '3600';
            break;
        default:
            $ed_error = sprintf(tr('Unknown zone type %s!'), $_POST['type']);
    }
    if ($ed_error === '_off_') {
        if ($add_mode) {
            if ($alias_id > 0) {
                $sql_param = array('alias_id' => $alias_id);
                $sql_query = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tid\n\t\t\t\t\tFROM\n\t\t\t\t\t\tpowerdns.domains\n\t\t\t\t\tWHERE\n\t\t\t\t\t\teasyscp_domain_alias_id = :alias_id\n\t\t\t\t";
                DB::prepare($sql_query);
                $data = DB::execute($sql_param, true);
            } else {
                $sql_param = array('domain_id' => $dmn_props['domain_id']);
                $sql_query = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tid\n\t\t\t\t\tFROM\n\t\t\t\t\t\tpowerdns.domains\n\t\t\t\t\tWHERE\n\t\t\t\t\t\teasyscp_domain_id = :domain_id\n\t\t\t\t";
                DB::prepare($sql_query);
                $data = DB::execute($sql_param, true);
            }
            $sql_param = array('domain_id' => $data['id'], 'name' => $_dns, 'type' => $_type, 'content' => $_text, 'ttl' => $_ttl, 'prio' => $_dns_srv_prio);
            $sql_query = "\n\t\t\t\tINSERT INTO\n\t\t\t\t\tpowerdns.records (domain_id, name, type, content, ttl, prio)\n\t\t\t\tVALUES\n\t\t\t\t\t(:domain_id, :name, :type, :content, :ttl, :prio)\n\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\t\tdomain_id = :domain_id, name = :name, type = :type, content = :content, ttl = :ttl, prio = :prio;\n\t\t\t";
            DB::prepare($sql_query);
            DB::execute($sql_param);
        } else {
            $sql_param = array('domain_id' => $domain_id, 'name' => $_dns, 'type' => $_type, 'content' => $_text, 'ttl' => $_ttl, 'prio' => $_dns_srv_prio, 'record_id' => $edit_id);
            $sql_query = "\n\t\t\t\t\tUPDATE\n\t\t\t\t\t\tpowerdns.records\n\t\t\t\t\tSET\n\t\t\t\t\t\tdomain_id = :domain_id,\n\t\t\t\t\t\tname\t= :name,\n\t\t\t\t\t\ttype = :type,\n\t\t\t\t\t\tcontent = :content,\n\t\t\t\t\t\tttl = :ttl,\n\t\t\t\t\t\tprio = :prio\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tid = :record_id\n\t\t\t";
            DB::prepare($sql_query);
            DB::execute($sql_param);
        }
        $admin_login = $_SESSION['user_logged'];
        write_log("{$admin_login}: " . ($add_mode ? 'add new' : ' modify') . " dns zone record.");
        unset($_SESSION['edit_ID']);
        return true;
    } else {
        set_page_message($ed_error, 'error');
        return false;
    }
}
Example #3
0
function playerList($event)
{
    global $drop_icon;
    $entries = $event->getEntries();
    $numentries = count($entries);
    echo "<form action=\"event.php\" method=\"post\">";
    echo "<input type=\"hidden\" name=\"name\" value=\"" . htmlentities($event->name) . "\" />";
    echo "<table id=\"event_player_list\">";
    echo "<tr><th colspan=\"6\" align=\"center\" id=\"player_count\">";
    echo "{$numentries} Registered Players";
    if ($event->active) {
        $active = $event->getActivePlayers();
        $numactive = count($active);
        echo " - {$numactive} still playing";
    }
    echo "</th></tr><tr><td>&nbsp;</td><tr>";
    echo "<input type=\"hidden\" name=\"view\" value=\"reg\">";
    if ($numentries > 0) {
        echo "<tr>";
        echo "<th>";
        if ($event->active == 1) {
            echo "Drop";
        }
        echo "</th>";
        echo "<th style=\"text-align: left\" colspan=\"2\">Player</th><th>Medal</th>";
        echo "<th style=\"text-align: center\">Deck</th><th>Delete</th></tr>";
    } else {
        echo "<tr><td align=\"center\" colspan=\"5\"><i>";
        echo "No players are currently registered for this event.</i></td></tr>";
    }
    foreach ($entries as $entry) {
        echo "<tr class=\"entry_row\" id=\"entry_row_{$entry->player->name}\">";
        // Show drop box if event is active.
        echo "<td align=\"center\">";
        if ($event->active == 1) {
            if ($entry->dropped()) {
                echo "{$drop_icon} {$entry->drop_round} <a href=\"event.php?player=" . urlencode($entry->player->name) . "&action=undrop&name=" . urlencode($event->name) . "\">(undo)</a>";
            } else {
                echo "<input type=\"checkbox\" name=\"dropplayer[]\" value=\"{$entry->player->name}\" />";
            }
        }
        echo "</td><td>";
        echo "{$entry->player->name}";
        echo "</td><td>";
        if ($entry->player->verified) {
            echo image_tag("verified.png", array("alt" => "Verified", "title" => "Player Verified on MTGO"));
        }
        echo "</td>";
        if (strcmp("", $entry->medal) != 0) {
            $img = medalImgStr($entry->medal);
        }
        echo "<td align=\"center\">{$img}</td>";
        if ($entry->deck) {
            $decklink = $entry->deck->linkTo();
        } else {
            $decklink = $entry->createDeckLink();
        }
        $rstar = "<font color=\"#FF0000\">*</font>";
        if ($entry->deck != NULL) {
            if ($entry->deck->cardcount < 60) {
                $decklink .= $rstar;
            }
            if ($entry->deck->cardcount < 6) {
                $decklink .= $rstar;
            }
        }
        echo "<td>{$decklink}</td>";
        echo "<td align=\"center\">";
        if ($entry->canDelete()) {
            echo "<input type=\"checkbox\" name=\"delentries[]\" value=\"{$entry->player->name}\" />";
        } else {
            not_allowed("Can't delete player, they have matches recorded.");
        }
        echo "</td></tr>";
    }
    echo "<tr id=\"row_new_entry\"><td>Add:</td><td>";
    stringField("newentry", "", 20);
    echo "</td><td>&nbsp;</td><td colspan=\"2\">";
    echo "<input id=\"update_reg\" type=\"submit\" name=\"mode\" value=\"Update Registration\" />";
    echo "</td></tr>";
    if ($event->active == 1) {
        echo "<tr><td colspan=\"6\">";
        echo "<p class=\"squeeze\">Players added after the event has started:</p>";
        echo "<ul>";
        echo "<li>receive 0 points for any rounds already started</li>";
        echo "<li>will be paired with the next round begins</li>";
        echo "</ul>";
        echo "</td></tr>";
    }
    echo "</table>";
    echo "</form>";
    echo "<div id=\"event_run_actions\">";
    echo "<form action=\"event.php\" method=\"post\">";
    echo "<input type=\"hidden\" name=\"view\" value=\"reg\" />";
    echo "<input type=\"hidden\" name=\"name\" value=\"" . htmlentities($event->name) . "\" />";
    echo "<p>Round Actions</p>";
    if ($event->active == 0 && $event->finalized == 0) {
        echo "<input id=\"start_event\" type=\"submit\" name=\"mode\" value=\"Start Event\" />";
    } else {
        if ($event->active == 1) {
            echo "<input id=\"start_event\" type=\"submit\" name=\"mode\" value=\"Recalculate Standings\" />";
            echo "<input id=\"start_event\" type=\"submit\" name=\"mode\" value=\"Reset Event\" />";
            echo "<input id=\"start_event\" type=\"submit\" name=\"mode\" value=\"Delete Matches and Re-Pair Round\" />";
        } else {
            echo "<input id=\"start_event\" type=\"submit\" name=\"mode\" value=\"Reactivate Event\" />";
            echo "<input id=\"start_event\" type=\"submit\" name=\"mode\" value=\"Recalculate Standings\" />";
            echo "<input id=\"start_event\" type=\"submit\" name=\"mode\" value=\"Assign Medals\" />";
        }
    }
    echo "</form>";
    echo "</div>";
}