Пример #1
0
def edit_hosts_file(path, new_hostname):
    try:
        hosts = read_file_contents(path)
        hosts += '\n' + hosts_mod_comment + '\n'
        hosts += '127.0.0.1\t{}\n'.format(new_hostname)
        write_file_contents(path, hosts)
    except:
        logger.error("exception while changing change {}".format(path))
Пример #2
0
    def _ensure_netifnames(self):
        """Add the kernel option ``net.ifnames=0`` to preserve old network
        naming convention"""

        data = read_file_contents(CMDLINE_TXT_PATH)

        if 'net.ifnames=' not in data:
            data = data + ' net.ifnames=0'

        write_file_contents(CMDLINE_TXT_PATH, data)
Пример #3
0
    def _ensure_netifnames(self):
        """Add the kernel option ``net.ifnames=0`` to preserve old network
        naming convention"""

        data = read_file_contents(CMDLINE_TXT_PATH)

        if 'net.ifnames=' not in data:
            data = data + ' net.ifnames=0'

        write_file_contents(CMDLINE_TXT_PATH, data)
Пример #4
0
def create_empty_hosts():
    import platform
    hostname = platform.node()
    new_hosts = '127.0.0.1   localhost\n127.0.1.1   {}\n'.format(hostname)

    logger.debug("writing new hosts file")
    write_file_contents(hosts_file, new_hosts)

    logger.debug("restoring original hosts permission")
    os.chmod(hosts_file, 0644)
Пример #5
0
def set_parental_enabled(setting, _password):
    logger.debug('set_parental_enabled: {}'.format(setting))

    # turning on
    if setting:
        logger.debug('enabling')

        logger.debug('setting password')
        write_file_contents(password_file, encrypt_password(_password))

        logger.debug('making the file root read-only')
        os.chmod(password_file, 0400)

        logger.debug('enabling parental controls')
        set_parental_level(get_parental_level())

        msg = N_("Parental lock enabled!")
        logger.debug(msg)

        return True, _(msg)

    # turning off
    else:
        # password matches
        if read_file_contents(password_file) == encrypt_password(_password):
            logger.debug('password accepted, disabling')

            logger.debug('clearing password')
            os.remove(password_file)

            logger.debug('disabling parental controls')
            set_parental_level(-1)

            msg = N_("Parental lock disabled!")
            logger.debug(msg)

            return True, _(msg)

        # password doesn't match
        else:
            msg = N_("Password doesn't match\nleaving parental lock enabled!")
            logger.debug(msg)

            return False, _(msg)
Пример #6
0
def set_hostname(new_hostname):
    if os.environ['LOGNAME'] != 'root':
        logger.error("Error: Settings must be executed with root privileges")

    # Check username chars
    new_hostname = re.sub('[^a-zA-Z0-9]', '', new_hostname).lower()

    if new_hostname == '':
        logger.error("no letters left in username after removing illegal ones")
        return

    if new_hostname == 'kano':
        logger.info(
            " not tryng to set hostname as it is the same as the default")
        return

    # check for missing hosts file
    if not os.path.exists(hosts_file):
        create_empty_hosts()

    # check if already done
    curr_hosts = read_file_contents_as_lines(hosts_file)
    if hosts_mod_comment in curr_hosts:
        logger.warn("/etc/hosts already modified, not changing")
        return

    # actually edit the hosts file
    edit_hosts_file(hosts_file, new_hostname)

    # edit the backup file.
    if os.path.exists(hosts_file_backup):
        edit_hosts_file(hosts_file_backup, new_hostname)

    try:
        write_file_contents('/etc/hostname', new_hostname + '\n')
    except:
        logger.error("exception while changing change /etc/hostname")
Пример #7
0
 def beta_111_to_beta_120(self, dummy_progress):
     purge("kano-unlocker")
     repo_url = "deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi"
     write_file_contents('/etc/apt/sources.list', repo_url + '\n')
     run_cmd_log('apt-get -y clean')
     run_cmd_log('apt-get -y update')
Пример #8
0
 def beta_111_to_beta_120(self, dummy_progress):
     purge("kano-unlocker")
     repo_url = "deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi"
     write_file_contents('/etc/apt/sources.list', repo_url + '\n')
     run_cmd_log('apt-get -y clean')
     run_cmd_log('apt-get -y update')
Пример #9
0
def write_blacklisted_sites(blacklist):
    write_file_contents(blacklist_file, '\n'.join(blacklist))
Пример #10
0
def write_whitelisted_sites(whitelist):
    write_file_contents(whitelist_file, '\n'.join(whitelist))