Browse Source

Add klish specific example

git-svn-id: https://klish.googlecode.com/svn/trunk@203 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
dbd9371306
28 changed files with 671 additions and 0 deletions
  1. 12 0
      xml-examples/klish/bin/klish
  2. 1 0
      xml-examples/klish/bin/klish-enable
  3. 1 0
      xml-examples/klish/etc/clish-enable/common.xml
  4. 1 0
      xml-examples/klish/etc/clish-enable/configure-mode.xml
  5. 1 0
      xml-examples/klish/etc/clish-enable/enable-mode.xml
  6. 1 0
      xml-examples/klish/etc/clish-enable/interface.xml
  7. 1 0
      xml-examples/klish/etc/clish-enable/overview.xml
  8. 1 0
      xml-examples/klish/etc/clish-enable/ping.xml
  9. 1 0
      xml-examples/klish/etc/clish-enable/route.xml
  10. 10 0
      xml-examples/klish/etc/clish-enable/startup.xml
  11. 1 0
      xml-examples/klish/etc/clish-enable/types.xml
  12. 20 0
      xml-examples/klish/etc/clish-xml/common.xml
  13. 55 0
      xml-examples/klish/etc/clish-xml/configure-mode.xml
  14. 74 0
      xml-examples/klish/etc/clish-xml/enable-mode.xml
  15. 28 0
      xml-examples/klish/etc/clish-xml/info-mode.xml
  16. 119 0
      xml-examples/klish/etc/clish-xml/interface.xml
  17. 45 0
      xml-examples/klish/etc/clish-xml/overview.xml
  18. 43 0
      xml-examples/klish/etc/clish-xml/ping.xml
  19. 109 0
      xml-examples/klish/etc/clish-xml/route.xml
  20. 62 0
      xml-examples/klish/etc/clish-xml/types.xml
  21. 1 0
      xml-examples/klish/etc/clish/common.xml
  22. 1 0
      xml-examples/klish/etc/clish/info-mode.xml
  23. 1 0
      xml-examples/klish/etc/clish/overview.xml
  24. 1 0
      xml-examples/klish/etc/clish/ping.xml
  25. 10 0
      xml-examples/klish/etc/clish/startup.xml
  26. 1 0
      xml-examples/klish/etc/clish/types.xml
  27. 8 0
      xml-examples/klish/etc/init.d/klish-init
  28. 62 0
      xml-examples/klish/usr/bin/nmask

+ 12 - 0
xml-examples/klish/bin/klish

@@ -0,0 +1,12 @@
+#!/bin/sh
+
+export SYSTEM_NAME=`hostname`
+
+progname=`basename $0`
+
+if [ "$progname" = "klish-enable" ]; then
+	export CLISH_PATH=/etc/clish-enable
+fi
+
+exec /usr/bin/clish "$@"
+

+ 1 - 0
xml-examples/klish/bin/klish-enable

@@ -0,0 +1 @@
+klish

+ 1 - 0
xml-examples/klish/etc/clish-enable/common.xml

@@ -0,0 +1 @@
+../clish-xml/common.xml

+ 1 - 0
xml-examples/klish/etc/clish-enable/configure-mode.xml

@@ -0,0 +1 @@
+../clish-xml/configure-mode.xml

+ 1 - 0
xml-examples/klish/etc/clish-enable/enable-mode.xml

@@ -0,0 +1 @@
+../clish-xml/enable-mode.xml

+ 1 - 0
xml-examples/klish/etc/clish-enable/interface.xml

@@ -0,0 +1 @@
+../clish-xml/interface.xml

+ 1 - 0
xml-examples/klish/etc/clish-enable/overview.xml

@@ -0,0 +1 @@
+../clish-xml/overview.xml

+ 1 - 0
xml-examples/klish/etc/clish-enable/ping.xml

@@ -0,0 +1 @@
+../clish-xml/ping.xml

+ 1 - 0
xml-examples/klish/etc/clish-enable/route.xml

@@ -0,0 +1 @@
+../clish-xml/route.xml

+ 10 - 0
xml-examples/klish/etc/clish-enable/startup.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema" 
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
+                     http://clish.sourceforge.net/XMLSchema/clish.xsd">
+
+	<STARTUP view="enable-view">
+	</STARTUP>
+
+</CLISH_MODULE>

