function validate_submission_token($token)
{
    if ($token != $_SESSION[CONST_SUBMISSION_TOKEN_KEY]) {
        message_error('Submission token has expired, please resubmit form');
    }
    regenerate_submission_token();
}
Beispiel #2
0
function validate_xsrf_token($token)
{
    if ($_SESSION[CONST_XSRF_TOKEN_KEY] != $token) {
        log_exception(new Exception('Invalid XSRF token. Was: "' . $token . '". Wanted: "' . $_SESSION[CONST_XSRF_TOKEN_KEY] . '"'));
        message_error('XSRF token mismatch');
        exit;
    }
}
function validate_captcha()
{
    $captcha = new Captcha\Captcha();
    $captcha->setPublicKey(CONFIG_RECAPTCHA_PUBLIC_KEY);
    $captcha->setPrivateKey(CONFIG_RECAPTCHA_PRIVATE_KEY);
    $response = $captcha->check();
    if (!$response->isValid()) {
        message_error("The reCAPTCHA wasn't entered correctly. Go back and try it again.");
    }
}
Beispiel #4
0
function delete_file($id)
{
    if (!is_valid_id($id)) {
        message_error('Invalid ID.');
    }
    db_delete('files', array('id' => $id));
    if (file_exists(CONST_PATH_FILE_UPLOAD . $id)) {
        unlink(CONST_PATH_FILE_UPLOAD . $id);
    }
}
function validate_two_factor_auth_code($code)
{
    require_once CONFIG_PATH_THIRDPARTY . 'Google2FA/Google2FA.php';
    $valid = false;
    $secret = db_select_one('two_factor_auth', array('secret'), array('user_id' => $_SESSION['id']));
    try {
        $valid = Google2FA::verify_key($secret['secret'], $code);
    } catch (Exception $e) {
        message_error('Could not verify key.');
    }
    return $valid;
}
Beispiel #6
0
function validate_captcha()
{
    try {
        $captcha = new \ReCaptcha\ReCaptcha(CONFIG_RECAPTCHA_PRIVATE_KEY, new \ReCaptcha\RequestMethod\CurlPost());
        $response = $captcha->verify($_POST['g-recaptcha-response'], get_ip());
        if (!$response->isSuccess()) {
            message_error("Captcha error: " . print_r($response->getErrorCodes(), true));
        }
    } catch (Exception $e) {
        log_exception($e);
        message_error('Caught exception processing captcha. Please contact ' . (CONFIG_EMAIL_REPLYTO_EMAIL ? CONFIG_EMAIL_REPLYTO_EMAIL : CONFIG_EMAIL_FROM_EMAIL));
    }
}
function download_file($file)
{
    validate_id(array_get($file, 'id'));
    // do we read the file off AWS S3?
    if (CONFIG_AWS_S3_KEY_ID && CONFIG_AWS_S3_SECRET && CONFIG_AWS_S3_BUCKET) {
        try {
            // Instantiate the S3 client with your AWS credentials
            $client = S3Client::factory(array('key' => CONFIG_AWS_S3_KEY_ID, 'secret' => CONFIG_AWS_S3_SECRET));
            $file_key = '/challenges/' . $file['id'];
            $client->registerStreamWrapper();
            // Send a HEAD request to the object to get headers
            $command = $client->getCommand('HeadObject', array('Bucket' => CONFIG_AWS_S3_BUCKET, 'Key' => $file_key));
            $filePath = 's3://' . CONFIG_AWS_S3_BUCKET . $file_key;
        } catch (Exception $e) {
            message_error('Caught exception uploading file to S3: ' . $e->getMessage());
        }
    } else {
        $filePath = CONFIG_PATH_FILE_UPLOAD . $file['id'];
        if (!is_readable($filePath)) {
            log_exception(new Exception("Could not read the requested file: " . $filePath));
            message_error("Could not read the requested file. An error report has been lodged.");
        }
    }
    // required for IE, otherwise Content-disposition is ignored
    if (ini_get('zlib.output_compression')) {
        ini_set('zlib.output_compression', 'Off');
    }
    header('Pragma: public');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Cache-Control: private', false);
    // required for certain browsers
    header('Content-Type: application/force-download');
    header('Content-Disposition: attachment; filename="' . $file['title'] . '";');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . $file['size']);
    // Stop output buffering
    if (ob_get_level()) {
        ob_end_flush();
    }
    flush();
    readfile($filePath);
}
Beispiel #8
0
<?php

