Example #1
0
    def change_admin_password(self, new_password, username=None, verify=True):
        if not username:
            username = self.username

        with self.ctx_config_block("system admin"):
            with self.ctx_edit_block(common.sanitize(username)):
                self.run_command(
                    "set password %s" % common.sanitize(new_password), True)

        if verify:
            if not self.verify_login(username, new_password):
                raise common.OperationalError(
                    "Password change verification failed")
            else:
                return True
def get_keywords_from_text(text):
    text = sanitize(text)
    rake_object = Rake("/home/**********/libs/rake/SmartStoplistv2.txt", 3, 15,
                       2)
    rake_keywords = rake_object.run(text)
    filtered_keywords = keyword_filter(rake_keywords, 'all', False)
    return filtered_keywords
Example #3
0
    def add(self, entry):
        if entry.rsplit(".", 1)[1] == "m3u":
            with open(os.path.join(config.playlist_location, entry)) as f:
                for music in f.readlines():
                    self.array.append(music.replace("\n", "").decode("UTF-8"))

        if dirmanager.found_entry(sanitize(entry)) is not None:
            self.array.append(entry)
Example #4
0
    def add(self, entry):
        if entry.rsplit(".", 1)[1] == "m3u":
            with open(os.path.join(config.playlist_location, entry)) as f:
                for music in f.readlines():
                    self.array.append(music.replace("\n", "").decode("UTF-8"))

        if dirmanager.found_entry(sanitize(entry)) is not None:
            self.array.append(entry)
Example #5
0
    def change_admin_password(self, new_password, verify=True):
        # TODO: verify that login user is admin user ("get admin name")

        self.run_command('set admin password "%s"' %
                         common.sanitize(new_password))
        self.save_and_apply()

        if verify:
            if not self.verify_login(self.username, new_password):
                raise OperationalError("Password change verification failed")
            else:
                return True
Example #6
0
def directory():
    if request.method == "POST":
        text = request.form['text']
        dirmanager.add_directory(sanitize(text))
        return  redirect("/")
    elif request.method == "DELETE":
        text = request.form['text']
        dirmanager.del_directory(sanitize(text))
        return  redirect("/")
    elif request.method == "GET":
        return '''
    <!doctype html>
    <title>Add New Directory</title>
    <h1>Add New Directory</h1>
    <form action="/control/directory/" method=post>
      <p><input type=text name=text>
         <input type=submit value=Send>
    </form>
    '''
    else:
        print "UPS" \
              ""
        abort(400)
Example #7
0
def directory():
    if request.method == "POST":
        text = request.form['text']
        dirmanager.add_directory(sanitize(text))
        return redirect("/")
    elif request.method == "DELETE":
        text = request.form['text']
        dirmanager.del_directory(sanitize(text))
        return redirect("/")
    elif request.method == "GET":
        return '''
    <!doctype html>
    <title>Add New Directory</title>
    <h1>Add New Directory</h1>
    <form action="/control/directory/" method=post>
      <p><input type=text name=text>
         <input type=submit value=Send>
    </form>
    '''
    else:
        print "UPS" \
              ""
        abort(400)
Example #8
0
    def add_admin(self,
                  username,
                  password,
                  privilege="prof_admin",
                  role=None,
                  sshkey=None,
                  ssh_only_key=False,
                  verify=True):

        # TODO: remove redundant code
        # TODO: abstract privileges

        if role:
            raise ValueError("Roles not supported")

        if ssh_only_key:
            raise NotImplementedError("ssh_only_key not implemented")

        with self.ctx_config_block("system admin"):
            with self.ctx_edit_block(common.sanitize(username)):
                self.run_command("set password %s" % common.sanitize(password),
                                 True)
                self.run_command(
                    "set accprofile %s" % common.sanitize(privilege), True)
                self.run_command("set trusthost1 192.168.50.50 192.168.50.50",
                                 True)

            if sshkey:
                self.run_command('set ssh-public-key1 "ssh-dss %s"' % sshkey,
                                 True)

        if verify:
            if not self.verify_login(username, password):
                raise common.OperationalError("Failed to add new admin")
            else:
                return True
Example #9
0
def uploadmusic():
    if request.method == 'POST':
        file = request.files['file']
        if file and file.filename.rsplit(".", 1)[1] in config.supported_extensions:
            filename = sanitize(file.filename)
            file.save(os.path.join(config.uploaded_location, filename))
            return redirect("/")
    return '''
    <!doctype html>
    <title>Upload new Music</title>
    <h1>Upload new Music File</h1>
    <form action="" method=post enctype=multipart/form-data>
      <p><input type=file name=file>
         <input type=submit value=Upload>
    </form>
    ''', 201
