libreschool-startpage/root/etc/e-smith/events/actions/startpage-force

83 lines
2.8 KiB
Python

#!/usr/bin/env python
import subprocess
import json
import sys
import os
import fnmatch
def set_startpage_firefox(homedir):
d = homedir + '/.mozilla/firefox/'
profiles = []
for root, dirs, files in os.walk(d):
for name in dirs:
p = os.path.join(root, name + '/prefs.js')
if os.path.isfile(p):
profiles.append(p)
for p in profiles:
with open(p, 'a') as f:
txt='user_pref("browser.startup.homepage", "http://' + _fqdn + '");'
f.write(txt)
return
def set_startpage_chrome(homedir):
d = homedir + '/.config/google-chrome/'
profiles = []
for root, dirs, files in os.walk(d):
for name in dirs:
p = os.path.join(root, name + '/Preferences')
if os.path.isfile(p):
profiles.append(p)
for p in profiles:
with open(p) as json_data:
data = json.load(json_data)
data['homepage'] = 'http://' + _fqdn
data['homepage_is_newtabpage'] = False
data['browser']['show_home_button'] = True
data['session']['restore_on_startup'] = 4
data['session']['startup_urls'] = ['http://' + _fqdn]
with open(p, 'w') as f:
json.dump(data, f)
return
def set_startpage_chromium(homedir):
d = homedir + '/.config/chromium/'
profiles = []
for root, dirs, files in os.walk(d):
for name in dirs:
p = os.path.join(root, name + '/Preferences')
if os.path.isfile(p):
profiles.append(p)
for p in profiles:
with open(p) as json_data:
data = json.load(json_data)
data['homepage'] = 'http://' + _fqdn
data['homepage_is_newtabpage'] = False
data['browser']['show_home_button'] = True
data['session']['restore_on_startup'] = 4
data['session']['startup_urls'] = ['http://' + _fqdn]
with open(p, 'w') as f:
json.dump(data, f)
return
_cfg = json.loads(subprocess.Popen(['/sbin/e-smith/db', 'configuration', 'showjson'],stdout=subprocess.PIPE).communicate()[0])
_SystemName = [x['type'] for x in _cfg if x['name']=='SystemName'][0]
_DomainName = [x['type'] for x in _cfg if x['name']=='DomainName'][0]
_fqdn = _SystemName + '.' + _DomainName
_users = json.loads(subprocess.Popen(['/sbin/e-smith/db', 'accounts', 'showjson'],stdout=subprocess.PIPE).communicate()[0])
_users = [x for x in _users if x['type']=='user' and x['name']!='admin']
# if a specific user has been requested, we filter the list
if len(sys.argv) > 1:
_users = [x for x in _users if x['name']==sys.argv[1]]
# if we have some user to parse
if len(_users) > 0:
for u in _users:
homedir = '/var/lib/nethserver/home/' + u['name']
set_startpage_firefox(homedir)
set_startpage_chrome(homedir)
set_startpage_chromium(homedir)