mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
...
This commit is contained in:
commit
35071d7212
78 files changed
+5570
No files matched your search
@@ -0,0 +1,135 @@
|
||||
import os, shutil, subprocess
|
||||
from socket import gethostname
|
||||
import cherrypy
|
||||
import simplejson as json
|
||||
from gettext import gettext as _
|
||||
from filedict import FileDict
|
||||
from modules.auth import require
|
||||
from plugin_mount import PagePlugin, FormPlugin
|
||||
import cfg
|
||||
from forms import Form
|
||||
from model import User
|
||||
from util import *
|
||||
|
||||
class Config(PagePlugin):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.register_page("sys.config")
|
||||
|
||||
@cherrypy.expose
|
||||
@require()
|
||||
def index(self):
|
||||
parts = self.forms('/sys/config')
|
||||
parts['title']=_("Configure this %s" % cfg.box_name)
|
||||
return self.fill_template(**parts)
|
||||
|
||||
def valid_hostname(name):
|
||||
"""Return '' if name is a valid hostname by our standards (not
|
||||
just by RFC 952 and RFC 1123. We're more conservative than the
|
||||
standard. If hostname isn't valid, return message explaining why."""
|
||||
|
||||
message = ''
|
||||
if len(name) > 63:
|
||||
message += "<br />Hostname too long (max is 63 characters)"
|
||||
|
||||
if not is_alphanumeric(name):
|
||||
message += "<br />Hostname must be alphanumeric"
|
||||
|
||||
if not name[0] in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
|
||||
message += "<br />Hostname must start with a letter"
|
||||
|
||||
return message
|
||||
|
||||
def set_hostname(hostname):
|
||||
"Sets machine hostname to hostname"
|
||||
cfg.log.info("Writing '%s' to /etc/hostname" % hostname)
|
||||
unslurp("/etc/hostname", hostname+"\n")
|
||||
try:
|
||||
retcode = subprocess.call("/etc/init.d/hostname.sh start", shell=True)
|
||||
if retcode < 0:
|
||||
cfg.log.error("Hostname restart terminated by signal: return code is %s" % retcode)
|
||||
else:
|
||||
cfg.log.debug("Hostname restart returned %s" % retcode)
|
||||
except OSError, e:
|
||||
raise cherrypy.HTTPError(500, "Hostname restart failed: %s" % e)
|
||||
|
||||
sys_store = filedict_con(cfg.store_file, 'sys')
|
||||
sys_store['hostname'] = hostname
|
||||
|
||||
class general(FormPlugin, PagePlugin):
|
||||
url = ["/sys/config"]
|
||||
order = 30
|
||||
|
||||
def help(self, *args, **kwargs):
|
||||
|
||||
## only expert users are going to get deep enough to see any timestamps
|
||||
if not cfg.users.expert():
|
||||
return ''
|
||||
return _(#"""<h2>Time Zone</h2>
|
||||
"""<p>Set your timezone to get accurate
|
||||
timestamps. %(product)s will use this information to set your
|
||||
%(box)s's systemwide timezone.</p>
|
||||
""" % {'product':cfg.product_name, 'box':cfg.box_name})
|
||||
|
||||
def main(self, message='', **kwargs):
|
||||
sys_store = filedict_con(cfg.store_file, 'sys')
|
||||
defaults = {'time_zone': "slurp('/etc/timezone').rstrip()",
|
||||
'hostname': "gethostname()",
|
||||
}
|
||||
for k,c in defaults.items():
|
||||
if not k in kwargs:
|
||||
try:
|
||||
kwargs[k] = sys_store[k]
|
||||
except KeyError:
|
||||
exec("if not '%(k)s' in kwargs: sys_store['%(k)s'] = kwargs['%(k)s'] = %(c)s" % {'k':k, 'c':c})
|
||||
|
||||
## Get the list of supported timezones and the index in that list of the current one
|
||||
module_file = __file__
|
||||
if module_file.endswith(".pyc"):
|
||||
module_file = module_file[:-1]
|
||||
time_zones = json.loads(slurp(os.path.join(os.path.dirname(os.path.realpath(module_file)), "time_zones")))
|
||||
for i in range(len(time_zones)):
|
||||
if kwargs['time_zone'] == time_zones[i]:
|
||||
time_zone_id = i
|
||||
break
|
||||
|
||||
## A little sanity checking. Make sure the current timezone is in the list.
|
||||
try:
|
||||
cfg.log('kwargs tz: %s, from_table: %s' % (kwargs['time_zone'], time_zones[time_zone_id]))
|
||||
except NameError:
|
||||
cfg.log.critical("Unknown Time Zone: %s" % kwargs['time_zone'])
|
||||
raise cherrypy.HTTPError(500, "Unknown Time Zone: %s" % kwargs['time_zone'])
|
||||
|
||||
## And now, the form.
|
||||
form = Form(title=_("General Config"),
|
||||
action="/sys/config/general/index",
|
||||
name="config_general_form",
|
||||
message=message )
|
||||
form.html(self.help())
|
||||
form.dropdown(_("Time Zone"), name="time_zone", vals=time_zones, select=time_zone_id)
|
||||
form.html("<p>Your hostname is the local name by which other machines on your LAN can reach you.</p>")
|
||||
form.text_input('Hostname', name='hostname', value=kwargs['hostname'])
|
||||
form.submit(_("Submit"))
|
||||
return form.render()
|
||||
|
||||
def process_form(self, time_zone='', hostname='', *args, **kwargs):
|
||||
sys_store = filedict_con(cfg.store_file, 'sys')
|
||||
message = ''
|
||||
if hostname != sys_store['hostname']:
|
||||
msg = valid_hostname(hostname)
|
||||
if msg == '':
|
||||
old_val = sys_store['hostname']
|
||||
try:
|
||||
set_hostname(hostname)
|
||||
except:
|
||||
cfg.log.info("Trying to restore old hostname value.")
|
||||
set_hostname(old_val)
|
||||
raise
|
||||
else:
|
||||
message += msg
|
||||
if time_zone != sys_store['time_zone']:
|
||||
src = os.path.join("/usr/share/zoneinfo", time_zone)
|
||||
cfg.log.info("Copying %s to /etc/localtime" % src)
|
||||
shutil.copy(src, "/etc/localtime")
|
||||
sys_store['time_zone'] = time_zone
|
||||
return message or "Settings updated."
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import os
|
||||
import cherrypy
|
||||
import simplejson as json
|
||||
from gettext import gettext as _
|
||||
from filedict import FileDict
|
||||
from modules.auth import require
|
||||
from plugin_mount import PagePlugin, FormPlugin
|
||||
import cfg
|
||||
from forms import Form
|
||||
from model import User
|
||||
from util import *
|
||||
|
||||
class experts(FormPlugin, PagePlugin):
|
||||
url = ["/sys/config"]
|
||||
order = 10
|
||||
|
||||
def help(self, *args, **kwargs):
|
||||
side = _(#"""<h2>Expert Mode</h2>
|
||||
"""
|
||||
<p>The %(box)s can be administered in two modes, 'basic'
|
||||
and 'expert'. Basic mode hides a lot of features and
|
||||
configuration options that most users will never need to think
|
||||
about. Expert mode allows you to get into the details.</p>
|
||||
|
||||
<p>Most users can operate the %(box)s by configuring the
|
||||
limited number of options visible in Basic mode. For the sake
|
||||
of simplicity and ease of use, we hid most of %(product)s's
|
||||
less frequently used options. But if you want more
|
||||
sophisticated features, you can enable Expert mode, and
|
||||
%(product)s will present more advanced menu options.</p>
|
||||
|
||||
<p>You should be aware that it might be possible to render
|
||||
your %(box)s inaccessible via Expert mode options.</p>
|
||||
""" % {'box':cfg.box_name, 'product':cfg.product_name})
|
||||
|
||||
return side
|
||||
|
||||
def main(self, expert=None, message='', **kwargs):
|
||||
"""Note that kwargs contains '':"submit" if this is coming
|
||||
from a submitted form. If kwargs is empty, it's a fresh form
|
||||
with no user input, which means it should just reflect the
|
||||
state of the stored data."""
|
||||
if not kwargs and expert == None:
|
||||
expert = cfg.users.expert()
|
||||
cfg.log("Expert mode is %s" % expert)
|
||||
form = Form(title=_("Expert Mode"),
|
||||
action="/sys/config/experts",
|
||||
name="expert_mode_form",
|
||||
message=message )
|
||||
form.html(self.help())
|
||||
form.checkbox(_("Expert Mode"), name="expert", checked=expert)
|
||||
form.submit(_("Submit"))
|
||||
return form.render()
|
||||
|
||||
def process_form(self, expert='', *args, **kwargs):
|
||||
user = cfg.users.get()
|
||||
|
||||
message = 'settings unchanged'
|
||||
|
||||
if expert:
|
||||
if not 'expert' in user['groups']:
|
||||
user['groups'].append('expert')
|
||||
message = "enabled"
|
||||
else:
|
||||
if 'expert' in user['groups']:
|
||||
user['groups'].remove('expert')
|
||||
message = "disabled"
|
||||
|
||||
cfg.users.set(user)
|
||||
return "Expert mode %s." % message
|
||||
@@ -0,0 +1,50 @@
|
||||
import os
|
||||
import cherrypy
|
||||
import simplejson as json
|
||||
from gettext import gettext as _
|
||||
from filedict import FileDict
|
||||
from auth import require
|
||||
from plugin_mount import PagePlugin, FormPlugin
|
||||
import cfg
|
||||
from forms import Form
|
||||
from model import User
|
||||
from util import *
|
||||
|
||||
sys_dir = "modules/installed/sys"
|
||||
|
||||
|
||||
class Sys(PagePlugin):
|
||||
order = 10
|
||||
def __init__(self, *args, **kwargs):
|
||||
cfg.log("!!!!!!!!!!!!!!!!!!!!")
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
self.register_page("sys")
|
||||
self.menu = cfg.main_menu.add_item(_("%s System" % cfg.product_name), "/sys", 100)
|
||||
self.menu.add_item(_("Configure"), "/sys/config", 10)
|
||||
self.menu.add_item(_("Package Manager"), "/sys/packages", 20)
|
||||
self.menu.add_item(_("Users and Groups"), "/sys/users", 15)
|
||||
|
||||
@cherrypy.expose
|
||||
def index(self):
|
||||
return self.fill_template(title=_("System Configuration"), main=_("""
|
||||
<p>In this section, you can control the %(product)s's
|
||||
underlying system, as opposed to its various applications and
|
||||
services. These options affect the %(product)s at its most
|
||||
general level. This is where you add/remove users, install
|
||||
applications, reboot, etc.</p>
|
||||
""" % {'product':cfg.product_name}))
|
||||
|
||||
@cherrypy.expose
|
||||
@require()
|
||||
def packages(self):
|
||||
side=_("""
|
||||
<h2>Help</h2>
|
||||
<p>On this page, you can add or remove %s plugins to your %s.</p>
|
||||
<p>Plugins are just Debian packages, so Debian's usual package management features should make this job fairly easy.</p>
|
||||
""" % (cfg.product_name, cfg.box_name))
|
||||
return self.fill_template(title=_("Add/Remove Plugins"), main=_("""
|
||||
<p>aptitude purge modules</p>
|
||||
<p>aptitude install modules</p>
|
||||
<p>The modules should depend on the appropriate Debian packages.</p>"""),
|
||||
sidebar_right=side)
|
||||
|
||||
@@ -0,0 +1,572 @@
|
||||
[
|
||||
"Africa/Abidjan",
|
||||
"Africa/Accra",
|
||||
"Africa/Addis_Ababa",
|
||||
"Africa/Algiers",
|
||||
"Africa/Asmara",
|
||||
"Africa/Asmera",
|
||||
"Africa/Bamako",
|
||||
"Africa/Bangui",
|
||||
"Africa/Banjul",
|
||||
"Africa/Bissau",
|
||||
"Africa/Blantyre",
|
||||
"Africa/Brazzaville",
|
||||
"Africa/Bujumbura",
|
||||
"Africa/Cairo",
|
||||
"Africa/Casablanca",
|
||||
"Africa/Ceuta",
|
||||
"Africa/Conakry",
|
||||
"Africa/Dakar",
|
||||
"Africa/Dar_es_Salaam",
|
||||
"Africa/Djibouti",
|
||||
"Africa/Douala",
|
||||
"Africa/El_Aaiun",
|
||||
"Africa/Freetown",
|
||||
"Africa/Gaborone",
|
||||
"Africa/Harare",
|
||||
"Africa/Johannesburg",
|
||||
"Africa/Kampala",
|
||||
"Africa/Khartoum",
|
||||
"Africa/Kigali",
|
||||
"Africa/Kinshasa",
|
||||
"Africa/Lagos",
|
||||
"Africa/Libreville",
|
||||
"Africa/Lome",
|
||||
"Africa/Luanda",
|
||||
"Africa/Lubumbashi",
|
||||
"Africa/Lusaka",
|
||||
"Africa/Malabo",
|
||||
"Africa/Maputo",
|
||||
"Africa/Maseru",
|
||||
"Africa/Mbabane",
|
||||
"Africa/Mogadishu",
|
||||
"Africa/Monrovia",
|
||||
"Africa/Nairobi",
|
||||
"Africa/Ndjamena",
|
||||
"Africa/Niamey",
|
||||
"Africa/Nouakchott",
|
||||
"Africa/Ouagadougou",
|
||||
"Africa/Porto-Novo",
|
||||
"Africa/Sao_Tome",
|
||||
"Africa/Timbuktu",
|
||||
"Africa/Tripoli",
|
||||
"Africa/Tunis",
|
||||
"Africa/Windhoek",
|
||||
"America/Adak",
|
||||
"America/Anchorage",
|
||||
"America/Anguilla",
|
||||
"America/Antigua",
|
||||
"America/Araguaina",
|
||||
"America/Argentina/Buenos_Aires",
|
||||
"America/Argentina/Catamarca",
|
||||
"America/Argentina/ComodRivadavia",
|
||||
"America/Argentina/Cordoba",
|
||||
"America/Argentina/Jujuy",
|
||||
"America/Argentina/La_Rioja",
|
||||
"America/Argentina/Mendoza",
|
||||
"America/Argentina/Rio_Gallegos",
|
||||
"America/Argentina/Salta",
|
||||
"America/Argentina/San_Juan",
|
||||
"America/Argentina/San_Luis",
|
||||
"America/Argentina/Tucuman",
|
||||
"America/Argentina/Ushuaia",
|
||||
"America/Aruba",
|
||||
"America/Asuncion",
|
||||
"America/Atikokan",
|
||||
"America/Atka",
|
||||
"America/Bahia",
|
||||
"America/Bahia_Banderas",
|
||||
"America/Barbados",
|
||||
"America/Belem",
|
||||
"America/Belize",
|
||||
"America/Blanc-Sablon",
|
||||
"America/Boa_Vista",
|
||||
"America/Bogota",
|
||||
"America/Boise",
|
||||
"America/Buenos_Aires",
|
||||
"America/Cambridge_Bay",
|
||||
"America/Campo_Grande",
|
||||
"America/Cancun",
|
||||
"America/Caracas",
|
||||
"America/Catamarca",
|
||||
"America/Cayenne",
|
||||
"America/Cayman",
|
||||
"America/Chicago",
|
||||
"America/Chihuahua",
|
||||
"America/Coral_Harbour",
|
||||
"America/Cordoba",
|
||||
"America/Costa_Rica",
|
||||
"America/Cuiaba",
|
||||
"America/Curacao",
|
||||
"America/Danmarkshavn",
|
||||
"America/Dawson",
|
||||
"America/Dawson_Creek",
|
||||
"America/Denver",
|
||||
"America/Detroit",
|
||||
"America/Dominica",
|
||||
"America/Edmonton",
|
||||
"America/Eirunepe",
|
||||
"America/El_Salvador",
|
||||
"America/Ensenada",
|
||||
"America/Fort_Wayne",
|
||||
"America/Fortaleza",
|
||||
"America/Glace_Bay",
|
||||
"America/Godthab",
|
||||
"America/Goose_Bay",
|
||||
"America/Grand_Turk",
|
||||
"America/Grenada",
|
||||
"America/Guadeloupe",
|
||||
"America/Guatemala",
|
||||
"America/Guayaquil",
|
||||
"America/Guyana",
|
||||
"America/Halifax",
|
||||
"America/Havana",
|
||||
"America/Hermosillo",
|
||||
"America/Indiana/Indianapolis",
|
||||
"America/Indiana/Knox",
|
||||
"America/Indiana/Marengo",
|
||||
"America/Indiana/Petersburg",
|
||||
"America/Indiana/Tell_City",
|
||||
"America/Indiana/Vevay",
|
||||
"America/Indiana/Vincennes",
|
||||
"America/Indiana/Winamac",
|
||||
"America/Indianapolis",
|
||||
"America/Inuvik",
|
||||
"America/Iqaluit",
|
||||
"America/Jamaica",
|
||||
"America/Jujuy",
|
||||
"America/Juneau",
|
||||
"America/Kentucky/Louisville",
|
||||
"America/Kentucky/Monticello",
|
||||
"America/Knox_IN",
|
||||
"America/La_Paz",
|
||||
"America/Lima",
|
||||
"America/Los_Angeles",
|
||||
"America/Louisville",
|
||||
"America/Maceio",
|
||||
"America/Managua",
|
||||
"America/Manaus",
|
||||
"America/Marigot",
|
||||
"America/Martinique",
|
||||
"America/Matamoros",
|
||||
"America/Mazatlan",
|
||||
"America/Mendoza",
|
||||
"America/Menominee",
|
||||
"America/Merida",
|
||||
"America/Mexico_City",
|
||||
"America/Miquelon",
|
||||
"America/Moncton",
|
||||
"America/Monterrey",
|
||||
"America/Montevideo",
|
||||
"America/Montreal",
|
||||
"America/Montserrat",
|
||||
"America/Nassau",
|
||||
"America/New_York",
|
||||
"America/Nipigon",
|
||||
"America/Nome",
|
||||
"America/Noronha",
|
||||
"America/North_Dakota/Center",
|
||||
"America/North_Dakota/New_Salem",
|
||||
"America/Ojinaga",
|
||||
"America/Panama",
|
||||
"America/Pangnirtung",
|
||||
"America/Paramaribo",
|
||||
"America/Phoenix",
|
||||
"America/Port-au-Prince",
|
||||
"America/Port_of_Spain",
|
||||
"America/Porto_Acre",
|
||||
"America/Porto_Velho",
|
||||
"America/Puerto_Rico",
|
||||
"America/Rainy_River",
|
||||
"America/Rankin_Inlet",
|
||||
"America/Recife",
|
||||
"America/Regina",
|
||||
"America/Resolute",
|
||||
"America/Rio_Branco",
|
||||
"America/Rosario",
|
||||
"America/Santa_Isabel",
|
||||
"America/Santarem",
|
||||
"America/Santiago",
|
||||
"America/Santo_Domingo",
|
||||
"America/Sao_Paulo",
|
||||
"America/Scoresbysund",
|
||||
"America/Shiprock",
|
||||
"America/St_Barthelemy",
|
||||
"America/St_Johns",
|
||||
"America/St_Kitts",
|
||||
"America/St_Lucia",
|
||||
"America/St_Thomas",
|
||||
"America/St_Vincent",
|
||||
"America/Swift_Current",
|
||||
"America/Tegucigalpa",
|
||||
"America/Thule",
|
||||
"America/Thunder_Bay",
|
||||
"America/Tijuana",
|
||||
"America/Toronto",
|
||||
"America/Tortola",
|
||||
"America/Vancouver",
|
||||
"America/Virgin",
|
||||
"America/Whitehorse",
|
||||
"America/Winnipeg",
|
||||
"America/Yakutat",
|
||||
"America/Yellowknife",
|
||||
"Antarctica/Casey",
|
||||
"Antarctica/Davis",
|
||||
"Antarctica/DumontDUrville",
|
||||
"Antarctica/Macquarie",
|
||||
"Antarctica/Mawson",
|
||||
"Antarctica/McMurdo",
|
||||
"Antarctica/Palmer",
|
||||
"Antarctica/Rothera",
|
||||
"Antarctica/South_Pole",
|
||||
"Antarctica/Syowa",
|
||||
"Antarctica/Vostok",
|
||||
"Arctic/Longyearbyen",
|
||||
"Asia/Aden",
|
||||
"Asia/Almaty",
|
||||
"Asia/Amman",
|
||||
"Asia/Anadyr",
|
||||
"Asia/Aqtau",
|
||||
"Asia/Aqtobe",
|
||||
"Asia/Ashgabat",
|
||||
"Asia/Ashkhabad",
|
||||
"Asia/Baghdad",
|
||||
"Asia/Bahrain",
|
||||
"Asia/Baku",
|
||||
"Asia/Bangkok",
|
||||
"Asia/Beirut",
|
||||
"Asia/Bishkek",
|
||||
"Asia/Brunei",
|
||||
"Asia/Calcutta",
|
||||
"Asia/Choibalsan",
|
||||
"Asia/Chongqing",
|
||||
"Asia/Chungking",
|
||||
"Asia/Colombo",
|
||||
"Asia/Dacca",
|
||||
"Asia/Damascus",
|
||||
"Asia/Dhaka",
|
||||
"Asia/Dili",
|
||||
"Asia/Dubai",
|
||||
"Asia/Dushanbe",
|
||||
"Asia/Gaza",
|
||||
"Asia/Harbin",
|
||||
"Asia/Ho_Chi_Minh",
|
||||
"Asia/Hong_Kong",
|
||||
"Asia/Hovd",
|
||||
"Asia/Irkutsk",
|
||||
"Asia/Istanbul",
|
||||
"Asia/Jakarta",
|
||||
"Asia/Jayapura",
|
||||
"Asia/Jerusalem",
|
||||
"Asia/Kabul",
|
||||
"Asia/Kamchatka",
|
||||
"Asia/Karachi",
|
||||
"Asia/Kashgar",
|
||||
"Asia/Kathmandu",
|
||||
"Asia/Katmandu",
|
||||
"Asia/Kolkata",
|
||||
"Asia/Krasnoyarsk",
|
||||
"Asia/Kuala_Lumpur",
|
||||
"Asia/Kuching",
|
||||
"Asia/Kuwait",
|
||||
"Asia/Macao",
|
||||
"Asia/Macau",
|
||||
"Asia/Magadan",
|
||||
"Asia/Makassar",
|
||||
"Asia/Manila",
|
||||
"Asia/Muscat",
|
||||
"Asia/Nicosia",
|
||||
"Asia/Novokuznetsk",
|
||||
"Asia/Novosibirsk",
|
||||
"Asia/Omsk",
|
||||
"Asia/Oral",
|
||||
"Asia/Phnom_Penh",
|
||||
"Asia/Pontianak",
|
||||
"Asia/Pyongyang",
|
||||
"Asia/Qatar",
|
||||
"Asia/Qyzylorda",
|
||||
"Asia/Rangoon",
|
||||
"Asia/Riyadh",
|
||||
"Asia/Riyadh87",
|
||||
"Asia/Riyadh88",
|
||||
"Asia/Riyadh89",
|
||||
"Asia/Saigon",
|
||||
"Asia/Sakhalin",
|
||||
"Asia/Samarkand",
|
||||
"Asia/Seoul",
|
||||
"Asia/Shanghai",
|
||||
"Asia/Singapore",
|
||||
"Asia/Taipei",
|
||||
"Asia/Tashkent",
|
||||
"Asia/Tbilisi",
|
||||
"Asia/Tehran",
|
||||
"Asia/Tel_Aviv",
|
||||
"Asia/Thimbu",
|
||||
"Asia/Thimphu",
|
||||
"Asia/Tokyo",
|
||||
"Asia/Ujung_Pandang",
|
||||
"Asia/Ulaanbaatar",
|
||||
"Asia/Ulan_Bator",
|
||||
"Asia/Urumqi",
|
||||
"Asia/Vientiane",
|
||||
"Asia/Vladivostok",
|
||||
"Asia/Yakutsk",
|
||||
"Asia/Yekaterinburg",
|
||||
"Asia/Yerevan",
|
||||
"Atlantic/Azores",
|
||||
"Atlantic/Bermuda",
|
||||
"Atlantic/Canary",
|
||||
"Atlantic/Cape_Verde",
|
||||
"Atlantic/Faeroe",
|
||||
"Atlantic/Faroe",
|
||||
"Atlantic/Jan_Mayen",
|
||||
"Atlantic/Madeira",
|
||||
"Atlantic/Reykjavik",
|
||||
"Atlantic/South_Georgia",
|
||||
"Atlantic/St_Helena",
|
||||
"Atlantic/Stanley",
|
||||
"Australia/ACT",
|
||||
"Australia/Adelaide",
|
||||
"Australia/Brisbane",
|
||||
"Australia/Broken_Hill",
|
||||
"Australia/Canberra",
|
||||
"Australia/Currie",
|
||||
"Australia/Darwin",
|
||||
"Australia/Eucla",
|
||||
"Australia/Hobart",
|
||||
"Australia/LHI",
|
||||
"Australia/Lindeman",
|
||||
"Australia/Lord_Howe",
|
||||
"Australia/Melbourne",
|
||||
"Australia/NSW",
|
||||
"Australia/North",
|
||||
"Australia/Perth",
|
||||
"Australia/Queensland",
|
||||
"Australia/South",
|
||||
"Australia/Sydney",
|
||||
"Australia/Tasmania",
|
||||
"Australia/Victoria",
|
||||
"Australia/West",
|
||||
"Australia/Yancowinna",
|
||||
"Brazil/Acre",
|
||||
"Brazil/DeNoronha",
|
||||
"Brazil/East",
|
||||
"Brazil/West",
|
||||
"CET",
|
||||
"CST6CDT",
|
||||
"Canada/Atlantic",
|
||||
"Canada/Central",
|
||||
"Canada/East-Saskatchewan",
|
||||
"Canada/Eastern",
|
||||
"Canada/Mountain",
|
||||
"Canada/Newfoundland",
|
||||
"Canada/Pacific",
|
||||
"Canada/Saskatchewan",
|
||||
"Canada/Yukon",
|
||||
"Chile/Continental",
|
||||
"Chile/EasterIsland",
|
||||
"Cuba",
|
||||
"EET",
|
||||
"EST",
|
||||
"EST5EDT",
|
||||
"Egypt",
|
||||
"Eire",
|
||||
"Etc/GMT",
|
||||
"Etc/GMT+0",
|
||||
"Etc/GMT+1",
|
||||
"Etc/GMT+10",
|
||||
"Etc/GMT+11",
|
||||
"Etc/GMT+12",
|
||||
"Etc/GMT+2",
|
||||
"Etc/GMT+3",
|
||||
"Etc/GMT+4",
|
||||
"Etc/GMT+5",
|
||||
"Etc/GMT+6",
|
||||
"Etc/GMT+7",
|
||||
"Etc/GMT+8",
|
||||
"Etc/GMT+9",
|
||||
"Etc/GMT-0",
|
||||
"Etc/GMT-1",
|
||||
"Etc/GMT-10",
|
||||
"Etc/GMT-11",
|
||||
"Etc/GMT-12",
|
||||
"Etc/GMT-13",
|
||||
"Etc/GMT-14",
|
||||
"Etc/GMT-2",
|
||||
"Etc/GMT-3",
|
||||
"Etc/GMT-4",
|
||||
"Etc/GMT-5",
|
||||
"Etc/GMT-6",
|
||||
"Etc/GMT-7",
|
||||
"Etc/GMT-8",
|
||||
"Etc/GMT-9",
|
||||
"Etc/GMT0",
|
||||
"Etc/Greenwich",
|
||||
"Etc/UCT",
|
||||
"Etc/UTC",
|
||||
"Etc/Universal",
|
||||
"Etc/Zulu",
|
||||
"Europe/Amsterdam",
|
||||
"Europe/Andorra",
|
||||
"Europe/Athens",
|
||||
"Europe/Belfast",
|
||||
"Europe/Belgrade",
|
||||
"Europe/Berlin",
|
||||
"Europe/Bratislava",
|
||||
"Europe/Brussels",
|
||||
"Europe/Bucharest",
|
||||
"Europe/Budapest",
|
||||
"Europe/Chisinau",
|
||||
"Europe/Copenhagen",
|
||||
"Europe/Dublin",
|
||||
"Europe/Gibraltar",
|
||||
"Europe/Guernsey",
|
||||
"Europe/Helsinki",
|
||||
"Europe/Isle_of_Man",
|
||||
"Europe/Istanbul",
|
||||
"Europe/Jersey",
|
||||
"Europe/Kaliningrad",
|
||||
"Europe/Kiev",
|
||||
"Europe/Lisbon",
|
||||
"Europe/Ljubljana",
|
||||
"Europe/London",
|
||||
"Europe/Luxembourg",
|
||||
"Europe/Madrid",
|
||||
"Europe/Malta",
|
||||
"Europe/Mariehamn",
|
||||
"Europe/Minsk",
|
||||
"Europe/Monaco",
|
||||
"Europe/Moscow",
|
||||
"Europe/Nicosia",
|
||||
"Europe/Oslo",
|
||||
"Europe/Paris",
|
||||
"Europe/Podgorica",
|
||||
"Europe/Prague",
|
||||
"Europe/Riga",
|
||||
"Europe/Rome",
|
||||
"Europe/Samara",
|
||||
"Europe/San_Marino",
|
||||
"Europe/Sarajevo",
|
||||
"Europe/Simferopol",
|
||||
"Europe/Skopje",
|
||||
"Europe/Sofia",
|
||||
"Europe/Stockholm",
|
||||
"Europe/Tallinn",
|
||||
"Europe/Tirane",
|
||||
"Europe/Tiraspol",
|
||||
"Europe/Uzhgorod",
|
||||
"Europe/Vaduz",
|
||||
"Europe/Vatican",
|
||||
"Europe/Vienna",
|
||||
"Europe/Vilnius",
|
||||
"Europe/Volgograd",
|
||||
"Europe/Warsaw",
|
||||
"Europe/Zagreb",
|
||||
"Europe/Zaporozhye",
|
||||
"Europe/Zurich",
|
||||
"GB",
|
||||
"GB-Eire",
|
||||
"GMT",
|
||||
"GMT+0",
|
||||
"Greenwich",
|
||||
"HST",
|
||||
"Hongkong",
|
||||
"Iceland",
|
||||
"Indian/Antananarivo",
|
||||
"Indian/Chagos",
|
||||
"Indian/Christmas",
|
||||
"Indian/Cocos",
|
||||
"Indian/Comoro",
|
||||
"Indian/Kerguelen",
|
||||
"Indian/Mahe",
|
||||
"Indian/Maldives",
|
||||
"Indian/Mauritius",
|
||||
"Indian/Mayotte",
|
||||
"Indian/Reunion",
|
||||
"Iran",
|
||||
"Israel",
|
||||
"Jamaica",
|
||||
"Japan",
|
||||
"Kwajalein",
|
||||
"Libya",
|
||||
"MET",
|
||||
"MST",
|
||||
"MST7MDT",
|
||||
"Mexico/BajaNorte",
|
||||
"Mexico/BajaSur",
|
||||
"Mexico/General",
|
||||
"Mideast/Riyadh87",
|
||||
"Mideast/Riyadh88",
|
||||
"Mideast/Riyadh89",
|
||||
"NZ",
|
||||
"NZ-CHAT",
|
||||
"Navajo",
|
||||
"PRC",
|
||||
"PST8PDT",
|
||||
"Pacific/Apia",
|
||||
"Pacific/Auckland",
|
||||
"Pacific/Chatham",
|
||||
"Pacific/Chuuk",
|
||||
"Pacific/Easter",
|
||||
"Pacific/Efate",
|
||||
"Pacific/Enderbury",
|
||||
"Pacific/Fakaofo",
|
||||
"Pacific/Fiji",
|
||||
"Pacific/Funafuti",
|
||||
"Pacific/Galapagos",
|
||||
"Pacific/Gambier",
|
||||
"Pacific/Guadalcanal",
|
||||
"Pacific/Guam",
|
||||
"Pacific/Honolulu",
|
||||
"Pacific/Johnston",
|
||||
"Pacific/Kiritimati",
|
||||
"Pacific/Kosrae",
|
||||
"Pacific/Kwajalein",
|
||||
"Pacific/Majuro",
|
||||
"Pacific/Marquesas",
|
||||
"Pacific/Midway",
|
||||
"Pacific/Nauru",
|
||||
"Pacific/Niue",
|
||||
"Pacific/Norfolk",
|
||||
"Pacific/Noumea",
|
||||
"Pacific/Pago_Pago",
|
||||
"Pacific/Palau",
|
||||
"Pacific/Pitcairn",
|
||||
"Pacific/Pohnpei",
|
||||
"Pacific/Ponape",
|
||||
"Pacific/Port_Moresby",
|
||||
"Pacific/Rarotonga",
|
||||
"Pacific/Saipan",
|
||||
"Pacific/Samoa",
|
||||
"Pacific/Tahiti",
|
||||
"Pacific/Tarawa",
|
||||
"Pacific/Tongatapu",
|
||||
"Pacific/Truk",
|
||||
"Pacific/Wake",
|
||||
"Pacific/Wallis",
|
||||
"Pacific/Yap",
|
||||
"Poland",
|
||||
"Portugal",
|
||||
"ROC",
|
||||
"ROK",
|
||||
"Singapore",
|
||||
"Turkey",
|
||||
"UCT",
|
||||
"US/Alaska",
|
||||
"US/Aleutian",
|
||||
"US/Arizona",
|
||||
"US/Central",
|
||||
"US/East-Indiana",
|
||||
"US/Eastern",
|
||||
"US/Hawaii",
|
||||
"US/Indiana-Starke",
|
||||
"US/Michigan",
|
||||
"US/Mountain",
|
||||
"US/Pacific",
|
||||
"US/Pacific-New",
|
||||
"US/Samoa",
|
||||
"UTC",
|
||||
"Universal",
|
||||
"W-SU",
|
||||
"Zulu"
|
||||
]
|
||||
@@ -0,0 +1,127 @@
|
||||
import os, cherrypy
|
||||
from gettext import gettext as _
|
||||
from auth import require
|
||||
from plugin_mount import PagePlugin, FormPlugin
|
||||
import cfg
|
||||
from forms import Form
|
||||
from util import *
|
||||
|
||||
class users(PagePlugin):
|
||||
def __init__(self, *args, **kwargs):
|
||||
PagePlugin.__init__(self, *args, **kwargs)
|
||||
self.register_page("sys.users")
|
||||
|
||||
@cherrypy.expose
|
||||
@require()
|
||||
def index(self):
|
||||
parts = self.forms('/sys/config')
|
||||
parts['title']=_("Manage Users and Groups")
|
||||
return self.fill_template(**parts)
|
||||
|
||||
class add(FormPlugin, PagePlugin):
|
||||
url = ["/sys/users"]
|
||||
order = 30
|
||||
|
||||
sidebar_left = ''
|
||||
sidebar_right = _("""<h2>Add User</h2><p>Adding a user via this
|
||||
administrative interface <b>might</b> create a system user.
|
||||
For example, if you provide a user with ssh access, she will
|
||||
need a system account. If you don't know what that means,
|
||||
don't worry about it.</p>""")
|
||||
|
||||
def main(self, username='', name='', email='', message=None, *args, **kwargs):
|
||||
form = Form(title="Add User",
|
||||
action="/sys/users/add/index",
|
||||
onsubmit="return md5ify('add_user_form', 'password')",
|
||||
name="add_user_form",
|
||||
message=message)
|
||||
form.text = '<script type="text/javascript" src="/static/js/md5.js"></script>\n'+form.text
|
||||
form.text_input(_("Username"), name="username", value=username)
|
||||
form.text_input(_("Full name"), name="name", value=name)
|
||||
form.text_input(_("Email"), name="email", value=email)
|
||||
form.text_input(_("Password"), name="password")
|
||||
form.text_input(name="md5_password", type="hidden")
|
||||
form.submit(label=_("Create User"), name="create")
|
||||
return form.render()
|
||||
|
||||
def process_form(self, username=None, name=None, email=None, md5_password=None, **kwargs):
|
||||
msg = ''
|
||||
|
||||
if not username: msg = add_message(msg, _("Must specify a username!"))
|
||||
if not md5_password: msg = add_message(msg, _("Must specify a password!"))
|
||||
|
||||
if cfg.users.get(username):
|
||||
msg = add_message(msg, _("User already exists!"))
|
||||
else:
|
||||
try:
|
||||
cfg.users.set(User(dict={'username':username, 'name':name, 'email':email, 'password':md5_password}))
|
||||
except:
|
||||
msg = add_message(msg, _("Error storing user!"))
|
||||
|
||||
if not msg:
|
||||
msg = add_message(msg, "%s saved." % username)
|
||||
|
||||
main = self.make_form(username, name, email, message=msg)
|
||||
return self.fill_template(title="", main=main, sidebar_left=self.sidebar_left, sidebar_right=self.sidebar_right)
|
||||
|
||||
class edit(FormPlugin, PagePlugin):
|
||||
url = ["/sys/users"]
|
||||
order = 35
|
||||
|
||||
sidebar_left = ''
|
||||
sidebar_right = _("""<h2>Edit Users</h2><p>Click on a user's name to
|
||||
go to a screen for editing that user's account.</p><h2>Delete
|
||||
Users</h2><p>Check the box next to a users' names and then click
|
||||
"Delete User" to remove users from %s and the %s
|
||||
system.</p><p>Deleting users is permanent!</p>""" % (cfg.product_name, cfg.box_name))
|
||||
|
||||
def main(self, msg=''):
|
||||
users = cfg.users.get_all()
|
||||
add_form = Form(title=_("Edit or Delete User"), action="/sys/users/edit", message=msg)
|
||||
add_form.html('<span class="indent"><b>Delete</b><br /></span>')
|
||||
for uname in sorted(users.keys()):
|
||||
add_form.html('<span class="indent"> %s ' %
|
||||
add_form.get_checkbox(name=uname) +
|
||||
'<a href="/sys/users/edit?username=%s">%s (%s)</a><br /></span>' %
|
||||
(uname, users[uname]['name'], uname))
|
||||
add_form.submit(label=_("Delete User"), name="delete")
|
||||
return add_form.render()
|
||||
|
||||
def process_form(self, **kwargs):
|
||||
if 'delete' in kwargs:
|
||||
msg = Message()
|
||||
usernames = find_keys(kwargs, 'on')
|
||||
cfg.log.info("%s asked to delete %s" % (cherrypy.session.get(cfg.session_key), usernames))
|
||||
if usernames:
|
||||
for username in usernames:
|
||||
if cfg.users.exists(username):
|
||||
try:
|
||||
cfg.users.remove(username)
|
||||
msg.add(_("Deleted user %s." % username))
|
||||
except IOError, e:
|
||||
if cfg.users.get('username', reload=True):
|
||||
m = _("Error on deletion, user %s not fully deleted: %s" % (username, e))
|
||||
cfg.log.error(m)
|
||||
msg.add(m)
|
||||
else:
|
||||
m = _('Deletion failed on %s: %s' % (username, e))
|
||||
cfg.log.error(m)
|
||||
msg.add(m)
|
||||
else:
|
||||
cfg.log.warning(_("Can't delete %s. User does not exist." % username))
|
||||
msg.add(_("User %s does not exist." % username))
|
||||
else:
|
||||
msg.add = _("Must specify at least one valid, existing user.")
|
||||
main = self.make_form(msg=msg.text)
|
||||
return self.fill_template(title="", main=main, sidebar_left=self.sidebar_left, sidebar_right=self.sidebar_right)
|
||||
|
||||
sidebar_right = ''
|
||||
u = cfg.users.get(kwargs['username'])
|
||||
if not u:
|
||||
main = _("<p>Could not find a user with username of %s!</p>" % kwargs['username'])
|
||||
return self.fill_template(template="err", title=_("Unnown User"), main=main,
|
||||
sidebar_left=self.sidebar_left, sidebar_right=sidebar_right)
|
||||
|
||||
main = _("""<h2>Edit User '%s'</h2>""" % u['username'])
|
||||
sidebar_right = ''
|
||||
return self.fill_template(title="", main=main, sidebar_left=self.sidebar_left, sidebar_right=sidebar_right)
|
||||
@@ -0,0 +1,73 @@
|
||||
import os
|
||||
import cherrypy
|
||||
import simplejson as json
|
||||
from gettext import gettext as _
|
||||
from filedict import FileDict
|
||||
from modules.auth import require
|
||||
from plugin_mount import PagePlugin, FormPlugin
|
||||
import cfg
|
||||
from forms import Form
|
||||
from model import User
|
||||
from util import *
|
||||
|
||||
class wan(FormPlugin, PagePlugin):
|
||||
url = ["/sys/config"]
|
||||
order = 20
|
||||
|
||||
def help(self, *args, **kwargs):
|
||||
if not cfg.users.expert():
|
||||
return ''
|
||||
return _(#"""<h4>Admin from WAN</h4>
|
||||
"""<p>If you check this box, this front
|
||||
end will be reachable from the WAN. If your %(box)s
|
||||
connects you to the internet, that means you'll be able to log
|
||||
in to the front end from the internet. This might be
|
||||
convenient, but it is also <b>dangerous</b>, since it can
|
||||
enable attackers to gain access to your %(box)s from the
|
||||
outside world. All they'll need is your username and
|
||||
passphrase, which they might guess or they might simply try
|
||||
every posible combination of letters and numbers until they
|
||||
get in. If you enable the WAN administration option, you
|
||||
<b>must</b> use long and complex passphrases.</p>
|
||||
|
||||
<p>For security reasons, neither WAN Administration nor WAN
|
||||
SSH is available to the `admin` user account.</p>
|
||||
|
||||
<p>TODO: in expert mode, tell user they can ssh in to enable
|
||||
admin from WAN, do their business, then disable it. It would
|
||||
be good to enable the option and autodisable it when the ssh
|
||||
connection dies.</p>
|
||||
""" % {'product':cfg.product_name, 'box':cfg.box_name})
|
||||
|
||||
def main(self, message='', **kwargs):
|
||||
store = filedict_con(cfg.store_file, 'sys')
|
||||
|
||||
defaults = {'wan_admin': "''",
|
||||
'wan_ssh': "''",
|
||||
'lan_ssh': "''",
|
||||
}
|
||||
for k,c in defaults.items():
|
||||
if not k in kwargs:
|
||||
try:
|
||||
kwargs[k] = store[k]
|
||||
except KeyError:
|
||||
exec("if not '%(k)s' in kwargs: store['%(k)s'] = kwargs['%(k)s'] = %(c)s" % {'k':k, 'c':c})
|
||||
|
||||
form = Form(title=_("Accessing the %s" % cfg.box_name),
|
||||
action="/sys/config/wan",
|
||||
name="admin_wan_form",
|
||||
message=message )
|
||||
form.html(self.help())
|
||||
if cfg.users.expert():
|
||||
form.checkbox(_("Allow access to Plinth from WAN"), name="wan_admin", checked=kwargs['wan_admin'])
|
||||
form.checkbox(_("Allow SSH access from LAN"), name="lan_ssh", checked=kwargs['lan_ssh'])
|
||||
form.checkbox(_("Allow SSH access from WAN"), name="wan_ssh", checked=kwargs['wan_ssh'])
|
||||
form.submit(_("Submit"))
|
||||
return form.render()
|
||||
|
||||
def process_form(self, wan_admin='', wan_ssh='', lan_ssh='', *args, **kwargs):
|
||||
store = filedict_con(cfg.store_file, 'sys')
|
||||
for field in ['wan_admin', 'wan_ssh', 'lan_ssh']:
|
||||
exec("store['%s'] = %s" % (field, field))
|
||||
return "Settings updated."
|
||||
|
||||
Reference in new issue
Block a user