瀏覽代碼

Get the next available SIP extension number

Bob Mottram 9 年之前
父節點
當前提交
2ae3f297e4
共有 3 個檔案被更改,包括 72 行新增0 行删除
  1. 2
    0
      Makefile
  2. 1
    0
      src/freedombone-adduser
  3. 69
    0
      src/freedombone-sipfreeext

+ 2
- 0
Makefile 查看文件

@@ -43,6 +43,7 @@ install:
43 43
 	install -m 755 src/${APP}-logging ${DESTDIR}${PREFIX}/bin
44 44
 	install -m 755 src/${APP}-addsipuser ${DESTDIR}${PREFIX}/bin
45 45
 	install -m 755 src/${APP}-rmsipuser ${DESTDIR}${PREFIX}/bin
46
+	install -m 755 src/${APP}-sipfreeext ${DESTDIR}${PREFIX}/bin
46 47
 	mkdir -m 755 -p ${DESTDIR}${PREFIX}/share/man/man1
47 48
 	install -m 644 man/${APP}.1.gz ${DESTDIR}${PREFIX}/share/man/man1
48 49
 	install -m 644 man/${APP}-keydrive.1.gz ${DESTDIR}${PREFIX}/share/man/man1
@@ -133,6 +134,7 @@ uninstall:
133 134
 	rm -f ${PREFIX}/bin/${APP}-logging
134 135
 	rm -f ${PREFIX}/bin/${APP}-addsipuser
135 136
 	rm -f ${PREFIX}/bin/${APP}-rmsipuser
137
+	rm -f ${PREFIX}/bin/${APP}-sipfreeext
136 138
 clean:
137 139
 	rm -f \#* \.#* debian/*.substvars debian/*.log
138 140
 	rm -fr deb.* debian/${APP}

+ 1
- 0
src/freedombone-adduser 查看文件

@@ -205,6 +205,7 @@ if grep -q "Blog domain" $COMPLETION_FILE; then
205 205
 fi
206 206
 
207 207
 if grep -q "install_sip" $COMPLETION_FILE; then
208
+	SIP_EXTENSION=$(freedombone-sipfreeext)
208 209
     freedombone-addsipuser -u $MY_USERNAME -e $SIP_EXTENSION -p "$NEW_USER_PASSWORD"
209 210
     if [ ! "$?" = "0" ]; then
210 211
         echo 'SIP user could not be added'

+ 69
- 0
src/freedombone-sipfreeext 查看文件

@@ -0,0 +1,69 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+
12
+# Returns the next free SIP extension number
13
+
14
+# License
15
+# =======
16
+#
17
+# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
18
+#
19
+# This program is free software: you can redistribute it and/or modify
20
+# it under the terms of the GNU General Public License as published by
21
+# the Free Software Foundation, either version 3 of the License, or
22
+# (at your option) any later version.
23
+#
24
+# This program is distributed in the hope that it will be useful,
25
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+# GNU General Public License for more details.
28
+#
29
+# You should have received a copy of the GNU General Public License
30
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
31
+
32
+CONFIG_FILE=/etc/sipwitch.conf
33
+
34
+extensions=()
35
+
36
+# get the used extensions
37
+for line in $ (cat $CONFIG_FILE)
38
+do
39
+    if [[ "$line" == "<extension>"* ]]; then
40
+        ext=$(echo "$line" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')
41
+        extensions+=($ext)
42
+    fi
43
+    if [[ "$line" == '</provision>' ]]; then
44
+        break
45
+    fi
46
+done
47
+
48
+#echo "used extensions:"
49
+#echo $extensions
50
+#echo " "
51
+
52
+# which is the first available unused extension ?
53
+for ext in $(seq 201 299);
54
+do
55
+    is_used=
56
+    for i in "${extensions[@]}"
57
+    do
58
+        if [[ "$i" == "$ext" ]]; then
59
+            is_used=1
60
+            break
61
+        fi
62
+    done
63
+    if [ ! $is_used ]; then
64
+        echo $ext;
65
+        break
66
+    fi
67
+done
68
+
69
+exit 0