Advertisement
ZaffreBlue

Quassel User Delete

May 30th, 2023
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Delete Quasselcore users from your SQLite database
  4. #
  5. # File: deleteuser-sqlite.sh
  6. # Author: Robbe Van der Gucht
  7. # License: BSD-3-Clause, GPLv2, GPLv3
  8. # License statements can be found at the bottom.
  9. # Any of the indicated licenses can be chosen for redistribution
  10. # and only requires one of the license statements to be preserved.
  11.  
  12. exeq()
  13. {
  14. # Execute SQL Query
  15. result=$(sqlite3 "${QUASSELDB}" "${1}")
  16. echo "${result}"
  17. }
  18.  
  19. usage()
  20. {
  21. echo "Usage: ${SCRIPT} username [database]"
  22. }
  23.  
  24. print_users()
  25. {
  26. sqlite3 "${QUASSELDB}" "SELECT quasseluser.userid, quasseluser.username FROM quasseluser ORDER BY quasseluser.userid;"
  27. }
  28.  
  29. # Main body
  30.  
  31. SCRIPT="${0}"
  32. QUASSELDB=""
  33. USER=""
  34.  
  35. if [ -z "${2}" ] ; then
  36. # No file supplied.
  37. QUASSELDB="quassel-storage.sqlite"
  38. else
  39. QUASSELDB="${2}"
  40. fi
  41.  
  42. if [ -z "${1}" ] ; then
  43. echo "No user supplied."
  44. echo "Pick one: "
  45. print_users
  46. usage
  47. exit 1
  48. else
  49. USER="${1}"
  50. fi
  51.  
  52. if [ -e "${QUASSELDB}" ] ; then
  53. echo "SELECTED DB: ${QUASSELDB}"
  54. else
  55. echo "SELECTED DB '${QUASSELDB}' does not exist."
  56. usage
  57. exit 2
  58. fi
  59.  
  60. if [ -z $(exeq "SELECT quasseluser.username FROM quasseluser WHERE username = '${USER}';") ] ; then
  61. echo "SELECTED USER '${USER}' does not exist."
  62. print_users
  63. usage
  64. exit 3
  65. else
  66. echo "SELECTED USER: ${USER}"
  67. fi
  68.  
  69. # Sadly SQLITE does not allow DELETE statements that JOIN tables.
  70. # All queries are written with a subquery.
  71. # Contact me if you know a better way.
  72.  
  73. backlogq="DELETE
  74. FROM backlog
  75. WHERE backlog.bufferid in (
  76. SELECT bufferid
  77. FROM buffer, quasseluser
  78. WHERE buffer.userid = quasseluser.userid
  79. AND quasseluser.username = '${USER}'
  80. );"
  81.  
  82. bufferq="DELETE
  83. FROM buffer
  84. WHERE buffer.userid in (
  85. SELECT userid
  86. FROM quasseluser
  87. WHERE quasseluser.username = '${USER}'
  88. );"
  89.  
  90. ircserverq="DELETE
  91. FROM ircserver
  92. WHERE ircserver.userid in (
  93. SELECT userid
  94. FROM quasseluser
  95. WHERE quasseluser.username = '${USER}'
  96. );"
  97.  
  98. identity_nickq="DELETE
  99. FROM identity_nick
  100. WHERE identity_nick.identityid in (
  101. SELECT identityid
  102. FROM quasseluser, identity
  103. WHERE quasseluser.userid = identity.userid
  104. AND quasseluser.username = '${USER}'
  105. );"
  106.  
  107. identityq="DELETE
  108. FROM identity
  109. WHERE identity.userid in (
  110. SELECT userid
  111. FROM quasseluser
  112. WHERE quasseluser.username = '${USER}'
  113. );"
  114.  
  115. networkq="DELETE
  116. FROM network
  117. WHERE network.userid in (
  118. SELECT userid
  119. FROM quasseluser
  120. WHERE quasseluser.username = '${USER}'
  121. );"
  122.  
  123. usersettingq="DELETE
  124. FROM user_setting
  125. WHERE user_setting.userid in (
  126. SELECT userid
  127. FROM quasseluser
  128. WHERE quasseluser.username = '${USER}'
  129. );"
  130.  
  131. quasseluserq="DELETE
  132. FROM quasseluser
  133. WHERE quasseluser.username = '${USER}'
  134. ;"
  135.  
  136. exeq "${backlogq}"
  137. exeq "${bufferq}"
  138. exeq "${ircserverq}"
  139. exeq "${identity_nickq}"
  140. exeq "${identityq}"
  141. exeq "${networkq}"
  142. exeq "${usersettingq}"
  143. exeq "${quasseluserq}"
  144.  
  145. #-----------------------------------------------------------------------------#
  146. # BSD-3-Clause
  147. # Copyright (c) 2018, Robbe Van der Gucht
  148. # All rights reserved.
  149.  
  150. # Redistribution and use in source and binary forms, with or without
  151. # modification, are permitted provided that the following conditions are met:
  152. # 1. Redistributions of source code must retain the above copyright
  153. # notice, this list of conditions and the following disclaimer.
  154. # 2. Redistributions in binary form must reproduce the above copyright
  155. # notice, this list of conditions and the following disclaimer in the
  156. # documentation and/or other materials provided with the distribution.
  157. # 3. All advertising materials mentioning features or use of this software
  158. # must display the following acknowledgement:
  159. # This product includes software developed by the <organization>.
  160. # 4. Neither the name of the <organization> nor the
  161. # names of its contributors may be used to endorse or promote products
  162. # derived from this software without specific prior written permission.
  163.  
  164. # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY
  165. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  166. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  167. # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  168. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  169. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  170. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  171. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  172. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  173. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  174.  
  175. #-----------------------------------------------------------------------------#
  176. # GPL Clauses
  177. # Copyright (c) 2018, Robbe Van der Gucht
  178. # All rights reserved.
  179.  
  180. # This program is free software: you can redistribute it and/or modify
  181. # it under the terms of the GNU General Public License as published by
  182. # the Free Software Foundation, either version 2 of the License, or
  183. # (at your option) any later version.
  184.  
  185. # This program is distributed in the hope that it will be useful,
  186. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  187. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  188. # GNU General Public License for more details.
  189.  
  190. # You should have received a copy of the GNU General Public License
  191. # along with this program. If not, see <http://www.gnu.org/licenses/>.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement