Ejemplo n.º 1
0
	def initialize(self, ip):
		# generate a new API token
		self.apitoken = generate_token()

		# remainder of settings
		self.ngroktoken = ""
		self.name = "%s Virtual Appliance" % app.config['POOL_NAME']
		self.subdomain = ""
		self.dynamicimages = 1
		# important, do not remove
		self.secret = generate_token(size=8, caselimit=True) # not used.  having fun yet?  
		self.cbapikey = ""
		self.cbapisecret = ""
		self.cbaccesstoken = ""
		self.cbrefreshtoken = ""

		# get geodata
		geo_data = get_geodata()
		self.latitude = geo_data['latitude']
		self.longitude = geo_data['longitude']

		# set local IP address
		self.local_ip = ip

		# create entry
		self.update(self)
Ejemplo n.º 2
0
def configure():
    # get the form for the page
    form = ApplianceForm(request.form)

    # get existing database entries
    appliance = db.session.query(Appliance).first()

    # page is POST'ing data
    if request.method == "POST":
        # clear settings cache
        Status().flush()

        # load the form into the appliance object (excluding API token)
        apitoken = appliance.apitoken
        form.populate_obj(appliance)
        appliance.apitoken = apitoken

        if form.validate_on_submit():
            # our form validates, so update the database
            appliance.update(appliance)

            # check the settings
            settings = Status().check_settings()

            if settings["coinbase"]:
                # sync up addresses with coinbase
                addresses = Addresses()
                addresses.sync(appliance)

                # grab the first address we got from coinbase
                address = db.session.query(Addresses).first()

                if address and address.subdomain:
                    # overload the appliance's existing subdomain with one from coinbase address
                    appliance.subdomain = address.subdomain
                    appliance.update()
                else:
                    # there exists no address with a subdomain, so we generate a new one
                    appliance.subdomain = generate_token(size=16, caselimit=True)
                    appliance.update()

                    # build the tunnel config file - ngrok will start after it's built
                appliance.build_tunnel_conf()

                # not ideal, but whatever
                os.system("monit restart ngrok")

                # form was valid, so say thanks
            flash("Setting have been saved.", "success")

        else:
            # form was not valid, so show errors
            flash("There were form errors. Please check your entries and try again.", "error")

            # populate map
    try:
        lat = float(appliance.latitude)
        lon = float(appliance.longitude)
    except ValueError, TypeError:
        geodata = get_geodata()
        appliance.latitude = geodata["latitude"]
        appliance.longitude = geodata["longitude"]
        appliance.update()
Ejemplo n.º 3
0
def configure():
    # get the form for the page
    form = ApplianceForm(request.form)

    # get existing database entries
    appliance = db.session.query(Appliance).first()

    # page is POST'ing data
    if request.method == 'POST':
        # clear settings cache
        Status().flush()

        # load the form into the appliance object (excluding API token)
        apitoken = appliance.apitoken
        form.populate_obj(appliance)
        appliance.apitoken = apitoken

        if form.validate_on_submit():
            # our form validates, so update the database
            appliance.update(appliance)

            # check the settings
            settings = Status().check_settings()

            if settings['coinbase']:
                # sync up addresses with coinbase
                addresses = Addresses()
                addresses.sync(appliance)

                # grab the first address we got from coinbase
                address = db.session.query(Addresses).first()

                if address and address.subdomain:
                    # overload the appliance's existing subdomain with one from coinbase address
                    appliance.subdomain = address.subdomain
                    appliance.update()
                else:
                    # there exists no address with a subdomain, so we generate a new one
                    appliance.subdomain = generate_token(size=16,
                                                         caselimit=True)
                    appliance.update()

                # build the tunnel config file - ngrok will start after it's built
                appliance.build_tunnel_conf()

                # not ideal, but whatever
                os.system('monit restart ngrok')

            # form was valid, so say thanks
            flash("Setting have been saved.", "success")

        else:
            # form was not valid, so show errors
            flash(
                "There were form errors. Please check your entries and try again.",
                "error")

    # populate map
    try:
        lat = float(appliance.latitude)
        lon = float(appliance.longitude)
    except ValueError, TypeError:
        geodata = get_geodata()
        appliance.latitude = geodata['latitude']
        appliance.longitude = geodata['longitude']
        appliance.update()