<?xml version="1.0" encoding="UTF-8"?>
<patton-config-generator version="1.3">
  <!-- Description of the Graphical User Interface (GUI). This is where you
       arrange the input elements the user is sees to configure
       the device. A GUI consists of one or more pages, each of which 
       contains a set of input elements.
       
       A 'text' element provides a text field input.
       An 'option' element shows a set of option circles defined by the nested 'item' element.
       A 'select' element shows a drop-down list defined by the nested 'item' element.
       
       Each element must contain a 'name' attribute.  The 'name' may be used in other elements
       to control visual behavior, or as substitutions in the config file later.
  -->
  <gui>
    <!-- Information displayed in the template selector-->
    <title>SN4970 / SN4971 Basic Setup</title>
    <description>This sets up your SN4970/71 with either an IPPBX or an ITSP SIP Trunk.</description>
    <!-- This GUI has a single page only -->
    <page title="SN4970 / SN4971 Setup">
      <!-- Page information -->
      <group label="User Login (optional)">
        <password name="password" label="Password" tip="This will optionally override the default password for 'admin'."/>
      </group>
      <group label="SmartNode IP Setup">
        <!-- Local IP address: static or DHCP -->
        <option name="ipType"  label="SmartNode IP" tip="Use a Static IP or DHCP for the SmartNode" default="dhcp">
          <item value="dhcp"   label="DHCP"   />
          <item value="static" label="Static" />
        </option>
        <text name="address" label="IP Address"         default="192.168.1.1"	 	 show-if="ipType[static]" />
        <text name="mask"    label="Netmask"            default="255.255.255.0"  show-if="ipType[static]" />
        <text name="gateway" label="Gateway"                                     show-if="ipType[static]" />
        <text name="dnssrv" label="DNS Server"                                   show-if="ipType[static]" />
      </group>     
      <group label="PRI ISDN Line Setup">
 				<select name="numline" label="# of PRI lines" default="1">
          <item value="1"   label="1 PRI port"    />
          <item value="4"  label="4 PRI ports"   />
        </select>
        <option name="lineType" label="PRI Line Type" default="e1">
          <item value="e1"   label="E1 to be used outside of USA"    />
          <item value="t1"  label="T1 for USA / LATAM"   />
        </option>
        <option name="lineMode" label="The SmartNode ISDN port(s) connect to" tip="Select what kind of ISDN line is going to be connected to the SmartNode" default="net">
          <item value="net" label="ISDN PBX" />
          <item value="user" label="ISDN PSTN Network"/>
        </option>
      </group> 
			<group label="SIP / VOIP Settings">
        <option name="sipselect" label="ITSP SIP Trunk or IPPBX?" default="ipPBX" tip="Select if an IPPBX with SIP registration or a SIP Trunk from your ITSP will be connected to the device">
          <item value="ipPBX"   label="IPPBX in LAN network"    />
          <item value="sipTrunk"  label="SIP Trunk to ITSP"   />
        </option>
        <text name="sipdomain" label="SIP domain or IP of ITSP or IPPBX" default="192.168.1.20"/>
        <text name="sipuser" label="SIP username" tip="This username and password has been provided by your ITSP or it will be used on your LAN IPPBX for it to register on the SmartNode "/>
        <password name="sippassWORD" label="Password" tip="This is for the SIP password corresponding to the above username"/>
      </group>
    </page>
  </gui>
  <!-- The following set of config-snippetiables are used as templates for the config below. The 'name'
       attribute from gui elements above may be used in the 'if' attribute to conditionally
       define a config-snippetiable.  The 'name' attribute from gui elements may also be used in the template,
       wrapped in '{' and '}' brackets, to substitute the value from the gui element.
  -->
  <config-snippet name="userName"       	 if="password[!(null)]">superuser admin password {password}</config-snippet>
  <config-snippet name="staticAddress" 		 if="ipType[static]">ipaddress WAN {address} {mask}</config-snippet>
  <config-snippet name="dhcpAddress"			 if="ipType[dhcp]">ipaddress DHCP</config-snippet>
  <config-snippet name="gwAddressDHCP"  	 if="ipType[dhcp]">bind ipaddress ROUTER WAN DHCP</config-snippet>
  <config-snippet name="dnsserver"				 if="ipType[static]">name-server address {dnssrv}</config-snippet>
  <config-snippet name="gwAddressstatic"   if="ipType[static]">bind ipaddress ROUTER WAN WAN</config-snippet>
  <config-snippet name="framing"     			 if="lineType[e1]">framing crc</config-snippet>
  <config-snippet name="framing"     			 if="lineType[t1]">framing esf</config-snippet>
  <config-snippet name="uniside"     			 if="lineMode[net]">net</config-snippet>
  <config-snippet name="uniside"     			 if="lineMode[user]">user</config-snippet>
  <config-snippet name="protocol"     		 if="lineType[e1]">dss1</config-snippet>
  <config-snippet name="protocol"     		 if="lineType[t1]">ni2</config-snippet>
  <config-snippet name="defaultRoute"  		 if="gateway[!(null)]+ipType[static]">
    routing-table DEFAULT
      route 0.0.0.0/0 gateway {gateway} metric 0
  </config-snippet>
  <config-snippet name="sipinbound"  if="sipselect[ipPBX]">
      authentication inbound
      authenticate 1 authentication-service AUTH_SRV username {sipuser}

    registration inbound
  </config-snippet>
  <config-snippet name="sipinbound"  if="sipselect[sipTrunk]">
      authentication outbound
      authenticate 1 authentication-service AUTH_SRV username {sipuser}

    registration outbound
      registrar {sipdomain}
      register auto
  </config-snippet>
  <config-snippet name="clocksrc"     		 	 if="numline[4]">
  clock-source 2 e1t1 0 1
  clock-source 3 e1t1 0 2
  clock-source 4 e1t1 0 3
  </config-snippet>
  <config-snippet name="route2isdn"     		 if="numline[4]">service SRV_HG</config-snippet>  
  <config-snippet name="route2isdn"     		 if="numline[1]">interface IF_ISDN_00</config-snippet>
  <config-snippet name="callHG"  if="numline[4]">
  interface isdn IF_ISDN_01
    route call dest-table RT_ISDN_TO_SIP
    call-reroute emit
    diversion emit
    user-side-ringback-tone
    caller-name

  interface isdn IF_ISDN_02
    route call dest-table RT_ISDN_TO_SIP
    call-reroute emit
    diversion emit
    user-side-ringback-tone
    caller-name

  interface isdn IF_ISDN_03
    route call dest-table RT_ISDN_TO_SIP
    call-reroute emit
    diversion emit
    user-side-ringback-tone
    caller-name

  service hunt-group SRV_HG
    drop-cause normal-unspecified
    drop-cause no-circuit-channel-available
    drop-cause network-out-of-order
    drop-cause temporary-failure
    drop-cause switching-equipment-congestion
    drop-cause access-info-discarded
    drop-cause circuit-channel-not-available
    drop-cause resources-unavailable
    route call 1 dest-interface IF_ISDN_00
    route call 2 dest-interface IF_ISDN_01
    route call 3 dest-interface IF_ISDN_02
    route call 4 dest-interface IF_ISDN_03
  </config-snippet>
  <config-snippet name="priport"  				 if="numline[4]">
