Templates

1.0.0-wpa_action.sh.j2

Synopsis: Template 1.0.0-wpa_action.sh.

Description of the template.

[templates/1.0.0-wpa_action.sh.j2]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
# {{ ansible_managed }}

version="1.0.0"
ifname=$1
cmd=$2
# TODO: test prams

{% if wpacli_action_script_log_to_file %}
logtofile="1"
{% else %}
logtofile="0"
{% endif %}
logfile="{{ wpacli_action_script_logfile }}"

if [ "$logtofile" = "1" ]; then
    my_date=`date +"%b %d %T"`
    printf "$my_date $ifname: $cmd \n" >> $logfile
fi

# wpa_supplicant reports connection to SSID. Start dhclient and
# restart routing
if [ "$cmd" = "CONNECTED" ]; then
    if [ "$logtofile" = "1" ]; then
	ssid=`wpa_cli -i$ifname status | grep ^ssid= | cut -f2- -d=`
	printf "$my_date $ifname: SSID: $ssid \n" >> $logfile
    fi
    message=`/etc/rc.d/dhclient forcestart $ifname 2>&1` # NOTE 1
    if [ "$logtofile" = "1" ]; then
	printf "$my_date $ifname: dhclient start: $message \n" >> $logfile
    fi
    message=`/etc/rc.d/routing restart 2>&1`
    if [ "$logtofile" = "1" ]; then
	printf "$my_date $ifname: routing restart: $message \n" >> $logfile
    fi
fi

# wpa_supplicant reports disconnection from SSID. Stop dhclient and
# restart routing
if [ "$cmd" = "DISCONNECTED" ]; then
    message=`/etc/rc.d/dhclient forcestop $ifname`
    if [ "$logtofile" = "1" ]; then
	printf "$my_date $ifname: dhclient forcestart: $message \n" >> $logfile
    fi
    message=`/etc/rc.d/routing restart 2>&1`
    if [ "$logtofile" = "1" ]; then
	printf "$my_date $ifname: routing restart: $message \n" >> $logfile
    fi
fi

exit 0

# NOTE 1
# We don't want /etc/network.subr to handle DHCP and instruct
# ifconfig, in rc.conf, to configure WPA only.
#      ifconfig_wlan1="WPA"
# When we use "/etc/rc.d/dhclient start wlan1" it complains
#      'wlan1' is not a DHCP-enabled interface
# Hence we use /etc/rc.d/dhclient forcestart $ifname in this script

# NOTE 2
# Example how to activate the script.
# wpa_cli -B -i wlan1 -a /root/bin/wpa_action.sh

# EOF

1.1.0-wpa_action.sh.j2

Synopsis: Template 1.1.0-wpa_action.sh.

Description of the template.

[templates/1.1.0-wpa_action.sh.j2]

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/sh
# {{ ansible_managed }}

version="1.1.0"
ifname=$1
cmd=$2
# TODO: test prams

{% if wpacli_action_script_log_to_file %}
logtofile="1"
{% else %}
logtofile="0"
{% endif %}
logfile="{{ wpacli_action_script_logfile }}"

{% if wpacli_action_script_ntp_set %}
ntp_set="1"
{% else %}
ntp_set="0"
{% endif %}
ntp_server="{{ wpacli_action_script_ntp_server }}"
ntpdate_flags="{{ wpacli_action_script_ntpdate_flags }}"

# functions
log() {
    if [ "$logtofile" = "1" ]; then
	my_date=`date +"%b %d %T"`
	printf "$my_date $ifname: $cmd: $message \n" >> $logfile
    fi
}

routing_restart() {
    cmd="/etc/rc.d/routing restart"
    message=`$cmd 2>&1`
    log
}

dhclient_forcestart() {
    cmd="/etc/rc.d/dhclient forcestart $ifname"  # NOTE 1
    message=`$cmd 2>&1`
    log
}

dhclient_forcestop() {
    cmd="/etc/rc.d/dhclient forcestop $ifname"
    message=`$cmd 2>&1`
    log
}

ntpd_stop() {
    cmd="/etc/rc.d/ntpd stop"
    message=`$cmd 2>&1`
    log
}

ntpd_start() {
    cmd="/etc/rc.d/ntpd start"
    message=`$cmd 2>&1`
    log
}

ntpdate_settimeofday() {
    cmd="/usr/sbin/ntpdate $ntpdate_flags $ntp_server"
    message=`$cmd 2>&1`
    log
}

log_SSID() {
    if [ "$logtofile" = "1" ]; then
	ssid=`wpa_cli -i$ifname status | grep ^ssid= | cut -f2- -d=`
	my_date=`date +"%b %d %T"`
	printf "$my_date $ifname: SSID: $ssid \n" >> $logfile
    fi
}

