예제 #1
0
def do_change_password():
    oldpassword = d2_hash(syndbb.request.form['oldpassword'])
    newpassword = d2_hash(syndbb.request.form['newpassword'])
    uniqid = syndbb.request.form['uniqid']

    if oldpassword and newpassword and uniqid:
        userid = checkSession(uniqid)
        if userid:
            user = d2_user.query.filter_by(user_id=userid).first()
            if user.password == oldpassword:
                user.password = newpassword
                syndbb.db.session.commit()

                check_session = d2_ip.query.filter_by(
                    user_id=user.user_id).filter_by(login=1).all()
                for usession in check_session:
                    syndbb.db.session.delete(usession)
                    syndbb.db.session.commit()
                syndbb.session.pop('logged_in', None)
                syndbb.flash(
                    'You have been logged out due to a password change.',
                    'danger')
                return "Password change successful."
            else:
                return "Invalid old password."
        else:
            return "Invalid Session"
    else:
        return "Invalid Request"
예제 #2
0
파일: upload.py 프로젝트: researcx/SynDBB
def upload_file():
    if syndbb.request.method == 'POST':
        image_types = [".jpg", ".jpeg", ".jpe"]
        if 'logged_in' in syndbb.session:
            userid = check_session_by_id(str(syndbb.session['logged_in']))
            uploader = syndbb.request.form['uploader']

            if 'anonymous' in syndbb.request.form:
                anonymous = 1
            else:
                anonymous = 0

            if 'timedelete' in syndbb.request.form:
                timedelete = 1
            else:
                timedelete = 0

            if userid:
                user = d2_user.query.filter_by(user_id=userid).first()
                if anonymous:
                    uploadfolder = syndbb.app.static_folder + "/data/uploads/" + d2_hash(
                        user.username + user.password)[:10] + "/"
                else:
                    uploadfolder = syndbb.app.static_folder + "/data/uploads/" + user.username + "/"
                if not syndbb.os.path.exists(uploadfolder):
                    syndbb.os.makedirs(uploadfolder)
                if 'file' not in syndbb.request.files:
                    syndbb.flash('No file selected.', 'danger')
                    return syndbb.redirect(syndbb.url_for(uploader))
                file = syndbb.request.files['file']
                if file.filename == '':
                    syndbb.flash('No file selected.', 'danger')
                    return syndbb.redirect(syndbb.url_for(uploader))
                if file:
                    filename = secure_filename(file.filename)
                    extension = syndbb.os.path.splitext(filename)[1]
                    newname = ''.join(
                        random.sample(
                            "-_" + string.ascii_uppercase +
                            string.ascii_lowercase + string.digits,
                            20)) + extension
                    file.save(syndbb.os.path.join(uploadfolder, newname))
                    if extension in image_types:
                        piexif.remove(uploadfolder + newname)
                    if uploader == 'upload_simple':
                        return "/upload/simple/?file=" + newname
                    else:
                        syndbb.flash('File uploaded successfully.', 'success')
                        syndbb.cache.delete_memoized(
                            syndbb.views.upload.get_user_files)

                        if anonymous:
                            fpath = d2_hash(user.username +
                                            user.password)[:10] + "/" + newname
                        else:
                            fpath = user.username + "/" + newname

                        return syndbb.redirect('/upload/view?file=' + fpath)
예제 #3
0
파일: upload.py 프로젝트: researcx/SynDBB
def delete_file():
    ufile = syndbb.request.args.get('file', '')
    uniqid = syndbb.request.args.get('uniqid', '')
    uploader = syndbb.request.args.get('uploader', '')
    if 'logged_in' in syndbb.session:
        userid = check_session_by_id(str(uniqid))
        if userid:
            user = d2_user.query.filter_by(user_id=userid).first()
            if uploader == "upload_anon":
                uploaded_file = syndbb.app.static_folder + "/data/uploads/" + d2_hash(
                    user.username + user.password)[:10] + "/" + ufile
            else:
                uploaded_file = syndbb.app.static_folder + "/data/uploads/" + user.username + "/" + ufile
            if syndbb.os.path.isfile(uploaded_file):
                syndbb.os.system("shred -u " + uploaded_file)
                syndbb.flash('File deleted successfully.', 'success')
                syndbb.cache.delete_memoized(
                    syndbb.views.upload.get_user_files)
                return syndbb.redirect(syndbb.url_for(uploader))
            else:
                syndbb.flash('No such file exists.', 'danger')
                return syndbb.redirect(syndbb.url_for(uploader))
        else:
            return syndbb.render_template('error_not_logged_in.html',
                                          title="Upload")
    else:
        return syndbb.render_template('error_not_logged_in.html',
                                      title="Upload")
