Add strongswan (#1330)
[openwrt.git] / package / strongswan / patches / 200-wakeup-showstatus.patch
1 diff -ruN strongswan-2.8.2-orig/programs/Makefile strongswan-2.8.2/programs/Makefile
2 --- strongswan-2.8.2-orig/programs/Makefile     2006-08-28 07:12:36.000000000 -0400
3 +++ strongswan-2.8.2/programs/Makefile  2007-02-05 00:27:47.214280563 -0500
4 @@ -22,7 +22,7 @@
5  SUBDIRS+=_realsetup _secretcensor _startklips _updown _updown_espmark
6  SUBDIRS+=auto barf ipsec look manual ranbits secrets starter
7  SUBDIRS+=rsasigkey send-pr setup showdefaults showhostkey calcgoo mailkey
8 -SUBDIRS+=ikeping examples openac scepclient
9 +SUBDIRS+=ikeping examples openac scepclient _showstatus wakeup
10  
11  ifeq ($(USE_LWRES),true)
12  SUBDIRS+=lwdnsq
13 diff -ruN strongswan-2.8.2-orig/programs/_showstatus/Makefile strongswan-2.8.2/programs/_showstatus/Makefile
14 --- strongswan-2.8.2-orig/programs/_showstatus/Makefile 1969-12-31 19:00:00.000000000 -0500
15 +++ strongswan-2.8.2/programs/_showstatus/Makefile      2007-02-05 00:31:11.380714322 -0500
16 @@ -0,0 +1,22 @@
17 +# Makefile for miscelaneous programs
18 +# Copyright (C) 2002  Michael Richardson       <mcr@freeswan.org>
19 +# 
20 +# This program is free software; you can redistribute it and/or modify it
21 +# under the terms of the GNU General Public License as published by the
22 +# Free Software Foundation; either version 2 of the License, or (at your
23 +# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
24 +# 
25 +# This program is distributed in the hope that it will be useful, but
26 +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
27 +# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
28 +# for more details.
29 +#
30 +# RCSID $Id: Makefile,v 1.3 2006/04/17 06:48:49 as Exp $
31 +
32 +FREESWANSRCDIR=../..
33 +include ${FREESWANSRCDIR}/Makefile.inc
34 +
35 +PROGRAM=_showstatus
36 +PROGRAMDIR=${LIBDIR}
37 +
38 +include ../Makefile.program
39 diff -ruN strongswan-2.8.2-orig/programs/_showstatus/_showstatus.8 strongswan-2.8.2/programs/_showstatus/_showstatus.8
40 --- strongswan-2.8.2-orig/programs/_showstatus/_showstatus.8    1969-12-31 19:00:00.000000000 -0500
41 +++ strongswan-2.8.2/programs/_showstatus/_showstatus.8 2007-02-05 00:36:00.650410824 -0500
42 @@ -0,0 +1,23 @@
43 +.TH _showstatus 8 "03 Feb 2007"
44 +.\"
45 +.\" RCSID $Id: _showstatus.8
46 +.\"
47 +.SH NAME
48 +ipsec _showstatus \- give state feedback via led or other method
49 +.SH SYNOPSIS
50 +.I _showstatus
51 +is invoked by _updown to trigger led's, or other distribution
52 +or platform specific behavior. Presently, the SES button is
53 +supported as a status light on OpenWRT platforms. The button
54 +is configurable by environment variable:
55 +-B IPSEC_STATUS_LED_START
56 +defaults to ses_orange, and
57 +-B IPSEC_STATUS_LED_VALID
58 +defaults to ses_white.
59 +.SH "SEE ALSO"
60 +ipsec(8), ipsec_updown(8).
61 +.SH HISTORY
62 +Man page written for the Linux strongSwan project <http://www.strongswan.org/>
63 +by Kevin Cody Jr. Original manpage for _updown by Michael Richardson.
64 +Original program written by Henry Spencer. Extended for the Linux strongSwan
65 +project <http://www.strongswan.org/> by Andreas Steffen.
66 diff -ruN strongswan-2.8.2-orig/programs/_showstatus/_showstatus.in strongswan-2.8.2/programs/_showstatus/_showstatus.in
67 --- strongswan-2.8.2-orig/programs/_showstatus/_showstatus.in   1969-12-31 19:00:00.000000000 -0500
68 +++ strongswan-2.8.2/programs/_showstatus/_showstatus.in        2007-02-05 00:55:56.563116192 -0500
69 @@ -0,0 +1,70 @@
70 +#! /bin/sh
71 +#
72 +# Copyright (C) 2007 Kevin Cody Jr. <kcody@vegaresearch.com>
73 +# 
74 +# This program is free software; you can redistribute it and/or modify it
75 +# under the terms of the GNU General Public License as published by the
76 +# Free Software Foundation; either version 2 of the License, or (at your
77 +# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
78 +# 
79 +# This program is distributed in the hope that it will be useful, but
80 +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
81 +# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
82 +# for more details.
83 +#
84 +# RCSID $Id: _showstatus.in
85 +
86 +
87 +LED_START=$IPSEC_STATUS_LED_START
88 +LED_VALID=$IPSEC_STATUS_LED_VALID
89 +
90 +[ -z "$LED_START" ] && LED_START="ses_orange"
91 +[ -z "$LED_VALID" ] && LED_VALID="ses_white"
92 +
93 +
94 +setled() {
95 +       led=$1
96 +       st=$2
97 +
98 +       [ -n "$led" -a -n "$st" ] || return
99 +       
100 +       if [ -w "/proc/diag/led/$led" ] ; then
101 +               echo "$st" > "/proc/diag/led/$led"
102 +       fi
103 +
104 +       # integrate other led control methods here
105 +
106 +}
107 +
108 +
109 +case "$1" in
110 +       'start')
111 +               [ -n "$LED_VALID" ] && setled "$LED_START" 1
112 +               [ -z "$LED_VALID" ] && setled "$LED_START" f
113 +               setled "$LED_VALID" 0
114 +               ;;
115 +       'stop')
116 +               setled "$LED_START" 0
117 +               setled "$LED_VALID" 0
118 +               ;;
119 +       'valid')
120 +               setled "$LED_VALID" 1
121 +               ;;
122 +       'invalid')
123 +               setled "$LED_VALID" 0
124 +               ;;
125 +       'up')
126 +               [ -n "$LED_VALID" ] && setled "$LED_START" 0
127 +               [ -z "$LED_VALID" ] && setled "$LED_START" 1
128 +               setled "$LED_VALID" 1
129 +               ;;
130 +       'down')
131 +               [ -n "$LED_VALID" ] && setled "$LED_START" 1
132 +               [ -z "$LED_VALID" ] && setled "$LED_START" f
133 +               setled "$LED_VALID" f
134 +               ;;
135 +       *)
136 +               echo "$0: unknown status $status" >&2
137 +               ;;
138 +esac
139 +
140 diff -ruN strongswan-2.8.2-orig/programs/wakeup/Makefile strongswan-2.8.2/programs/wakeup/Makefile
141 --- strongswan-2.8.2-orig/programs/wakeup/Makefile      1969-12-31 19:00:00.000000000 -0500
142 +++ strongswan-2.8.2/programs/wakeup/Makefile   2007-02-05 00:28:03.960726309 -0500
143 @@ -0,0 +1,22 @@
144 +# Makefile for miscelaneous programs
145 +# Copyright (C) 2002  Michael Richardson       <mcr@freeswan.org>
146 +# 
147 +# This program is free software; you can redistribute it and/or modify it
148 +# under the terms of the GNU General Public License as published by the
149 +# Free Software Foundation; either version 2 of the License, or (at your
150 +# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
151 +# 
152 +# This program is distributed in the hope that it will be useful, but
153 +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
154 +# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
155 +# for more details.
156 +#
157 +# RCSID $Id: Makefile,v 1.3 2006/04/17 06:48:49 as Exp $
158 +
159 +FREESWANSRCDIR=../..
160 +include ${FREESWANSRCDIR}/Makefile.inc
161 +
162 +PROGRAM=wakeup
163 +PROGRAMDIR=${LIBDIR}
164 +
165 +include ../Makefile.program
166 diff -ruN strongswan-2.8.2-orig/programs/wakeup/wakeup.8 strongswan-2.8.2/programs/wakeup/wakeup.8
167 --- strongswan-2.8.2-orig/programs/wakeup/wakeup.8      1969-12-31 19:00:00.000000000 -0500
168 +++ strongswan-2.8.2/programs/wakeup/wakeup.8   2007-02-05 00:36:34.029298760 -0500
169 @@ -0,0 +1,16 @@
170 +.TH wakeup 8 "03 Feb 2007"
171 +.\"
172 +.\" RCSID $Id: wakeup.8
173 +.\"
174 +.SH NAME
175 +ipsec wakeup \- stalled and down connection detection
176 +.SH SYNOPSIS
177 +.I wakeup
178 +is invoked by cron and checks ipsec status, whacking as necessary.
179 +.SH "SEE ALSO"
180 +ipsec(8), ipsec_whack(8).
181 +.SH HISTORY
182 +Man page written for the Linux strongSwan project <http://www.strongswan.org/>
183 +by Kevin Cody Jr. Original manpage for _updown by Michael Richardson.
184 +Original program written by Henry Spencer. Extended for the Linux strongSwan
185 +project <http://www.strongswan.org/> by Andreas Steffen.
186 diff -ruN strongswan-2.8.2-orig/programs/wakeup/wakeup.in strongswan-2.8.2/programs/wakeup/wakeup.in
187 --- strongswan-2.8.2-orig/programs/wakeup/wakeup.in     1969-12-31 19:00:00.000000000 -0500
188 +++ strongswan-2.8.2/programs/wakeup/wakeup.in  2007-02-05 00:28:03.961726336 -0500
189 @@ -0,0 +1,38 @@
190 +#! /bin/sh
191 +# wakeup script
192 +#
193 +# Copyright (C) 2007 Kevin Cody Jr. <kcody@vegaresearch.com>
194 +# 
195 +# This program is free software; you can redistribute it and/or modify it
196 +# under the terms of the GNU General Public License as published by the
197 +# Free Software Foundation; either version 2 of the License, or (at your
198 +# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
199 +# 
200 +# This program is distributed in the hope that it will be useful, but
201 +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
202 +# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
203 +# for more details.
204 +#
205 +
206 +# only applicable when ipsec is running
207 +[ -e /var/run/pluto.pid ] || exit
208 +
209 +# loop through any erouted tunnels in the HOLD state
210 +for f in  `ipsec status | awk '/erouted HOLD/{ print $2 }' | cut -f1 -d\: | cut -f2 -d\"` ; do
211 +
212 +        # only whack if no pending events at all exists
213 +        ipsec status | grep STATE | grep -q $f ||
214 +                ipsec whack --name $f --initiate --asynchronous
215 +
216 +done
217 +
218 +# loop through any tunnels that don't quite exist
219 +for f in `ipsec status | awk '/prospective erouted/{ print $2 }' | cut -f1 -d: | grep -v \# | cut -f2 -d\"` ; do
220 +
221 +        ipsec status | grep STATE_QUICK | grep -q $f || {
222 +                ipsec status | grep STATE_MAIN | grep -q $f && ipsec down $f
223 +                ipsec up $f
224 +        }
225 +
226 +done
227 +