On Thu, 29 Apr 2010 22:14:57 +0200
J-P Human <jphu...@gmail.com> wrote:

> Hi
> 
Hello


> I have Dspam 3.9.0 stable using the MySQL backend, I would like to
> know how I can completely delete a specific users preferences and
> token data etc from the DB as if they were never there.
> 
I have a script written for that. I have however not updated it to be able to 
handle all possible configuration options (stuff like split config, MySQL 
communication over socket and such).

Anyway... look at the attached script. Maybe you can use it?


> Thanks
> J-P Human
> 
-- 
Kind Regards from Switzerland,

Stevan Bajić
#!/bin/bash
# Copyright 2003-2009 Stevan Bajic <ste...@bajic.ch>
# Distributed under the terms of the GNU Affero General Public License v3
#
# Purpose: Delete DSPAM user from MySQL.
##

[ "$1" = "" ] && echo "Missing username" && exit 1

_dspam_sysconfdir=$(dspam --version|sed -n "s:^.*\-\-sysconfdir\=\([^\'\"\t ]*\).*:\1:gIp");
_dspam_data=$(dspam --version|sed -n "s:^.*\-\-with\-dspam\-home\=\([^\'\"\t ]*\).*:\1:gIp");

if [ "${_dspam_sysconfdir}" = "" ];
then
	echo "Error: Could not get DSPAM system config directory";
	exit 1
elif [ "${_dspam_data}" = "" ];
then
	echo "Error: Could not get DSPAM home directory";
	exit 1
elif [ ! -d "${_dspam_sysconfdir}" ];
then
	echo "Error: DSPAM system config directory does not exist";
	exit 1
elif [ ! -d "${_dspam_data}" ];
then
	echo "Error: DSPAM home directory does not exist";
	exit 1
elif [ ! -f "${_dspam_sysconfdir}/dspam.conf" ];
then
	echo "Error: DSPAM dspam.conf file does not exist";
	exit 1
fi

_dspam_mysql_host="$(grep --color=no -i "^MySQLServer[[:space:]]" ${_dspam_sysconfdir}/dspam.conf|head -n 1|awk '{print $2}')"
_dspam_mysql_port="$(grep --color=no -i "^MySQLPort[[:space:]]" ${_dspam_sysconfdir}/dspam.conf|head -n 1|awk '{print $2}')"
_dspam_mysql_user="$(grep --color=no -i "^MySQLUser[[:space:]]" ${_dspam_sysconfdir}/dspam.conf|head -n 1|awk '{print $2}')"
_dspam_mysql_password="$(grep --color=no -i "^MySQLPass[[:space:]]" ${_dspam_sysconfdir}/dspam.conf|head -n 1|awk '{print $2}')"
_dspam_mysql_db="$(grep --color=no -i "^MySQLDb[[:space:]]" ${_dspam_sysconfdir}/dspam.conf|head -n 1|awk '{print $2}')"

if [ "${1:0:1}" = "@" ]
then
	_dspam_user_uid="$(mysql --user="${_dspam_mysql_user}" --password="${_dspam_mysql_password}" --host="localhost" --batch --skip-column-names -e "USE ${_dspam_mysql_db};SELECT dspam_virtual_uids.uid FROM dspam_virtual_uids WHERE 1 AND dspam_virtual_uids.username LIKE '%${1}%';")"
else
	_dspam_user_uid="$(mysql --user="${_dspam_mysql_user}" --password="${_dspam_mysql_password}" --host="localhost" --batch --skip-column-names -e "USE ${_dspam_mysql_db};SELECT uid FROM dspam_virtual_uids WHERE 1 AND username='${1}';")"
fi

if [ "${_dspam_user_uid}" = "" ];
then
	echo "Error: Can not get UID for user ${1}";
	exit 1
fi

for foo in ${_dspam_user_uid}
do
	_dspam_delete_uid="USE ${_dspam_mysql_db};$(mysql --user="${_dspam_mysql_user}" --password="${_dspam_mysql_password}" --host="localhost" --batch --skip-column-names -e "USE ${_dspam_mysql_db};SHOW TABLES;" | sed "s:^\(.*\)$:DELETE FROM \1 WHERE uid='${foo}';:g")";
	echo "Executing:"
	echo ${_dspam_delete_uid}
	mysql --user="${_dspam_mysql_user}" --password="${_dspam_mysql_password}" --host="localhost" --batch --skip-column-names -e "${_dspam_delete_uid};"
done

find ${_dspam_data}/data/ -type d -name "*${1}" -exec rm -rvf "{}" ";"
------------------------------------------------------------------------------
_______________________________________________
Dspam-user mailing list
Dspam-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dspam-user

Reply via email to