예제 #4
0
def do_change_password():
    old_password = syndbb.request.form['oldpassword']
    new_password = syndbb.request.form['newpassword']
    uniqid = syndbb.request.form['uniqid']

    if old_password and new_password and uniqid:
        userid = check_session_by_id(uniqid)
        if userid:
            user = d2_user.query.filter_by(user_id=userid).first()
            if syndbb.core_config['ldap']['enabled'] :
                new_password_hash = syndbb.request.form['newpassword_hash']
                is_ldap_user = ldap_user.query.filter(syndbb.core_config['ldap']['attribute_cn'] + ': '+user.username).first()
                if is_ldap_user:
                    valid = syndbb.ldap.authenticate(user.username, old_password, syndbb.core_config['ldap']['attribute_cn'], syndbb.core_config['ldap']['base_dn'] )
                    if valid:
                        ldapuser = ldap_user.query.filter(syndbb.core_config['ldap']['attribute_cn'] + ': '+user.username).first()
                        ldapuser.password = ldap_hash(new_password)
                        ldapuser.save()
        
                        user.password = d2_hash(new_password_hash)
                        syndbb.db.session.commit()
                    else:
                        return "Invalid old password."
            else:
                if user.password == d2_hash(old_password):
                    user.password = d2_hash(new_password)
                    syndbb.db.session.commit()
                else:
                     return "Invalid old password."
            check_session = d2_ip.query.filter_by(user_id=user.user_id).filter_by(login=1).all()
            for usession in check_session:
                syndbb.db.session.delete(usession)
                syndbb.db.session.commit()
            syndbb.session.pop('logged_in', None)
            syndbb.flash('You have been logged out due to a password change.', 'danger')
            return "Password change successful."
        else:
            return "Invalid Session"
    else:
        return "Invalid Request"
예제 #5
0
def dologin():
    if 'logged_in' in syndbb.session:
        userid = checkSession(str(syndbb.session['logged_in']))
        if userid:
            return "You are already logged in!"

    username = syndbb.request.form['username']
    password = d2_hash(syndbb.request.form['password'])

    user = d2_user.query.filter_by(username=username).first()
    my_ip = syndbb.request.remote_addr
    useragent = syndbb.request.headers.get('User-Agent')

    if user:
        session_id = str(syndbb.uuid.uuid1())
        if user.password == password:
            login_ip = d2_ip(my_ip, useragent, user.user_id,
                             unix_time_current(), 1, syndbb.request.path,
                             session_id,
                             d2_hash(my_ip)[:10])
            syndbb.db.session.add(login_ip)
            syndbb.db.session.commit()

            syndbb.session['logged_in'] = session_id
            syndbb.session.permanent = True

            user.last_login = unix_time_current()

            return "Login successful."
        else:
            login_ip = d2_ip(my_ip, user.user_id, unix_time_current(), 0,
                             syndbb.request.path)
            syndbb.db.session.add(login_ip)
            syndbb.db.session.commit()
            return "Invalid password."
    else:
        return "Invalid username."
예제 #6
0
파일: admin.py 프로젝트: researcx/SynDBB
def admin_do_change_password():
    userpassword = syndbb.request.form['user_id']
    newpassword = d2_hash(syndbb.request.form['newpassword'])
    uniqid = syndbb.request.form['uniqid']

    if userpassword and newpassword and uniqid:
        userid = check_session_by_id(uniqid)
        if userid:
            user = d2_user.query.filter_by(user_id=userid).first()
            if user.rank >= 900:
                pwuser = d2_user.query.filter_by(user_id=userpassword).first()
                if user:
                    pwuser.password = newpassword
                    syndbb.db.session.commit()
                    return "Password change successful."
                else:
                    return "Invalid old password."
            else:
                return "No Permission"
        else:
            return "Invalid Session"
    else:
        return "Invalid Request"
