Example #1
0
def get_mixed_username():
    if is_registered():
        profile = load_profile()
        username = profile['kanoworld_username']
    else:
        username = get_user_unsudoed()
    return username
Example #2
0
def set_locale_param(param, locale, skip_check=False):
    # FIXME: Don't use the .xsessionrc file to set the locale
    XSESSION_RC_FILE = os.path.join(get_home_by_username(get_user_unsudoed()),
                                    '.xsessionrc')
    if not skip_check and not is_locale_installed(locale):
        install_locale(locale)

    param_found = False
    new_param_line = 'export {}={}'.format(param, locale)
    new_config_file = []

    if os.path.exists(XSESSION_RC_FILE):
        xsession_file = read_file_contents_as_lines(XSESSION_RC_FILE)

        for line in xsession_file:
            if param in line:
                line = new_param_line
                param_found = True

            new_config_file.append(line)

    if not param_found:
        new_config_file.append(new_param_line)

    with open(XSESSION_RC_FILE, 'w') as conf_file:
        conf_file.write('\n'.join(new_config_file))

    chown_path(XSESSION_RC_FILE)
Example #3
0
def get_mixed_username():
    if is_registered():
        profile = load_profile()
        username = profile['kanoworld_username']
    else:
        username = get_user_unsudoed()
    return username
Example #4
0
def set_locale_param(param, locale, skip_check=False):
    # FIXME: Don't use the .xsessionrc file to set the locale
    XSESSION_RC_FILE = os.path.join(get_home_by_username(get_user_unsudoed()),
                                    '.xsessionrc')
    if not skip_check and not is_locale_installed(locale):
        install_locale(locale)

    param_found = False
    new_param_line = 'export {}={}'.format(param, locale)
    new_config_file = []

    if os.path.exists(XSESSION_RC_FILE):
        xsession_file = read_file_contents_as_lines(XSESSION_RC_FILE)

        for line in xsession_file:
            if param in line:
                line = new_param_line
                param_found = True

            new_config_file.append(line)

    if not param_found:
        new_config_file.append(new_param_line)

    with open(XSESSION_RC_FILE, 'w') as conf_file:
        conf_file.write('\n'.join(new_config_file))

    chown_path(XSESSION_RC_FILE)
Example #5
0
def schedule_delete_user(name=None):
    status = Status.get_instance()

    if status.stage != Status.DISABLED_STAGE:
        msg = _("A different task has been scheduled already. Reboot to"
                " finish the task before scheduling another one.")
        raise StatusError(msg)

    if not name:
        name = get_user_unsudoed()

    # Remove the user from the kano users
    # so it is not considered when reconfiguring the login
    cmd='usermod {} -G {}'.format(name, name)
    os.system(cmd)

    reconfigure_autostart_policy()

    status.stage = Status.DELETE_USER_STAGE
    status.username = name
    status.save()

    # Converting name to unicode for safety and then back to bytes for print.
    print _("The '{string_username}' user will be deleted on the next"
            " reboot.").format(string_username=unicode(name)).encode('utf8')
Example #6
0
def get_mixed_username():
    if is_registered():
        import mercury  # Lazy import to avoid dynamically linking with global import
        kw = mercury.KanoWorld(kw_url)
        username = kw.get_username()
    else:
        username = get_user_unsudoed()
    return username
Example #7
0
def kill_apps():
    # since kano-updater is run as root, need to inform
    # kanolauncher about user
    user = get_user_unsudoed()
    home = os.path.join('/home/', user)
    variables = 'HOME={} USER={}'.format(home, user)
    run_cmd('{} /usr/bin/kano-launcher /bin/true kano-kill-apps'.format(
        variables))
Example #8
0
def kill_apps():
    # since kano-updater is run as root, need to inform
    # kanolauncher about user
    user = get_user_unsudoed()
    home = os.path.join('/home/', user)
    variables = 'HOME={} USER={}'.format(home, user)
    run_cmd('{} /usr/bin/kano-launcher /bin/true kano-kill-apps'.format(
        variables))