# log interface and command
if [ "$logtofile" = "1" ]; then
    my_date=`date +"%b %d %T"`
    printf "$my_date $ifname: $cmd \n" >> $logfile
fi

# wpa_supplicant reports connection to SSID. Start dhclient and
# restart routing
if [ "$cmd" = "CONNECTED" ]; then
    log_SSID
    dhclient_forcestart
    routing_restart
    if [ "$ntp_set" = "1" ]; then  # NOTE 3
	ntpd_stop
	ntpdate_settimeofday
	ntpd_start
    fi
fi

# wpa_supplicant reports disconnection from SSID. Stop dhclient and
# restart routing
if [ "$cmd" = "DISCONNECTED" ]; then
    dhclient_forcestop
    routing_restart
fi

exit 0

# NOTE 1
# We don't want /etc/network.subr to handle DHCP. Therefor we instruct
# ifconfig, in rc.conf, to configure WPA only
#      ifconfig_wlan1="WPA"
# When we use "/etc/rc.d/dhclient start wlan1" it complains
#      'wlan1' is not a DHCP-enabled interface
# Hence we use /etc/rc.d/dhclient forcestart $ifname in this script.

# NOTE 2
# Example how to activate the script
# wpa_cli -B -i wlan1 -a /root/bin/wpa_action.sh

# NOTE 3
# In a wifi-only system, /etc/rc.d/ntpdate will time-out if it
# executes before /etc/rc.d/wpa_supplicant connects to the network
# (See rcorder /etc/rc.d/*)

# EOF

dma-auth.conf.j2

Synopsis: Template dma-auth.conf.

Description of the template.

[templates/dma-auth.conf.j2]

1
2
3
4
5
6
# {{ ansible_managed }}
# Format: myuser|smtp.gmail.com:mypassword
{% for item in cl_dma_authconf %}
{{ item }}
{% endfor %}
# EOF

handlers-auto1.yml.j2

Synopsis: Template handlers-auto1.yml.

Description of the template.

[templates/handlers-auto1.yml.j2]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
---
# {{ ansible_managed }}
# Automatically generated file with handlers.
{% for iitem in item.value.handlers %}

- name: {{ item.key }} {{ iitem.handler }}
  {{ iitem.module }}:
{% for param in iitem.params %}
    {{ param }}
{% endfor %}
{% if iitem.conditions is defined %}
  when:
{% for condition in iitem.conditions %}
    {{ condition }}
{% endfor %}
{% endif %}

{% endfor %}

# EOF

handlers-auto2.yml.j2

Synopsis: Template handlers-auto2.yml.

Description of the template.

[templates/handlers-auto2.yml.j2]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
---
# {{ ansible_managed }}
# Automatically generated file with handlers.
{% for iitem in item.value.handlers %}

- name: {{ iitem.handler }}
  {{ iitem.module }}:
{% for param in iitem.params %}
    {{ param }}
{% endfor %}
{% if iitem.conditions is defined %}
  when:
{% for condition in iitem.conditions %}
    {{ condition }}
{% endfor %}
{% endif %}

{% endfor %}

# EOF

hosts.j2

Synopsis: Template hosts.

Description of the template.

[templates/hosts.j2]

1
2
3
4
5
6
7
8
9
# {{ ansible_managed }}
{{ cl_hosts_localhost_IPv6 }}	localhost localhost.{{ cl_domain }}
{{ cl_hosts_localhost_IPv4 }}	localhost localhost.{{ cl_domain }}

{% for item in cl_hosts %}
{{ item.ip }}    {{ item.fqdn }} {{ item.hostname|default('') }}
{% endfor %}

# EOF

loader.conf.j2

Synopsis: Template loader.conf.

Description of the template.

[templates/loader.conf.j2]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# {{ ansible_managed }}

# bsd_cimage_loaderconf_data
{% for item in cl_loaderconf_data %}
{{ item }}
{% endfor %}

# bsd_cimage_loaderconf_sysctl
{% for item in cl_loaderconf_sysctl %}
{{ item }}
{% endfor %}

# bsd_cimage_loaderconf_modules
{% for item in cl_loaderconf_modules %}
{{ item }}_load="YES"
{% endfor %}

# EOF

mailer.conf.j2

Synopsis: Template mailer.conf.

Description of the template.

[templates/mailer.conf.j2]

1
2
3
4
5
6
# {{ ansible_managed }}
# https://www.freebsd.org/cgi/man.cgi?mailer.conf
{% for item in cl_mailerconf %}
{{ item }}
{% endfor %}
# EOF

ntp.conf-minimal.j2