예제 #7
0
def site_api():
    apikey = syndbb.request.form['api']
    if apikey == syndbb.core_config['site']['api']:
        # 127.0.0.1:5000/api/site/?api=INVALID_API&create_thread=true&username=admin&category=general&content=hello&title=test&icon=shitpost&anon=0
        if 'create_thread' in syndbb.request.form:
            username = syndbb.request.form['username']
            category = syndbb.request.form['category']
            content = syndbb.request.form['content']
            title = syndbb.request.form['title']
            icon = syndbb.request.form['icon']
            anon = syndbb.request.form['anon']

            if not username: return "username not set"
            if not category: return "category not set"
            if not content: return "content not set"
            if not title: return "title not set"
            if not icon: return "icon not set"
            if not anon: return "anon not set"

            message = """Posting as: &username=""" + username + """<br/>
                Category: &category=""" + category + """<br/>
                Content: &content=""" + content + """<br/>
                Title: &title=""" + title + """<br/>
                Icon: &icon=""" + icon + """<br/>
                Anon: &anon=""" + anon + """<br/>
                <br/>"""

            user = d2_user.query.filter_by(username=username).first()
            if not user: return "user not found"
            category = d2_channels.query.filter_by(short_name=category).first()
            if not category: return "category not found"
            thread = d2_activity.query.filter_by(
                title=html_escape(title)).first()
            if thread: return str(thread.id)
            tcontent = d2_activity.query.filter_by(content=content).first()
            if tcontent: return str(tcontent.id)

            allowed_icons = []  # allow all icons in the posticons folder
            for ticon in get_post_icons(whitelist=False):
                allowed_icons.append(ticon[1])
            # allowed_icons = ['art', 'attention', 'banme', 'computers', 'en', 'event', 'fap', 'funny', 'gaming', 'gross', 'help', 'hot', 'letsplay', 'link', 'music', 'newbie', 'news', 'photos', 'politics', 'poll', 'postyour', 'question', 'rant', 'release', 'repeat', 'request', 'school', 'serious', 'shitpost', 'stupid', 'tv', 'unfunny', 'weird', 'whine']
            if icon not in allowed_icons:
                return "thread icon does not exist (allowed: " + str(
                    allowed_icons) + ")"

            create_thread = d2_activity(user.user_id,
                                        unix_time_current(), content, 0, 0,
                                        html_escape(title), category.id,
                                        unix_time_current(), 0, 0, icon,
                                        int(anon))
            syndbb.db.session.add(create_thread)
            syndbb.db.session.flush()
            thread_id = str(create_thread.id)
            syndbb.db.session.commit()

            get_post_thumbnail(thread_id, 'resize', False)

            syndbb.cache.delete_memoized(
                syndbb.models.channels.get_thread_contents)
            syndbb.cache.delete_memoized(
                syndbb.models.channels.get_thread_list)
            syndbb.cache.delete_memoized(syndbb.models.activity.get_activity)
            syndbb.cache.delete_memoized(
                syndbb.views.xml_feed.feed_threads_xml)
            syndbb.cache.delete_memoized(
                syndbb.models.channels.replies_to_post)
            return str(thread_id)
        # 127.0.0.1:5000/api/site/?api=INVALID_API&create_post=true&username=admin&reply_to_thread=23&reply_to_post=23&content=hello&anon=0
        if 'create_post' in syndbb.request.form:
            username = syndbb.request.form['username']
            content = syndbb.request.form['content']
            reply_to_thread = syndbb.request.form['reply_to_thread']
            reply_to_post = syndbb.request.form[
                'reply_to_post']  #leave as 0 for no reply to any post
            anon = syndbb.request.form['anon']

            if not username: return "username not set"
            if not content: return "content not set"
            if not reply_to_thread: return "reply_to_thread not set"
            if not reply_to_post: reply_to_post = 0
            if not anon: return "anon not set"

            # message = """Replying as: &username="""+username+"""<br/>
            #     To thread: &reply_to_thread="""+reply_to_thread+"""<br/>
            #     To post: &reply_to_post="""+reply_to_post+"""<br/>
            #     Content: &content="""+content+"""<br/>
            #     Anon: &anon="""+anon+"""<br/>
            #     <br/>"""

            user = d2_user.query.filter_by(username=username).first()
            if not user: return "user not found"
            thread = d2_activity.query.filter_by(id=reply_to_thread).first()
            if not thread: return "thread not found"
            if int(reply_to_post) != 0:
                post = d2_activity.query.filter_by(id=reply_to_post).first()
                if not post: return "post not found"

            cthread = d2_activity.query.filter_by(replyto=0).filter_by(
                content=content).first()
            if cthread: return "reply exists"
            tfcontent = d2_activity.query.filter_by(
                replyto=thread.id).filter_by(content=content).first()
            if tfcontent: return "reply exists"

            create_reply = d2_activity(user.user_id, unix_time_current(),
                                       content, int(reply_to_thread),
                                       int(reply_to_post), '', 0, 0, 0, 0, 1,
                                       int(anon))
            syndbb.db.session.add(create_reply)
            syndbb.db.session.flush()
            reply_id = str(create_reply.id)
            syndbb.db.session.commit()

            get_post_thumbnail(reply_id, 'resize', False)

            syndbb.cache.delete_memoized(
                syndbb.models.channels.get_thread_contents)
            syndbb.cache.delete_memoized(
                syndbb.models.channels.get_thread_list)
            syndbb.cache.delete_memoized(syndbb.models.activity.get_activity)
            syndbb.cache.delete_memoized(syndbb.views.xml_feed.feed_posts_xml)
            syndbb.cache.delete_memoized(
                syndbb.models.channels.replies_to_post)

            return str(reply_id)
        if 'create_user' in syndbb.request.form:
            username = syndbb.request.form['username']
            password = syndbb.request.form['password']
            rank = syndbb.request.form['rank']

            if not username: return "username not set"
            if not password: return "password not set"
            if not rank: return "rank not set"

            user = d2_user.query.filter_by(username=username).first()
            if user:
                return "A user with that username already exists."
            else:
                create_user = d2_user(username=username,
                                      display_name='',
                                      token='',
                                      title='',
                                      bio='',
                                      status='',
                                      status_time=0,
                                      rank=rank,
                                      avatar_date=0,
                                      password=d2_hash(password),
                                      post_count=0,
                                      line_count=0,
                                      word_count=0,
                                      profanity_count=0,
                                      karma_positive=0,
                                      karma_negative=0,
                                      points=0,
                                      join_date=unix_time_current(),
                                      last_login=unix_time_current(),
                                      last_activity=unix_time_current(),
                                      irc_auth='',
                                      upload_auth='',
                                      user_auth='',
                                      upload_url='local',
                                      nsfw_toggle=0,
                                      full_avatar=0,
                                      tags='')
                syndbb.db.session.add(create_user)
                syndbb.db.session.flush()
                created_user_id = str(create_user.user_id)
                syndbb.db.session.commit()

            return str(created_user_id)
    else:
        return 0
