Search

Showing posts with label Ebox. Show all posts
Showing posts with label Ebox. Show all posts

22 May 2009

HTTP Proxy

8.1. General configuration

Through HTTP Proxy → General you can access into the eBox's proxy HTTP general configuration.

At the configuration window these options are detailed:

Transparent proxy

If transparent proxy is enabled, every eBox user will use the transparent proxy without noticing it. If it is disabled, you should configure each browser to work through the proxy.

Warning

Transparent proxy feature is only working when eBox has at least an internal and an external interface

Port

You can assign a proxy port. It will be used by the browsers, inside the network, to connect to Internet.

Default policy

It is the default policy for the proxy users. Free (allow all) access, filter contents or always deny access can be selected. Later, this policy can be modified for each network object where you need an specific behaviour, as it is explained below

Warning

If you establish a configuration which denies access to administration interface from the machines connected to eBox, you should allow the host where you want to connect from, or you could lose the connection with the web interface.

8.2. Filter settings

At HTTP Proxy → Filter settings, you can select the filter settings to those elements of this network which set their policy to filter.

Warning

The filter needs a 'filter' policy to be in effect

You may set the content filter threshold which establishes a restriction level to web contents with explicit sex and violence items to be filtered by the proxy.

To perform a more detailed filter policy. A tab menu is shown with the following elements:

File extensions filtering

You may choose which file extensions are allowed to be downloaded through the HTTP proxy. To allow extensions you must edit the row and check the box in the Allow element. A special "All extensions" form exists to apply the same policy to all extensions at once. You may add as many extensions you require by adding new ones. Several ones are set by eBox.

Any extension not listed here is, by default, allowed. In future releases, this behaviour may change.

MIME type filtering

You may select which file MIME types are allowed to be downloaded through the HTTP proxy. The management is analogous to the extension filtering explained above.

Domains filtering

You may customise which domains are allowed or denied to visit by editing the table Domains list. Write the full domain name, whose default behaviour you require to change. The domain name does not require the "www" string. For instance, you add as allowed domain "www.warp.es", we'd set "warp.es" domain.

Furthermore, you may block those domain sites which are not in the domains list overriding default allowance policy. It also let block those sites which does not have a fully qualified name (FQDN) and, therefore, they use an IP address to access to their content

8.3. Policy establishment

Through HTTP Proxy → Objects' Policy it is possible to establish one connection policy for every network object, allowing a different configuration for each newly created objects. This configuration will be applied previously to the eBox global policy for the selected objects.

Firewall

6.1. Firewall in eBox

One of the most important features in eBox is its firewall module. You can access it through Firewall . There you can make packet filtering (Section 6.3) or port redirection (Section 6.2).

The firewall has different behaviour with external or internal network interfaces.

The internal interfaces are connected to local networks. They had not restrictions as the external interfaces have.

The external interfaces are connected to external networks and eBox only allows redirections from them.

6.2. Port Redirects

Port redirects allow to get external traffic into a host behind a eBox system with firewall module installed. You can get the configuration of these options at Firewall → Redirects .

If you need to add a new redirect, first select your desired Interface which will listen incoming connections. This should be one of the interfaces previously selected as external. Moreover, it should be assigned the External port where you expect your incoming traffic, and the protocol that will be used.

You should enter the destination system IP address and its Port where packets would go on.

Once you have selected this data, you just need to select between the different Actions, the Add one, and click on it.

To remove a rule, you should select remove between the available Actions, and click on it.

Redirect configuration can be modified by changing its parameters and clicking on their modify Actions.

6.3. Packet filter

From Firewall → Packet filter you can configure packet filter rules. You may use the abstractions provided above such as network services and network objects. Using these concepts enhances the rules flexibility and clearness, reducing the amount.

At first sight, we have five different traffic flows to set your firewall rules to them.

From internal networks to eBox

These rules are meant to control access from internal network interfaces to services running on your eBox machine. Several eBox modules may add filtering rules for you to manage eBox services easily.

For internal networks

These rules allow you to control access from your internal networks to the Internet, and traffic between your internal networks.

Coming out from eBox

These rules allow you to control access from eBox to external services.

From external networks to eBox

These rules allow you to control access from external networks to services running on your eBox machine.

From external networks to internal networks

These rules allow you to control access from external networks to internal networks.

Take into account to the last two set of rules that it is granted access to untrusted networks to your managed networks. This may compromise your network security. As eBox secure by default policy recommends, do not modify these rules unless you know what you are doing. The figure Figure 6.1 try to make up the concept:

Figure 6.1. Firewall rules set

Firewall rules set

The deny policy for eBox firewall is a ignorance one. Every denied packet is filtered and discarded without any notification.

Every set of rules define a fixed behaviour for the traffic flows that they apply. These rules will be matched from top to the bottom, thus order is important. Each rule consists of these following fields, some of them are only available to several rule set by construction:

Decision

Accept or deny. This explicitly accepts or denies a traffic flow.

Source

The traffic flow origin. It may be a network object or a single IP address. This field is available for every rule set except for "Filtering rules for traffic coming out from eBox"

Destination