Example #9
0
 def beta_110_to_beta_111(self):
     install('kano-sound-files kano-init-flow')
     # Create first boot file so we don't annoy existent users
     username = get_user_unsudoed()
     first_boot = '/home/%s/.kano-settings/first_boot' % username
     try:
         open(first_boot, 'w').close()
     except:
         pass
Example #10
0
 def beta_110_to_beta_111(self):
     install('kano-sound-files kano-init-flow')
     # Create first boot file so we don't annoy existent users
     username = get_user_unsudoed()
     first_boot = '/home/%s/.kano-settings/first_boot' % username
     try:
         open(first_boot, 'w').close()
     except:
         pass
Example #11
0
 def beta_123_to_beta_124(self):
     # Rename Snake custom theme
     username = get_user_unsudoed()
     path = '/home/%s/Snake-content/' % username
     old_name = 'custom_theme'
     if os.path.exists(path + old_name):
         new_name = 'custom-theme.xml'
         try:
             os.rename(path + old_name, path + new_name)
         except Exception:
             pass
Example #12
0
 def beta_123_to_beta_124(self):
     # Rename Snake custom theme
     username = get_user_unsudoed()
     path = '/home/%s/Snake-content/' % username
     old_name = 'custom_theme'
     if os.path.exists(path + old_name):
         new_name = 'custom-theme.xml'
         try:
             os.rename(path + old_name, path + new_name)
         except Exception:
             pass
Example #13
0
def get_current_wallpapers():
    """
        Returns the current wallpaper configuration.

        :return: A map of wallpaper types to file paths.
        :rtype: dict
    """

    wallpapers = {key: None for key in SIZE_SUFFIX_MAP.iterkeys()}
    wallpapers.update(_get_wallpaper_from_kdeskrc(KDESKRC_SYSTEM))

    home_dir = KDESKRC_HOME_TEMPLATE.format(user=get_user_unsudoed())
    wallpapers.update(_get_wallpaper_from_kdeskrc(home_dir))

    return wallpapers
Example #14
0
def get_current_wallpapers():
    """
        Returns the current wallpaper configuration.

        :return: A map of wallpaper types to file paths.
        :rtype: dict
    """

    wallpapers = {key: None for key in SIZE_SUFFIX_MAP.iterkeys()}
    wallpapers.update(_get_wallpaper_from_kdeskrc(KDESKRC_SYSTEM))

    home_dir = KDESKRC_HOME_TEMPLATE.format(user=get_user_unsudoed())
    wallpapers.update(_get_wallpaper_from_kdeskrc(home_dir))

    return wallpapers
Example #15
0
def load_profile():
    ''' Read profile data from file containing profile information and return
    it as a dict. If such a file is not present, then a new dict is created
    :returns: profile data as a dict
    :rtype: dict
    '''
    data = read_json(profile_file)
    if not data:
        data = dict()
        # if the profile file doesn't exist make sure that the new one
        # is created with the right version
        data['version'] = 2
    if 'version' not in data:
        data.pop('avatar', None)
        data.pop('environment', None)
    data['username_linux'] = get_user_unsudoed()
    return data
Example #16
0
def load_profile():
    ''' Read profile data from file containing profile information and return
    it as a dict. If such a file is not present, then a new dict is created
    :returns: profile data as a dict
    :rtype: dict
    '''
    data = read_json(profile_file)
    if not data:
        data = dict()
        # if the profile file doesn't exist make sure that the new one
        # is created with the right version
        data['version'] = 2
    if 'version' not in data:
        data.pop('avatar', None)
        data.pop('environment', None)
    data['username_linux'] = get_user_unsudoed()
    return data
Example #17
0
    def refresh_menu_button(self):
        description = ''

        if self._setting_param:
            description = get_setting(self._setting_param)
        else:
            if self.name == 'wifi':
                if common.has_internet:
                    description = 'Connected'
                else:
                    description = 'Not connected'

            elif self.name == 'account':
                description = get_user_unsudoed()

            elif self.name == 'display':
                return

        self.menu_button.description.set_text(description)