예제 #8
0
파일: upload.py 프로젝트: researcx/SynDBB
def get_user_files(userid, anon=0, gallery=0, album=0):
    user = d2_user.query.filter_by(user_id=userid).first()

    if anon:
        uname = d2_hash(user.username + user.password)[:10]
    else:
        uname = user.username

    uploadfolder = syndbb.app.static_folder + "/data/uploads/" + uname + "/"
    thumbfolder = syndbb.app.static_folder + "/data/uploads/.thumbnails/"

    if not syndbb.os.path.exists(uploadfolder):
        syndbb.os.makedirs(uploadfolder)
    if not syndbb.os.path.exists(thumbfolder):
        syndbb.os.makedirs(thumbfolder)

    image_types = [".jpg", ".jpeg", ".jpe", ".gif", ".png", ".bmp"]
    audio_types = [".mp3", ".ogg", ".wav"]
    video_types = [".webm", ".mp4", ".avi", ".mpg", ".mpeg"]
    text_types = [".txt", ".pdf", ".doc"]
    archive_types = [".zip", ".rar", ".7z", ".tar", ".gz"]

    total_size = sum(
        syndbb.os.path.getsize(uploadfolder + f)
        for f in syndbb.os.listdir(uploadfolder)
        if syndbb.os.path.isfile(uploadfolder + f))

    uploadurl = user.upload_url
    if uploadurl == "local":
        uploadurl = cdn_path() + "/data/uploads/"
    else:
        uploadurl = "https://" + uploadurl + "/"

    file_list = []
    for fn in syndbb.os.listdir(uploadfolder):
        filepath = uploadfolder + "/" + fn
        if syndbb.os.path.isfile(filepath):
            filetime = int(syndbb.os.stat(filepath).st_mtime)
            filesize = syndbb.os.path.getsize(filepath)
            extension = syndbb.os.path.splitext(fn)[1].lower()
            hashname = hashlib.sha256(fn.encode()).hexdigest()
            if extension in image_types:
                if anon:
                    type_icon = '<i class="silk-icon icon_picture" aria-hidden="true"></i>'
                else:
                    type_icon = '<img src="' + cdn_path(
                    ) + '/data/uploads/.thumbnails/' + hashname + '.png" alt="' + fn + '" class="uploadimg"></a>'
                    thumbpath = thumbfolder + hashname + ".png"
                    if not syndbb.os.path.isfile(thumbpath):
                        im = Image.open(filepath)
                        im.thumbnail((150, 150))
                        im.save(thumbpath, "PNG")
            elif extension in audio_types:
                type_icon = '<i class="fa fa-file-audio-o" aria-hidden="true"></i>'
            elif extension in video_types:
                type_icon = '<i class="ffa fa-file-video-o" aria-hidden="true"></i>'
            elif extension in text_types:
                type_icon = '<i class="fa fa-file-text-o" aria-hidden="true"></i>'
            elif extension in archive_types:
                type_icon = '<i class="fa fa-file-archive-o" aria-hidden="true"></i>'
            else:
                type_icon = '<i class="fa fa-file-o" aria-hidden="true"></i>'

            file_list.append([filetime, filesize, fn, type_icon])

    file_list.sort(reverse=True)

    return {
        'file_list': file_list,
        'uploadurl': uploadurl,
        'file_count': len(file_list),
        'total_size': total_size,
        'user_name': uname
    }