The traffic flow target. It may be a network object or a single IP address. This field is available for "For internal networks", "Coming out from eBox" and "From external networks to internal networks" filtering rules.

Service

The traffic flow service as it is described in Chapter 5. The match could be inverse one, i.e. the inverse "any" service is "none" service. This is a compulsory field, therefore in order to create a new rule, it is required to have a network service. If it does not exist, you must make up previously.

Description

An optional description to ease the firewall rule set management.

19 May 2009

Network services

5.1. Network services in eBox

As it happened in Chapter 4, the network services are an abstraction to ease the management of your network. Each network service describes a set of ports for Internet protocols where service accepts requests. Providing a name plus an optional description allows you to manage the network service policies more intuitively and less error-prone.

The network services are used by firewall module (Chapter 6) and traffic shaping module (Chapter 19). Anyway, as eBox philosophy every feature which use a network service must use this module to work with and ease the administration life.

5.2. Network services management

In order to get the network service management you may go to Services.

As you may notice, there are several services which have been created by eBox for you. These services are used by eBox modules afterwards. For instance, dhcp service is described as an internal service called 'Dynamic Host Configuration Protocol'.This service is read-only as it is already managed by dhcp module automatically. Each service has a configuration where the service protocol, well-known source and destination ports are set. There are three special services which define the generic abstraction for every service (any) and every TCP/UDP service. They are entered to handle easily rules defined in other modules that depends on this network services.

You may input a new service with these following elements:

Service name

The name for the service which refers uniquely this service in the system

Description

This field defines the verbose description for the network service to ease the administration management. It is an optional field.

Internal

When a network service is set as internal, those protocol/port pairs that owns this service will be set as busy, that is not available for others services to use.

Configuration

The service configuration is a multiple value configuration setting which may contain these three elements:

Protocol

The Internet protocol which may set one of these values: TCP/UDP, TCP, UDP, GRE, ICMP or "any". If the protocol is set to GRE or ICMP, then it is banned to set any port since it is banned by protocol construction

Source port

A well-known source port may contain one of the following:

  • Any. Indicates any port for that protocol or set of them

  • Single port. Indicates a single port for that protocol or set of them

  • Port range. Indicates a port range including all of them for that protocol or set of them

Destination port

Analogously with source port, the same elements appear in destination port.

You might inspect several system-defined services prior to add your own ones. Anyway, a user-defined service may be created when additional network services be installed on top of an eBox installation, for example introducing FTP (File Transfer Protocol) service.

Example 5.1. Service configuration example

  • Service name. ftp

  • Description. File Transfer Protocol

  • Internal. yes

  • Configuration:

    • protocol: tcp, source port: any, destination port: 20 (Define the control connection channel)

    • protocol: tcp, source port: any, destination port: 21 (Define the data flow connection channel)

Network objects

4.1. What the network objects are?

Network objects are an easy way to give a name to a network item, or a group of them. They are used to simplify network configuration management, allowing you to choose different behaviors for each item or group of them with just a descriptive name.

Network objects can be used, for instance, to five a name to an IP or a group of IPs. If the object is a group of IPs, instead of defining some rules for each IP, every IP inside the object will acquire that configuration.


4.2. Network objects management

Network objects used by eBox can be created, modified and erased in an easy and intuitive way using the web interface.

You may add as many objects you want. A name must be provided to the object. After that, you may enter into members field where you may define:

  • Name : name assigned to the member.

  • IP address : member IP address

  • Network mask : network mask, using CIDR notation

  • MAC (optional): hardware address -or MAC address- of the network interface corresponding to that IP address.

Editing an object or a member of it is done by clicking the pencil icon in Action field. Likewise the object/member removal is done by clicking on the trash can icon.

29 April 2009

Network Configuration

3.1. Network interfaces

You can enter into network interfaces configuration at Network → Interfaces at the left menu.

For each network interface we can choose a new name and its configuration. Available configurations are:

Static

It will assign permanently an IP address to the network interface. Once you have chosen the configuration, you can set if this network interface is external[1], its IP address and its network mask.

DHCP

When you select this option for configuration, the network interface will be configured dynamically if a DHCP Server exists on the network. The only configuration parameter is the ability to be an external interface.

Trunk 802.1Q

When this method is selected, the interface applies a mechanism which allows multiple bridged networks to transparently share the same physical network link without leakage of information between networks, i.e. doing trunking.

Not configured

Network interface won't be configured.

3.1.1. Virtual interfaces

A virtual interface is the one which is attached to a real one, and it is used to listen or serve another IP address apart from the real one, that is, the real interface can assist two or more networks just creating as many virtual interfaces as needed.

It's possible to create new virtual interfaces bound to any interface configured as static.

Once you have configured static interface, a form will be shown to add virtual interfaces, where you can assign their name, IP address and network mask.


3.2. DNS Servers

You can set IP addresses for the name servers that you want to use to resolve host names. You may set as many name servers as you want, the first one is primary one which whether it becomes down, the secondary one is used instead and so on.

Warning

You have to remember that, if your network interfaces are configured with DHCP, your network settings could be overwritten.


3.3. Diagnostic tools

You can use this tools to check if your network settings are correct.