Example #18
0
    def refresh_menu_button(self):
        description = ''

        if self._setting_param:
            description = get_setting(self._setting_param)
        else:
            if self.name == 'wifi':
                if common.has_internet:
                    description = _("Connected")
                else:
                    description = _("Not connected")

            elif self.name == 'account':
                description = get_user_unsudoed()

            elif self.name == 'display':
                return

        self.menu_button.description.set_text(description)
Example #19
0
def change_wallpaper(path, name):
    logger.info('set_wallpaper / change_wallpaper image_name:{}'.format(name))

    # home directory
    user = get_user_unsudoed()
    deskrc_path = KDESKRC_HOME_TEMPLATE.format(user=user)

    conf_params = {}
    for size, suffix in SIZE_SUFFIX_MAP.iteritems():
        conf_param = PARAM_NAME_TEMPLATE.format(size=size)
        image = os.path.join(path, "{}{}".format(name, suffix))
        conf_params[conf_param] = "  {param}: {image}".format(param=conf_param,
                                                              image=image)

    found = False
    newlines = []

    if os.path.isfile(deskrc_path):
        with open(deskrc_path, 'r') as kdesk_conf:
            for kdesk_conf_line in kdesk_conf:
                for conf_param, conf_line in conf_params.iteritems():
                    if conf_param in kdesk_conf_line:
                        kdesk_conf_line = conf_line
                        found = True

                newlines.append(kdesk_conf_line + '\n')

    if found:
        # Overwrite config file with new lines
        with open(deskrc_path, 'w') as outfile:
            outfile.writelines(newlines)
    else:
        # Not found so add it
        with open(deskrc_path, 'a') as outfile:
            for conf_line in conf_params.itervalues():
                outfile.write(conf_line + '\n')

    # Refresh the wallpaper
    os.system('sudo -u {user} kdesk -w'.format(user=user))

    return 0
Example #20
0
def change_wallpaper(path, name):
    logger.info('set_wallpaper / change_wallpaper image_name:{}'.format(name))

    # home directory
    user = get_user_unsudoed()
    deskrc_path = KDESKRC_HOME_TEMPLATE.format(user=user)

    conf_params = {}
    for size, suffix in SIZE_SUFFIX_MAP.iteritems():
        conf_param = PARAM_NAME_TEMPLATE.format(size=size)
        image = os.path.join(path, "{}{}".format(name, suffix))
        conf_params[conf_param] = "  {param}: {image}".format(param=conf_param,
                                                              image=image)

    found = False
    newlines = []

    if os.path.isfile(deskrc_path):
        with open(deskrc_path, 'r') as kdesk_conf:
            for kdesk_conf_line in kdesk_conf:
                for conf_param, conf_line in conf_params.iteritems():
                    if conf_param in kdesk_conf_line:
                        kdesk_conf_line = conf_line
                        found = True

                newlines.append(kdesk_conf_line + '\n')

    if found:
        # Overwrite config file with new lines
        with open(deskrc_path, 'w') as outfile:
            outfile.writelines(newlines)
    else:
        # Not found so add it
        with open(deskrc_path, 'a') as outfile:
            for conf_line in conf_params.itervalues():
                outfile.write(conf_line + '\n')

    # Refresh the wallpaper
    os.system('sudo -u {user} kdesk -w'.format(user=user))

    return 0
Example #21
0
def launch_chromium(*args):
    user_name = get_user_unsudoed()
    run_bg('su - ' + user_name + ' -c chromium')
Example #22
0
password_file = "/etc/kano-parental-lock"
hosts_file = '/etc/hosts'
hosts_file_backup = '/etc/kano-hosts-parental-backup'
hosts_mod_comment = '# Modified to add username'

chromium_policy_file = '/etc/chromium/policies/managed/policy.json'
sentry_config = os.path.join(settings_dir, 'sentry')

youtube_safe_cookie = '/usr/share/kano-video/cookies/youtube_safe/cookies.db'
youtube_nosafe_cookie = '/usr/share/kano-video/cookies/youtube_nosafe/cookies.db'
browser_safe_cookie = '/usr/share/kano-video/cookies/browser_safe/cookies.db'
browser_nosafe_cookie = '/usr/share/kano-video/cookies/browser_nosafe/cookies.db'
midori_cookie = '.config/midori'
youtube_cookie = '.config/midori/youtube'