Example #10
0
def uploadplaylist():
    if request.method == 'POST':
        file = request.files['file']
        if file and file.filename.rsplit(".", 1)[1] is "m3u":
            filename = sanitize(file.filename)
            file.save(os.path.join(config.playlist_location, filename))
            return redirect("/")
    return '''
    <!doctype html>
    <title>Upload new Playlist</title>
    <h1>Upload new Playlist</h1>
    <form action="" method=post enctype=multipart/form-data>
      <p><input type=file name=file>
         <input type=submit value=Upload>
    </form>
    ''', 201
Example #11
0
def uploadplaylist():
    if request.method == 'POST':
        file = request.files['file']
        if file and file.filename.rsplit(".", 1)[1] is "m3u":
            filename = sanitize(file.filename)
            file.save(os.path.join(config.playlist_location, filename))
            return redirect("/")
    return '''
    <!doctype html>
    <title>Upload new Playlist</title>
    <h1>Upload new Playlist</h1>
    <form action="" method=post enctype=multipart/form-data>
      <p><input type=file name=file>
         <input type=submit value=Upload>
    </form>
    ''', 201
Example #12
0
def uploadmusic():
    if request.method == 'POST':
        file = request.files['file']
        if file and file.filename.rsplit(".",
                                         1)[1] in config.supported_extensions:
            filename = sanitize(file.filename)
            file.save(os.path.join(config.uploaded_location, filename))
            return redirect("/")
    return '''
    <!doctype html>
    <title>Upload new Music</title>
    <h1>Upload new Music File</h1>
    <form action="" method=post enctype=multipart/form-data>
      <p><input type=file name=file>
         <input type=submit value=Upload>
    </form>
    ''', 201
Example #13
0
    def add_admin(self,
                  username,
                  password,
                  privilege="read-only",
                  role=None,
                  sshkey=None,
                  ssh_only_key=False,
                  verify=True):

        self.run_command('set admin user "%s" password "%s" privilege "%s"' %
                         (common.sanitize(username), common.sanitize(password),
                          common.sanitize(privilege)))

        if role:
            self.run_command(
                'set admin user "%s" role "%s"' %
                (common.sanitize(username), common.sanitize(role)))

        if sshkey:
            self.run_command(
                'set ssh pka-dsa user-name "%s" key "%s"' %
                (common.sanitize(username), common.sanitize(sshkey)))

            if ssh_only_key:
                self.run_command(
                    'set admin scs password disable username "%s"' %
                    (common.sanitize(username)))

        if verify:
            if sshkey and ssh_only_key:
                raise NotImplementedError(
                    "Verification not supported for passwordless SSH login")

            if not self.verify_login(username, password):
                raise OperationalError("Failed to add new admin user")
            else:
                return True

        self.save_and_apply()