Selecting Network → Diagnostics you could make a ping to a reachable host through your network interfaces, or you can resolve a domain name.

The output of this operations will be shown on this page, corresponding with the standard output of the GNU/Linux commands ping and dig.


3.4. Gateways

Through this section you can set the gateways where your network traffic is directed. It is very useful in order to split or do balance your Internet traffic.

Choosing Network → Gateways you could add as many gateways as you want. The following attributes are required when adding a gateway:

Name

It is the logical name associated to the gateway in eBox which is used in other eBox modules. It should be unique.

IP Address

The static gateway IP address. Its value has to be unique as well.

Interface

The interface from where the gateway is reachable. That is, it is the interface where packets can be routed to get to the gateway.

Upload

The maximum upload rate (in Kilobits per second) you can have towards the connection from eBox to the gateway. It will surely depend on the sort of connection provided by your ISP.

Download

The maximum download rate (in Kilobits per second) you can obtain towards the connection from the gateway to eBox.

Weight

It is the weight associated to this gateway. It is used by balance traffic section to apply special rules applied to multiple gateways.

Default

It is set to determine whether the gateway is the default one or not. This implies that any packet which does not have a explicit gateway to be routed through will come out through the default one. Note that just one gateway can be the default one at the same time.

Warning

Each gateway should be reachable from at least one interface. eBox checks so for each interface whose configuration is static. If the interface is configured via DHCP, this inspection will be skipped since it is impossible to determine.

The correct values for upload and download rate are critical to ensure the correct functionality from traffic shaping module.

Once you have added a gateway, it will appear at the Gateway list . Then, you can delete it or edit the values set previously through the icons which appear on the right side of the list.


3.5. Balance traffic and multigateway rules

3.5.1. Requirements

In order to use these two features, at least two gateways configured are required. Check out this section to know how to create them.

3.5.2. Balance traffic

You can enable traffic balancing via Network → Balance traffic in order to share your traffic through different routes. The traffic distribution relies on a weighted sum from the gateway weights which are set on gateway attributes (See Gateways section to know how configured them).

A typical configuration could be as follows: you have two gateways configured where one has the double rate capacity (A) than the other one (B). Thus you may want to balance traffic in 2:1 proportion, that is, gateway A will deliver the double traffic than B. To achieve so, you should set the weight parameter to A to 2 and gateway B will have weight set to 1.

3.5.3. Multigateway rules

It may be needed to route explicitly traffic by a certain gateway, to do so, you should use the multigateway rules which mark the packets to be delivered through the gateway selected.

The packets are matched depending on the rules given to be directed to the asked gateway. You can select the traffic according to the following factors:

Protocol

It could be TCP, UDP or any.

Interface

The source interface where traffic comes from. The list only includes internal interfaces.

Source

You can select a source IP address or an eBox network object. (See this chapter for details)

Source port

You can choose a source port. You must select a protocol different from any to be able to direct traffic depending on the source port.

Destination

You can select a destination IP address or an eBox network object.

Destination port

You can choose a destination port. The same policy from source port is applied here.

After editing at least one of the factors you can select a previously defined gateway to direct traffic which matches with the defined attributes.

Once the rule has been added to the multigateway rule list, you may edit or delete a previous defined rule through its icons depicted on its right side.


3.6. Routes

In advanced configurations, defining a set of gateways and rules to applied them is not sufficient. Thus the user defined Example 3.1 routing table may help:

Example 3.1. Static route use case

“ I have some machines that are on the outside, connected to the external LAN of the eBox and I would like all users who connect to VPN server to connect to those machines via the VPN tunnel. ”


In those cases, we may use static routes. This table specifies those networks whose traffic is redirected to a fixed gateway, which must be reachable from eBox host. Each route must have an unique network to route. Moreover, an optional description is provided to allow administrator to add information to the route and ease so the maintenance.



[1] On eBox, an interface is defined as external when its connection is directed to Internet. For instance, its IP address can be an static public one. However, internal interface is those where clients from your internal network are connected.

28 April 2009

System Configuration Ebox

2.1. User interface general configuration

Interface general configuration is accessed through System → General from the left menu.

From this section you can make three major changes over the eBox management interface:

Password change

It allows the password modification to administrate eBox.

Language Selection

eBox can show its information on different languages. You could choose them here.

Management interface TCP Port

TCP Port where eBox management interface is bound.

2.1.1. Password change

To change your password, you should enter current password, for security reasons, and the new one twice, so it can be confirmed. Next, you have to accept the input data and not forgive that it's mandatory to save changes, using the upper menu, to make them definitive.

2.1.2. Language selection

Select your preferred language from the list and confirm your changes by submitting the form. This time won't be necessary to "Save Changes" to make it effective.

2.1.3. Management Interface TCP Port

If the port value is changed to something different to 443, form is submitted and changed are saved, you will be able to access to eBox typing: https://hostname:PORT/eBox on your browser, with PORT as the new PORT value. For instance: https://www.warp.es:444/eBox.

Note

Please, remember that after saving changes of the management interface port, some seconds are needed before eBox can work on the new port.


2.2. Backup

You can get eBox backups management through System → Backup from the left menu.