require '../../../include/ctf.inc.php';
enforce_authentication(CONST_USER_CLASS_MODERATOR);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    validate_id($_POST['id']);
    validate_xsrf_token($_POST[CONST_XSRF_TOKEN_KEY]);
    if ($_POST['action'] == 'edit') {
        db_update('categories', array('title' => $_POST['title'], 'description' => $_POST['description'], 'exposed' => $_POST['exposed'], 'available_from' => strtotime($_POST['available_from']), 'available_until' => strtotime($_POST['available_until'])), array('id' => $_POST['id']));
        redirect(CONFIG_SITE_ADMIN_RELPATH . 'edit_category.php?id=' . $_POST['id'] . '&generic_success=1');
    } else {
        if ($_POST['action'] == 'delete') {
            if (!$_POST['delete_confirmation']) {
                message_error('Please confirm delete');
            }
            db_delete('categories', array('id' => $_POST['id']));
            $challenges = db_select_all('challenges', array('id'), array('category' => $_POST['id']));
            foreach ($challenges as $challenge) {
                delete_challenge_cascading($challenge['id']);
            }
            redirect(CONFIG_SITE_ADMIN_RELPATH . '?generic_success=1');
        }
    }
}
Beispiel #9
0
<?php

require '../include/mellivora.inc.php';
login_session_refresh();
if (strlen(array_get($_GET, 'code')) != 2) {
    message_error('Please supply a valid country code');
}
$country = db_select_one('countries', array('id', 'country_name', 'country_code'), array('country_code' => $_GET['code']));
if (!$country) {
    message_error('No country found with that code');
}
head($country['country_name']);
if (cache_start('country_' . $_GET['code'], CONFIG_CACHE_TIME_COUNTRIES)) {
    section_head(htmlspecialchars($country['country_name']) . country_flag_link($country['country_name'], $country['country_code'], true), '', false);
    $scores = db_query_fetch_all('
            SELECT
               u.id AS user_id,
               u.team_name,
               u.competing,
               co.id AS country_id,
               co.country_name,
               co.country_code,
               SUM(c.points) AS score,
               MAX(s.added) AS tiebreaker
            FROM users AS u
            LEFT JOIN countries AS co ON co.id = u.country_id
            LEFT JOIN submissions AS s ON u.id = s.user_id AND s.correct = 1
            LEFT JOIN challenges AS c ON c.id = s.challenge
            WHERE u.competing = 1 AND co.id = :country_id
            GROUP BY u.id
            ORDER BY score DESC, tiebreaker ASC', array('country_id' => $country['id']));
                ModelSeoLink::newInstance()->insertRec(null, $new_href_to, $new_href_from, $new_contact);
                message_ok(__('Reciprocal Link was successfully created', 'all_in_one'));
            } else {
                message_error(__('Error when creating reciprocal link', 'all_in_one') . ': ' . __('Your referral URL and URL with your link cannot be empty!', 'all_in_one'));
            }
        }
    }
    if (Params::getParam('link_rec_add_update') == 'email') {
        foreach (osc_has_links_rec_seo() as $links) {
            if (Params::getParam('seo_email_send' . $links['seo_link_id']) == 'on' or Params::getParam('seo_email_send' . $links['seo_link_id']) == 1) {
                $detail = ModelSeoLink::newInstance()->getRecLinkById($links['seo_link_id']);
                if (filter_var($detail['seo_contact'], FILTER_VALIDATE_EMAIL) and $detail['seo_contact'] != '') {
                    email_link_problem($detail['seo_href_from'], $detail['seo_href_to'], $detail['seo_contact']);
                    message_ok(__('Owner of website', 'all_in_one') . ' ' . $detail['seo_href_from'] . ' ' . __('was successfully informed that backlink was not found', 'all_in_one'));
                } else {
                    message_error(__('Error when sending email to reciprocal link', 'all_in_one') . ' #' . $links['seo_link_id'] . ': ' . __('Contact email is not valid or is empty!', 'all_in_one'));
                }
            }
        }
    }
}
?>

<div id="settings_form">
  <?php 
echo config_menu();
?>

  <form name="promo_form" id="promo_form" action="<?php 
echo osc_admin_base_url(true);
?>
Beispiel #11
0
function sql_exception(PDOException $e)
{
    log_exception($e);
    message_error('An SQL exception occurred. Please check the exceptions log.');
}
Beispiel #12
0
<?php