Example #14
0
	parser.add_argument('-o','--outputPath', help = 'output path')
	arguments = parser.parse_args()

	if not arguments.outputPath:
		arguments.outputPath = os.path.dirname(arguments.csvFile) + '/chipYaml'

	year = datetime.date.today().year

	with open(arguments.csvFile) as csvFile:
		csvReader = csv.reader(csvFile)
		firstRow = next(csvReader)
		paths, labels = parseFirstRow(firstRow)
		yaml = ruamel.yaml.YAML()
		yaml.register_class(Reference)
		for row in csvReader:
			yamlFilename = os.path.join(arguments.outputPath, common.sanitize(parseString(row[0])[0]) + '.yaml')
			print('Generating {}...'.format(yamlFilename))
			with open(yamlFilename, 'w') as yamlFile:
				dictionary = parseRow(row, paths)
				dictionary = addLabels(dictionary, labels)
				yamlFile.write("#\n"
						"# file: {}\n"
						"#\n"
						"# author: Copyright (C) {} Kamil Szczygiel http://www.distortec.com "
						"http://www.freddiechopin.info\n"
						"#\n"
						"# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a "
						"copy of the MPL was not\n"
						"# distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.\n"
						"#\n"
						"# Automatically generated file - do not edit!\n"
    parser = argparse.ArgumentParser()
    parser.add_argument('csvFile', help='input CSV file')
    parser.add_argument('outputPath', help='output path')
    arguments = parser.parse_args()

    year = datetime.date.today().year

    with open(arguments.csvFile) as csvFile:
        csvReader = csv.reader(csvFile)
        firstRow = next(csvReader)
        paths, labels = parseFirstRow(firstRow)
        yaml = ruamel.yaml.YAML()
        for row in csvReader:
            yamlFilename = os.path.join(
                arguments.outputPath,
                common.sanitize(parseString(row[0])[0]) + '.yaml')
            print('Generating {}...'.format(yamlFilename))
            with open(yamlFilename, 'w') as yamlFile:
                dictionary = parseRow(row, paths)
                dictionary = addLabels(dictionary, labels)
                yamlFile.write(
                    "#\n"
                    "# file: {}\n"
                    "#\n"
                    "# author: Copyright (C) {} Kamil Szczygiel http://www.distortec.com "
                    "http://www.freddiechopin.info\n"
                    "#\n"
                    "# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a "
                    "copy of the MPL was not\n"
                    "# distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.\n"
                    "#\n"
Example #16
0
	relativeDistortosPath = posixpath.relpath(posixpath.realpath(arguments.distortosPath),
			posixpath.realpath(arguments.outputPath))
	relativeOutputPath = posixpath.relpath(posixpath.realpath(arguments.outputPath),
			posixpath.realpath(arguments.distortosPath))

	jinjaEnvironment = jinja2.Environment(trim_blocks = True, lstrip_blocks = True, keep_trailing_newline = True,
			loader = jinja2.FileSystemLoader(['.', arguments.distortosPath]))
	jinjaEnvironment.add_extension(RaiseExtension)
	jinjaEnvironment.filters['sanitize'] = common.sanitize
	jinjaEnvironment.globals['board'] = board
	jinjaEnvironment.globals['distortosPath'] = relativeDistortosPath
	jinjaEnvironment.globals['enumerate'] = enumerate
	jinjaEnvironment.globals['len'] = len
	jinjaEnvironment.globals['outputPath'] = relativeOutputPath
	jinjaEnvironment.globals['sanitizedBoard'] = common.sanitize(board)
	jinjaEnvironment.tests['fullMatch'] = isFullMatch

	metadata = []

	for currentDirectory, directories, filenames in os.walk('.', followlinks = True):
		# jinja expects forward slashes on all systems - https://github.com/pallets/jinja/issues/767
		currentDirectory = currentDirectory.replace('\\', '/')
		localFilenames = [posixpath.join(currentDirectory, filename) for filename in filenames]
		for metadataFilename in fnmatch.filter(localFilenames, '*/boardTemplates/*.metadata'):
			print('Loading {}'.format(metadataFilename))
			try:
				metadataFragment = jinjaEnvironment.get_template(metadataFilename).render(dictionary = dictionary)
			except jinja2.exceptions.TemplateAssertionError as exception:
				sys.exit("{}:{}: error: {}".format(exception.filename, exception.lineno, exception.message))
			metadata += ast.literal_eval('[' + metadataFragment + ']')
Example #17
0
        posixpath.realpath(arguments.outputPath),
        posixpath.realpath(arguments.distortosPath))

    jinjaEnvironment = jinja2.Environment(trim_blocks=True,
                                          lstrip_blocks=True,
                                          keep_trailing_newline=True,
                                          loader=jinja2.FileSystemLoader(
                                              ['.', arguments.distortosPath]))
    jinjaEnvironment.add_extension(RaiseExtension)
    jinjaEnvironment.filters['sanitize'] = common.sanitize
    jinjaEnvironment.globals['board'] = board
    jinjaEnvironment.globals['distortosPath'] = relativeDistortosPath
    jinjaEnvironment.globals['enumerate'] = enumerate
    jinjaEnvironment.globals['len'] = len
    jinjaEnvironment.globals['outputPath'] = relativeOutputPath
    jinjaEnvironment.globals['sanitizedBoard'] = common.sanitize(board)
    jinjaEnvironment.globals['year'] = datetime.date.today().year
    jinjaEnvironment.tests['fullMatch'] = isFullMatch

    metadata = []

    for currentDirectory, directories, filenames in os.walk('.',
                                                            followlinks=True):
        # jinja expects forward slashes on all systems - https://github.com/pallets/jinja/issues/767
        currentDirectory = currentDirectory.replace('\\', '/')
        localFilenames = [
            posixpath.join(currentDirectory, filename)
            for filename in filenames
        ]
        for metadataFilename in fnmatch.filter(localFilenames,
                                               '*/boardTemplates/*.metadata'):