From the backup page, you can make a copy of the last saved eBox state or restore previous saved backups. Two backup modes are available in eBox which are described below.

2.2.1. Backup modes

Configuration Backup

Backs up only the configuration from eBox including all managed services. Its size could be a few KBs.

Full Backup

Backs up the eBox configuration and other data which are not necessary for eBox to work. For example, it stores files from shared directories or log messages. Its size is larger than previous mode and can occupy GBs. It can be used to restore only configuration part because it is wrapped inside.

2.2.2. Saving your current state

Both backup modes need a description and can be stored in hard disk or in a removable device such as CD and DVD.

In first case, when backup is done, a new entry will appear on the backups' list, showing date, description and possible actions related to the recent backup.

If you want to save a copy in a CD/DVD, you should have a writer installed in your eBox machine and enter a blank or re-writable disk. This backup will be stored in the disk and it won't appear in backup list anymore.

Note

It is important to remember that the backed up configuration is the last saved configuration through the top-right "Save changes" button.

If you insert a re-writable CD/DVD, the content which remained inside would be replaced with the eBox backup.


2.2.3. Backup Restore

There are three different ways to restore a backup.

  1. You can recover an eBox backup from a file browsing in your own system clicking Browse... and do restore after setting an eBox backup file.

  2. The eBox backup can be stored in a removable disk as well. After inserting a CD/DVD with an eBox backup, with Restore from disk the eBox saved state in this kind of storage devices can be restored.

  3. Finally, an eBox backup can be restored from the backups' list which is explained in detail in Section 2.2.4.

In order to restore a backup, two different restore mode can be done:

  1. Full Restore: Available from a full backup mode, everything kept in this backup can be restored.

  2. Configuration Restore: Available from both backup modes. It just restores the configuration state for eBox.

Then, you should check it to see if it is all correct or make the appropriate changes and, finally, save it.

2.2.4. Backups' list

Backups' list has the eBox backups made during its working period. Actions on each element from that list, located at the right, let restore a backup, download a file with a backup, store the backup a removable device (CD/DVD) or remove a backup from the eBox.


2.3. System Halt/Reboot

Our web interface to halt or reboot the computer where eBox is installed in, is reachable through System → Halt/Reboot.

You shouldn't forget that if your eBox system is your Internet gateway, you will lose connection to the global network meanwhile eBox is halt.


2.4. Bug reports generation

If you find a problem while eBox is running, you can fill a file with the bug report at System → Bug report and send it by e-mail to support@ebox-platform.com


2.5. Date/Time Configuration

You can access to date/time configuration in System → Date/Time and System → Timezone .

At System → Date/Time , you can adjust eBox date and time. There are two different options to adjust date and time correctly: by hand, setting as "Disabled" NTP Server synchronisation, and using an external NTP Server, setting as "Enabled" NTP synchronisation.

By hand

If synchronisation with other NTP server is disabled, date and time adjust will be manual. Selecting corresponding values, shown in the page, for system date and time values.

Using another NTP Server

If date/time synchronisation with a NTP Server is enabled, another configuration will be shown, where you can specify until a maximum of three NTP Servers where eBox will ask for date and time, using current timezone from the system configuration.

At System → Timezone you can configure the system timezone. You just need to select you geographic zone from the list at the left, and a city from the list at the right, both belonging your time zone, and accept your configuration.

Warning

When you make a change, it is possible your system becomes unstable, so you'd better to restart the whole machine after saving changes.


2.6. Module status

Each eBox module status is managed from here instead of having to enable every module from one of its configuration page. This allows us to have in a single sight which modules are enabled analogously the module summary in Summary page. Each eBox module is disabled by default including base modules such as Network (Chapter 3) or Firewall (Chapter 6).

There are modules which depends on another to be enabled. In a typical installation, for example, the squid module has a chain of dependencies to be enabled as shown: squid -> firewall -> network. So to enable Squid module, firstly the dependant modules must be enabled first. A module may have multiple module dependencies to work.

The first time you enable a module, eBox will ask to perform several actions and file modifications that you must accept explicitly to enable the module. This is so to comply the Debian policy which indicate that every package must manage its own data and if it modifies configuration/data from other packages the user must accept explicitly those modifications. Every action to perform has a reason which is explained accordingly. Until you save changes, the modules that you may enable would not be committed.

Every time a user make a modification in an eBox-controlled file, eBox will realise that a change may be done when saving changes. And it will ask you again to override your changes. This monitoring is only done on those modules which are enabled. If every configuration setting is done through eBox UI, no more dialogues of this kind will be shown.

In order to disable a module, just click status column of the desired module. If the module is a dependency from other modules, this action will disable them as well.

25 March 2009

Introducing Ebox

1.1.�Intended audience

This guide is written for developers interested in writing new modules with new features for eBox, and for those who need to change or extend the base eBox framework.

eBox is written in perl and is mostly object-oriented. It is assumed that readers know how to write object oriented programs in perl. Some features of the language or the libraries used in eBox may be discussed, but no attempt has been made to document those aspects throughly.

Some experience writing object oriented applications and using design patterns in any language should be useful, but you should be fine just with the basic concepts of object oriented programming.

