Exemple #1
0
 def set_superuser_password(self):
     form = SuperuserPasswordForm()
     if form.validate_on_submit():
         location = form.location.data
         password = form.password.data
         instance = form.instance.data
         murmur.set_superuser_password(location, password, instance)
         return redirect('/admin/tools/')
     return redirect('/admin/tools/')
Exemple #2
0
 def set_superuser_password(self):
     form = SuperuserPasswordForm()
     if form.validate_on_submit():
         region = form.region.data
         password = form.password.data
         instance = form.instance.data
         murmur.set_superuser_password(region, password, instance)
         return redirect('/admin/tools/')
     return redirect('/admin/tools/')
Exemple #3
0
    def create(self, id):
        form = DeployTokenServerForm()
        token = Token.query.filter_by(uuid=id).first_or_404()
        package = get_package_by_name(token.package)

        ctx = {
            'slots': package.get('slots', None),
            'duration': package.get('duration', None)
        }

        if form.validate_on_submit():

            try:
                # Generate UUID
                gen_uuid = str(uuid.uuid4())

                # Create POST request to murmur-rest api to create a new server
                welcome_msg = render_template("mumble/upgrade_welcome_message.html", gen_uuid=gen_uuid)

                # Initialize payload for murmur-rest request
                payload = {
                    'password': form.password.data,
                    'welcometext': welcome_msg,
                    'users': ctx['slots'],
                    'registername': form.channel_name.data
                }

                # Create virtual murmur server and set SuperUser password
                server_id = murmur.create_server_by_location(form.location.data, payload)
                murmur.set_superuser_password(form.location.data, form.superuser_password.data, server_id)

                # Create database entry
                s = Server()
                s.duration = ctx['duration']
                s.password = form.password.data
                s.uuid = gen_uuid
                s.type = 'upgrade'
                s.mumble_instance = server_id
                s.mumble_host = murmur.get_murmur_hostname(form.location.data)
                s.cvp_uuid = str(uuid.uuid4())

                # Expire token
                token.activation_date = datetime.datetime.utcnow()
                token.active = False
                db.session.add(s)
                db.session.add(token)
                db.session.commit()

                # Send task to delete server on expiration
                tasks.delete_server.apply_async([gen_uuid], eta=s.expiration)

                # Send email to user if email was set
                if token.email is not None:
                    email_ctx = {
                        'url': 'http://guildbit.com/server/%s' % gen_uuid,
                        'package': token.package,
                        'expiration': 'expiration here',
                        'superuser_password': form.superuser_password.data
                    }
                    msg = Message(
                        "Guildbit - Server Created",
                        sender=settings.DEFAULT_MAIL_SENDER,
                        recipients=[token.email])

                    msg.html = render_template("emails/payment_server_created.html", ctx=email_ctx)
                    mail.send(msg)

                return redirect(url_for('ServerView:get', id=s.uuid))

            except:
                import traceback
                db.session.rollback()
                traceback.print_exc()

        return render_template('payment/create.html', form=form, token=token, ctx=ctx)
Exemple #4
0
    def create(self, id):
        form = DeployTokenServerForm()
        form.region.choices = get_active_hosts_by_type('upgrade')
        token = Token.query.filter_by(uuid=id).first_or_404()
        package = Package.query.filter_by(id=token.package_id).first_or_404()

        ctx = {
            'slots': package.slots,
            'duration': package.duration
        }

        if form.validate_on_submit():
            try:
                # Generate UUID
                gen_uuid = str(uuid.uuid4())

                # Create POST request to murmur-rest api to create a new server
                welcome_msg = render_template("mumble/upgrade_welcome_message.html", gen_uuid=gen_uuid)

                # Initialize payload for murmur-rest request
                payload = {
                    'password': form.password.data,
                    'welcometext': welcome_msg,
                    'users': ctx['slots'],
                    'registername': form.channel_name.data
                }

                # Create virtual murmur server and set SuperUser password
                server_id = murmur.create_server_by_region(form.region.data, payload)
                murmur.set_superuser_password(form.region.data, form.superuser_password.data, server_id)

                # Create database entry
                s = Server()
                s.duration = ctx['duration']
                s.password = form.password.data
                s.uuid = gen_uuid
                s.type = 'upgrade'
                s.mumble_instance = server_id
                s.mumble_host = murmur.get_murmur_hostname(form.region.data)
                s.cvp_uuid = str(uuid.uuid4())
                s.status = 'active'

                # Expire token
                token.activation_date = datetime.datetime.utcnow()
                token.active = False
                token.email = form.email.data
                db.session.add(s)
                db.session.add(token)
                db.session.commit()

                # Send task to delete server on expiration
                tasks.delete_server.apply_async([gen_uuid], eta=s.expiration)

                # Send email to user if email was set
                if form.email.data is not None:
                    email_ctx = {
                        'url': 'http://guildbit.com/server/%s' % gen_uuid,
                        'package': token.package,
                        'expiration': 'expiration here',
                        'superuser_password': form.superuser_password.data
                    }
                    msg = Message(
                        "Guildbit - Server Created",
                        sender=settings.DEFAULT_MAIL_SENDER,
                        recipients=[form.email.data])

                    msg.html = render_template("emails/payment_server_created.html", ctx=email_ctx)
                    try:
                        mail.send(msg)
                    except:
                        import traceback
                        traceback.print_exc()

                return redirect(url_for('ServerView:get', uuid=s.uuid))

            except:
                import traceback
                db.session.rollback()
                traceback.print_exc()

        return render_template('payment/create.html', form=form, token=token, ctx=ctx)