Home-made Web GUI Configuration Generator

A friend asked me about configuration generator last week, which reminded me to review the topic of home-made configuration generator 🙂

I used Excel and Powershell to generate configuration before. I tried to make a Web GUI Configuration Generator this time, using PHP index and trigger pre-defined XML templates. index.php also handles output. Example and steps are as below:

1) Build a web server

I am using macbook and simply enable Apache and PHP support.

How to build local web server on mac: https://discussions.apple.com/docs/DOC-3083

Another good reference: http://osxdaily.com/2012/09/10/enable-php-apache-mac-os-x/

(Your mac may support nano editor by native. ‘nano’ is much more convenient than ‘vi’ to edit files)

2) Save index.php and XML templates to web server root folder

File can be downloaded from (I found template from GitHub and modified. Please read original author declaration before use): 

https://dl.dropboxusercontent.com/u/36482628/WordPress/Web_Config_Generator.zip

Test access to index.php file. It supports the selection of multiple templates.

web_gui1

3) Modify templetes

tpl is xml template file, it can be open by any text editor. All variables are defined and consumed in the template file in consistent to xml syntax. The example template uses the following variable types.

  • ‘simple’ question type: simple text variable
  • ‘switch’ question type: dropdown list variable
  • ‘checkbox’ question type: checkbox variable

I made an example template for SVI HSRP configuration generation. It can be downloaded from  the previous dropbox link or content at the end of the blog. It is a simple use case and doesn’t include variable manipulation such as calculation.

Upon selecting the template to use, the following page shows:

web_gui2

Upon clicking submit, the following output result shows:

web_gui3.png

1_VLAN_CREATION.tpl

<xml>
<!–

Simple question type, will create a text input, and replace the match with what was entered

shortname = value that will be used in “NAME” attribut of form element to identify this question
description = Text shown on form to describe desired input.
–>
<question type=”simple” shortname=”vlan_id” description=”VLAN ID”>
<!– Whereever this string is found in template (Surrounded by [% and %]) we will
replace it with the text entered in the form –>
<match>VLANID</match>
</question>
<question type=”simple” shortname=”vlan_ip1″ description=”Primary SVI IP”>
<!– Whereever this string is found in template (Surrounded by [% and %]) we will
replace it with the text entered in the form –>
<match>SVIIP1</match>
</question>

<question type=”simple” shortname=”vlan_ip2″ description=”Secondary SVI IP”>
<!– Whereever this string is found in template (Surrounded by [% and %]) we will
replace it with the text entered in the form –>
<match>SVIIP2</match>
</question>

<question type=”simple” shortname=”vlan_vip” description=”VLAN VIP”>
<!– Whereever this string is found in template (Surrounded by [% and %]) we will
replace it with the text entered in the form –>
<match>VLANVIP</match>
</question>

<question type=”simple” shortname=”IP_mask” description=”IP MASK”>
<!– Whereever this string is found in template (Surrounded by [% and %]) we will
replace it with the text entered in the form –>
<match>IPMASK</match>
</question>

<!–

Question type switch, will create a drop down, and let you choose between several options

shortname = value that will be used in “NAME” attribut of form element to identify this question
description = Text shown on form to describe desired input.
–>
<question type=”switch” shortname=”vrf” description=”SELECT VRF”>
<!–
Define’s an availible option in the dropdown, shortname and description like for questions.
–>
<option shortname=”red” description=”RED VRF”>
<!–
If this option is selected in the form, we will go through each block, and replace the string matched
in the match element (surrounded by [% and %], with the contents of the replace element.
–>
<block>
<match>VRF</match>
<replace>RED_VRF</replace>
</block>
<block>
</block>
</option>
<option shortname=”green” description=”GREEN VRF”>
<block>
<match>VRF</match>
<replace>GREEN_VRF</replace>
</block>
<block>
</block>
</option>
</question>

<!–
Question type Checkbox, if checked will replace string in match element (Surrounded by [% and %]) with
contents of replace element. If not checked, will replace with nothing (will remove string in match element
from template
–>
<question type=”checkbox” shortname=”preempt” description=”HSRP PREEMPT”>
<match>PREEMPT</match>
<replace>preempt</replace>
</question>
</xml>
–BEGIN-TEMPLATE–

Core 1
interface vlan [% VLANID %]
ip vrf forwarding [% VRF %]
ip address [% SVIIP1 %] [% IPMASK %]
standby [% VLANID %] ip [% VLANVIP %]
standby [% VLANID %] priority 150
standby [% VLANID %] [% PREEMPT %]

*************************************************************

Core 2
interface vlan [% VLANID %]
ip vrf forwarding [% VRF %]
ip address [% SVIIP2 %] [% IPMASK %]
standby [% VLANID %] ip [% VLANVIP %]
standby [% VLANID %] [% PREEMPT %]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s