An effort has been made to provide examples for all aspects of eBox development explained in this guide. Most of them come straight from existing and working modules. Furthermore, a complete module is developed step by step in Chapter�8. It's a real module so that chapter should cover all the parts of a complete and working module.

1.2.�What is eBox?

eBox is a platform for the development and deployment of security and work-group related services on a local network. It is configured through a web interface that integrates all services in a consistent and easy to use way. Its goal is to be usable by non-experts.

eBox is meant to be installed on a dedicated machine, all configuration tasks are performed through the eBox web interface. This means that the configuration of the underlying services is one-way: eBox modules generate configuration files, overwriting system files in some cases (although that tends to be avoided if possible) and manual changes to those files are not detected by eBox. This simplifies the implementation and usage of the package but has the disadvantage that developers need to be careful if they use their own system for testing purposes.

eBox design is modular, new modules providing new services and features can be developed independently from its core package. eBox simplifies the deployment of new modules and the updates of existing ones with a software management module, which is also independent from the eBox base package.

The system is based on Linux and has been developed on top of Debian, no support is provided for other Linux distributions as there are some "debianisms" in some of the modules. Porting to other Linux distributions should be quite easy, and porting to other Unix like operating systems such as OpenBSD would take a little more work but it should still be doable, and worth it.

eBox is based on a few software packages, which are used for several purposes:

Linux 2.6

eBox relies on some features provided by the kernel, some are available only on the 2.6 series. Among these features are netfilter (for the firewall), 802.1q (for VLANs) and ipsec.

perl and mod_perl

All eBox modules are implemented in perl, the web interface runs under mod_perl for performance reasons.

mason

mason is a templating system for perl, it is used to generate HTML for the web based user interface and to generate configuration files.

apache

The web interface is served by apache, we usually use the apache-perl Debian package.

gconf

eBox stores its configuration using gconf2 and its perl library bindings.

sudo

Apache runs as an unprivileged user, all eBox modules use sudo to execute commands that need to be run as root.

The base eBox package provides a development framework for new modules. By using this framework modules automatically get features like configuration backups and reversion of changes in the configuration before they are saved. The features available to module developers will be explained in detail in later chapters.

1.3.�Terminology

A few conventions are used throughout this guide regarding several concepts:

Booleans.�Whenever we need to talk about a boolean value passed to a method or returned by it, we will refer to a true value as true and to a false value as undef or false.

Perl modules and eBox modules.�There may be some confusion in some parts of the guide about the term module as the term may refer to an eBox module or a perl module. An eBox module is the complete set of classes (and perl modules) and other files that provide a self-contained functionality for eBox and that may be installed or uninstalled independently from the rest of eBox. A perl module is basically a perl source file.

Whenever there is no possibility of confusion, we'll just write module, otherwise we'll write explicitly perl module since this meaning will be the one used less frequently.

1.4.�How a module works

The typical eBox module handles the configuration of a daemon, possibly integrated with other eBox modules. The developer decides in what ways should the user be able to configure the daemon, this ways do not necessarily map directly to the daemon configuration options on a one-to-one relationship. The developer may pick a sane default value for most of the options and hide them from the user, showing him just the ones that he feels are important. Even further, an option changed by the user through the web interface may cause configuration changes in several real configuration options or even on several eBox modules. The main goal is to have an user interface as simple, easy to use, and integrated as possible, while providing the user with a rich set of features.

However, there may be modules that do not handle the configuration of a network service. An example is the 'sysinfo' module in the base system, it just gathers system information to be shown in the Summary page and provides a few menu entries for features that do not belong to any module in particular. The module parent class defines several abstract methods that real modules are free to leave unimplemented. Thus, a module may just provide info in the Summary, add new menu items, handle a network service or all of the above.

The normal, and most interesting, case is the module described in the first paragraph. Such a module has three parts.

  • It defines and implements an API that will let the GUI, other modules or plain perl scripts configure the daemon it is going to handle.

  • The second is the GUI, which is a set of CGIs that show the current configuration to the user and let him change it, these CGIs use the API defined earlier to fetch the configuration info and make changes to it.

  • The third part of the module is usually quite small, it translates all the configuration information stored in GConf into firewall rules, configuration files and commands that make the network service behave as the user expects. It also takes care of starting, stopping and restarting the service when needed.

This separation between the GUI and the backend opens the possibility for other means of changing the configuration. One such means is through perl scripts, these is useful when making packages for a distribution, the package maintainer can write a simple script to import the current system configuration into eBox, or set up some default values. Another use of the API is for other modules, the firewall module is the most used case, almost all modules need tell the firewall to open some port for them. In the future a wrapper may be written around these APIs to publish them through web-services, this would make eBox configurable programmatically over the network.

Besides these three parts, the module has some other minor parts, like its piece of the summary page in the web interface, menu entries, dependency declarations, backups of configuration pieces not stored in GConf, etc.