+ 1 - 0
xml-examples/klish/etc/clish-enable/types.xml

@@ -0,0 +1 @@
+../clish-xml/types.xml

+ 20 - 0
xml-examples/klish/etc/clish-xml/common.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema" 
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
+                     http://clish.sourceforge.net/XMLSchema/clish.xsd">
+	<!--=======================================================-->
+
+<COMMAND name="exit"
+	help="Exit from the CLI">
+	<ACTION builtin="clish_close"/>
+</COMMAND>
+
+<COMMAND name="!"
+	help="Comments">
+	<ACTION>echo</ACTION>
+</COMMAND>
+
+</CLISH_MODULE>
+
+

+ 55 - 0
xml-examples/klish/etc/clish-xml/configure-mode.xml

@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema" 
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
+                     http://clish.sourceforge.net/XMLSchema/clish.xsd">
+	<!--=======================================================-->
+
+<VIEW name="configure-view"
+	prompt="${SYSTEM_NAME}(config)# "
+	restore="depth">
+
+<!------ Inheritance ------>
+
+	<NAMESPACE ref="enable-view" 
+		prefix="do"
+		help="true"
+		completion="true"/>
+
+	<COMMAND name="do"
+		help="To run exec commands in config mode"/>
+
+<!------ Virtual commands ------>
+
+	<COMMAND name="no"
+		help="Negate a command or set its defaults"/>
+
+	<COMMAND name="ip"
+		help="Global IP configuration subcommands"/>
+
+	<COMMAND name="no ip"
+		help="Global IP configuration subcommands"/>
+
+<!------ Simple configuration mode commands ------>
+
+	<COMMAND name="exit"
+		help="Exit from configure mode"
+		view="enable-view">
+	</COMMAND>
+
+	<COMMAND name="hostname"
+		help="Set system's network name">
+		<PARAM name="hostname"
+			help="This system's network name"
+			ptype="STRING"/>
+		<CONFIG priority="0x1000"/>
+		<ACTION>
+		hostname "${hostname}"
+		echo "${hostname}" > /etc/hostname
+		sed -i "s|^127\.0\.0\.1.*$|127.0.0.1 localhost ${hostname}|" /etc/hosts
+		</ACTION>
+	</COMMAND>
+
+</VIEW>
+
+</CLISH_MODULE>

+ 74 - 0
xml-examples/klish/etc/clish-xml/enable-mode.xml

@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema" 
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
+                     http://clish.sourceforge.net/XMLSchema/clish.xsd">
+	<!--=======================================================-->
+<VIEW name="enable-view"
+	prompt="${SYSTEM_NAME}# ">
+
+<!------ Inheritance ------>
+
+	<NAMESPACE ref="ping-view" 
+		help="true"
+		completion="true"/>
+
+<!------ Simple enable mode commands ------>
+
+	<COMMAND name="disable"
+		help="Turn off privileged commands">
+		<ACTION builtin="clish_close"/>
+	</COMMAND>
+
+	<COMMAND name="reboot"
+		help="Halt and perform a cold restart">
+		<ACTION>reboot</ACTION>
+	</COMMAND>
+
+	<COMMAND name="configure"
+		help="Enter configuration mode"/>
+
+	<COMMAND name="configure terminal"
+		help="Configure from the terminal"
+		view="configure-view">
+	</COMMAND>
+
+<!------ Show commands ------>
+
+	<COMMAND name="show"
+		help="Show running system information"/>
+
+	<COMMAND name="show ip"
+		help="IP information"/>
+
+	<COMMAND name="show diag"
+		help="Show diagnostic information for port adapters/modules">
+		<ACTION>lspci</ACTION>
+	</COMMAND>
+
+	<COMMAND name="show running-config"
+		help="Current operating configuration">
+		<CONFIG operation="dump"/>
+	</COMMAND>
+
+	<COMMAND name="show startup-config"
+		help="Contents of startup configuration">
+		<ACTION>cat /etc/startup-config</ACTION>
+	</COMMAND>
+
+<!------ Copy commands ------>
+
+	<COMMAND name="copy"
+		help="Copy from one file to another"/>
+
+	<COMMAND name="copy running-config"
+		help="Copy from current system configuration"/>
+
+	<COMMAND name="copy running-config startup-config"
+		help="Copy to startup configuration">
+		<CONFIG operation="dump" file="/etc/startup-config"/>
+	</COMMAND>
+
+</VIEW>
+
+</CLISH_MODULE>

