4c801b29d6a089dd6ab0d2b535702e26ad980b13
[anna.git] / example / diameter / launcher / deployments / advanced / clientSocketManager.sh
1 #!/bin/bash
2 > curl_log.txt
3 TRACE="--trace-ascii curl_log.txt"
4 SERVER=`cat .httpServer`
5 ENTITY=`cat .entity 2>/dev/null`
6 # If missing following, 1 is assigned (ENTITY_SS_1 is ENTITY_SS - 1)
7 ENTITY_SS=`cat .entityServerSessions 2>/dev/null`
8 [[ "$ENTITY_SS" = "" ]] && ENTITY_SS=1
9 TARGET=$2
10
11 use () {
12    echo
13    echo
14    echo "Use: $0 <hide|show|hidden|shown> \"[<address>:<port>]|[socket id]\""
15    echo
16    echo "Hides/shows/query hidden state/query shown state, the socket/s provided."
17    echo "If missing server (first parameter) all applications sockets will be affected by action."
18    echo "If missing socket (second parameter) for specific server, all its sockets will be affected by action."
19    echo
20    exit
21 }
22
23 states () {
24    echo
25    echo "Select option to switch (0 = quit):"
26    echo
27    option=1 
28    for i in `echo $ENTITY | sed 's/,/ /g'`
29    do
30       for j in `seq 0 $ENTITY_SS_1`
31       do
32          TARGET="${i}|${j}"
33          RES=$(curl -m 1 --data "shown|$TARGET" ${SERVER} 2>&1 | tail -1 | grep "true$")
34          res=hidden
35          [[ "$RES" != "" ]] && res=shown
36          echo "${option}. $TARGET     ($res)"
37          action=show
38          [[ "$RES" != "" ]] && action=hide
39          echo "curl -m 1 --data \"$action|$TARGET\" ${SERVER}" > .switch_${option}
40          chmod a+x .switch_${option}
41          option=$((option+1))
42       done
43    done
44    echo
45 }
46
47 if test "$ENTITY" != ""
48 then
49    ENTITY_SS_1=$((ENTITY_SS-1))
50    while true
51    do
52       states
53       read option
54       [[ "$option" = "0" ]] && break
55       .switch_${option} 
56    done
57    echo
58    echo "Exiting"
59    rm .switch_*
60    exit
61 else
62    [[ "$1" = "" ]] && use
63 fi
64
65 echo
66 echo
67 operation="$1|$TARGET"
68 [[ "$TARGET" = "" ]] && operation="$1"
69 curl -m 1 --data "$operation" $TRACE ${SERVER}
70