That's all there is to it, creating a module is as simple as following these steps:

  • Decide what daemon your module is going to handle and learn how it works and how to set it up.

  • Plan what options you are going to expose to the user through the web interface, and how they may interact with other eBox modules

  • Define and implement the API that will let the GUI manipulate the necessary configuration options. The main class in your module should inherit from EBox::GConfModule, this class wraps the GConf API and transparently implements some useful features that all eBox modules need to have.

  • Create the CGIs and HTML templates that will let the user interact with the module. CGIs should inherit from the EBox::CGI::Base class which, again, provides some features transparently to all its children.

  • Write the code needed to make the daemon work, possibly generating a configuration file and setting up a firewall rule using the EBox::Firewall class. Configuration files are generated almost trivially with mason, which is the template system also used to generate the HTML pages for the GUI.

The size and complexity of a module depends directly on the complexity of the service involved and the amount of configuration items exposed to the user. The necessary work to make a small eBox module is minimal, take the DNSCache module as an example, its CGIs add up to 49 lines of code and the module itself is 134 lines long.

The directory structure of an eBox module may look quite complex for a newcomer. A usual eBox module directory should look like this:

AUTHORS     configure.ac  INSTALL     Makefile.am  README   stubs/
autogen.sh COPYING NEWS schemas/ tools/ ChangeLog
debian/ m4/ po/ src/ www/ migration/

The more important directories are src/, schemas/, www/, stubs/ and migration/.

The src/ directory contains the source code for the module. Inside this directory two directories can be found: EBox and templates. The EBox directory contains the Perl source code files, including a CGI subdirectory with the web frontend for the module. The templates directory is used to store the Mason templates, which will be used to generate the HTML output.

The schemas/ directory contains gconf schemas, used to define the configuration schemas for modules, and optionally provide default values for some options.

The www/ directory contains images and stylesheets that will be used in the web frontend.

The stubs/ is used to store Mason templates to generate configuration files for the module services.

The migration/ stores the migration perl scripts to upgrade from an eBox module version to a newer one.

1.5.�A Model-View-Controller module

Bear Section�1.4 in mind, a new way to develop eBox modules have been developed. It relies on Model-View-Controller design pattern, which an architectural pattern used in large software projects to decouple highly data (model) and user interface (view) so that developer can change the data architecture wihout changing the user interface and vice versa. A new component is added, the controller, which manages data access and business logic acting as an intermediate between them.

Thus with our new architecture the eBox MVC conception will be the following:

Model

Our model is defined as a perl module which is a subclass of EBox::Model::DataTable or one of the subclasses.

View

The already defined Mason templates are used to show the information to the user.

Controller

The CGIs which are mapped from the Mason templates to do actions. There are some default actions already implemented.

In Chapter�7, there is a large explanation about how it works internally. Below we are only going to introduce the main components which an eBox developer requires to know to build up an eBox MVC's module.

A basic MVC based module should have, at least, these three main parts:

  • A series of data models which represent the information you want to store to configure your desired service.

  • Manage your service daemon (if any) accessing to the data model, add menu entry, summary and make the data contained in the model(s) available to the eBox system.

  • Expose the desired API to other eBox modules, perl scripts and SOAP interface.

1.5.1.�Model creation

A model is just a table concept, that is, an array of rows which have a defined fixed definition, the table description. This table description contains a series of EBox::Types which are instances of EBox::Types::Abstract, these eBox types try to include the required representation for eBox configuration parameters, a brief list could be:

Basic types

Basic types include are: Boolean, Int, Text, Password, Select (an enumeration) or Link, which describe a type that stores a simple link reference.

Network related types

These comprise IPAddr which represents an IP address, MACAddr which is a Ethernet address, Service which matches with port and protocol such as /etc/services does and PortRange which describes a single port number, a port range or any port.

Composite types

Currently, just a Union type has been developed which represents a type is used from a defined list of options. If none of options are suitable, a Union::Text may be used with this purpose.

The data storage is managed automatically by the model itself. A model stores its information under a GConf directory which must set explicitly at the model creation. However, you can set dynamically which becomes the model instance in a submodel. The submodels are model instances whose GConf directory is set dynamically, not only at the runtime. Its usage is intimately with EBox::Types::HasMany, which describes a relationship between a field from a model with another model indicating that field contains the whole data from another model.

Apart from the table description, it is required to set several attributes such as the name, the printable name, if it is ordered, etc... Some model definition examples may help to understand the subject:

Example�1.1.�Object model definition

sub _table
{
my @tableHead =
(

new EBox::Types::Text
(
'fieldName' => 'name',
'printableName' => __('Name'),
'size' => '12',
'unique' => 1,
'editable' => 1
),
new EBox::Types::HasMany
(
'fieldName' => 'members',
'printableName' => __('Members'),
'foreignModel' => 'MemberTable',
'view' => '/ebox/Object/View/MemberTable',
'backView' => '/ebox/Object/View/MemberTable',
'size' => '1',
)

);

my $dataTable =
{
'tableName' => 'ObjectTable',
'printableTableName' => __('Objects'),
'automaticRemove' => 1,
'modelDomain' => 'Objects',
'defaultActions' => ['add', 'del', 'editField' ],
'tableDescription' => \@tableHead,
'class' => 'dataTable',
'help' => __('Objects'),
'printableRowName' => __('object'),
};

return $dataTable;
}