+ 28 - 0
xml-examples/klish/etc/clish-xml/info-mode.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema" 
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
+                     http://clish.sourceforge.net/XMLSchema/clish.xsd">
+	<!--=======================================================-->
+
+<VIEW name="info-view"
+	prompt="${SYSTEM_NAME}&gt; ">
+
+<!------ Inheritance ------>
+
+	<NAMESPACE ref="ping-view" 
+		help="true"
+		completion="true"/>
+
+<!------ Simple non-priveledged mode commands ------>
+
+	<COMMAND name="enable"
+		help="Turn on privileged commands">
+		<DETAIL>
+		</DETAIL>
+		<ACTION>su -c klish-enable</ACTION>
+	</COMMAND>
+
+</VIEW>
+
+</CLISH_MODULE>

+ 119 - 0
xml-examples/klish/etc/clish-xml/interface.xml

@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema" 
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
+                     http://clish.sourceforge.net/XMLSchema/clish.xsd">
+	<!--=======================================================-->
+
+<VIEW name="enable-view">
+
+	<COMMAND name="show interfaces"
+		help="Interface status and configuration">
+		<ACTION>ip addr show</ACTION>
+	</COMMAND>
+
+	<COMMAND name="show ip interface"
+		help="IP interface status and configuration">
+		<ACTION>ip addr show</ACTION>
+	</COMMAND>
+
+</VIEW>
+
+<VIEW name="configure-view">
+
+	<COMMAND name="interface"
+		help="Select an interface to configure"/>
+
+	<COMMAND name="interface ethernet"
+		help="Ethernet IEEE 802.3"
+		view="configure-if-view"
+		viewid="iface=eth${iface_num}">
+		<PARAM name="iface_num"
+			help="Ethernet interface number"
+			ptype="IFACE_NUM"/>
+		<CONFIG priority="0x2001" pattern="^${__line}$"/>
+	</COMMAND>
+
+</VIEW>
+
+<VIEW name="configure-if-view"
+	prompt="${SYSTEM_NAME}(config-if-${iface})# "
+	depth="1">
+
+<!------ Inheritance ------>
+
+	<NAMESPACE ref="configure-view"
+		help="false"
+		completion="true"/>
+
+<!------ Simple configure-if mode commands ------>
+
+	<COMMAND name="exit"
+		help="Exit from interface configuration mode">
+		<ACTION builtin="clish_nested_up"/>
+	</COMMAND>
+
+	<COMMAND name="no"
+		help="Negate a command or set its defaults"/>
+
+	<COMMAND name="ip"
+		help="Interface Internet Protocol config commands"/>
+
+	<COMMAND name="no ip"
+		help="Interface Internet Protocol config commands"/>
+
+<!------ IP address ------>
+
+	<COMMAND name="ip address"
+		help="Set the IP address of an interface">
+		<PARAM name="ip_method"
+			help="Method to get IP"
+			ptype="SUBCOMMAND"
+			mode="switch">
+			<PARAM name="dhcp"
+				help="IP Address negotiated via DHCP"
+				ptype="SUBCOMMAND"
+				mode="subcommand"/>
+			<PARAM name="ip"
+				help="IP address"
+				ptype="IP_ADDR_MASK"/>
+		</PARAM>
+		<CONFIG/>
+		<ACTION>
+			if test "${ip_method}" = "dhcp"; then
+				dhclient ${iface}
+			elif test "${ip_method}" = "ip"; then
+				ip addr show dev ${iface} | grep "inet " | (while read a b c; do ip addr del $b dev ${iface}; done)
+				ip addr add ${ip} dev ${iface}
+			fi
+		</ACTION>
+	</COMMAND>
+
+	<COMMAND name="no ip address"
+		help="Set the IP address of an interface">
+		<CONFIG operation="unset" pattern="^ip address"/>
+		<ACTION>
+			ip addr show dev ${iface} | grep "inet " | (while read a b c; do ip addr del $b dev ${iface}; done)
+		</ACTION>
+	</COMMAND>
+
+<!------ Enable/Disable ------>
+
+	<COMMAND name="disable"
+		help="Disable the selected interface">
+		<CONFIG operation="unset" pattern="^enable"/>
+		<ACTION>
+			ip link set ${iface} down
+		</ACTION>
+	</COMMAND>
+
+	<COMMAND name="enable"
+		help="Enable the selected interface">
+		<CONFIG/>
+		<ACTION>
+			ip link set ${iface} up
+		</ACTION>
+	</COMMAND>
+</VIEW>
+
+</CLISH_MODULE>

