1. About this Guide
This guide will help you modifying PacketFence to your particular needs. It also contains information on how to add support for new switches.
The latest version of this guide is available at https://packetfence.org/documentation/.
1.1. Other sources of information
- Network Devices Configuration Guide
-
Covers switch, controllers and access points configuration.
- Administration Guide
-
Covers PacketFence installation, configuration and administration.
NEWS
-
Covers noteworthy features, improvements and bug fixes by release.
UPGRADE
-
Covers compatibility related changes, manual instructions and general notes about upgrading.
ChangeLog
-
Covers all changes to the source code.
These files are included in the package and release tarballs.
2. Documentation
The in-depth or more technical documentation is always as close to the code
as possible. Always look at the POD
doc
[1].
To do so, the preferred way is using the perldoc
command as follows:
perldoc lib/pfconfig/cached.pm
3. AsciiDoc documentation
3.1. Documentation Conventions
Some markup examples used in this overview are based on new Asciidoctor features and they are not a part of the standard set of elements. Please, use the :experimental:
tag in the header of your document to enable this functionality.
Element | Mark-up | Example rendered output |
---|---|---|
Application name |
No special markup |
The foo application. |
Code blocks |
[source,golang] ---- package main import "fmt" func main() { fmt.Println("Hello World !") } ---- |
|
Code - inline |
`print("Hello, World!")` |
|
Command block |
---- $ echo "Hello, World!" > hello.txt ---- |
$ echo "Hello, World!" > hello.txt |
Command - inline |
Use the [command]`oc get` command to get a list of services. |
Use the |
Emphasis for a term |
Use _this_ approach. |
Use this approach. |
Filenames or directory paths |
Edit the [filename]`pf.conf` file as required and save your changes. The [filename]`networks.conf` configuration file is located in the [filename]`/usr/local/pf/` directory. |
Edit the The |
GUI Text |
The web browser displays *404* for an unreachable URL. |
The web browser displays 404 for an unreachable URL. |
GUI Button (experimental feature, Asciidoctor only) |
Click btn:[Save As] to save the file under a different name. |
Click Save As to save the file under a different name. |
GUI Menu (experimental feature, Asciidoctor only) |
Navigate to menu:File[Import>Import csv] to import a csv file. |
Navigate to to import a csv file. |
GUI button and menu (non-experimental) |
Navigate to _Configuration -> Policies and Access Control_ |
Navigate to Configuration → Policies and Access Control |
Inline Image |
image::image.png[width=25px] |
|
Block Image |
.Tux image::image.png[width=100px] |
Figure 1. Tux
|
Inline operations and user input |
The `GET` operation can be used to do something. Answer by typing `Yes` or `No` when prompted. |
The Answer by typing |
Keyboard shortcuts (experimental feature, Asciidoctor only) |
kbd:[Ctrl+Alt+Del] |
Ctrl+Alt+Del |
Link (external) |
link:http://www.packetfence.org[PacketFence] |
|
Lists Note Do not put steps in bold.
|
.Ordered list . First item . Second item . Third item .Unordered list * This * That * The other .Definition or labeled list Term A:: description Term B:: description .Checklist * [ ] first step ** [ ] first task ** [ ] second task * [ ] second step * [ ] third step |
Ordered list
Unordered list
Definition or labeled list
Checklist
|
Literal value |
The function returns `true`. |
The function returns |
Package |
Install the [package]`packetfence` package. |
Install the |
Product name |
No special markup. Use {nbsp} in the company and product names. Example: Inverse{nbsp}Inc. |
Inverse Inc. |
Reference to PacketFence guides |
See the PacketFence link:guide-url[_Installation Guide_] for more information. |
See the PacketFence Installation Guide for more information. |
System or software variable to be replaced by the user |
Use the following command to roll back a deployment, specifying the deployment name: `oc rollback _deployment_`. |
Use the following command to roll back a deployment, specifying the deployment name: |
System or software configuration parameter or environment variable |
Use the `_IP_ADDRESS_` environment variable for the server IP address. |
Use the |
System item, daemon, or service |
Include the `pf::Switch` library. Stop the `pfqueue` daemon. Start the `iptables` service. |
Include the Stop the Start the |
3.1.1. Shell commands in code blocks
-
Remove useless characters in code blocks like
#
or$
-
Split long lines with
\
3.2. Checklist to create a new guide
-
❏ create PacketFence_GUIDENAME.asciidoc based on PacketFence Template Guide
-
❏ create PacketFence_GUIDENAME-docinfo.xml with only
copyright
tag -
❏ update
all
target in Makefile -
❏ update packaging (if necessary)
-
❏ update website listing to add a new guide
4. Code conventions
4.1. Code style
We are slowly migrating away from an automated perltidy
code style. The
reason we are not doing another pass of tidy is that it messes up code
history and makes maintainer’s job more complicated than it should be. Every
new change uses the new guidelines so over time the old code style will
slowly disappear.
-
Lines of 120 character width maximum
-
No tab characters
-
Stay consistent with surrounding white spaces
-
Document each subroutine in POD format (
perldoc perlpod
) -
Use constants instead of hard coded strings or numbers (use
constant
orReadonly
modules) -
in object-oriented modules we use CamelCase [2] notation (ex:
$radiusRequest->getVoIpAttributes();
) -
in procedural modules we use Perl’s usual notation (ex:
$node_info{'pid'} = $current_request{'pid'};
) -
regular expressions should be documented (with the
/x
modifier)if ($phone_number =~ / ^\(?([2-9]\d{2})\)? # captures first 3 digits allows parens (?:-|.|\s)? # separator -, ., space or nothing (\d{3}) # captures 3 digits (?:-|.|\s)? # separator -, ., space or nothing (\d{4})$ # captures last 4 digits /x) { return "$1$2$3"; }
-
SQL
should be capitalized, properly indented and always use named fields (no *)$node_statements->{'node_add_sql'} = get_db_handle()->prepare(<<'SQL'); INSERT INTO node ( mac, pid, category_id, status, voip, bypass_vlan, detect_date, regdate, unregdate, lastskip, user_agent, computername, dhcp_fingerprint, last_arp, last_dhcp, notes, ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) SQL
5. HTTP JSON API
PacketFence provides an HTTP JSON API which exposes most of its functionality.
The full API specification for:
-
the latest stable release is available from: https://packetfence.org/doc/api/
-
the latest devel release is available from: https://packetfence.org/doc/api-devel/
The API is exposed on 127.0.0.1 (localhost) as well as the management interface of the server for remote calls. Users access the API on TCP port 9999 over a secure connection (HTTPS).
Authentication can be done using either the webservices credentials or any credentials that are valid on the web admin interface.
5.1. How to use the API
5.1.1. On a PacketFence server
The pfperl-api
command located in /usr/local/pf/sbin/
directory can be use directly from a PacketFence server to query the API without having to specify an authentication token
and extra-parameters.
Example to get your general configuration:
/usr/local/pf/sbin/pfperl-api get /api/v1/config/base/general \
| python -m json.tool
Example to create a node:
/usr/local/pf/sbin/pfperl-api get -M POST /api/v1/nodes/ \
-c '{"mac":"22:33:44:55:66:77","pid":"host/MYCOMPUTER"}' \
| python -m json.tool
5.1.2. On a different computer
First, get an authentication token with the webservices credentials or an admin account:
curl -X POST "https://PF_MANAGEMENT_IP:9999/api/v1/login" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d "{\"username\":\"admin\",\"password\":\"admin\"}" \
--insecure |
python -m json.tool
You will get following response :
{
"token": "MY_TOKEN"
}
Then use this token to query the API. The following example fetches the general configuration:
curl -X GET "https://PF_MANAGEMENT_IP:9999/api/v1/config/base/general" \
-H "accept: application/json" \
-H "Authorization: MY_TOKEN" \
--insecure |
python -m json.tool
Although the API should mostly stay the same, backward compatibility is not 100% guaranteed for the moment until the v1 API reaches full maturity.
6. Customizing PacketFence
6.1. Captive Portal
6.1.1. Presentation
XHTML Templates
Captive portal content use Template Toolkit
templates. The default template files are located in /usr/local/pf/html/captive-portal/templates
.
You can freely edit the HTML
code in these files.
Each template relies on layout.html
for the common top and bottom portions of the page.
Internationalized AUP
In the event that you need an Acceptable Usage Policy that should be translated in different languages in the captive portal, you can create specially named templates that will be used for different languages.
For example, if the browser locale is es_ES
, creating a template named aup_text.es.html
will display this AUP when it detects this locale.
Same goes for a browser with locale en_US
, where creating a template named aup_text.en.html
will be used for English browsers.
The template aup_text.html
is used as the final fallback for all locales.
Note that you cannot use the full locale in the template name (i.e. aup_text.en_US.html
) as only the two letter prefix should be used.
CSS
The default stylesheet is the result of processing some Sass files structured around the solid inuitcss architectural foundation.
-
/usr/local/pf/html/common/Gruntfile.js
— the task runner configuration file -
/usr/local/pf/html/common/package.js
— the npm dependencies required to process the Sass files -
/usr/local/pf/html/common/scss/
— the directory containing the Sass source files -
/usr/local/pf/html/common/styles.css
— the generated stylesheet
In order to prepare your environment to process the Sass files, you need to install grunt (the task runner) and additional nodejs modules, including the various inuitcss components:
sudo npm install -g grunt-cli cd /usr/local/pf/html/common npm install
Once all modules are downloaded, you can customize the Sass files and generate a new stylesheet:
grunt dist
To change the color palette of the captive portal, modify the file scss/_settings.colors.scss
.
Workflow
When a HTTP
request is received by the Apache web server, the following workflow happens:
-
URL is compared against the redirection instructions in
/usr/local/pf/conf/httpd.conf.d/captive-portal-cleanurls.conf
-
Requested CGI script in
/usr/local/pf/html/captive-portal/
is executed -
CGI script calls a
generate_<type>
which is defined in/usr/local/pf/lib/pf/web.pm
-
The
generate_<type>
function populate the proper template in/usr/local/pf/html/captive-portal/templates
in order to render the page
Remediation Pages
The remediation page shown to the user during isolation are specified through
the URL parameter of the given security event in /usr/local/pf/conf/security_events.conf
.
In its default configuration, PacketFence uses Template Toolkit to render text provided
in the directory /usr/local/pf/html/captive-portal/templates/security_events
and obeys
to everything mentioned in the Presentation section.
Translations
The language of the user registration pages is selected through the
general.locale
configuration parameter. Translatable strings are handled
differently for the Remediation pages and the rest of the captive portal:
-
Remediation pages
Strings defined in the security event pages (in
/usr/local/pf/html/captive-portal/templates/security_events
) will be looked up in the translation files in/usr/local/pf/conf/locale/..
and if a translation is available the translated string will be the one visible on the captive portal.Also, if you create a security event template with the name of your locale in
/usr/local/pf/html/captive-portal/templates/security_events
in the format:<template_name>.<locale_name>.html
. It will be loaded instead of the default<template_name>.html
and so you can put strings and HTML directly in your target language without the hassle of escaping everything properly as you would need to do withgettext
.For example, if
malware.es_ES.html
exists and you are using thees_ES
(Spanish) locale then it will be loaded instead ofmalware.html
on a security event set to load themalware
template. -
Rest of the captive portal
In the templates, if a string is in a
i18n()
call it will be translated. Alsopf::web
takes care of performing some of the other translations.
6.2. Adding custom fields to the database
You can, if needed, add additional fields to the PacketFence database. Keep in mind though that this might lead to more work when you upgrade to the next PacketFence version. Depending on the degree of integration of these fields with PacketFence, you’ll have to execute one or more of the following steps
6.2.1. Adding a field to the database only
In this case, the field is part of one of the main PacketFence tables, but PacketFence is unaware of it. PacketFence won’t consult the field and won’t be able to modify it. A possible usage scenario would be a 3rd party application which maintains this field.
Since PacketFence doesn’t have to know about the field, all you have to do is execute your SQL ALTER
TABLE
query and you are done.
6.2.2. Adding a field and giving PacketFence read-only access
In this case, PacketFence can show the contents of the table using both
pfcmd
but won’t be able to modify the contents of the field.
Start by modifying the database table using an SQL ALTER TABLE
query.
Then, modify the Perl module having the same name as the table you have added the field to, i.e. If you
added the field to the node table, then edit /usr/local/pf/lib/pf/node.pm
. You’ll have to modify the
SQL SELECT
queries at the beginning of the file to include your new field and, possibly the functions
using these queries. If your new field should be used in reports, the dashboard or graphs, you’ll also
have to modify the queries in /usr/local/pf/lib/pf/pfcmd/graph.pm
, /usr/local/pf/lib/pf/pfcmd/report.pm
and /usr/local/pf/lib/pf/pfcmd/dashboard.pm
.
6.2.3. Adding a field and giving PacketFence read-write access
Start by creating the read-only field as described above.
Then, modify the SQL UPDATE
and INSERT
queries in the database tables'
Perl module, as well as the associated functions.
6.3. VLAN assignment
PacketFence uses the getRegisteredRole
function defined in pf::role::custom
to determine a node’s VLAN. Here’s the default function:
sub getRegisteredRole { #$switch is the switch object (pf::Switch) #$ifIndex is the ifIndex of the computer connected to #$mac is the mac connected #$node_info is the node info hashref (result of pf::node's node_view on $mac) #$conn_type is set to the connection type expressed as the constant in pf::config #$user_name is set to the RADIUS User-Name attribute (802.1X Username or MAC address under MAC Authentication) #$ssid is the name of the SSID (Be careful: will be empty string if radius non-wireless and undef if not radius) my ($self, $switch, $ifIndex, $mac, $node_info, $connection_type, $user_name, $ssid) = @_; my $logger = Log::Log4perl->get_logger(); return $switch->getVlanByName('normalVlan'); }
As you can see, the function receives several parameters (such as the switch and full node details) which allow you to return the VLAN in a way that matches exactly your needs!
7. SNMP
7.1. Introduction
Good places to start reading about SNMP are http://en.wikipedia.org/wiki/SNMP and http://www.net-snmp.org/.
When working with SNMP, you’ll sooner or later (in fact more sooner than later) be confronted with having
to translate between OIDs and variable names. When the OIDs are part of the Cisco MIBs, you can use the
following tool to do the translation: http://tools.cisco.com/Support/SNMP/public.jsp. Otherwise, you’ll
have to use snmptranslate
for example and setup your own collection of MIBs, provided (hopefully) by
the manufacturer of your network equipment.
7.2. Obtaining switch and port information
Below are some example of how to obtain simple switch and port information using SNMP. We’ll assume that
your switch understands SNMP v2, has the read community public
defined and is reachable at 192.168.1.10
.
7.2.1. Switch Type
snmpwalk -v 2c -c public 192.168.1.10 sysDescr
7.2.2. Switchport indexes and descriptions
snmpwalk -v 2c -c public 192.168.1.10 ifDescr
7.2.3. Switchport types
snmpwalk -v 2c -c public 192.168.1.10 ifType
7.2.4. Switchport status
snmpwalk -v 2c -c public 192.168.1.10 ifAdminStatus snmpwalk -v 2c -c public 192.168.1.10 ifOperStatus
8. Supporting new network hardware
PacketFence is designed to ease the addition of support for new network hardware referred to as Network
Devices. All supported network devices are represented through Perl objects with an extensive use of inheritance.
Adding support for a new product comes down to extending the pf::Switch
class (in /usr/local/pf/lib/pf
).
The starting point to adding support for a new network device should be the vendor’s documentation! First of all, you’ll have to figure out the exact capabilities of the switch and how these capabilities will fit into PacketFence. Is it a Switch, an Access-Point or a Wireless Controller?
8.1. Switch
Will you be able to use only link change traps? Does your switch allow you to use MAC notification traps? Port Security? MAC Authentication? 802.1X?
8.1.1. Link change capabilities
You need to define a new class which inherits from pf::Switch
and defines
at least the following functions:
-
getMacAddrVlan
-
getVersion
-
getVlan
-
getVlans
-
isDefinedVlan
-
parseTrap
-
_getMacAtIfIndex
-
_setVlan
The parseTrap
function will need to return an hash with keys trapType
and
trapIfIndex
. The associated values must be up
or down
for trapType
and the traps' ifIndex
for trapIfIndex
. See a similar switch’s
implementation for inspiration. Usually recent modules are better coded than
older ones.
8.1.2. MAC notification capabilities
In addition to the functions mentioned for link change, you need to define the following function:
-
isLearntTrapsEnabled
Also, your parseTrap
function will need to return trapOperation
, trapVlan
and trapMac
keys in addition to trapType
equals mac
. See a similar switch’s
implementation for inspiration. Usually recent modules are better coded than
older ones.
8.1.3. Port security capabilities
In addition to the functions mentioned for link change, you need to define the following functions:
-
isPortSecurityEnabled
-
authorizeMAC
In this case, the parseTrap
function needs to return secureMacAddrViolation
for the
trapType
key. See a similar switch’s implementation for inspiration. Usually
recent modules are better coded than older ones.
8.1.4. MAC Authentication
NAS-Port translation
Often the ifIndex
provided by the switch in a RADIUS Access-Request
is
not the same as it’s real world physical equivalent. For example in Cisco
requests are in the 50xxx while physical ifIndex are 10xxx. In order for
PacketFence to properly shut the port or request re-authentication a
translation between the two is required. To do so provide an implementation
of the following interface:
-
NasPortToIfIndex
MAC Authentication re-evaluation
MAC Authentication re-evaluation is necessary in order to provoke a VLAN change in the PacketFence
system. This happens for instance when a node is isolated based on an IDS event or when the user
successfully authenticates through the captive portal. The default implementation in
pf::Switch
will bounce the port if there is no Voice over IP (VoIP) devices connected to the
port. Otherwise it will do nothing and send an email. If your device has specific needs (for example it
doesn’t support RADIUS Dynamic VLAN Assignments) override:
-
handleReAssignVlanTrapForWiredMacAuth
Please note that the default implementation works 99% of the time. If you are unsure whether to override, it means you don’t need to override.
Once the MAC Authentication works, add the Wired MAC Auth capability to the switch’s code with:
sub supportsWiredMacAuth { return $TRUE; }
8.1.5. 802.1X
NAS-Port translation
Often the ifIndex
provided by the switch in a RADIUS Access-Request
is
not the same as it’s real world physical equivalent. For example in Cisco
requests are in the 50xxx while physical ifIndex are 10xxx. In order for
PacketFence to properly shut the port or request re-authentication a
translation between the two is required. To do so provide an implementation
of the following interface:
-
NasPortToIfIndex
So far the implementation has been the same for MAC Authentication and 802.1X.
Force 802.1X re-authentication
802.1X re-authentication is necessary in order to provoke a VLAN change in the PacketFence system.
This happens for instance when a node is isolated based on an IDS event or when the user successfully
authenticates through the captive portal. The default implementation in pf::Switch
uses SNMP and the
standard IEEE8021-PAE-MIB
and is generally well supported. If the default implementation to
force 802.1X re-authentication doesn’t work override:
-
dot1xPortReauthenticate
Proper 802.1X implementations will perform re-authentication while still allowing traffic to go through for supplicants under re-evaluation.
Once the 802.1X
works, add the Wired Dot1X capability to the switch’s code with:
sub supportsWiredDot1x { return $TRUE; }
8.1.6. RADIUS Dynamic Authorization (RFC3576)
RADIUS Dynamic Authorization also known as RADIUS Change of Authorization (CoA) or RADIUS Disconnect Messages is supported by PacketFence starting with version 3.1.
On wired network devices CoA can be used to change the security posture of a MAC and perform other
functions like bounce a port. So far we only encountered support for CoA on the wired side on the Cisco
hardware. For an implementation example check _radiusBounceMac
in pf::Switch::Cisco
.
8.1.7. Floating Network Devices Support
Floating Network Devices are described in the Administration Guide under "Floating Network Devices" in the "Optional Components" section. Refer to this documentation if you don’t know what Floating Network Devices are.
In order to support Floating Network Devices on a switch, you need to implement the following methods:
-
setPortSecurityEnableByIfIndex($ifIndex, $enable)
-
isTrunkPort($ifIndex)
-
setModeTrunk($ifIndex, $enable)
-
setTaggedVlans($ifIndex, $switch_locker_ref, @vlans)
-
removeAllTaggedVlans($ifIndex, $switch_locker_ref)
You might need to implement the following:
-
enablePortConfigAsTrunk($mac, $switch_port, $switch_locker, $taggedVlans)
Provided by
pf::Switch
core as the glue betweensetModeTrunk()
,setTaggedVlans()
andremoveAllTaggedVlans()
. Override if necessary. -
disablePortConfigAsTrunk($switch_port)
Provided by
pf::Switch
core as the glue betweensetModeTrunk()
,setTaggedVlans()
andremoveAllTaggedVlans()
. Override if necessary. -
enablePortSecurityByIfIndex($ifIndex)
Provided by
pf::Switch
core as a slim accessor tosetPortSecurityEnableByIfIndex()
. Override if necessary. -
disablePortSecurityByIfIndex($ifIndex)
Provided by
pf::Switch
core as a slim accessor tosetPortSecurityEnableByIfIndex()
. Override if necessary. -
enableIfLinkUpDownTraps($ifIndex)
Provided by
pf::Switch
core as a slim accessor tosetIfLinkUpDownTrapEnable
. Override if necessary. -
disableIfLinkUpDownTraps($ifIndex)
Provided by
pf::Switch
core as a slim accessor tosetIfLinkUpDownTrapEnable
. Override if necessary.
Once all the required methods are implemented, enable the capability in the switch’s code with:
sub supportsFloatingDevice { return $TRUE; }
8.2. Wireless Access-Points or Controllers
8.2.1. Minimum hardware requirements
PacketFence’s minimum requirements regarding Wireless hardware is:
-
definition of several SSID with several VLANs inside every SSID (minimum of 2 VLANs per SSID)
-
RADIUS authentication (MAC Authentication / 802.1X)
-
Dynamic VLAN assignment through RADIUS attributes
-
a means to de-associate or de-authenticate a client through CLI (Telnet or SSH), SNMP, RADIUS Dyn-Auth [3] or WebServices
Most of these features are available on enterprise grade Access Points (AP) or Controllers. Where the situation starts to vary wildly is for deauthentication support.
8.2.2. De-authentication techniques
CLI (SSH or Telnet)
An error prone interface and requires preparation for the SSH access or is insecure for Telnet. Not recommended if you can avoid it.
SNMP
SNMP de-authentication works well when available. However Vendor support is not consistent and the OID to use are not standard.
RADIUS Dynamic Authorization (RFC3576)
RADIUS Dynamic Authorization also known as RADIUS Change of Authorization (CoA) or RADIUS Disconnect Messages is supported by PacketFence starting with version 3.1. When supported it is the preferred technique to perform de-authentication. It is standard and requires less configuration from the user.
An actual implementation can be found in pf::Switch::Aruba
.
8.2.3. Template module
Start with a copy of the template module pf/lib/pf/Switch/WirelessModuleTemplate.pm
and fill in appropriate documentation and code.
8.2.4. Required methods
You need to implement at least:
getVersion()
-
Fetches firmware version
parseTrap()
-
Parses the SNMP Traps sent by the hardware. For wireless hardware an empty method like the one in
pf::Switch::WirelessModuleTemplate
is ok. deauthenticateMac()
-
Performs deauthentication
supportsWirelessMacAuth()
-
Return
$TRUE
if MAC-Authentication is supported supportsWirelessDot1x()
-
Return
$TRUE
if 802.1X (aka WPA-Enterprise) is supported
8.2.5. Override methods
If default implementation of the following methods doesn’t work you will need to override them:
extractSsid()
-
Extract SSID from RADIUS Request
8.2.6. Special case: bridged versus tunneled modes and deauthentication
It is important to validate the Access-Point (AP) to Controller relationship when operating in bridged
mode versus when operating in tunneled mode. For example, some hardware will send the RADIUS Access-Request
from the AP when in bridged mode even though it is controlled by a controller. This behavior impacts
deauthentication because it still needs to be performed on the controller. To support this behavior a
switches.conf
parameter was introduced: controller_ip
.
When adding a new Wireless module try to validate the bridged versus tunneled behavior and modify
deauthenticateMac()
to honor controller_ip
if required.
8.3. The "adding a new network device module in PacketFence" checklist
Here’s a quick rundown of the several files you need to edit in order to add a new switch into PacketFence. There’s a plan to reduce this amount of work in progress see issue #1085.
-
Tested model and firmware version should be documented in module’s POD
-
Any bugs and limitations should be documented in module’s POD
-
Add it to
pf/html/admin/configuration/switches_add.php
andswitches_edit.php
-
Make sure that all tests pass
-
Add configuration documentation to the Network Devices Guide
-
Add switch to the Network Devices Guide’s switch chart
-
Add switch to the chart in
README.network-devices
9. Developer recipes
9.1. Running development version
9.1.1. Bleeding edge
For day to day development one can run a checkout of the current development branch in
/usr/local/pf/
and develop there within a working setup.
Prerequisites
-
Vagrant (>= 1.9.3)
-
Virtualbox if you wan to use Virtualbox as a provider for Vagrant
-
libvirt, KVM/QEMU and vagrant-libvirt if you want to use libvirt as a provider for Vagrant
Initial setup
Following steps assume you use a CentOS machine but you can have same behavior under Debian.
sudo yum install -y epel-release
sudo yum install -y git python-pip
pip install --user ansible
pip install --user mazer
git clone https://github.com/inverse-inc/packetfence.git
cd packetfence/addons/vagrant
mazer install --lockfile=collections_lockfile.yml
ansible-galaxy install -r requirements.yml
vagrant up pfcendev
vagrant reload pfcendev
At the end of this process, you will have latest PacketFence’s source code,
running in a CentOS 7 virtual machine, located in /usr/local/pf
with all dependencies installed as RPM packages. You can directly develop from
/usr/local/pf
.
Web admin should be reachable through management IP address of pfcendev
machine, configured in addons/vagrant/inventory/hosts
.
9.1.2. Not so bleeding edge
Using the development yum
repository and upgrade PacketFence often is a good way to proceed.
Check our snapshots download page for
instructions.
Make sure you read the UPGRADE
document after every upgrades to avoid any surprises.
9.2. New Exception handling techniques under testing
Little attention was given to error-handling in PacketFence’s early design. This is understandable as it wasn’t probably the most bang-for-the-buck thing to do. However we must now live with a large code base that explodes at runtime or that doesn’t differentiate an erroneous condition from an undefined or 0 value. Refactoring to improve error-handling will be gradual but new code should follow these tips:
-
use
Try::Tiny
-
wrap stuff in
try {...} catch {...};
(and optionally afinally {...};
) -
in the code use
die(...);
to throw an exception and make the error message meaningful -
in the catch block, use
$logger->logcarp("explanation: $_")
if I want output to the CLI, otherwise, choose wisely
This catches a lot of errors (including runtime crashers) and allows us to recover from these conditions.
So far, it is mandatory to wrap the Web Services enabled network devices modules' code since
SOAP::Lite
will die on you if host is unreachable for example (actually it’s LWP::UserAgent
who will).
10. Contributing
Here are some golden rules of contributing to PacketFence:
-
Be active on the developer mailing list
The place to be if you want to contribute to the PacketFence project is our developers mailing list: https://lists.sourceforge.net/lists/listinfo/packetfence-devel. Let us know your issues, what you are working on and how you want to solve your problems. The more you collaborate the greater the chances that your work will be incorporated in a timely fashion.
-
Use the issue tracker: https://packetfence.org/bugs/
Good chances that the bug you want to fix or the feature you want to implement is already filed and that information in the ticket will help you.
-
Please provide small, focused and manageable patches or pull-requests
If you plan on doing a lot of code, use git
and track our current stable branch called stable
. Develop the
feature in small chunks and stay in touch with us. This way it’ll be merged quickly in our code base. Ideally
there would be no big code dumps after finishing a feature.
10.1. Creating patches
Patches should be sent in unified diff format. This can be obtained from the
diff
or git
tools.
diff -u oldfile newfile
or from a checkout of the PacketFence source code from git
:
git diff
10.2. Translations
The internationalization process uses gettext
. If you are new to gettext
, please consult
http://www.gnu.org/software/gettext/manual/gettext.html#Overview for a quick introduction.
The PO files are stored in /usr/local/pf/conf/locale
. List that directory to see the languages
we currently have translations for.
10.2.1. Online using Transifex
We use the hosted service Transifex to translate PacketFence’s PO files. It offers the possibility to translate all the strings online as well as providing a command-line tool to push your changes. It’s very convenient.
To use Transifex, you must first sign up for a free account here: https://www.transifex.net/plans/signup/free/
-
Once registered, request a new team for your language
-
Once authorized, you’ll be able to start/continue translating PacketFence in your language
If you need further help about using Transifex, you might want to have a look here.
10.2.2. Using traditional method
If you want to add support for a new language, please follow these steps:
-
create a new language subdirectory in
/usr/local/pf/conf/locale
-
change into your newly created directory
-
create a new subdirectory
LC_MESSAGES
-
change into your newly created directory
-
copy the file
/usr/local/pf/conf/locale/en/LC_MESSAGES/packetfence.po
into your directory -
translate the message strings in
packetfence.po
-
create the MO file by executing:
/usr/bin/msgfmt packetfence.po
Submit your new translation to the PacketFence project by contacting us at packetfence-devel@lists.sourceforge.net.
10.3. Admin GUI
The Admin GUI can be customized via Controllers and templates.
10.3.1. Templates
You can add customize templates to the /usr/local/pf/html/pfappserver/root-custom/
folder to override current templates.
However when doing this you must keep track of any changes to those templates across versions.
10.3.2. Stylesheets and JavaScript
The main stylesheet is the result of processing some Sass files structured around the excellent Bootstrap framework.
-
/usr/local/pf/html/pfappserver/root/static/Gruntfile.js
— the task runner configuration file -
/usr/local/pf/html/pfappserver/root/static/package.js
— the npm dependencies required to process the Sass files and to package the JavaScript code -
/usr/local/pf/html/pfappserver/root/static/bower.json
— the list of required components -
/usr/local/pf/html/pfappserver/root/static/scss/
— the directory containing the Sass source files -
/usr/local/pf/html/pfappserver/root/static/css/styles.css
— the generated stylesheet -
/usr/local/pf/html/pfappserver/root/static/js/vendor/
— the directory containing the external JavaScript libraries
In order to prepare your environment, you need to install grunt (the task runner) and bower (the package manager):
sudo npm install -g grunt-cli sudo npm install -g bower cd /usr/local/pf/html/pfappserver/root/static/ npm install bower install
Once all modules and components are downloaded, you can customize the Sass files or JavaScript files and generate a new version of the static files:
grunt dist
10.3.3. Controllers
You change the behavior of the controllers by modifying the controllers in the path.
/usr/local/pf/html/pfappserver/lib/pfappserver/Controller/
However when doing this you must keep track of any changes to those Controllers across versions.
11. Additional Information
For more information, please consult the mailing archives or post your questions to it. For details, see:
-
packetfence-announce@lists.sourceforge.net: Public announcements (new releases, security warnings etc.) regarding PacketFence
-
packetfence-devel@lists.sourceforge.net: Discussion of PacketFence development
-
packetfence-users@lists.sourceforge.net: User and usage discussions
12. Commercial Support and Contact Information
For any questions or comments, do not hesitate to contact us by writing an email to: support@inverse.ca.
Inverse (http://inverse.ca) offers professional services around PacketFence to help organizations deploy the solution, customize, migrate versions or from another system, performance tuning or aligning with best practices.
Hourly rates or support packages are offered to best suit your needs.
Please visit http://inverse.ca/ for details.
13. GNU Free Documentation License
Please refer to http://www.gnu.org/licenses/fdl-1.2.txt for the full license.