function confirmnewsletterunsubscribe($lang, $arglist)
{
    head('title', translate('newsletter:title', $lang));
    head('description', false);
    head('keywords', false);
    head('robots', 'noindex, nofollow');
    $banner = build('banner', $lang);
    list($timestamp, $mail) = $arglist;
    $bad_mail = false;
    $bad_time = false;
    if (!newsletter_get_user($mail)) {
        $bad_mail = true;
    }
    if (time() - $timestamp > 3600) {
        $bad_time = true;
    }
    $subscribe_page = $unsubscribe_page = false;
    $internal_error = false;
    $contact_page = false;
    if ($bad_mail or $bad_time) {
        $unsubscribe_page = url('newsletterunsubscribe', $lang);
    } else {
        $r = newsletter_delete_user($mail);
        if (!$r) {
            $internal_error = true;
        } else {
            require_once 'serveripaddress.php';
            require_once 'emailme.php';
            global $sitename;
            $ip = server_ip_address();
            $timestamp = strftime('%Y-%m-%d %H:%M:%S', time());
            $subject = 'unsubscribe' . '@' . $sitename;
            $msg = $ip . ' ' . $timestamp . ' ' . $lang . ' ' . $mail;
            @emailme($subject, $msg);
            $subscribe_page = url('newslettersubscribe', $lang);
        }
    }
    if ($internal_error) {
        $contact_page = url('contact', $lang);
    }
    $errors = compact('bad_mail', 'bad_time', 'internal_error', 'contact_page');
    $content = view('confirmnewsletterunsubscribe', $lang, compact('mail', 'subscribe_page', 'unsubscribe_page', 'errors'));
    $output = layout('standard', compact('banner', 'content'));
    return $output;
}
Exemplo n.º 2
0
function login($lang)
{
    $with_name = true;
    $with_captcha = true;
    $with_facebook = false;
    $with_newuser = true;
    $with_newpassword = true;
    if ($with_facebook) {
        require_once 'facebook.php';
        $facebook = facebook();
    }
    $login = $password = $code = $token = false;
    if (isset($_SESSION['login'])) {
        $login = $_SESSION['login'];
    }
    $action = 'init';
    if (isset($_POST['login_enter'])) {
        $action = 'enter';
    }
    switch ($action) {
        case 'init':
            if ($with_facebook) {
                $facebook_user = $facebook->getUser();
                if ($facebook_user) {
                    try {
                        $facebook_user_profile = $facebook->api('/me', 'GET');
                        if (!empty($facebook_user_profile['email'])) {
                            $login = $facebook_user_profile['email'];
                        }
                        $action = 'facebook';
                    } catch (FacebookApiException $e) {
                    }
                    $facebook->destroySession();
                }
            }
            break;
        case 'enter':
            if (isset($_POST['login_login'])) {
                $login = strtolower(strflat(readarg($_POST['login_login'])));
            }
            if (isset($_POST['login_password'])) {
                $password = readarg($_POST['login_password']);
            }
            if (isset($_POST['login_code'])) {
                $code = readarg($_POST['login_code']);
            }
            if (isset($_POST['login_token'])) {
                $token = readarg($_POST['login_token']);
            }
            break;
        default:
            break;
    }
    $missing_code = false;
    $bad_code = false;
    $bad_token = false;
    $missing_login = false;
    $bad_login = false;
    $missing_password = false;
    $access_denied = false;
    switch ($action) {
        case 'enter':
            if (!isset($_SESSION['login_token']) or $token != $_SESSION['login_token']) {
                $bad_token = true;
                break;
            }
            if ($with_captcha) {
                if (!$code) {
                    $missing_code = true;
                    break;
                }
                $captcha = isset($_SESSION['captcha']['login']) ? $_SESSION['captcha']['login'] : false;
                if (!$captcha or $captcha != strtoupper($code)) {
                    $bad_code = true;
                    break;
                }
            }
            if (!$password) {
                $missing_password = true;
            }
            /* fall thru */
        /* fall thru */
        case 'facebook':
            if (!$login) {
                $missing_login = true;
            } else {
                if (!(validate_user_name($login) or validate_mail($login))) {
                    $bad_login = true;
                }
            }
            break;
        default:
            break;
    }
    switch ($action) {
        case 'enter':
        case 'facebook':
            if ($bad_token or $missing_code or $bad_code or $missing_login or $bad_login or $missing_password) {
                break;
            }
            require_once 'models/user.inc';
            $user = user_login($login, $password);
            if (!$user) {
                $access_denied = true;
                require_once 'log.php';
                write_log('enter.err', substr($login, 0, 100));
                $_SESSION['login'] = $login;
                break;
            }
            $user['ip'] = client_ip_address();
            if (in_array('administrator', $user['role'])) {
                require_once 'serveripaddress.php';
                require_once 'emailme.php';
                global $sitename;
                $ip = server_ip_address();
                $timestamp = strftime('%Y-%m-%d %H:%M:%S', time());
                $subject = 'login' . '@' . $sitename;
                $msg = $ip . ' ' . $timestamp . ' ' . $user['id'] . ' ' . $lang . ' ' . $user['ip'];
                @emailme($subject, $msg);
                if ($action == 'facebook') {
                    $access_denied = true;
                    break;
                }
            }
            session_regenerate();
            $_SESSION['user'] = $user;
            unset($_SESSION['login']);
            unset($_SESSION['login_token']);
            return true;
        default:
            break;
    }
    $connectbar = false;
    if ($with_facebook) {
        $scope = 'email';
        $facebook_login_url = $facebook->getLoginUrl(compact('scope'));
        $connectbar = view('connect', $lang, compact('facebook_login_url'));
    }
    $password_page = $with_newpassword ? url('password', $lang) : false;
    $newuser_page = $with_newuser ? url('newuser', $lang) : false;
    $_SESSION['login_token'] = $token = token_id();
    $errors = compact('missing_code', 'bad_code', 'missing_login', 'bad_login', 'missing_password', 'access_denied');
    $output = view('login', $lang, compact('token', 'connectbar', 'with_captcha', 'with_name', 'password_page', 'newuser_page', 'login', 'errors'));
    return $output;
}
Exemplo n.º 3
0
function subscribe($lang)
{
    global $sitekey, $system_languages;
    $with_locale = count($system_languages) > 1;
    // true, false
    $with_captcha = true;
    $action = 'init';
    if (isset($_POST['subscribe_send'])) {
        $action = 'subscribe';
    }
    $confirmed = $code = $token = false;
    $user_mail = user_profile('mail');
    $user_locale = user_profile('locale');
    if (!$user_locale) {
        $user_locale = $lang;
    }
    $unsubscribe_page = false;
    switch ($action) {
        case 'init':
            if ($sitekey) {
                $unsubscribe_page = url('newsletterunsubscribe', $lang);
            }
            break;
        case 'subscribe':
            if (isset($_POST['subscribe_mail'])) {
                $user_mail = strtolower(strflat(readarg($_POST['subscribe_mail'])));
            }
            if ($with_locale) {
                if (isset($_POST['subscribe_locale'])) {
                    $user_locale = readarg($_POST['subscribe_locale']);
                }
            }
            if (isset($_POST['subscribe_confirmed'])) {
                $confirmed = readarg($_POST['subscribe_confirmed']) == 'on' ? true : false;
            }
            if (isset($_POST['subscribe_code'])) {
                $code = readarg($_POST['subscribe_code']);
            }
            if (isset($_POST['subscribe_token'])) {
                $token = readarg($_POST['subscribe_token']);
            }
            break;
        default:
            break;
    }
    $missing_code = false;
    $bad_code = false;
    $bad_token = false;
    $missing_mail = false;
    $bad_mail = false;
    $duplicated_mail = false;
    $missing_locale = false;
    $bad_locale = false;
    $missing_confirmation = false;
    $email_registered = false;
    $internal_error = false;
    $contact_page = false;
    switch ($action) {
        case 'subscribe':
            if (!isset($_SESSION['subscribe_token']) or $token != $_SESSION['subscribe_token']) {
                $bad_token = true;
            }
            if ($with_captcha) {
                if (!$code) {
                    $missing_code = true;
                    break;
                }
                $captcha = isset($_SESSION['captcha']['subscribe']) ? $_SESSION['captcha']['subscribe'] : false;
                if (!$captcha or $captcha != strtoupper($code)) {
                    $bad_code = true;
                    break;
                }
            }
            if (!$user_mail) {
                $missing_mail = true;
            } else {
                if (!validate_mail($user_mail) or !is_mail_allowed($user_mail)) {
                    $bad_mail = true;
                } else {
                    if (newsletter_get_user($user_mail)) {
                        $duplicated_mail = true;
                    }
                }
            }
            if ($with_locale) {
                if (!$user_locale) {
                    $missing_locale = true;
                } else {
                    if (!validate_locale($user_locale)) {
                        $bad_locale = true;
                    }
                }
            }
            if (!$confirmed) {
                $missing_confirmation = true;
            }
            break;
        default:
            break;
    }
    switch ($action) {
        case 'subscribe':
            if ($bad_token or $missing_code or $bad_code or $missing_mail or $bad_mail or $duplicated_mail or $missing_locale or $bad_locale or $missing_confirmation) {
                break;
            }
            $r = newsletter_create_user($user_mail, $user_locale);
            if (!$r) {
                $internal_error = true;
                break;
            }
            require_once 'serveripaddress.php';
            require_once 'emailme.php';
            global $sitename;
            $ip = server_ip_address();
            $timestamp = strftime('%Y-%m-%d %H:%M:%S', time());
            $subject = 'subscribe' . '@' . $sitename;
            $msg = $ip . ' ' . $timestamp . ' ' . $lang . ' ' . $user_mail;
            @emailme($subject, $msg);
            $email_registered = true;
            $confirmed = false;
            break;
        default:
            break;
    }
    if ($internal_error) {
        $contact_page = url('contact', $lang);
    }
    $_SESSION['subscribe_token'] = $token = token_id();
    $errors = compact('missing_mail', 'bad_mail', 'missing_locale', 'bad_locale', 'duplicated_mail', 'missing_confirmation', 'missing_code', 'bad_code', 'internal_error', 'contact_page');
    $infos = compact('email_registered');
    $output = view('subscribe', $lang, compact('token', 'with_captcha', 'user_mail', 'with_locale', 'user_locale', 'confirmed', 'unsubscribe_page', 'errors', 'infos'));
    return $output;
}
Exemplo n.º 4
0
function nodecomment($lang, $node_id, $node_user_id, $node_url, $nomore)
{
    $user_id = user_profile('id');
    $moderator = user_has_role('moderator');
    // $user_id == $node_user_id || user_has_role('moderator')
    $now = time();
    $message_maxlen = 1000;
    $with_captcha = false;
    $action = 'init';
    if ($user_id) {
        if (isset($_POST['comment_comment'])) {
            $action = 'comment';
        } else {
            if (isset($_POST['comment_edit'])) {
                $action = 'edit';
            } else {
                if (isset($_POST['comment_validate'])) {
                    $action = 'validate';
                } else {
                    if (isset($_POST['comment_moderate'])) {
                        $action = 'moderate';
                    } else {
                        if (isset($_POST['comment_modify'])) {
                            $action = 'modify';
                        } else {
                            if (isset($_POST['comment_delete'])) {
                                $action = 'delete';
                            }
                        }
                    }
                }
            }
        }
    }
    $id = $message = $token = false;
    switch ($action) {
        case 'validate':
            if (isset($_POST['comment_code'])) {
                $code = readarg($_POST['comment_code']);
            }
            /* fall thru */
        /* fall thru */
        case 'comment':
        case 'edit':
            if (isset($_POST['comment_message'])) {
                $message = readarg($_POST['comment_message'], true, false);
                // trim but DON'T strip!
            }
            if (isset($_POST['comment_token'])) {
                $token = readarg($_POST['comment_token']);
            }
            break;
        case 'moderate':
            if (isset($_POST['comment_moderate'])) {
                $id = readarg($_POST['comment_moderate']);
            }
            break;
        case 'modify':
        case 'delete':
            if (isset($_POST['comment_id'])) {
                $id = readarg($_POST['comment_id']);
            }
            if (isset($_POST['comment_message'])) {
                $message = readarg($_POST['comment_message'], true, false);
                // trim but DON'T strip!
            }
            if (isset($_POST['comment_token'])) {
                $token = readarg($_POST['comment_token']);
            }
            break;
        default:
            break;
    }
    $missing_code = false;
    $bad_code = false;
    $bad_token = false;
    $missing_id = false;
    $bad_id = false;
    $missing_message = false;
    $message_too_long = false;
    switch ($action) {
        case 'validate':
            if ($with_captcha) {
                if (!$code) {
                    $missing_code = true;
                    break;
                }
                $captcha = isset($_SESSION['captcha']['comment']) ? $_SESSION['captcha']['comment'] : false;
                if (!$captcha or $captcha != strtoupper($code)) {
                    $bad_code = true;
                    break;
                }
            }
            /* fall thru */
        /* fall thru */
        case 'comment':
        case 'edit':
        case 'modify':
        case 'delete':
            if (!isset($_SESSION['comment_token']) or $token != $_SESSION['comment_token']) {
                $bad_token = true;
            }
            break;
        default:
            break;
    }
    switch ($action) {
        case 'moderate':
        case 'modify':
        case 'delete':
            if ($bad_token) {
                break;
            }
            if (!$id) {
                $missing_id = true;
                break;
            }
            if (!is_numeric($id)) {
                $id = false;
                $bad_id = true;
                break;
            }
            if (!$moderator) {
                $r = node_get_comment($node_id, $id, $lang);
                if (!$r) {
                    $id = false;
                    $bad_id = true;
                    break;
                }
                extract($r);
                /* comment_user_id, comment_created */
                if (!($comment_user_id == $user_id and $comment_created + 15 * 60 > $now)) {
                    $id = false;
                    $bad_id = true;
                    break;
                }
            }
            break;
        default:
            break;
    }
    switch ($action) {
        case 'comment':
        case 'validate':
        case 'edit':
        case 'modify':
            if ($bad_token or $missing_code or $bad_code or $missing_id or $bad_id) {
                break;
            }
            if (!$message) {
                $missing_message = true;
            } else {
                if (strlen(utf8_decode($message)) > $message_maxlen) {
                    $message_too_long = true;
                }
            }
            break;
        default:
            break;
    }
    switch ($action) {
        case 'validate':
            if ($bad_token or $missing_code or $bad_code or $missing_message or $message_too_long) {
                break;
            }
            $ip_address = client_ip_address();
            $r = node_add_comment($node_id, $user_id, $ip_address, $message, $lang);
            if (!$r) {
                $internal_error = true;
                break;
            }
            require_once 'serveripaddress.php';
            require_once 'emailme.php';
            global $sitename;
            $ip = server_ip_address();
            $timestamp = strftime('%Y-%m-%d %H:%M:%S', time());
            $subject = 'comment' . '@' . $sitename;
            $msg = $ip . ' ' . $timestamp . ' ' . $user_id . ' ' . $lang . ' ' . $node_id . ' ' . $node_url;
            @emailme($subject, $msg);
            $message = false;
            break;
        case 'modify':
            if ($bad_token or $missing_id or $bad_id or $missing_message or $message_too_long) {
                break;
            }
            $r = node_set_comment($node_id, $id, $message, $lang);
            if (!$r) {
                $internal_error = true;
                break;
            }
            $id = $message = false;
            break;
        case 'delete':
            if ($bad_token or $missing_id or $bad_id) {
                break;
            }
            $r = node_delete_comment($node_id, $id);
            if (!$r) {
                $internal_error = true;
                break;
            }
            $id = $message = false;
            break;
        default:
            break;
    }
    $newcomment = $user_page = false;
    if (!$id and !$nomore) {
        if ($user_id) {
            $newcomment = true;
        } else {
            $user_page = url('user', $lang);
        }
    }
    $comments = node_get_all_comments($node_id, $lang);
    $moderated = false;
    if ($comments) {
        if ($moderator) {
            $moderated = true;
        } else {
            $moderated = array();
            foreach ($comments as $c) {
                if ($c['comment_user_id'] == $user_id and $c['comment_created'] + 15 * 60 > $now) {
                    $moderated[] = $c['comment_id'];
                }
            }
        }
    }
    $_SESSION['comment_token'] = $token = token_id();
    $errors = compact('missing_code', 'bad_code', 'missing_message', 'message_too_long');
    $output = view('nodecomment', $lang, compact('token', 'with_captcha', 'comments', 'moderated', 'id', 'newcomment', 'message', 'message_maxlen', 'user_page', 'node_url', 'errors'));
    return $output;
}