username = get_user_unsudoed()

# TODO: is this needed?
if username != 'root':
    blacklist_file = os.path.join(settings_dir, 'blacklist')
    whitelist_file = os.path.join(settings_dir, 'whitelist')


def get_parental_enabled():
    enabled = os.path.exists(password_file)
    logger.debug('get_parental_enabled: {}'.format(enabled))
    return enabled


def get_parental_level():
    if not get_parental_enabled():
Example #23
0
#!/usr/bin/env python

# paths.py
#
# Copyright (C) 2014, 2015 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
#

import os

from kano.logging import logger
from kano.utils import get_user_unsudoed, get_home_by_username

linux_user = get_user_unsudoed()
home_directory = get_home_by_username(linux_user)

# setting up directories
dir_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

# rules path
rules_local = os.path.join(dir_path, 'rules')
rules_usr = '******'
if os.path.exists(rules_local):
    rules_dir = rules_local
elif os.path.exists(rules_usr):
    rules_dir = rules_usr
else:
    logger.warn("Neither local nor usr rules found!")

# bin path
bin_local = os.path.join(dir_path, 'bin')
Example #24
0

# TODO: Make this safety measure cleaner
if not hasattr(__builtins__, '_'):
    def _(s):
        return s

import re
import os
from kano.utils import run_cmd, read_file_contents, sed, enforce_root, \
    read_file_contents_as_lines, get_user_unsudoed, get_home_by_username, \
    chown_path

SUPPORTED_LIST_FILE = '/usr/share/i18n/SUPPORTED'
LOCALE_GEN_FILE = '/etc/locale.gen'
XSESSION_RC_FILE = os.path.join(get_home_by_username(get_user_unsudoed()),
                                '.xsessionrc')
