mandriva server setup documentation · mandriva server setup documentation, release 2.0 mandriva...

29
Mandriva Server Setup Documentation Release 2.0 Jean-Philippe Braun November 13, 2014

Upload: others

Post on 14-Aug-2020

57 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup DocumentationRelease 2.0

Jean-Philippe Braun

November 13, 2014

Page 2: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux
Page 3: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Contents

1 Contents 31.1 MSS architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Module description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.3 Module desc.json examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.4 Module __init__.py examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151.5 Internationalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

2 Indices and tables 23

i

Page 4: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

ii

Page 5: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux OS.

Mandriva Server Setup was primarely designed for Mandriva Enterprise Server in order to quickly configure systemservices like Mandriva Directory Server.

The use of MSS is simple. MSS act like a wizard and follow simple steps :

1. selection of a component

2. display some pre-installation text

3. add medias with or without authentication (optional)

4. install packages

5. let the user input some configuration info (optional)

6. launch a configuration script using the user’s configuration (optional)

Contents 1

Page 6: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

2 Contents

Page 7: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

CHAPTER 1

Contents

1.1 MSS architecture

MSS is composed of two parts :

1. a XML-RPC agent which execute commands on the computers and manipulate the data. The agent is written inPython.

2. a webserver providing an interface to control the XML-RPC agent. The webserver is cherrypy and the interfaceis written with Django.

1.1.1 MSS XML-RPC agent (mss.agent python package)

The XML-RPC agent handles all the modules that can be installed through MSS. A module is the description of acomponent you would like to install and configure in the MSS interface.

A module is characterized by :

1. name

2. description

3. rpm packages

4. medias to add in order to install the packages

5. dependencies with other MSS modules

6. conflicts with other MSS modules

7. configuration fields for user input

8. a shell script to do the configuration

Most of this information is written in an JSON file. For example, this is the description of the mysql module:

{"slug": "mysql","name": "MySQL database","description": "MySQL relational database","packages": [

{"name": "all","rpms": ["mysql", "mysql-client"]

}

3

Page 8: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

],"conflict": ["mysqlmax"],"config": [

{"type": "password","name": "current_mypasswd","show": "configured","label": "Current password","help": "Current MySQL root password."

},{

"type": "password","name": "mypasswd","require": "yes","label": "New password","help": "New MySQL root password. Set here the new password"

}],"standalone": false

}

For mor detailled info check Module description

1.1.2 MSS web interface (mss.www python package)

The MSS web interface is served by the cherrypy webserver. Django is used on top of cherrypy as it provides nicefeatures for templating, url naming, internationalization, authentication backends in a modular approach.

1.2 Module description

The stock modules are located in the modules directory.

Each module directory contains:

• a JSON file describing the module, desc.json

• an __init__.py file because a module is also a python module

• some python functions to retrieve the current configuration in the __init__.py file (optional)

• gettext files

• a setup script (optional)

• templates files used by the setup script (optional)

1.2.1 The desc.json file

For full examples of the desc.json file check-out the Module desc.json examples page.

Basic description

The module is identified by its slug. Basically it uses the same name of the module’s directory.

4 Chapter 1. Contents

Page 9: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