Synopsis: Template ntp.conf-minimal.

Description of the template.

[templates/ntp.conf-minimal.j2]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# {{ ansible_managed }}
{% for option in fp_ntp_config_options %}
{{ option }}
{% endfor %}
{% for pool in fp_ntp_config_pool %}
pool {{ pool }}
{% endfor %}
{% for restrict in fp_ntp_config_restrict %}
restrict {{ restrict }}
{% endfor %}
{% if fp_ntp_config_leapfile %}
leapfile {{ fp_ntp_config_leapfile }}
{% endif %}

revaliases.j2

Synopsis: Template revaliases.

Description of the template.

[templates/revaliases.j2]

1
2
3
4
5
6
# {{ ansible_managed }}
# Format: local_account:outgoing_address:mailhub
{% for item in cl_ssmtp_revaliases %}
{{ item }}
{% endfor %}
# EOF

ssmtp.conf.j2

Synopsis: Template ssmtp.conf.

Description of the template.

[templates/ssmtp.conf.j2]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# {{ ansible_managed }}

# The user that gets all the mails (UID < 1000, usually the admin)
# root=username@gmail.com
root={{ cl_ssmtp_postmaster_address }}

# The mail server (where the mail is sent to), both port 465 or 587 should be acceptable
# See also https://support.google.com/mail/answer/78799
# mailhub=smtp.gmail.com:587
mailhub={{ cl_ssmtp_mailhub }}

# The address where the mail appears to come from for user authentication.
# rewriteDomain=gmail.com
rewriteDomain={{ cl_ssmtp_rewriteDomain }}

# The full hostname.  Must be correctly formed, fully qualified domain
# name or GMail will reject connection.
# hostname=yourlocalhost.yourlocaldomain.tld
hostname={{ cl_ssmtp_srv }}

# Use SSL/TLS before starting negotiation
#UseTLS=Yes
#UseSTARTTLS=Yes
UseTLS={{ cl_ssmtp_UseTLS }}
UseSTARTTLS={{ cl_ssmtp_UseSTARTTLS }}

# Username/Password
#AuthUser=username
#AuthPass=password
#AuthMethod=LOGIN
AuthUser={{ cl_ssmtp_AuthUser }}
AuthPass={{ cl_ssmtp_AuthPass }}
AuthMethod={{ cl_ssmtp_AuthMethod }}

# Email 'From header's can override the default domain?
#FromLineOverride=yes
FromLineOverride={{ cl_ssmtp_FromLineOverride }}

# EOF

wpa_cli.j2

Synopsis: Template wpa_cli.

Description of the template.

[templates/wpa_cli.j2]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh
# {{ ansible_managed }}"

# PROVIDE: wpa_cli
# REQUIRE: mountcritremote
# KEYWORD: nojail nostart

. /etc/rc.subr
. /etc/network.subr

name="wpa_cli"
desc="Frontend to WPA/802.11i Supplicant for wireless network
devices. Run in daemon mode executing the action file based on events
from wpa_supplicant"
rcvar=

ifn="$2"
if [ -z "$ifn" ]; then
	return 1
fi

load_rc_config $name

command="${wpa_cli_program}"
pidfile="/var/run/${name}/${ifn}.pid"
command_args="-B -i $ifn -P $pidfile -p ${wpa_cli_ctrl_interface} -a ${wpa_cli_action_file}"
required_files="${wpa_cli_action_file}"

run_rc_command "$1"

# EOF

wpa_supplicant.conf.j2

Synopsis: Template wpa_supplicant.conf.

Description of the template.

[templates/wpa_supplicant.conf.j2]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# {{ ansible_managed }}
{% for gvar in cl_wpasupconf_global %}
{{ gvar.key }}={{ gvar.value }}
{% endfor %}
{% for net in item.network %}
{% for nvar in net.conf %}
{% if loop.first %}

network={
{% endif %}
        {{ nvar.key }}={{ nvar.value }}
{% if loop.last %}
}
{% endif %}
{% endfor %}
{% endfor %}

# EOF

wpa_supplicant.conf.wlan0.j2

Synopsis: Template wpa_supplicant.conf.wlan0.

Description of the template.

[templates/wpa_supplicant.conf.wlan0.j2]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# {{ ansible_managed }}
{% for gvar in cl_wpasupconf_global %}
{{ gvar.key }}={{ gvar.value }}
{% endfor %}
{% for net in cl_wpasupconf_wlan0.network %}
{% for nvar in net.conf %}
{% if loop.first %}

network={
{% endif %}
        {{ nvar.key }}={{ nvar.value }}
{% if loop.last %}
}
{% endif %}
{% endfor %}
{% endfor %}

# EOF