예제 #9
0
def doregister():
    if 'logged_in' in syndbb.session:
        userid = check_session_by_id(str(syndbb.session['logged_in']))
        if userid:
            return "You are already logged in!"

    username = syndbb.request.form['username']
    password = syndbb.request.form['password']
    tos = syndbb.request.form['tos']

    my_ip = gdpr_check(syndbb.request.remote_addr)
    my_ip_hash = get_ip_hash(syndbb.request.remote_addr)
    
    # tor = requests.get('https://check.torproject.org/exit-addresses', verify=False, timeout=5, stream=True)
    
    # torlines = ""
    
    # for line in tor.iter_lines():
    #     if line: torlines += str(line)
    
    # for ip_tor in torlines:
    #     ip_tor = ip_tor.replace("\n","")
    #     if "ExitAddress" in ip_tor:
    #         ip_tor = ip_tor.split(" ")[1]
    #         if my_ip == ip_tor:
    #             return "You seem to be using Tor or a proxy."
                
    # response = query(ip=my_ip)
    # if response.ip.appears == True:
    #     return "You seem to be using Tor or a proxy, or your IP is blacklisted for spam."
    
    if not tos:
        return "You have not agreed to the rules and terms of service."
    
    # if not token:
    #     return "You must verify yourself."
    
    # if captcha['success'] == False:
    #     return "You must verify yourself."

    if username and password:
        if not syndbb.core_config['site']['registration']:
            return 'Registration is disabled.'
        if syndbb.core_config['site']['invite_only']:
            code = syndbb.request.form['code']
            invites = d2_invites.query.filter_by(code=code, used_by=0).first()
            if not invites:
                return 'The invite code provided is invalid.'
        if not syndbb.re.search('^[a-z][a-z0-9-_]{2,32}$', username, syndbb.re.IGNORECASE):
            return "Invalid username (must match IRC standards)."
        user = d2_user.query.filter_by(username=username).first()
        if user:
            return "A user with that username already exists."
        else:  
            useragent = syndbb.request.headers.get('User-Agent')
            session_hash = d2_hash(syndbb.request.remote_addr + useragent + d2_hash(str(syndbb.uuid.uuid1())))[:20]
            similar_user = d2_hash(syndbb.request.remote_addr + useragent)[:20]

            create_user = d2_user(username=username, display_name='', token='', title='', bio='[i]Welcome to my profile![/i]', status='', status_time=0, rank=1, avatar_date=0, password=d2_hash(syndbb.request.form['password_hash']) if syndbb.core_config['ldap']['enabled']  else d2_hash(password), post_count=0, line_count=0, word_count=0, profanity_count=0, karma_positive=0, karma_negative=0, points=0, join_date=unix_time_current(), last_login=unix_time_current(), last_activity=unix_time_current(), irc_auth='', upload_auth='', user_auth=similar_user, upload_url='local', nsfw_toggle=0, full_avatar=0, tags="Location:This_Website new_user")
            syndbb.db.session.add(create_user)
            syndbb.db.session.flush()
            created_user_id = str(create_user.user_id)
            syndbb.db.session.commit()

            if syndbb.core_config['ldap']['enabled'] :
                ldap_add_user = ldap_user(
                    display_name=username,
                    username=username,
                    surname=username,
                    password=ldap_hash(password)
                )
                ldap_add_user.save()

            login_ip = d2_ip(my_ip, useragent, created_user_id, unix_time_current(), 1, syndbb.request.path, session_hash, my_ip_hash)
            syndbb.db.session.add(login_ip)
            syndbb.db.session.commit()
            if syndbb.core_config['site']['invite_only'] :
                invites.used_by = created_user_id
            syndbb.db.session.commit()

            syndbb.session['logged_in'] = session_hash
            return "Registration successful."
    else:
        return "Invalid request."