{"slug": "module1","name": "My module","description": "A great module",

Categorization and location

For the module to appear in the web client you need to set it’s section and optionnaly a category in this section.

"standalone": true,"categories": [

{"slug": "users","name": "Users"

}],"module": {

"section": "core"}

Sections are defined in modules/sections.json.

The module can be hidden when using standalone = false.

Actions

Action menu to display when the module has been configured. Currently only html links are supported.

"actions": [{

"type": "link","name": "Management interface","value": "https://@HOSTNAME@/mmc/main.php"

},{

"type": "link","name": "Webmail interface","value": "http://@HOSTNAME@/roundcubemail/"

}],

Repositories

MSS allows you to add repositories on the system to install packages.

• @slug: name used in the urmpi.cfg file

• @name: name displayed in the web interface when adding the repository

• @url: location of the repository

• @restricted: if repository need an HTTP authentication

• @options: options passed to the package manager when adding the media

@ARCH@ will be replaced by the machine arch (x86_64 or i586).

1.2. Module description 5

Page 10: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

"repositories": [{

"slug": "repo1","name": "Repository one","url": "http://mirror.mandriva.com/one/@ARCH@/","restricted": false,"options": "--updates"

},{

"slug": "repo2","name": "Repository two","url": "http://mirror.mandriva.com/two/@ARCH@/","restricted": true,"options": "--distrib"

}]

Packages

Your module may install some packages. The packages can be arch dependant.

• @name: i586 | x86_64 | all

"packages": [{

"name": "all","rpms": [

"openldap-servers","openldap-clients"

]},{

"name": "i686","rpms": [

"libsasl2-plug-gssapi"]

},{

"name": "x86_64","rpms": [

"lib64sasl2-plug-gssapi"]

}]

Conflicts

If the module conflicts with other modules in MSS.

"module": {"conflicts": ["module2"]

}

6 Chapter 1. Contents

Page 11: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

Dependencies

You can add dependencies with other modules. If some module is added as a dependency it will be installed andconfigured before the current module.

"module": {"dependencies": ["module34", "module23"]

}

Module configuration

The module configuration may need some information provided by the user. Several field can be used to gather theinformation needed to run a configuration script.

Configuration definition starts with :

"config": [

Then add some form fields.

Simple text field

• @name: field name

• @require: the field is mandatory (optional)

• @default: default value for the field - can be a string or a custom method (optional)

• @validation: fqdn | ip | custom method (validate the field data - optional)

• @label: verbose name of the field

• @help: verbose help for the field

{"type": "text","name": "server1","label": "Server 1 IP","help": "The first server IP address","require": "yes","default": "127.0.0.1","validation": "ip"

}

The custom method for validation or the default value must be declared in the module’s __init__.py file.

Password field

The generated form will add automatically a second password field to validate the password in the web client.

• @name: field name

• @require: the field is mandatory (optional)

• @default: default value for the field - can be a string or a custom method (optional)

1.2. Module description 7

Page 12: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

{"type": "password","name": "passwd","label": "Password","help": "The server password","require": "yes","default": ""

}

Multi text field

Same as a text field but with the multi option. Will allow the user to specify multiple value for this field.

{"type": "text","multi": "yes","name": "param1",...

}

Network field

This special field let the user input a network description (ip/netmask)

• @name: field name

• @format: long | short (/24 or /255.255.255.0 - format used in the config script)

• @default: default value for the field - can be a string or a custom method (optional)

• @validation: network (optional)

{"type": "network","name": "bind_networks","format": "short","validation": "network","default": "get_networks","label": "My networks","help": "Specify which networks are authorized to resolve external queries with your DNS server (recursion). eg: 192.168.0.0/255.255.255.0."

}

Select list field

• @name: field name

• @require: yes | no

• @options: list of values

{"type": "options","name": "popimap_proto","require": "yes","label": "Protocols supported","help": "Protocols that the dovecot server will provide.",

8 Chapter 1. Contents

Page 13: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

"options": [{ "name": "IMAPS and POP3S", "value": "imap imaps pop3 pop3s" },{ "name": "IMAPS", "value": "imaps imap" },{ "name": "POP3S", "value": "pop3s pop3" }

]}

Checkbox field

• @name: field name

• @default: on | off

{"type": "check","name": "fw_lan","default": "on","label": "Allow mail services access from internal networks","help": "Configure the firewall to accept smtp/imap/pop3 connections on interfaces configured as ’internal’"

}

For full examples of the desc.json file check-out the Module desc.json examples page.

1.2.2 The __init__.py file

Because a MSS module is also a python module, a __init__.py must be created. This file may contain two pythonfunctions related to the module configuration.

If the module has a configuration script, the function get_config_info() has to be declared.

get_config_info()Returns module script name and parameters

Return type tuple (“script name”, [”list”, “of”, “params”])

MSS use this function to get the name of the configuration script and the order of the parameters used to call thescript. The script name is relative to the module directory. The names of the parameters are the field names used inthe configuration description in desc.json.

If you want to retrieve the current configuration of the module when configuring the module you have to write aget_current_config() function.

get_current_config()Returns current configuration of the module

Return type dict { “param1”: value, “param2”: value, ... }

The values returned by this function replaces the default values set in in the configuration description in desc.json.Have a look in mds_* modules for some examples.

After a module is configured on MSS, the module is automatically tagged as configured in the MSS database. You canalso write a check_configured() function that tells MSS if the module is configured or not. This will overridethe database value.

check_configured()Returns module’s configuration state

Return type bool

1.2. Module description 9

Page 14: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

1.2.3 Dynamic configuration fields

If you want to generate configuration fields dynamically you can create a custom field in desc.json:

"config": [{

"type": "custom","name": "interfaces"

}]

Then in __init__.py write the get_<field_name>_config function to return the fields definition in python.A good example is in the network module. The method will create configuration fields for all network interfacesavailable on the host.

Example of mds_mmc module

Configuration definition in desc.json :

"config": [{

"type": "password","name": "mdspasswd","require": "yes","label": "Administrator password","help": "The administrator password of the web interface for managing MBS users and services."

},{

"type": "check","name": "fw_lan","default": "on","label": "Allow access from internal networks","help": "Configure the firewall to allow access to the web interface from internal networks"

},{

"type": "check","name": "fw_wan","default": "off","label": "Allow access from external networks","help": "Configure the firewall to allow access to the web interface from external networks"

}],

__init__.py file :

1 # -*- coding: UTF-8 -*-2 #3 # (c) 2010-2012 Mandriva, http://www.mandriva.com/4 #5 # This file is part of Mandriva Server Setup6 #7 # MSS is free software; you can redistribute it and/or modify8 # it under the terms of the GNU General Public License as published by9 # the Free Software Foundation; either version 2 of the License, or

10 # (at your option) any later version.11 #12 # MSS is distributed in the hope that it will be useful,13 # but WITHOUT ANY WARRANTY; without even the implied warranty of

10 Chapter 1. Contents

Page 15: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 # GNU General Public License for more details.16 #17 # You should have received a copy of the GNU General Public License18 # along with MSS; if not, write to the Free Software19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,20 # MA 02110-1301, USA.21

22 def get_config_info():23 return ("setup-mmc.sh", [’mdspasswd’, ’fw_lan’, ’fw_wan’])

1.2.4 The setup script and templates

To run modules configuration the MSS agent runs shell scripts as root in the background. The script name and itsparameters launch by MSS have to be declared in the get_config_info() function.

mds_webmail script example :

1 #!/bin/bash2 # Copyright Mandriva 2009, 2010 all rights reserved3

4 . ’../functions.sh’5

6 check_root7

8 fw_lan=$19 fw_wan=$2

10

11 roundcube_db_conf_template="templates/db.inc.php.tpl"12 roundcube_main_conf_template="templates/main.inc.php.tpl"13 mbs_logo="templates/mbs_logo.png"14

15 # copy the logo16 cp -f $mbs_logo /usr/share/roundcubemail/skins/17

18 # copy the db config19 backup /etc/roundcubemail/db.inc.php20 cat $roundcube_db_conf_template > /etc/roundcubemail/db.inc.php21

22 # setup the roundcube db23 if [ -f /var/lib/roundcubemail/sqlite.db ]; then24 rm -f /var/lib/roundcubemail/sqlite.db25 fi26 mkdir -p /var/lib/roundcubemail27 chown apache /var/lib/roundcubemail28 sqlite /var/lib/roundcubemail/sqlite.db < /usr/share/roundcubemail/SQL/sqlite.initial.sql29 chown apache:apache /var/lib/roundcubemail/sqlite.db30 chmod 0600 /var/lib/roundcubemail/sqlite.db31

32 # set correct permissions33 chown -R apache.apache /usr/share/roundcubemail/34 chown -R apache.apache /var/log/roundcubemail/35

36 # http -> https redirection37 https_redirect roundcubemail /etc/httpd/conf/webapps.d/roundcubemail.conf38

39 restart_service httpd

1.2. Module description 11

Page 16: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

40

41 # copy main config42 backup /etc/roundcubemail/main.inc.php43 cat $roundcube_main_conf_template > /etc/roundcubemail/main.inc.php44

45 # configure the Firewall46 [ $fw_lan == "on" ] && mss-add-shorewall-rule -a Web/ACCEPT -t lan47 [ $fw_wan == "on" ] && mss-add-shorewall-rule -a Web/ACCEPT -t wan48 restart_service shorewall49

50 info_b $"Webmail Roundcube is installed on your server."51 info $"You can access the webmail interface at https://@HOSTNAME@/roundcubemail/."

Script templates

The setup script may use some configuration file templates which are located in a templates directory in themodule’s directory.

Script output

MSS agent will capture all messages from stdout and stderr to display them in the web interface in real time when thescript runs. When the script ends a configuration summary with warnings and errors can be displayed to the user.

MSS checks every line in the script output to get a code corresponding to a message level. For example echo"8Webmail RoundCube is activated on your server." is a info level message that will be displayedin the configuration summary in bold.

Other codes :

• 1 : warning level code

• 2 : error level code

• 7 : info level code

• 8 : info level code (bold output)

Other messages won’t be displayed in the configuration summary but in the detailed output.

String replacement

MSS will replace some tags and patterns to have a better output

TAG / Pattern Replacement@HOSTNAME@ Replace with the server IP or name@BR@ Replace with html <br />@B@text@B@ Replace with <strong>text</strong>http://foo.com Replace with an html link

12 Chapter 1. Contents

Page 17: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

1.3 Module desc.json examples

1.3.1 mds_mmc module

{"slug": "mds_mmc","name": "MBS administration web interface","description": "Users and groups management","desc": "Users and groups management","categories": [

{"slug": "users","name": "Users"

}],"actions": [

{"type": "link","name": "Management interface","value": "https://@HOSTNAME@/mmc/main.php"

}],"packages": [

{"name": "all","rpms": [

"mmc-web-base","mmc-web-bulkimport","mmc-web-services","mmc-web-dashboard","mmc-web-shorewall","mmc-web-packages","python-mmc-base","python-mmc-bulkimport","python-mmc-services","python-mmc-dashboard","python-mmc-shorewall","python-mmc-packages","mmc-agent","openldap-servers","nss_ldap","openldap-clients","pam_ldap","openldap-mandriva-dit","apache-mod_ssl"

]}

],"config": [

{"type": "password","name": "mdspasswd","require": "yes","label": "Administrator password","help": "The administrator password of the web interface for managing MBS users and services."

},{

1.3. Module desc.json examples 13

Page 18: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

"type": "check","name": "fw_lan","default": "on","label": "Allow access from internal networks","help": "Configure the firewall to allow access to the web interface from internal networks"

},{

"type": "check","name": "fw_wan","default": "off","label": "Allow access from external networks","help": "Configure the firewall to allow access to the web interface from external networks"

}],"dependencies": ["system", "network"],"postinstall": {

"reboot": "yes"},"module": {

"section": "core","dependencies": ["system", "network"],"reboot": true

}}

1.3.2 mds_mail module

{"slug": "mds_mail","name": "Mail Service","description": "Complete mail service with POP/IMAP, anti-virus and anti-spam toolkits","desc": "Complete mail service with POP/IMAP, anti-virus and anti-spam toolkits","categories": [

{"slug": "mail","name": "Mail"

}],"actions": [

{"type": "link","name": "Management interface","value": "https://@HOSTNAME@/mmc/main.php"

}],"packages": [

{"name": "all","rpms": ["postfix",

"postfix-ldap","mmc-web-mail","python-mmc-mail","amavisd-new","spamassassin","spamassassin-tools","clamd","dovecot",

14 Chapter 1. Contents

Page 19: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

"dovecot-plugins-ldap","dovecot-plugins-sieve","dovecot-plugins-managesieve"]

}],"config": [

{"type": "network","name": "smtpd_mynetworks","format": "short","validation": "network","default": "get_networks","label": "My networks","help": "Specify which clients are authorized to send mails through the mail server without authentication."

},{

"type": "options","name": "popimap_proto","require": "yes","label": "Protocols supported","help": "Protocols that the dovecot server will provide.","options": [

{ "name": "IMAPS and POP3S", "value": "imap imaps pop3 pop3s" },{ "name": "IMAPS", "value": "imaps imap" },{ "name": "POP3S", "value": "pop3s pop3" }

]},{

"type": "check","name": "fw_lan","default": "on","label": "Allow mail services access from internal networks","help": "Configure the firewall to accept smtp/imap/pop3 connections on interfaces configured as ’internal’"

},{

"type": "check","name": "fw_wan","default": "off","label": "Allow mail services access from external networks","help": "Configure the firewall to accept smtp/imap/pop3 connections on interfaces configured as ’external’"

}],"dependencies": ["mds_mmc"],"module": {

"section": "core","dependencies": ["mds_mmc"]

}}

1.4 Module __init__.py examples

1.4.1 mds_mmc module

# -*- coding: UTF-8 -*-#

1.4. Module __init__.py examples 15

Page 20: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

# (c) 2010-2012 Mandriva, http://www.mandriva.com/## This file is part of Mandriva Server Setup## MSS is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## MSS is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with MSS; if not, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,# MA 02110-1301, USA.

def get_config_info():return ("setup-mmc.sh", [’mdspasswd’, ’fw_lan’, ’fw_wan’])

1.4.2 mds_mail module

# -*- coding: UTF-8 -*-## (c) 2010 Mandriva, http://www.mandriva.com/## $Id$## This file is part of Mandriva Server Setup## MSS is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## MSS is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with MSS; if not, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,# MA 02110-1301, USA.

import refrom subprocess import Popen, PIPEfrom IPy import IP

from mss.agent.lib.utils import ethernet_ifs

def get_config_info():return (’setup-mail.sh’, [’smtpd_mynetworks’, ’popimap_proto’, ’fw_lan’, ’fw_wan’])

16 Chapter 1. Contents

Page 21: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

def get_current_config(module):

# get postfix configp = Popen([’/usr/sbin/postconf’, ’-h’, ’myhostname’], stdout=PIPE)smtpd_myhostname = p.communicate()[0].strip()

p = Popen([’/usr/sbin/postconf’, ’-h’, ’mynetworks’], stdout=PIPE)networks = p.communicate()[0].strip().split(’,’)smtpd_mynetworks = []for net in networks:

tmp = IP(net).strNormal(2).split(’/’)if len(tmp) > 1:

ip = tmp[0]mask = tmp[1]smtpd_mynetworks.append((ip, mask))

# get dovecot configh = open(’/etc/dovecot.conf’)f = h.read()h.close()

popimap_proto = re.search(’^protocols[\s]*=[\s]*(.*)$’, f, re.MULTILINE)if popimap_proto:

popimap_proto = popimap_proto.group(1).strip()else:

popimap_proto = ""

return {’smtpd_myhostname’: smtpd_myhostname,’smtpd_mynetworks’: smtpd_mynetworks, ’popimap_proto’: popimap_proto}

def get_networks(module):"""Return networks of the local machine"""

networks = []for iface in ethernet_ifs():

networks.append((iface[2], iface[3]))

return networks

1.4.3 network module

# -*- coding: UTF-8 -*-## (c) 2012 Mandriva, http://www.mandriva.com/## This file is part of Mandriva Server Setup## MSS is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## MSS is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

1.4. Module __init__.py examples 17

Page 22: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with MSS; if not, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,# MA 02110-1301, USA.

import osimport netifaces

from mss.agent.lib.utils import grep, get_config_optionfrom mss.agent.managers.translation import TranslationManager

_ = TranslationManager().translate

def get_config_info():args = []for interface in netifaces.interfaces():

if interface.startswith("eth"):args.append(interface + "_name")args.append(interface + "_type")args.append(interface + "_method")args.append(interface + "_addr")args.append(interface + "_netmask")args.append(interface + "_dns1")args.append(interface + "_dns2")args.append(interface + "_domain")args.append(interface + "_gateway")

args = args + ["fw_mss_lan", "fw_ssh_lan", "fw_mss_wan", "fw_ssh_wan"]return ("setup-network.sh", args)

def get_interfaces_config(config):"""Dynamic configuration for ethernet interfaces"""CONFIG_DIR = "/etc/sysconfig/network-scripts"for interface in netifaces.interfaces():

if interface.startswith("eth") or interface.startswith("br"):if_file = os.path.join(CONFIG_DIR, "ifcfg-%s" % interface)if_detail = netifaces.ifaddresses(interface)configured = os.path.exists(if_file) and netifaces.AF_INET in if_detailmethod = "none"addr = ""netmask = ""dns1 = ""dns2 = ""domain = ""gateway = ""type = ""with open(’/etc/shorewall/interfaces’) as h:

for line in h.readlines():if interface in line:

type = line.split()[0]break

if configured:if grep("BOOTPROTO=dhcp", if_file):

18 Chapter 1. Contents

Page 23: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

method = "dhcp"else:

method = "static"addr = if_detail[netifaces.AF_INET][0][’addr’]netmask = if_detail[netifaces.AF_INET][0][’netmask’]dns1 = get_config_option(if_file, "DNS1")dns2 = get_config_option(if_file, "DNS2")domain = get_config_option(if_file, "DOMAIN")gateway = get_config_option(if_file, "GATEWAY")

config.append({’slug’: ’network’,’type’: ’subtitle’, ’label’: interface})

config.append({’slug’: ’network’, ’name’: interface + ’_name’,’type’: ’text’, ’hidden’: ’yes’, ’default’: interface})

config.append({’slug’: ’network’,’name’: interface + ’_type’,’show_if_unconfigured’: ’yes’,’require’: ’yes’,’default’: type,’label’: _(’Interface type’, ’network’),’help’: _(’Choose "External" if the interface is connected to the Internet. If the interface is connected to an internal network, choose "Internal"’, ’network’),’type’: ’options’,’options’: [

{’name’: _(’Internal network’, ’network’), ’value’: ’lan’ + interface[-1]},{’name’: _(’External network’, ’network’), ’value’: ’wan’ + interface[-1]}

]})

config.append({’slug’: ’network’,’name’: interface + ’_method’,’default’: method,’require’: ’yes’,’label’: _(’Configuration method’, ’network’),’type’: ’options’,’options’: [

{’name’: _(’No configuration’, ’network’), ’value’: ’none’},{’name’: _(’DHCP configuration’, ’network’), ’value’: ’dhcp’},{’name’: _(’Manual configuration’, ’network’), ’value’: ’static’,’toggle’: [interface + ’_addr’, interface + ’_netmask’, interface + ’_dns1’,

interface + ’_dns2’, interface + ’_domain’, interface + ’_gateway’]}]})

config.append({’slug’: ’network’,’name’: interface + ’_addr’,’default’: addr,’label’: _(’IP Address’, ’network’),’type’: ’text’, ’validation’: ’ip’})

config.append({’slug’: ’network’,’name’: interface + ’_netmask’,’default’: netmask,’label’: _(’Netmask’, ’network’),’type’: ’text’, ’validation’: ’ip’})

config.append({’slug’: ’network’,’name’: interface + ’_dns1’,’default’: dns1,’label’: _(’First DNS server’, ’network’),’type’: ’text’, ’validation’: ’ip’})

config.append({’slug’: ’network’,’name’: interface + ’_dns2’,

1.4. Module __init__.py examples 19

Page 24: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

’default’: dns2,’label’: _(’Second DNS server’, ’network’),’type’: ’text’, ’validation’: ’ip’})

config.append({’slug’: ’network’,’name’: interface + ’_domain’,’default’: domain,’label’: _(’Domain search’, ’network’),’type’: ’text’, ’validation’: ’fqdn’})

config.append({’slug’: ’network’,’name’: interface + ’_gateway’,’default’: gateway,’label’: _(’Gateway’, ’network’),’type’: ’text’, ’validation’: ’ip’})

config.append({’slug’: ’network’,’type’: ’subtitle’, ’label’: _(’Firewall configuration’, ’network’)})

config.append({’slug’: ’network’,’name’: ’fw_mss_lan’,’default’: ’on’,’label’: _(’Allow access to Mandriva Server Setup from internal networks’, ’network’),’type’: ’check’})

config.append({’slug’: ’network’,’name’: ’fw_ssh_lan’,’default’: ’on’,’label’: _(’Allow SSH access from internal networks’, ’network’),’type’: ’check’})

config.append({’slug’: ’network’,’name’: ’fw_mss_wan’,’default’: ’off’,’label’: _(’Allow access to Mandriva Server Setup from external networks’, ’network’),’type’: ’check’})

config.append({’slug’: ’network’,’name’: ’fw_ssh_wan’,’default’: ’on’,’label’: _(’Allow SSH access from external networks’, ’network’),’type’: ’check’})

return config

1.5 Internationalization

MSS uses gettext facilities for internationalization support.

Translation files must be located in locale/<lang>/LC_MESSAGES/<module_name>.po in the module’sdirectory.

You can use the build_pot.sh script to extract the strings of desc.json to create the modules po file thanks tojson2po.

The strings marked for translation in the setup script are also extracted by this script. We use the standard bash methodto translate strings with gettext. In your setup script:

info $"Administrator name : root"info $"Administrator password : $mypass"

You can also translate strings in the module python files like this:

20 Chapter 1. Contents

Page 25: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

from mss.agent.managers.translation import TranslationManager_ = TranslationManager().translate

_(’Text to translate’, ’module_slug’)

1.5. Internationalization 21

Page 26: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

22 Chapter 1. Contents

Page 27: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

CHAPTER 2

Indices and tables

• genindex

• modindex

23

Page 28: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Mandriva Server Setup Documentation, Release 2.0

24 Chapter 2. Indices and tables

Page 29: Mandriva Server Setup Documentation · Mandriva Server Setup Documentation, Release 2.0 Mandriva Server Setup is a graphical tool for install, configure software on any MandrivaLinux

Index

Ccheck_configured() (built-in function), 9

Gget_config_info() (built-in function), 9get_current_config() (built-in function), 9

25