+ 45 - 0
xml-examples/klish/etc/clish-xml/overview.xml

@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema" 
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
+                     http://clish.sourceforge.net/XMLSchema/clish.xsd">
+ 	<!--=======================================================-->
+	<OVERVIEW>
+CONTEXT SENSITIVE HELP
+[?] - Display context sensitive help. This is either a list of possible
+      command completions with summaries, or the full syntax of the 
+      current command. A subsequent repeat of this key, when a command
+      has been resolved, will display a detailed reference.
+
+AUTO-COMPLETION
+The following keys both perform auto-completion for the current command line.
+If the command prefix is not unique then the bell will ring and a subsequent
+repeat of the key will display possible completions.
+
+[enter] - Auto-completes, syntax-checks then executes a command. If there is 
+          a syntax error then offending part of the command line will be
+          highlighted and explained.
+
+[space] - Auto-completes, or if the command is already resolved inserts a space.
+
+MOVEMENT KEYS
+[CTRL-A] - Move to the start of the line
+[CTRL-E] - Move to the end of the line.
+[up]     - Move to the previous command line held in history.
+[down]   - Move to the next command line held in history.
+[left]   - Move the insertion point left one character.
+[right]  - Move the insertion point right one character.
+
+DELETION KEYS
+[CTRL-C]    - Delete and abort the current line
+[CTRL-D]    - Delete the character to the right on the insertion point.
+[CTRL-K]    - Delete all the characters to the right of the insertion point.
+[CTRL-U]    - Delete the whole line.
+[backspace] - Delete the character to the left of the insertion point.
+
+ESCAPE SEQUENCES
+!!  - Subsitute the the last command line.
+!N  - Substitute the Nth command line (absolute as per 'history' command)
+!-N - Substitute the command line entered N lines before (relative)
+    </OVERVIEW>
+</CLISH_MODULE>

+ 43 - 0
xml-examples/klish/etc/clish-xml/ping.xml

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema" 
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
+                     http://clish.sourceforge.net/XMLSchema/clish.xsd">
+	<!--=======================================================-->
+
+<VIEW name="ping-view"
+	prompt="${SYSTEM_NAME}# ">
+
+	<COMMAND name="ping"
+		help="Send echo messages">
+		<PARAM name="ip"
+			help="IP echo"
+			ptype="STRING"
+			mode="subcommand"
+			optional="true"/>
+		<PARAM name="addr"
+			help="Ping destination address or hostname"
+			ptype="STRING"/>
+		<ACTION>
+		ping ${addr}
+		</ACTION>
+	</COMMAND>
+
+	<COMMAND name="traceroute"
+		help="Trace route to destination">
+		<PARAM name="ip"
+			help="IP trace"
+			ptype="STRING"
+			mode="subcommand"
+			optional="true"/>
+		<PARAM name="addr"
+			help="Trace route to destination address or hostname"
+			ptype="STRING"/>
+		<ACTION>
+		traceroute ${addr}
+		</ACTION>
+	</COMMAND>
+
+</VIEW>
+
+</CLISH_MODULE>

+ 109 - 0
xml-examples/klish/etc/clish-xml/route.xml