예제 #10
0
def dologin():
    if 'logged_in' in syndbb.session:
        userid = check_session_by_id(str(syndbb.session['logged_in']))
        if userid:
            return "You are already logged in!"

    username = syndbb.request.form['username']
    password = syndbb.request.form['password']

    user = d2_user.query.filter_by(username=username).first()
    my_ip = gdpr_check(syndbb.request.remote_addr)
    my_ip_hash = get_ip_hash(syndbb.request.remote_addr)
    useragent = syndbb.request.headers.get('User-Agent')
    session_hash = d2_hash(syndbb.request.remote_addr + useragent + d2_hash(str(syndbb.uuid.uuid1())))[:20]

    if user:
        if syndbb.core_config['ldap']['enabled'] :
            password_hash = syndbb.request.form['password_hash']
            is_ldap_user = ldap_user.query.filter(syndbb.core_config['ldap']['attribute_cn'] + ': '+username).first()
            if user.password == d2_hash(password_hash):
                if not is_ldap_user:
                    login_ip = d2_ip(my_ip, useragent, user.user_id, unix_time_current(), 1, syndbb.request.path, session_hash, my_ip_hash)
                    syndbb.db.session.add(login_ip)
                    syndbb.db.session.commit()
                    
                    syndbb.session['logged_in'] = session_hash
                    syndbb.session.permanent = True
                    
                    user.last_login = unix_time_current()

                    ldap_add_user = ldap_user(
                        display_name=username,
                        username=username,
                        surname=username,
                        password=ldap_hash(password)
                    )
                    ldap_add_user.save()
                    return "Login successful."

            valid = syndbb.ldap.authenticate(username, password, syndbb.core_config['ldap']['attribute_cn'], syndbb.core_config['ldap']['base_dn'] )
            if not valid:
                login_ip = d2_ip(my_ip, useragent, user.user_id, unix_time_current(), 0, syndbb.request.path, "N/A", my_ip_hash)
                syndbb.db.session.add(login_ip)
                syndbb.db.session.commit()
                return 'Invalid credentials.'
                
            login_ip = d2_ip(my_ip, useragent, user.user_id, unix_time_current(), 1, syndbb.request.path, session_hash, my_ip_hash)
            syndbb.db.session.add(login_ip)
            syndbb.db.session.commit()

            syndbb.session['logged_in'] = session_hash
            syndbb.session.permanent = True
            return 'Login successful.'
        else:
            if user.password == d2_hash(password):
                login_ip = d2_ip(my_ip, useragent, user.user_id, unix_time_current(), 1, syndbb.request.path, session_hash, my_ip_hash)
                syndbb.db.session.add(login_ip)
                syndbb.db.session.commit()
                
                syndbb.session['logged_in'] = session_hash
                syndbb.session.permanent = True
                
                user.last_login = unix_time_current()
                
                return "Login successful."
            else:
                login_ip = d2_ip(my_ip, useragent, user.user_id, unix_time_current(), 0, syndbb.request.path, "N/A", my_ip_hash)
                syndbb.db.session.add(login_ip)
                syndbb.db.session.commit()
                return "Invalid credentials."
    else:
        return "Invalid credentials."