As it is shown, a model is used to describe an eBox object, which has a name and a group of members which are described in Example�1.2:

Example�1.2.�Object member model definition

sub _table
{
my @tableHead =
(

new EBox::Types::Text
(
'fieldName' => 'name',
'printableName' => __('Name'),
'size' => '12',
'unique' => 1,
'editable' => 1
),
new EBox::Types::IPAddr
(
'fieldName' => 'ipaddr',
'printableName' => __('IP Address'),
'editable' => 1,
),
new EBox::Types::MACAddr
(
'fieldName' => 'macaddr',
'printableName' => __('MAC Address'),
'editable' => 1,
'optional' => 1
),


);

my $dataTable =
{
'tableName' => 'MemberTable',
'printableTableName' => __('Members'),
'automaticRemove' => 1,
'defaultActions' => ['add', 'del', 'editField' ],
'modelDomain' => 'Objects',
'tableDescription' => \@tableHead,
'class' => 'dataTable',
'help' => __('Objects'),
'printableRowName' => __('member'),
};

return $dataTable;
}

As you may see, every field has some attributes as well as the model itself. Just note the actions are the allowed actions to apply to that model. For instance, you can add, delete rows, edit fields... Several attributes are allowed for every type and model, if they are not explicitly set at the model definition, they are treated as false value. That is, if it is a boolean type or empty string if the type is an string.

The best part of it comes from forms. Typical eBox scenarios contain a set of tables and forms. So the information that a form may show can be stored in a data model as described above. However, it has some significant differences. A form data model looks like a table data model with just one row which is always shown to be edited. A form model definition is similar to a table data model one as Example�1.3 depicts:

Example�1.3.�Jabber dispatcherconfiguration form data model definition

sub _table
{

my @tableDesc =
(
new EBox::Types::Text(
fieldName => 'server',
printableName => __('Jabber server name'),
size => 12,
editable => 1,
),
new EBox::Types::Int(
fieldName => 'port',
printableName => __('Port'),
size => 6,
editable => 1,
defaultValue => 5222,
),
new EBox::Types::Text(
fieldName => 'user',
printableName => __('Jabber user name'),
size => 12,
editable => 1,
),
new EBox::Types::Password(
fieldName => 'password',
printableName => __('User password'),
size => 12,
editable => 1,
minLength => 4,
maxLength => 25,
),
new EBox::Types::Boolean(
fieldName => 'subscribe',
printableName => __('Subscribe'),
editable => 1,
),
new EBox::Types::Text(
fieldName => 'adminJID',
printableName => __('Administrator Jabber Identifier'),
size => 12,
editable => 1,
),
);

my $dataForm = {
tableName => 'JabberDispatcherForm',
printableTableName => __('Configure Jabber dispatcher'),
modelDomain => 'Events',
tableDescription => \@tableDesc,
class => 'dataForm',
help => __('In order to configure the Jabber event dispatcher ' .
'is required to be registered at the chosen Jabber ' .
'server or check subscribe to do register. The administrator ' .
'identifier should follow the pattern: user@domain[/resource]'),
};

return $dataForm;

}

As you may notice, fields at a form can contain default values. This is done due to have default eBox configuration working. For example, you may want to enable a service to a specific port whose value does not modify the service if the default value is set.

1.5.1.1.�User input management

Once the definition is set you may want to validate the user input. Types do some validation, for instance, IPAddr checks if the parameters contain a valid IP. However, there are cases where the developer requires to do extra validation. To achieve so, there are two methods to override validateRow and validateTypedRow.

Furthermore, actions have callbacks to called after an action have been finished. Therefore add action has addedRowNotify, edit updatedRowNotify and so on. This allows you to manage the updated information to do something different from just storing updating information at GConf database.

1.5.2.�Model view

This section explains how the data model is shown at eBox user interface. If you just want to show a data model in eBox, a new menu entry is required. Its URL must have this pattern: ${modelDomain}/View/${tableName}. The modelDomain and tableName are attributes which have been already set at the data model definition. A table model will show up an empty table and a HTML form will appear if a form model is defined, they are named as their viewers.

You may wish to combine the several models in the same page. Here where the model composites play its role. The model composites are containers which stores two kinds of components: models and composites, thus you can create complex composites to find the more usable and adapted user interface for your needs. The current available layouts are:

top-bottom

The components are shown in order from top to the bottom.

tabbed

The component viewers are displayed in a tabbed way. That is, each component is shown when the tab name is clicked

Define a model composite is even simpler than a model one as it depicts in this example:

Example�1.4.�A sample model composite definition

sub _description
{

my $description =
{
components => [
'EnableForm',
'ConfigurationComposite',
],
layout => 'top-bottom',
name => 'GeneralComposite',
printableName => __('Events'),
compositeDomain => 'Events',
help => __('Events module may help you to make eBox ' .
'inform you about events that happen at eBox ' .
'in some different ways'),
};

return $description;

}

The components are referenced using its name, tableName at models and name at composites. In order to display a composite based page, it is required to change the menu entry. In this case, the URL to call must follow this pattern ${compositeDomain}/Composite/${name}. That's all you need to display your models together in a single page.