@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema" 
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
+                     http://clish.sourceforge.net/XMLSchema/clish.xsd">
+	<!--=======================================================-->
+
+<VIEW name="enable-view">
+
+<!------ Show routing information ------>
+
+	<COMMAND name="show ip route"
+		help="IP routing table">
+		<ACTION>ip route show</ACTION>
+	</COMMAND>
+
+</VIEW>
+
+
+<VIEW name="configure-view">
+
+<!------ Enable/Disable routing ------>
+
+	<COMMAND name="ip routing"
+		help="Enable IP routing">
+		<CONFIG operation="unset" pattern="^no ip routing"/>
+		<ACTION>
+		echo "1" > /proc/sys/net/ipv4/ip_forward
+		</ACTION>
+	</COMMAND>
+
+	<COMMAND name="no ip routing"
+		help="Disable IP routing">
+		<CONFIG priority="0x1500"/>
+		<ACTION>
+		echo "0" > /proc/sys/net/ipv4/ip_forward
+		</ACTION>
+	</COMMAND>
+
+<!------ Default gateway ------>
+
+	<COMMAND name="ip default-gateway"
+		help="Specify default gateway (if not routing IP)">
+		<PARAM name="ip"
+			help="IP address of default gateway"
+			ptype="IP_ADDR"/>
+		<CONFIG priority="0x9000" splitter="false"/>
+		<ACTION>
+			ip route replace to default via ${ip}
+		</ACTION>
+	</COMMAND>
+
+	<COMMAND name="no ip default-gateway"
+		help="Specify default gateway (if not routing IP)">
+		<CONFIG operation="unset" pattern="^ip default-gateway"/>
+		<ACTION>
+			ip route delete to default
+		</ACTION>
+	</COMMAND>
+
+<!------ Set/Unset static route ------>
+
+	<COMMAND name="ip route"
+		help="Establish static routes">
+		<PARAM name="ip"
+			help="Destination prefix"
+			ptype="IP_ADDR_MASK"/>
+		<PARAM name="route_target"
+			help="Route target"
+			ptype="STRING"
+			mode="switch">
+			<PARAM name="ethernet"
+				help="Ethernet IEEE 802.3"
+				ptype="SUBCOMMAND"
+				mode="subcommand">
+					<PARAM name="iface_num"
+						help="Ethernet interface number"
+						ptype="IFACE_NUM"/>
+			</PARAM>
+			<PARAM name="forward"
+				help="Forwarding router's address"
+				ptype="IP_ADDR"/>
+		</PARAM>
+		<CONFIG priority="0x9002" pattern="^ip route ${ip} " splitter="false"/>
+		<ACTION>
+		if test "${route_target}" = "ethernet"; then
+			ip route replace to ${ip} dev eth${iface_num}
+			exit $?
+		elif test "${route_target}" = "forward"; then
+			ip route replace to ${ip} via ${forward}
+			exit $?
+		fi
+		</ACTION>
+	</COMMAND>
+
+	<COMMAND name="no ip route"
+		help="Establish static routes">
+		<PARAM name="ip"
+			help="Destination prefix"
+			ptype="IP_ADDR_MASK"/>
+		<CONFIG operation="unset" pattern="^ip route ${ip} "/>
+		<ACTION>
+		ip route delete to ${ip}
+		</ACTION>
+	</COMMAND>
+
+</VIEW>
+
+</CLISH_MODULE>

+ 62 - 0
xml-examples/klish/etc/clish-xml/types.xml

@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema" 
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
+                     http://clish.sourceforge.net/XMLSchema/clish.xsd">
+    <!--=======================================================-->
+	<PTYPE name="VLAN_ID" 
+		pattern="(409[0-5]|40[0-8][0-9]|[1-3][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[1-9])"
+		help="Number in the range 1-4095"/>
+	<!--=======================================================-->
+	<PTYPE name="IP_ADDR"
+		pattern="(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))"
+		help="A.B.C.D"/>
+	<!--=======================================================-->
+	<PTYPE name="UINT"
+		pattern="[0-9]+"
+		help="Unsigned integer"/>
+	<!--=======================================================-->
+	<PTYPE name="STRING"
+		pattern=".+"
+		help="String"/>
+	<!--=======================================================-->
+	<PTYPE name="SUBCOMMAND"
+		pattern="[^\]+"
+		help="String"/>
+	<!--=======================================================-->
+	<PTYPE name="BOOL"
+		method="select"
+		pattern="true(1) false(0)"
+		help="Boolean choice"/>
+	<!--=======================================================-->
+	<PTYPE name="IFACE_NUM"
+		pattern="[0-9]+"
+		help="Interface number"/>
+	<!--=======================================================-->
+	<PTYPE name="PROTO"
+		method="select"
+		pattern="ip(ip) ipencap(ipencap) icmp(icmp) igmp(igmp) tcp(tcp) udp(udp)"
+		help="Protocol choice"/>
+	<!--=======================================================-->
+	<PTYPE name="SERVICE"
+		pattern="((ftp)|(telnet)|(sntp)|(smtp)|(http)|([0-9]+))"
+		help="Port"/>
+	<!--=======================================================-->
+	<PTYPE name="IP_ADDR_MASK"
+		pattern="(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(/(1[0-9]|2[0-9]|3[0-2]|[0-9]))?"
+		help="A.B.C.D[/mask]"/>
+	<!--=======================================================-->
+	<PTYPE name="IP_ADDR_ANY"
+		pattern="((((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(/(1[0-9]|2[0-9]|3[0-2]|[0-9]))?)|(any)"
+		help="A.B.C.D[/mask] or any"/>
+	<!--=======================================================-->
+	<PTYPE name="PORT_MASK_ANY"
+		pattern='^(([0-9]+(/0x[0-9a-f]+)?)|(any))$'
+		help="Port[/mask]" />
+	<!--=======================================================-->
+	<PTYPE name="SEQ"
+		pattern="^[0-9]*[1-9][0-9]*"
+		help="Entry number"/>
+	<!--=======================================================-->
+
+</CLISH_MODULE>