예제 #11
0
def doregister():
    if 'logged_in' in syndbb.session:
        userid = checkSession(str(syndbb.session['logged_in']))
        if userid:
            return "You are already logged in!"

    username = syndbb.request.form['username']
    password = d2_hash(syndbb.request.form['password'])
    tos = syndbb.request.form['tos']
    token = syndbb.request.form['coinhive-captcha-token']

    my_ip = syndbb.request.remote_addr

    tor = requests.get('https://check.torproject.org/exit-addresses',
                       verify=False,
                       timeout=5,
                       stream=True)

    torlines = ""

    for line in tor.iter_lines():
        if line: torlines += str(line)

    for ip_tor in torlines:
        ip_tor = ip_tor.replace("\n", "")
        if "ExitAddress" in ip_tor:
            ip_tor = ip_tor.split(" ")[1]
            if my_ip == ip_tor:
                return "You seem to be using Tor or a proxy."

    response = query(ip=my_ip)
    if response.ip.appears == True:
        return "You seem to be using Tor or a proxy, or your IP is blacklisted for spam."

    if not tos:
        return "You have not agreed to the rules and terms of service."

    if not token:
        return "You must verify yourself."

    udata = {'secret': syndbb.captcha_key, 'token': token, 'hashes': "256"}
    headers = {'content-type': 'application/x-www-form-urlencoded'}
    reg = requests.post("https://api.coinhive.com/token/verify",
                        headers=headers,
                        data=udata,
                        verify=False)
    captcha = json.loads(reg.text)

    if captcha['success'] == False:
        return "You must verify yourself."

    if username and password:
        #        invites = d2_invites.query.filter_by(code=code, used_by=0).first()
        #        if not invites:
        #            return 'The invite code provided is invalid.'
        if not syndbb.re.search('^[a-z][a-z0-9-_]{2,32}$', username,
                                syndbb.re.IGNORECASE):
            return "Invalid username (must match IRC standards)."
        user = d2_user.query.filter_by(username=username).first()
        if user:
            return "A user with that username already exists."
        else:
            create_user = d2_user(username, '', '', '', 0, 0, '', '', '', '',
                                  '', 0, password, 0, 0, 0, 0, 0, 0, 0,
                                  unix_time_current(), unix_time_current(),
                                  unix_time_current(), '', '', '')
            syndbb.db.session.add(create_user)
            syndbb.db.session.flush()
            created_user_id = str(create_user.user_id)
            syndbb.db.session.commit()

            useragent = syndbb.request.headers.get('User-Agent')
            session_id = str(syndbb.uuid.uuid1())
            login_ip = d2_ip(my_ip, useragent, created_user_id,
                             unix_time_current(), 1, syndbb.request.path,
                             session_id,
                             d2_hash(my_ip)[:10])
            syndbb.db.session.add(login_ip)
            syndbb.db.session.commit()

            #            invites.used_by = created_user_id
            syndbb.db.session.commit()

            syndbb.session['logged_in'] = session_id
            return "Registration successful."
    else:
        return "Invalid request."