port e1t1 0 1
  port-type {lineType}
  clock auto
  {framing}
  encapsulation q921

  q921
    permanent-layer2
    uni-side auto
    encapsulation q931

    q931
      protocol {protocol}
      uni-side {uniside}
      encapsulation cc-isdn
      bind interface SWITCH IF_ISDN_01

port e1t1 0 1
  no shutdown

port e1t1 0 2
  port-type {lineType}
  clock auto
  {framing}
  encapsulation q921

  q921
    permanent-layer2
    uni-side auto
    encapsulation q931

    q931
      protocol {protocol}
      uni-side {uniside}
      encapsulation cc-isdn
      bind interface SWITCH IF_ISDN_02

port e1t1 0 2
  no shutdown

port e1t1 0 3
  port-type {lineType}
  clock auto
  {framing}
  encapsulation q921

  q921
    permanent-layer2
    uni-side auto
    encapsulation q931

    q931
      protocol {protocol}
      uni-side {uniside}
      encapsulation cc-isdn
      bind interface SWITCH IF_ISDN_03

port e1t1 0 3
  no shutdown
  </config-snippet>
  <!-- This is the master configuration template for the device. It contains placeholders
       enclosed in '{' and '}' brackets. These placeholders will be replaced by the gui
       element value matching the 'name' attrribute or from config-snippet elements defined above.
       If one of the placeholders is not explicitly replaced, it is removed from the configuration.
       
       We support a simple way of generating product-specific configurations: You may list
       multiple configs, each for a different set of products; If the product is "OS330"; it 
       will match "OS3301", "OS3302", and "OS3304". While if product is "OS3302|OS3304"; 
       it will only match "OS3302" and "OS3304". The same attributes may be used in the 
       'config-snippet' elements above.
  -->
  <config cli-version="4.0" product="SN497" file="startup-config">