+ 1 - 0
xml-examples/klish/etc/clish/common.xml

@@ -0,0 +1 @@
+../clish-xml/common.xml

+ 1 - 0
xml-examples/klish/etc/clish/info-mode.xml

@@ -0,0 +1 @@
+../clish-xml/info-mode.xml

+ 1 - 0
xml-examples/klish/etc/clish/overview.xml

@@ -0,0 +1 @@
+../clish-xml/overview.xml

+ 1 - 0
xml-examples/klish/etc/clish/ping.xml

@@ -0,0 +1 @@
+../clish-xml/ping.xml

+ 10 - 0
xml-examples/klish/etc/clish/startup.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema" 
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema
+                     http://clish.sourceforge.net/XMLSchema/clish.xsd">
+
+<STARTUP view="info-view">
+</STARTUP>
+
+</CLISH_MODULE>

+ 1 - 0
xml-examples/klish/etc/clish/types.xml

@@ -0,0 +1 @@
+../clish-xml/types.xml

+ 8 - 0
xml-examples/klish/etc/init.d/klish-init

@@ -0,0 +1,8 @@
+#! /bin/sh
+
+# Start conf server
+/usr/bin/konfd >/dev/null 2>/dev/null &
+
+# Initialize system with startup-config
+CLISH_VIEW=configure-view /bin/klish-enable /etc/startup-config
+

+ 62 - 0
xml-examples/klish/usr/bin/nmask

@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# Convert netmask in dot notation to CIDR
+
+mask2cidr() {
+    nbits=0
+    IFS=.
+    for dec in $1 ; do
+        case $dec in
+            255) nbits=$(expr $nbits + 8);;
+            254) nbits=$(expr $nbits + 7);;
+            252) nbits=$(expr $nbits + 6);;
+            248) nbits=$(expr $nbits + 5);;
+            240) nbits=$(expr $nbits + 4);;
+            224) nbits=$(expr $nbits + 3);;
+            192) nbits=$(expr $nbits + 2);;
+            128) nbits=$(expr $nbits + 1);;
+            0);;
+            *) return 1;;
+        esac
+    done
+    echo "$nbits"
+    return 0
+}
+
+#cidr2mask() {
+#  local i mask=""
+#  local full_octets=$(($1/8))
+#  local partial_octet=$(($1%8))
+#
+#  for ((i=0;i<4;i+=1)); do
+#    if [ $i -lt $full_octets ]; then
+#      mask+=255
+#    elif [ $i -eq $full_octets ]; then
+#      mask+=$((256 - 2**(8-$partial_octet)))
+#    else
+#      mask+=0
+#    fi  
+#    test $i -lt 3 && mask+=.
+#  done
+#
+#  echo $mask
+#}
+
+## main ##
+
+if [ $# -lt 2 ]; then
+	return 1
+fi
+
+# if dot notation
+if [ "$1" = "-d" ]; then
+	mask=$2
+	numbits=$(mask2cidr $mask)
+	if [ "x$numbits" != "x" ]; then
+		echo "$numbits"
+	fi
+	exit 0
+
+elif [ "$1" = "-c" ]; then
+	echo "Under construction"
+fi