require '../../../include/mellivora.inc.php';
enforce_authentication(CONFIG_UC_MODERATOR);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    validate_xsrf_token($_POST['xsrf_token']);
    if ($_POST['action'] == 'new') {
        $id = db_insert('hints', array('added' => time(), 'added_by' => $_SESSION['id'], 'challenge' => $_POST['challenge'], 'visible' => $_POST['visible'], 'body' => $_POST['body']));
        if ($id) {
            invalidate_cache('hints');
            redirect(CONFIG_SITE_ADMIN_RELPATH . 'edit_hint.php?id=' . $id);
        } else {
            message_error('Could not insert new hint.');
        }
    }
}
function register_account($email, $password, $team_name, $country, $type = null, $phoneNo, $age, $eduI, $eduLevel, $fullName, $instanceID)
{
    if (!CONFIG_ACCOUNTS_SIGNUP_ALLOWED) {
        message_error('Registration is currently closed.');
    }
    if (empty($email) || empty($password) || empty($team_name)) {
        message_error('Please fill in all the details correctly.');
    }
    if (isset($type) && !is_valid_id($type)) {
        message_error('That does not look like a valid team type.');
    }
    if (strlen($team_name) > CONFIG_MAX_TEAM_NAME_LENGTH || strlen($team_name) < CONFIG_MIN_TEAM_NAME_LENGTH) {
        message_error('Your team name was too long or too short.');
    }
    validate_email($email);
    if (!allowed_email($email)) {
        message_error('Email not on whitelist. Please choose a whitelisted email or contact organizers.');
    }
    $num_countries = db_select_one('countries', array('COUNT(*) AS num'));
    if (!isset($country) || !is_valid_id($country) || $country > $num_countries['num']) {
        message_error('Please select a valid country.');
    }
    $user = db_select_one('users', array('id'), array('team_name' => $team_name, 'email' => $email), null, 'OR');
    if ($user['id']) {
        message_error('An account with this team name or email already exists.');
    }
    $user_id = db_insert('users', array('email' => $email, 'passhash' => make_passhash($password), 'team_name' => $team_name, 'added' => time(), 'enabled' => CONFIG_ACCOUNTS_DEFAULT_ENABLED ? '1' : '0', 'user_type' => isset($type) ? $type : 0, 'country_id' => $country, 'DOB' => $age, 'mobileNo' => $phoneNo, 'eduInstitution' => $eduI, 'eduLevel' => $eduLevel, 'fullName' => $fullName, 'instanceID' => $instanceID));
    // insertion was successful
    if ($user_id) {
        // log signup IP
        log_user_ip($user_id);
        // if account isn't enabled by default, display message and die
        if (!CONFIG_ACCOUNTS_DEFAULT_ENABLED) {
            message_generic('Signup successful', 'Thank you for registering!
            Your chosen email is: ' . htmlspecialchars($email) . '.
            Make sure to check your spam folder as emails from us may be placed into it.
            Please stay tuned for updates!');
        } else {
            return true;
        }
    }
    // no rows were inserted
    return false;
}
Beispiel #14
0
<?php

require '../include/mellivora.inc.php';
login_session_refresh();
if (strlen(array_get($_GET, 'code')) != 2) {
    message_error(lang_get('please_supply_country_code'));
}
$country = db_select_one('countries', array('id', 'country_name', 'country_code'), array('country_code' => $_GET['code']));
if (!$country) {
    message_error(lang_get('please_supply_country_code'));
}
head($country['country_name']);
if (cache_start(CONST_CACHE_NAME_COUNTRY . $_GET['code'], CONFIG_CACHE_TIME_COUNTRIES)) {
    section_head(htmlspecialchars($country['country_name']) . country_flag_link($country['country_name'], $country['country_code'], true), '', false);
    $scores = db_query_fetch_all('
            SELECT
               u.id AS user_id,
               u.team_name,
               u.competing,
               co.id AS country_id,
               co.country_name,
               co.country_code,
               SUM(c.points) AS score,
               MAX(s.added) AS tiebreaker
            FROM users AS u
            LEFT JOIN countries AS co ON co.id = u.country_id
            LEFT JOIN submissions AS s ON u.id = s.user_id AND s.correct = 1
            LEFT JOIN challenges AS c ON c.id = s.challenge
            WHERE u.competing = 1 AND co.id = :country_id
            GROUP BY u.id
            ORDER BY score DESC, tiebreaker ASC', array('country_id' => $country['id']));
Beispiel #15
0
function validate_email($email)
{
    if (!valid_email($email)) {
        log_exception(new Exception('Invalid Email'));
        message_error('That doesn\'t look like an email. Please go back and double check the form.');
    }
}
Beispiel #16
0
<?php

require '../include/mellivora.inc.php';
enforce_authentication();
validate_id($_GET['id']);
$file = db_query_fetch_one('
    SELECT
      f.id,
      f.title,
      f.size,
      c.available_from
    FROM files AS f
    LEFT JOIN challenges AS c ON c.id = f.challenge
    WHERE f.id = :id', array('id' => $_GET['id']));
if (empty($file)) {
    message_error('No file found with this ID');
}
if (time() < $file['available_from'] && !user_is_staff()) {
    message_error('This file is not available yet.');
}
download_file($file);
<?php

require '../../../include/mellivora.inc.php';
enforce_authentication(CONFIG_UC_MODERATOR);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    validate_xsrf_token($_POST['xsrf_token']);
    if ($_POST['action'] == 'new') {
        $id = db_insert('restrict_email', array('added' => time(), 'added_by' => $_SESSION['id'], 'rule' => $_POST['rule'], 'white' => $_POST['whitelist'], 'priority' => $_POST['priority'], 'enabled' => $_POST['enabled']));
        if ($id) {
            redirect(CONFIG_SITE_ADMIN_RELPATH . 'list_restrict_email.php?generic_success=1');
        } else {
            message_error('Could not insert new email restriction.');
        }
    }
}
Beispiel #18
0
        }
    }
    // stage 1, part 2
    if ($_POST['action'] == 'reset_password') {
        if (CONFIG_RECAPTCHA_ENABLE_PUBLIC) {
            validate_captcha();
        }
        $user = db_select_one('users', array('id', 'team_name', 'email'), array('email' => $_POST[md5(CONFIG_SITE_NAME . 'EMAIL')]));
        if ($user['id']) {
            $auth_key = hash('sha256', generate_random_string(128));
            db_insert('reset_password', array('added' => time(), 'user_id' => $user['id'], 'ip' => get_ip(true), 'auth_key' => $auth_key));
            $email_subject = 'Password recovery for team ' . htmlspecialchars($user['team_name']);
            // body
            $email_body = htmlspecialchars($user['team_name']) . ', please follow the link below to reset your password:'******'reset_password?action=choose_password&auth_key=' . $auth_key . '&id=' . $user['id'] . "\r\n" . "\r\n" . 'Regards,' . "\r\n" . CONFIG_SITE_NAME;
            // send details to user
            send_email(array($user['email']), $email_subject, $email_body);
        }
        message_generic('Success', 'If the email you provided was found in the database, an email has now been sent to it with further instructions!');
    } else {
        if ($_POST['action'] == 'choose_password' && is_valid_id($auth['user_id'])) {
            $new_password = $_POST[md5(CONFIG_SITE_NAME . 'PWD')];
            if (empty($new_password)) {
                message_error('You can\'t have an empty password');
            }
            $new_passhash = make_passhash($new_password);
            db_update('users', array('passhash' => $new_passhash), array('id' => $auth['user_id']));
            db_delete('reset_password', array('user_id' => $auth['user_id']));
            message_generic('Success', 'Your password has been reset.');
        }
    }
}
Beispiel #19
0
<?php

