22.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. # database access and persistent storage for registrar on postgres
  3. # Copyright (C) 2007 1&1 Internet AG
  4. #
  5. # This file is part of Kamailio, a free SIP server.
  6. #
  7. # Kamailio is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version
  11. #
  12. # Kamailio is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. . include/common
  21. . include/require.sh
  22. . include/database.sh
  23. if ! (check_sipsak && check_kamailio && check_module "db_postgres" && check_postgres); then
  24. exit 0
  25. fi ;
  26. SIPDOMAIN=127.0.0.1
  27. CFG=22.cfg
  28. $BIN -L $MOD_DIR -Y $RUN_DIR -P $PIDFILE -w . -f $CFG > /dev/null
  29. ret=$?
  30. sleep 1
  31. # register a user
  32. sipsak -U -C sip:[email protected] -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN &> /dev/null
  33. ret=$?
  34. if [ "$ret" -eq 0 ]; then
  35. $CTL ul show | grep "AOR:: 49721123456789" > /dev/null
  36. ret=$?
  37. fi;
  38. if [ "$ret" -eq 0 ]; then
  39. TMP=`${PSQL} "select COUNT(*) from location where username='49721123456789';"`
  40. if [ "$TMP" -eq 0 ] ; then
  41. ret=1
  42. fi;
  43. fi;
  44. if [ "$ret" -eq 0 ]; then
  45. # unregister the user
  46. sipsak -U -C "*" -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN -x 0 &> /dev/null
  47. fi;
  48. if [ "$ret" -eq 0 ]; then
  49. $CTL ul show | grep "AOR:: 49721123456789" > /dev/null
  50. ret=$?
  51. if [ "$ret" -eq 0 ]; then
  52. ret=1
  53. else
  54. ret=0
  55. fi;
  56. fi;
  57. if [ "$ret" -eq 0 ]; then
  58. ret=`$PSQL "select COUNT(*) from location where username='49721123456789';" | tail -n 1`
  59. fi;
  60. $PSQL "delete from location where username like '49721123456789%';"
  61. if [ "$ret" -eq 0 ]; then
  62. # register again
  63. sipsak -U -C sip:[email protected] -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN &> /dev/null
  64. ret=$?
  65. fi;
  66. kill_kamailio
  67. # restart to test preload_udomain functionality
  68. $BIN -w . -f $CFG > /dev/null
  69. ret=$?
  70. sleep 1
  71. if [ "$ret" -eq 0 ]; then
  72. # check if the contact is still registered
  73. sipsak -U -C empty -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN -q "Contact: <sip:[email protected]>" &> /dev/null
  74. ret=$?
  75. fi;
  76. # check if the methods value is correct
  77. if [ "$ret" -eq 0 ]; then
  78. $CTL ul show | grep "Methods:: 4294967295" &> /dev/null
  79. ret=$?
  80. fi;
  81. kill_kamailio
  82. $PSQL "delete from location where username like '49721123456789%';"
  83. exit $ret