1.5.3.�Data model publishing and access

Just get the magic done, it is required to publish the models and composites. To achieve so, the eBox modules, which are subclasses of EBox::GConfModule, must inherit from EBox::Model::ModelProvider and EBox::Model::CompositeProvider interfaces, implementing its respectively methods models and composites, which returns an array reference of model and composite instances that lives within this eBox module realm. An example could be the next one:

Example�1.5.�Model and composite publishing example

sub models {
my ($self) = @_;

return [
$self->configureLogModel(),
$self->forcePurgeModel(),
];
}

sub composites
{

my ($self) = @_;

return [
$self->_configureLogComposite(),
];

}

Once the models are published and ready to be displayed, they actually have to do something to manage its service. Current data model API is quite experimental in the way it is constantly evolving to satisfy the client needs. The main components that use data model are migration scripts and eBox module itself to obtain the required data to configure the service.

The main method to retrieve the data model is rows which returns an array reference which contains the rows from that data model. You can filter the result using a filter string or get the result from a defined page, since data model allows filtering and paging. Each array component contains the return value from row which is a hash reference containing the following key - value pairs:

id

Each row has an identifier which allows distinguishing from the others inside the data model. You can use it as well as indexer calling the row method.

order

A data model can be ordered or not. If so, the rows are ordered in the same order they have been added. Furthermore, you might tailor the order overriding _tailoredOrder to give rows in the desired order.

values

Array reference which contains eBox types, which were explained previously.

valueHash

Hash reference indexed by field name whose values are eBox types as values does.

plainValueHash

For convenience, some methods have been added to help accessing the methods. This one returns a hash reference containing field name - value pairs.

printableValueHash

Similar to the previous one, it returns a hash reference containing field name - printable value pairs.

The rows may be quite complex. An dumped from a result could clarify the subject:

Example�1.6.�Rows dumped result

[
{
'order' => undef,
'plainValueHash' => {
'members' => {
...
},
'name' => 'RRHH',
'id' => 'x6666'
},
'valueHash' => {
'members' => bless( {
...
}, 'EBox::Types::HasMany' ),
'name' => bless( {
'unique' => 1,
'value' => 'RRHH',
'printableName' => 'Name',
'model' => $VAR1->[0]{'valueHash'}{'members'}{'model'},
'HTMLSetter' => '/ajax/setter/textSetter.mas',
'optional' => 0,
'size' => '12',
'row' => $VAR1->[0],
'editable' => 1,
'type' => 'text',
'HTMLViewer' => '/ajax/viewer/textViewer.mas',
'fieldName' => 'name'
}, 'EBox::Types::Text' )
},
'values' => [
$VAR1->[0]{'valueHash'}{'name'},
$VAR1->[0]{'valueHash'}{'members'}
],
'id' => 'x6666',
'printableValueHash' => {
'members' => {
'model' => 'MemberTable',
'values' => [
{
'macaddr' => undef,
'name' => 'Claudia',
'id' => 'memb44',
'ipaddr' => '192.168.1.92/32'
}
],
'directory' => 'objectTable/keys/x6666/members'
},
'name' => 'RRHH',
'id' => 'x6666'
},
'readOnly' => 0
},
];


With the ease of use in mind, form data model allows accessing directly to the value, printable value attributes or the whole type using as method name the field name. For instance, at jabber dispatcher configuration form data model, you can access to the value, printable value and the instanced type itself of user property calling userValue, userPrintableValue and userType respectively.

Nevertheless, you may search for rows which match a fixed criterion, this implies the match is done against the field value. Four methods make the work for you, find, findAll, findValue and findValueAll. They are divided in two groups, the ones which returns the valueHash and the ones which returns the printableValueHash and has the 'Value' word in their names. Moreover, if the method ends with 'All' words, returns not just the first row which matchs but also the possible remainder rows which match the criterion as well. Taking the previous data model a search with $model->find( 'name' => 'RHHH' ), the dumped return value is:

{
'members' => {
'model' => 'MemberTable',
'values' => [
{
'macaddr' => undef,
'name' => 'Claudia',
'id' => 'memb44',
'ipaddr' => '192.168.1.92/32'
}
],
'directory' => 'objectTable/keys/x6666/members'
},
'name' => 'RRHH',
'id' => 'x6666'
}

Final part of developing with MVC framework is expose the desired API to other eBox modules, perl scripts and SOAP clients. Two main options are probable, just disclose the instanced data model allowing full access to the model using in the way we used above or integrate some helper methods to access to the most important features which clients use most. The latter is likely the chosen if the data model rises in its complexity. A module which consists of several data models connected with each other indicates that a simple API may help the module's clients.

1.5.4.�When is this approach suitable?

As you may see, the MVC framework is powerful scheme to develop in eBox. However, it is not so impressive yet. It is still under development and some optimization as well as lack of some features. For instance, an eBox type to manage file uploading from the user, automatic getter and setter methods,...

dikutip dari ebox-platform.com

Tentang Penulis

My photo
Tangerang, Banten, Indonesia
Luchu bgt ngga cih..

Komentar


ShoutMix chat widget

Tomy Kurniawan © 2008