How to use the octoprint.server.util.flask.restricted_access function in OctoPrint

To help you get started, weโ€™ve selected a few OctoPrint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vitormhenrique / OctoPrint-Enclosure / octoprint_enclosure / __init__.py View on Github external
    @restricted_access
    def send_shell_command(self, identifier):
        rpi_output = [r_out for r_out in self.rpi_outputs if self.to_int(r_out['index_id']) == identifier].pop()

        command = rpi_output['shell_script']
        self.shell_command(command)
        return make_response('', 204)
github vitormhenrique / OctoPrint-Enclosure / octoprint_enclosure / __init__.py View on Github external
    @restricted_access
    def set_auto_shutdown(self, identifier):
        if "application/json" not in request.headers["Content-Type"]:
            return make_response("expected json", 400)
        try:
            data = request.json
        except BadRequest:
            return make_response("malformed request", 400)

        if 'status' not in data:
            return make_response("missing status attribute", 406)

        value = data["status"]

        if not value:
            suffix = 'auto_shutdown'
            queue_id = '{0!s}_{1!s}'.format(str(identifier), suffix)
github OctoPrint / OctoPrint-FirmwareUpdater / octoprint_firmwareupdater / __init__.py View on Github external
	@octoprint.server.util.flask.restricted_access
	def status(self):
		return flask.jsonify(flashing=self._flash_thread is not None)
github tohara / OctoPrint-BigBoxFirmware / octoprint_bigboxfirmware / __init__.py View on Github external
    @octoprint.plugin.BlueprintPlugin.route("/firmwareprofiles/", methods=["DELETE"])
    @octoprint.server.util.flask.restricted_access
    @octoprint.server.admin_permission.require(403)
    def deleteProfile(self, identifier):
        dataFolder = self.get_plugin_data_folder()
        file_path = dataFolder + '/profiles/' + identifier
           
        if os.path.isfile(file_path):
            os.remove(file_path)
                 
        return flask.make_response("", 204)
github tohara / OctoPrint-BigBoxFirmware / octoprint_bigboxfirmware / __init__.py View on Github external
    @octoprint.plugin.BlueprintPlugin.route("/firmwareprofiles/", methods=["PATCH"])
    @octoprint.server.util.flask.restricted_access
    @octoprint.server.admin_permission.require(403)
    def updateProfile(self, identifier):
        dataFolder = self.get_plugin_data_folder()
        profile_folder = dataFolder + '/profiles'
        
        if not os.path.isdir(profile_folder):
            os.mkdir(profile_folder)
            
        profile_id = flask.request.json['profile']['id']
        
        profile_file = open(profile_folder + '/' + profile_id, 'w+b')
        
        profile_file.write(str(flask.request.json))
        profile_file.flush()
        profile_file.close()
github vitormhenrique / OctoPrint-Enclosure / octoprint_enclosure / __init__.py View on Github external
    @restricted_access
    def requested_gcode_command(self, identifier):
        rpi_output = [r_out for r_out in self.rpi_outputs if self.to_int(r_out['index_id']) == identifier].pop()
        self.send_gcode_command(rpi_output['gcode'])
        return make_response('', 204)
github tohara / OctoPrint-BigBoxFirmware / octoprint_bigboxfirmware / __init__.py View on Github external
    @octoprint.plugin.BlueprintPlugin.route("/make", methods=["POST"])
    @octoprint.server.util.flask.restricted_access
    @octoprint.server.admin_permission.require(403)
    def make_marlin(self):
        
        avrdudePath = '/usr/bin/avrdude'
        selectedPort = flask.request.json['selected_port'] if flask.request.json.has_key('selected_port') else ''
        profileId = flask.request.json['profileId']
        dataFolder = self.get_plugin_data_folder()
        buildFolder = dataFolder + '/tmp'
        hexPath = buildFolder + '/Marlin.hex'
        libPath = self._basefolder + '/lib'
        arduinoLibPath = libPath + '/arduino-1.6.8'
        makeFilePath = libPath + '/Makefile'
        
        profile = self.getProfileFromId(profileId)
        repoPath = self.getRepoNamePath(profile['url'])
        marlinFolder = repoPath + '/Marlin'
github vitormhenrique / OctoPrint-Enclosure / octoprint_enclosure / __init__.py View on Github external
    @restricted_access
    def update_ui_requested(self):
        self.update_ui()
        return make_response('', 204)
github tohara / OctoPrint-BigBoxFirmware / octoprint_bigboxfirmware / __init__.py View on Github external
    @octoprint.plugin.BlueprintPlugin.route("/updateRepos/", methods=["POST"])
    @octoprint.server.util.flask.restricted_access
    @octoprint.server.admin_permission.require(403)
    def saveRepos(self):
        repoList = flask.request.json['repoUrlList']
        
        self._sendStatus(line='Checking if there are any changes.', stream='message')
        
        for exsitingRepo in self.getRepos():
            if exsitingRepo['repoUrl'] not in map(lambda x: x['repoUrl'], repoList):
                repoUserFolder = self.getRepoUserPath(exsitingRepo['repoUrl'])
                #print 'Going to delete:', exsitingRepo['repoUrl']
                self.execute(['rm', '-rfv', self.getRepoName(exsitingRepo['repoUrl'])], cwd= repoUserFolder)
                self.removeRepoFromDefLib(exsitingRepo['repoUrl'])
        
        for repo in repoList:
            
            if repo['add']:
github OctoPrint / OctoPrint-FirmwareUpdater / octoprint_firmwareupdater / __init__.py View on Github external
	@octoprint.server.util.flask.restricted_access
	@octoprint.server.admin_permission.require(403)
	def flash_firmware(self):
		if self._printer.is_printing():
			error_message = "Cannot flash firmware, printer is busy"
			self._send_status("flasherror", subtype="busy", message=error_message)
			return flask.make_response(error_message, 409)

		value_source = flask.request.json if flask.request.json else flask.request.values

		if not "port" in value_source:
			error_message = "Cannot flash firmware, printer port is not specified"
			self._send_status("flasherror", subtype="port", message=error_message)
			return flask.make_response(error_message, 400)

		method = self._settings.get(["flash_method"])