{userName}
clock local default-offset +01:00

profile aaa DEFAULT
  method 1 local rule required
  method 2 none rule required

console
  use profile aaa DEFAULT

telnet-server
  use profile aaa DEFAULT
  no shutdown

ssh-server
  use profile aaa DEFAULT
  no shutdown

snmp-server
  shutdown

web-server http
  use profile aaa DEFAULT
  no shutdown

system
  clock-source 1 e1t1 0 0
	{clocksrc}
ntp
  server 0.patton.pool.ntp.org
  server 1.patton.pool.ntp.org
  server 2.patton.pool.ntp.org
  server 3.patton.pool.ntp.org
  no shutdown

dns-server
  {dnsserver}
  no shutdown

profile tls DEFAULT
  no authentication incoming
  no authentication outgoing
  private-key pki:private-key/DEFAULT
  own-certificate 1 pki:own-certificate/DEFAULT

profile tone-set DEFAULT

profile tone-set default

profile voip DEFAULT
  codec 1 g711alaw64k rx-length 20 tx-length 20
  codec 2 g711ulaw64k rx-length 20 tx-length 20
  fax transmission 1 relay t38-udp
  fax transmission 2 bypass g711alaw64k rx-length 20 tx-length 20
  fax transmission 3 bypass g711ulaw64k rx-length 20 tx-length 20
  fax bypass-method signaling
  modem transmission 1 bypass g711alaw64k rx-length 20 tx-length 20
  modem transmission 2 bypass g711ulaw64k rx-length 20 tx-length 20
  modem bypass-method signaling

profile pstn DEFAULT

profile sip DEFAULT

context ip ROUTER

  interface WAN
    {staticAddress}
    {dhcpAddress}
  {defaultRoute}

profile ppp DEFAULT

context bridge

context cs SWITCH
  no shutdown

  routing-table called-e164 RT_ISDN_TO_SIP
    route T2 dest-interface IF_SIP

  interface isdn IF_ISDN_00
    route call dest-table RT_ISDN_TO_SIP
    call-reroute emit
    diversion emit
    user-side-ringback-tone
    caller-name    
	{callHG}
  interface sip IF_SIP
    bind context sip-gateway GW_SIP
    route call dest-{route2isdn}
    remote {sipdomain}
    trust remote

authentication-service AUTH_SRV
  username {sipuser} password {sippassWORD} encrypted

location-service SER_LOC
  domain 1 {sipdomain}
  match-any-domain

  identity-group DEFAULT
   {sipinbound}

  identity {sipuser} inherits DEFAULT

context sip-gateway GW_SIP
  bind location-service SER_LOC

  interface SIP
    transport-protocol udp+tcp 5060
    no transport-protocol tls
    {gwAddressDHCP}
    {gwAddressstatic} 

context sip-gateway GW_SIP
  no shutdown

port ethernet 0 0
  bind interface ROUTER WAN
  no shutdown

port e1t1 0 0
  port-type {lineType}
  clock auto
  {framing}
  encapsulation q921

  q921
    permanent-layer2
    uni-side auto
    encapsulation q931

    q931
      protocol {protocol}
      uni-side {uniside}
      encapsulation cc-isdn
      bind interface SWITCH IF_ISDN_00

port e1t1 0 0
  no shutdown
{priport}
</config>
</patton-config-generator>