require '../../include/ctf.inc.php';
$redirect_url = array_get($_POST, 'redirect');
if (user_is_logged_in()) {
    redirect($redirect_url);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($_POST['action'] == 'login') {
        $email = $_POST[md5(CONFIG_SITE_NAME . 'USR')];
        $password = $_POST[md5(CONFIG_SITE_NAME . 'PWD')];
        $remember_me = isset($_POST['remember_me']);
        if (login_create($email, $password, $remember_me)) {
            enforce_2fa();
            redirect($redirect_url);
        } else {
            message_error('Login failed? Helpful.');
        }
    }
}
Beispiel #20
0
function delete_challenge_cascading($id)
{
    if (!is_valid_id($id)) {
        message_error('Invalid ID.');
    }
    try {
        db_begin_transaction();
        db_delete('challenges', array('id' => $id));
        db_delete('submissions', array('challenge' => $id));
        db_delete('hints', array('challenge' => $id));
        $files = db_select_all('files', array('id'), array('challenge' => $id));
        foreach ($files as $file) {
            delete_file($file['id']);
        }
        db_end_transaction();
    } catch (PDOException $e) {
        db_rollback_transaction();
        log_exception($e);
    }
}
Beispiel #21
0
function register_account($email, $password, $team_name, $country, $type = null)
{
    if (!CONFIG_ACCOUNTS_SIGNUP_ALLOWED) {
        message_error(lang_get('registration_closed'));
    }
    if (empty($email) || empty($password) || empty($team_name)) {
        message_error(lang_get('please_fill_details_correctly'));
    }
    if (isset($type) && !is_valid_id($type)) {
        message_error(lang_get('invalid_team_type'));
    }
    if (strlen($team_name) > CONFIG_MAX_TEAM_NAME_LENGTH || strlen($team_name) < CONFIG_MIN_TEAM_NAME_LENGTH) {
        message_error('team_name_too_long_or_short');
    }
    validate_email($email);
    if (!allowed_email($email)) {
        message_error(lang_get('email_not_whitelisted'));
    }
    $num_countries = db_select_one('countries', array('COUNT(*) AS num'));
    if (!isset($country) || !is_valid_id($country) || $country > $num_countries['num']) {
        message_error(lang_get('please_supply_country_code'));
    }
    $user = db_select_one('users', array('id'), array('team_name' => $team_name, 'email' => $email), null, 'OR');
    if ($user['id']) {
        message_error(lang_get('user_already_exists'));
    }
    $user_id = db_insert('users', array('email' => $email, 'passhash' => make_passhash($password), 'team_name' => $team_name, 'added' => time(), 'enabled' => CONFIG_ACCOUNTS_DEFAULT_ENABLED ? '1' : '0', 'user_type' => isset($type) ? $type : 0, 'country_id' => $country));
    // insertion was successful
    if ($user_id) {
        // log signup IP
        log_user_ip($user_id);
        // signup email
        $email_subject = lang_get('signup_email_subject', array('site_name' => CONFIG_SITE_NAME));
        // body
        $email_body = lang_get('signup_email_success', array('team_name' => htmlspecialchars($team_name), 'site_name' => CONFIG_SITE_NAME, 'signup_email_availability' => CONFIG_ACCOUNTS_DEFAULT_ENABLED ? lang_get('signup_email_account_availability_message_login_now') : lang_get('signup_email_account_availability_message_login_later'), 'signup_email_password' => CONFIG_ACCOUNTS_EMAIL_PASSWORD_ON_SIGNUP ? lang_get('your_password_is') . ': ' . $password : lang_get('your_password_was_set')));
        // send details to user
        send_email(array($email), $email_subject, $email_body);
        // if account isn't enabled by default, display message and die
        if (!CONFIG_ACCOUNTS_DEFAULT_ENABLED) {
            message_generic(lang_get('signup_successful'), lang_get('signup_successful_text', array('email' => htmlspecialchars($email))));
        } else {
            return true;
        }
    }
    // no rows were inserted
    return false;
}
Beispiel #22
0
function saveuser($uid, $name, $uname, $email, $femail, $url, $pass, $vpass, $bio, $user_avatar, $user_icq, $user_occ, $user_from, $user_intrest, $user_sig, $user_viewemail, $user_aim, $user_yim, $user_msnm, $attach, $usend_email, $uis_visible, $user_lnl, $C1, $C2, $C3, $C4, $C5, $C6, $C7, $C8, $M1, $M2, $T1, $T2, $B1, $MAX_FILE_SIZE, $raz_avatar)
{
    global $NPDS_Prefix;
    global $user, $userinfo, $system, $minpass;
    $cookie = cookiedecode($user);
    $check = $cookie[1];
    $result = sql_query("SELECT uid, email FROM " . $NPDS_Prefix . "users WHERE uname='{$check}'");
    list($vuid, $vemail) = sql_fetch_row($result);
    if ($check == $uname and $uid == $vuid) {
        if (isset($pass) && "{$pass}" != "{$vpass}") {
            message_error("<i class=\"fa fa-exclamation\"></i>&nbsp;" . translate("Both passwords are different. They need to be identical.") . "<br /><br />", "");
        } elseif ($pass != "" && strlen($pass) < $minpass) {
            message_error("<i class=\"fa fa-exclamation\"></i>&nbsp;" . translate("Sorry, your password must be at least") . " <strong>{$minpass}</strong> " . translate("characters long") . "<br /><br />", "");
        } else {
            $stop = userCheck("edituser", $email);
            if (!$stop) {
                if ($bio) {
                    $bio = FixQuotes(strip_tags($bio));
                }
                if ($attach) {
                    $t = 1;
                } else {
                    $t = 0;
                }
                if ($user_viewemail) {
                    $a = 1;
                } else {
                    $a = 0;
                }
                if ($usend_email) {
                    $u = 1;
                } else {
                    $u = 0;
                }
                if ($uis_visible) {
                    $v = 0;
                } else {
                    $v = 1;
                }
                if ($user_lnl) {
                    $w = 1;
                } else {
                    $w = 0;
                }
                if ($url != "") {
                    if (!substr_count($url, "http://")) {
                        $url = "http://" . $url;
                    }
                    if (trim($url) == "http://") {
                        $url = "";
                    }
                }
                include_once "modules/upload/upload.conf.php";
                global $avatar_size;
                if (!$avatar_size) {
                    $avatar_size = "80*100";
                }
                $avatar_limit = explode("*", $avatar_size);
                if ($DOCUMENTROOT != "") {
                    $rep = $DOCUMENTROOT;
                } else {
                    global $DOCUMENT_ROOT;
                    if ($DOCUMENT_ROOT) {
                        $rep = $DOCUMENT_ROOT;
                    } else {
                        $rep = $_SERVER['DOCUMENT_ROOT'];
                    }
                }
                if ($B1 != "none") {
                    global $language;
                    include_once "modules/upload/lang/upload.lang-{$language}.php";
                    include_once "modules/upload/clsUpload.php";
                    $upload = new Upload();
                    $upload->maxupload_size = $MAX_FILE_SIZE;
                    $field1_filename = trim($upload->getFileName("B1"));
                    $suffix = strtoLower(substr(strrchr($field1_filename, '.'), 1));
                    if ($suffix == "gif" or $suffix == "jpg" or $suffix == "png") {
                        $field1_filename = removeHack(preg_replace('#[/\\\\:\\*\\?"<>|]#i', '', rawurldecode($field1_filename)));
                        $field1_filename = preg_replace('#\\.{2}|config.php|/etc#i', '', $field1_filename);
                        if ($field1_filename) {
                            if ($autorise_upload_p) {
                                $user_dir = $racine . "/users_private/" . $uname . "/";
                                if (!is_dir($rep . $user_dir)) {
                                    @umask("0000");
                                    if (@mkdir($rep . $user_dir, 0777)) {
                                        $fp = fopen($rep . $user_dir . "index.html", 'w');
                                        fclose($fp);
                                    } else {
                                        $user_dir = $racine . "/users_private/";
                                    }
                                }
                            } else {
                                $user_dir = $racine . "/users_private/";
                            }
                            if ($upload->saveAs($uname . "." . $suffix, $rep . $user_dir, "B1", true)) {
                                $old_user_avatar = $user_avatar;
                                $user_avatar = $user_dir . $uname . "." . $suffix;
                                $img_size = @getimagesize($rep . $user_avatar);
                                if ($img_size[0] > $avatar_limit[0] or $img_size[1] > $avatar_limit[1]) {
                                    $raz_avatar = true;
                                }
                                if ($racine == "") {
                                    $user_avatar = substr($user_avatar, 1);
                                }
                            }
                        }
                    }
                }
                if ($raz_avatar) {
                    if (strstr($user_avatar, "/users_private")) {
                        @unlink($rep . $user_avatar);
                        @unlink($rep . $old_user_avatar);
                    }
                    $user_avatar = "blank.gif";
                }
                if ($pass != '') {
                    cookiedecode($user);
                    if (!$system) {
                        $pass = crypt($pass, $pass);
                    }
                    sql_query("UPDATE " . $NPDS_Prefix . "users SET name='{$name}', email='{$email}', femail='" . removeHack($femail) . "', url='" . removeHack($url) . "', pass='******', bio='" . removeHack($bio) . "', user_avatar='{$user_avatar}', user_icq='" . removeHack($user_icq) . "', user_occ='" . removeHack($user_occ) . "', user_from='" . removeHack($user_from) . "', user_intrest='" . removeHack($user_intrest) . "', user_sig='" . removeHack($user_sig) . "', user_aim='" . removeHack($user_aim) . "', user_yim='" . removeHack($user_yim) . "', user_msnm='" . removeHack($user_msnm) . "', user_viewemail='{$a}', send_email='{$u}', is_visible='{$v}', user_lnl='{$w}' WHERE uid='{$uid}'");
                    $result = sql_query("SELECT uid, uname, pass, storynum, umode, uorder, thold, noscore, ublockon, theme FROM " . $NPDS_Prefix . "users WHERE uname='{$uname}' AND pass='******'");
                    if (sql_num_rows($result) == 1) {
                        $userinfo = sql_fetch_assoc($result);
                        docookie($userinfo['uid'], $userinfo['uname'], $userinfo['pass'], $userinfo['storynum'], $userinfo['umode'], $userinfo['uorder'], $userinfo['thold'], $userinfo['noscore'], $userinfo['ublockon'], $userinfo['theme'], $userinfo['commentmax'], "");
                    }
                } else {
                    sql_query("UPDATE " . $NPDS_Prefix . "users SET name='{$name}', email='{$email}', femail='" . removeHack($femail) . "', url='" . removeHack($url) . "', bio='" . removeHack($bio) . "', user_avatar='{$user_avatar}', user_icq='" . removeHack($user_icq) . "', user_occ='" . removeHack($user_occ) . "', user_from='" . removeHack($user_from) . "', user_intrest='" . removeHack($user_intrest) . "', user_sig='" . removeHack($user_sig) . "', user_aim='" . removeHack($user_aim) . "', user_yim='" . removeHack($user_yim) . "', user_msnm='" . removeHack($user_msnm) . "', user_viewemail='{$a}', send_email='{$u}', is_visible='{$v}', user_lnl='{$w}' WHERE uid='{$uid}'");
                }
                sql_query("UPDATE " . $NPDS_Prefix . "users_status SET attachsig='{$t}' WHERE uid='{$uid}'");
                $result = sql_query("SELECT uid FROM " . $NPDS_Prefix . "users_extend WHERE uid='{$uid}'");
                if (sql_num_rows($result) == 1) {
                    sql_query("UPDATE " . $NPDS_Prefix . "users_extend SET C1='" . removeHack($C1) . "', C2='" . removeHack($C2) . "', C3='" . removeHack($C3) . "', C4='" . removeHack($C4) . "', C5='" . removeHack($C5) . "', C6='" . removeHack($C6) . "', C7='" . removeHack($C7) . "', C8='" . removeHack($C8) . "', M1='" . removeHack($M1) . "', M2='" . removeHack($M2) . "', T1='" . removeHack($T1) . "', T2='" . removeHack($T2) . "', B1='{$B1}' WHERE uid='{$uid}'");
                } else {
                    $result = sql_query("INSERT INTO " . $NPDS_Prefix . "users_extend VALUES ('{$uid}','" . removeHack($C1) . "', '" . removeHack($C2) . "', '" . removeHack($C3) . "', '" . removeHack($C4) . "', '" . removeHack($C5) . "', '" . removeHack($C6) . "', '" . removeHack($C7) . "', '" . removeHack($C8) . "', '" . removeHack($M1) . "', '" . removeHack($M2) . "', '" . removeHack($T1) . "', '" . removeHack($T2) . "', '{$B1}')");
                }
                if ($pass != "") {
                    logout();
                } else {
                    header("location: user.php?op=edituser");
                }
            } else {
                message_error($stop, "");
            }
        }
    } else {
        Header("Location: index.php");
    }
}
Beispiel #23
0
 if (CONFIG_RECAPTCHA_ENABLE_PRIVATE) {
     validate_captcha();
 }
 if ($_POST['action'] == 'submit_flag') {
     validate_id($_POST['challenge']);
     if (empty($_POST['flag'])) {
         message_error('Did you really mean to submit an empty flag?');
     }
     $submissions = db_select_all('submissions', array('correct', 'added'), array('user_id' => $_SESSION['id'], 'challenge' => $_POST['challenge']));
     // make sure user isn't "accidentally" submitting a correct flag twice
     $latest_submission_attempt = 0;
     $num_attempts = 0;
     foreach ($submissions as $submission) {
         $latest_submission_attempt = max($submission['added'], $latest_submission_attempt);
         if ($submission['correct']) {
             message_error('You may only submit a correct flag once.');
         }
         $num_attempts++;
     }
     // get challenge information
     $challenge = db_select_one('challenges', array('flag', 'category', 'case_insensitive', 'automark', 'available_from', 'available_until', 'num_attempts_allowed', 'min_seconds_between_submissions'), array('id' => $_POST['challenge']));
     $seconds_since_submission = $time - $latest_submission_attempt;
     if ($seconds_since_submission < $challenge['min_seconds_between_submissions']) {
         message_generic('Sorry', 'You may not submit another solution for this challenge for another ' . seconds_to_pretty_time($challenge['min_seconds_between_submissions'] - $seconds_since_submission));
     }
     if ($challenge['num_attempts_allowed'] && $num_attempts >= $challenge['num_attempts_allowed']) {
         message_generic('Sorry', 'You\'ve already tried ' . $challenge['num_attempts_allowed'] . ' times. Sorry!');
     }
     if ($challenge['available_from'] && $time < $challenge['available_from']) {
         message_generic('Sorry', 'This challenge hasn\'t started yet.');
     }
Beispiel #24
0
<?php

require '../include/mellivora.inc.php';
$user = db_select_one('users', array('id', 'enabled'), array('download_key' => $_GET['team_key']));
if (!is_valid_id($user['id'])) {
    log_exception(new Exception('Invalid team key used for download'));
    message_error(lang_get('invalid_team_key'));
}
if (!$user['enabled']) {
    message_error(lang_get('user_not_enabled'));
}
$file = db_query_fetch_one('
    SELECT
      f.id,
      f.title,
      f.size,
      f.md5,
      c.available_from
    FROM files AS f
    LEFT JOIN challenges AS c ON c.id = f.challenge
    WHERE f.download_key = :download_key', array('download_key' => $_GET['file_key']));
if (!is_valid_id($file['id'])) {
    log_exception(new Exception('Invalid file key used for download'));
    message_error(lang_get('no_file_found'));
}
if (time() < $file['available_from'] && !user_is_staff()) {
    message_error(lang_get('file_not_available'));
}
download_file($file);
Beispiel #25
0
<?php

require '../../../include/mellivora.inc.php';
enforce_authentication(CONST_USER_CLASS_MODERATOR);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    validate_xsrf_token($_POST[CONST_XSRF_TOKEN_KEY]);
    if ($_POST['action'] == 'new') {
        $id = db_insert('categories', array('added' => time(), 'added_by' => $_SESSION['id'], 'title' => $_POST['title'], 'description' => $_POST['description'], 'available_from' => strtotime($_POST['available_from']), 'available_until' => strtotime($_POST['available_until'])));
        if ($id) {
            redirect(CONFIG_SITE_ADMIN_RELPATH . 'edit_category.php?id=' . $id);
        } else {
            message_error('Could not insert new category.');
        }
    }
}
Beispiel #26
0
function message_generic_error($head = true, $foot = true, $exit = true)
{
    message_error(lang_get('generic_error'), $head, $foot, $exit);
}
Beispiel #27
0
                            $_SESSION['info'] = message_info("User " . $login . " updated successfully.");
                            header("Location: ../showcase/php/php_showcase_db_diagnostics.php");
                        } else {
                            $_SESSION['error'] = message_error(pg_last_error($db_connection));
                            header("Location: ../showcase/php/php_showcase_data_manipulation.php");
                        }
                    } else {
                        header("Location: ../showcase/php/php_showcase_data_manipulation.php");
                    }
                } else {
                    $_SESSION['error'] = message_warning("User with login {$login} already exists.");
                    header("Location: ../showcase/php/php_showcase_data_manipulation.php");
                }
            }
        } else {
            $_SESSION['error'] = message_error("Error while checking for existing user: "******"Location: ../showcase/php/php_showcase_data_manipulation.php");
        }
    }
}
function create_error_string($login, $password, $email, $gender)
{
    $login_pattern = "^\\s+\$";
    $password_pattern = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{4,15}\$";
    //^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$
    // Based on a regex by Michael Rushton
    //$email_pattern = '/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD';
    $errors_occurred = false;
    $error_string = "Errors: <ul>";
    if (strlen(trim($login)) == 0 || preg_match($login_pattern, $login)) {
        $error_string .= "<li>login cannot be empty nor contain spaces</li>";
Beispiel #28
0
<?php

require '../../include/mellivora.inc.php';
enforce_authentication(CONST_USER_CLASS_MODERATOR);
head('IP log');
menu_management();
$where = array();
if (is_valid_ip(array_get($_GET, 'ip'))) {
    section_head('Teams using IP ' . $_GET['ip']);
    $where['ip'] = ip2long($_GET['ip']);
} else {
    if (is_valid_id(array_get($_GET, 'user_id'))) {
        section_head('IP log for user');
        $where['user_id'] = $_GET['user_id'];
    } else {
        message_error('Must supply either IP or user ID');
    }
}
echo '
    <table id="files" class="table table-striped table-hover">
      <thead>
        <tr>
          <th>Team name</th>
          <th>Hostname</th>
          <th>First used</th>
          <th>Last used</th>
          <th>Times used</th>
        </tr>
      </thead>
      <tbody>
    ';
Beispiel #29
0
        if ($_GET['status'] == 'incorrect') {
            message_dialog('Sorry! That wasn\'t correct', 'Incorrect flag', 'Ok', 'challenge-attempt incorrect on-page-load');
        } else {
            if ($_GET['status'] == 'manual') {
                message_inline_blue('<h1>Your submission is awaiting manual marking.</h1>', false);
            }
        }
    }
}
$categories = db_select_all('categories', array('id', 'title', 'description', 'available_from', 'available_until'), array('exposed' => 1), 'title ASC');
// determine which category to display
if (isset($_GET['category'])) {
    validate_id($_GET['category']);
    $current_category = array_search_matching_key($_GET['category'], $categories, 'id');
    if (!$current_category) {
        message_error(lang_get('no_category_for_id'), false);
    }
} else {
    // if no category is selected, display
    // the first available category
    foreach ($categories as $cat) {
        if ($time > $cat['available_from'] && $time < $cat['available_until']) {
            $current_category = $cat;
            break;
        }
    }
    // if no category has been made available
    // we'll just set it to the first one
    // alphabetically and display an error
    // message
    if (!isset($current_category)) {
        if ($_GET['status'] == 'incorrect') {
            message_inline_red('<h1>Incorrect flag, try again.</h1>', false);
        } else {
            if ($_GET['status'] == 'manual') {
                message_inline_blue('<h1>Your submission is awaiting manual marking.</h1>', false);
            }
        }
    }
}
$categories = db_select_all('categories', array('id', 'title', 'description', 'available_from', 'available_until', 'instanceID'), array('instanceID' => $_SESSION["IID"]), 'title ASC');
if (isset($_GET['category'])) {
    validate_id($_GET['category']);
    // select our chosen category
    $current_category = db_select_one('categories', array('id', 'title', 'description', 'available_from', 'available_until'), array('id' => $_GET['category']));
    if (!$current_category) {
        message_error('No category found with that ID', false);
    }
} else {
    // if no category is selected, display
    // the first available category
    foreach ($categories as $cat) {
        if ($time > $cat['available_from'] && $time < $cat['available_until']) {
            $current_category = $cat;
            break;
        }
    }
    // if no category has been made available
    // we'll just set it to the first one
    // alphabetically and display an error
    // message
    if (!isset($current_category)) {