LOCALE_PARAMS = [
    # 'LANG',  # Determines the default locale in the absence of other locale related environment variables
    'LANGUAGE',  #
    'LC_ADDRESS',  # Convention used for formatting of street or postal addresses
    'LC_COLLATE',  # Collation order
    'LC_CTYPE',  # Character classification and case conversion
    'LC_MONETARY',  # Monetary formatting
    'LC_MEASUREMENT',  # Default measurement system used within the region
    'LC_MESSAGES',  # Format of interactive words and responses
    'LC_NUMERIC',  # Numeric formatting
    'LC_PAPER',  # Default paper size for region
    'LC_RESPONSE',  # Determines how responses (such as Yes and No) appear in the local language
    'LC_TELEPHONE',  # Conventions used for representation of telephone numbers
    'LC_TIME'  # Date and time formats
#!/usr/bin/env python
# This file needs to be prepended to tutorial files, for
# them to work

import os
import sys

from kano.utils import get_user_unsudoed, get_home_by_username
DIR_PATH = os.path.join(get_home_by_username(get_user_unsudoed()),
                        'make-light')

if __name__ == '__main__' and __package__ is None:
    if DIR_PATH != '/usr':
        sys.path.insert(1, DIR_PATH)

from make_light.boards.base.aliases import *
from time import *
import time
from datetime import datetime
import datetime
from random import *
import random
from math import *
import math
import os

debug = False
simulation = False
token = ''

if 'POWERUP_DEBUG' in os.environ:
 def test_xsession_rc_file_path(self):
     self.assertEqual(locale.XSESSION_RC_FILE,
                      os.path.join('/home', utils.get_user_unsudoed(),
                                   '.xsessionrc'))
Example #27
0
def launch_chromium(*args):
    user_name = get_user_unsudoed()
    arguments=''.join(*args)
    run_bg('su - ' + user_name + ' -c "chromium {}"'.format(arguments))
Example #28
0
def launch_midori(*args):
    user_name = get_user_unsudoed()
    arguments=''.join(*args)
    run_bg('su - ' + user_name + ' -c "midori {}"'.format(arguments))
Example #29
0
#!/usr/bin/env python
# This file needs to be prepended to tutorial files, for
# them to work

import os
import sys

from kano.utils import get_user_unsudoed, get_home_by_username
DIR_PATH = os.path.join(
    get_home_by_username(get_user_unsudoed()), 'make-light'
)

if __name__ == '__main__' and __package__ is None:
    if DIR_PATH != '/usr':
        sys.path.insert(1, DIR_PATH)

from make_light.boards.base.aliases import *
from time import *
import time
from datetime import datetime
import datetime
from random import *
import random
from math import *
import math
import os

debug = False
simulation = False
token = ''
Example #30
0
#!/usr/bin/env python

# paths.py
#
# Copyright (C) 2014, 2015 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
#

import os

from kano.logging import logger
from kano.utils import get_user_unsudoed, get_home_by_username

linux_user = get_user_unsudoed()
home_directory = get_home_by_username(linux_user)

# setting up directories
dir_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

# rules path
rules_local = os.path.join(dir_path, 'rules')
rules_usr = '******'
if os.path.exists(rules_local):
    rules_dir = rules_local
elif os.path.exists(rules_usr):
    rules_dir = rules_usr
else:
    logger.warn('Neither local nor usr rules found!')

# bin path
bin_local = os.path.join(dir_path, 'bin')
Example #31
0
second_level_domains = [
    'com.af', 'com.af', 'com.ag', 'com.ai', 'co.ao', 'com.ar', 'com.au',
    'com.bd', 'com.bh', 'com.bn', 'com.bo', 'com.br', 'co.bw', 'com.bz',
    'com.kh', 'co.ck', 'g.cn', 'com.co', 'co.cr', 'com.cu', 'com.cy', 'com.do',
    'com.ec', 'com.eg', 'com.et', 'com.fj', 'com.gh', 'com.gi', 'com.gt',
    'com.hk', 'co.id', 'co.il', 'co.in', 'com.jm', 'co.jp', 'co.ke', 'co.kr',
    'com.kw', 'com.lb', 'com.lc', 'co.ls', 'com.ly', 'co.ma', 'com.mm',
    'com.mt', 'com.mx', 'com.my', 'com.mz', 'com.na', 'com.nf', 'com.ng',
    'com.ni', 'com.np', 'co.nz', 'com.om', 'com.pa', 'com.pe', 'com.ph',
    'com.pk', 'com.pg', 'com.pr', 'com.py', 'com.qa', 'com.sa', 'com.sb',
    'com.sg', 'com.sl', 'com.sv', 'co.th', 'com.tj', 'com.tn', 'com.tr',
    'com.tw', 'co.tz', 'com.ua', 'co.ug', 'co.uk', 'com.uy', 'co.uz', 'com.vc',
    'co.ve', 'co.vi', 'com.vn', 'co.za', 'co.zm', 'co.zw'
]

username = get_user_unsudoed()

# TODO: is this needed?
if username != 'root':
    blacklist_file = os.path.join(settings_dir, 'blacklist')
    whitelist_file = os.path.join(settings_dir, 'whitelist')


def get_parental_enabled():
    enabled = os.path.exists(password_file)
    logger.debug('get_parental_enabled: {}'.format(enabled))
    return enabled


def get_parental_level():
    if not get_parental_enabled():
Example #32
0
 def test_xsession_rc_file_path(self):
     self.assertEqual(
         locale.XSESSION_RC_FILE,
         os.path.join('/home', utils.get_user_unsudoed(), '.xsessionrc'))
def _sync():
    run_cmd_log(
        "su '{}' -c 'kano-sync --skip-kdesk --sync --backup --upload-tracking-data -s'".format(get_user_unsudoed())
    )
Example #34
0
def launch_midori(*args):
    user_name = get_user_unsudoed()
    arguments = ''.join(*args)
    run_bg('su - ' + user_name + ' -c "midori {}"'.format(arguments))
Example #35
0
def launch_chromium(*args):
    user_name = get_user_unsudoed()
    arguments = ''.join(*args)
    run_bg('su - ' + user_name + ' -c "chromium {}"'.format(arguments))