#!/bin/bash

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

cd /opt/td-config/scripts

if [ "$#" == "0" ]; then
    gksudo -D /usr/share/applications/tcc-config.desktop 'python tcc-config.py --control tactical'
else
	if [ "$1" == 'true' ]; then
		gksudo -D /usr/share/applications/tcc-config.desktop 'python tcc-config.py --control tactical --upgrade=true'
	elif [ "$1" == 'false' ]; then
		gksudo -D /usr/share/applications/tcc-config.desktop 'python tcc-config.py --control tactical --upgrade=false'
	elif [ "$1" == '-d' -o "$1" == '--desync' ]; then
		if [ $USER != 'root' ]; then
                        echo "Root user privileges required."
			exit 0
                fi

                echo ""
                echo "Network Injector (Tactical Control Center)"
                echo ""
                echo "Desync the Network Injector from current server..."
                rm -f /opt/td-config/share/server 2> /dev/null
		rm -f /opt/td-config/share/port 2> /dev/null
		rm -f /opt/td-config/share/key 2> /dev/null
		rm -f /opt/td-config/share/cookie 2> /dev/null
		echo "Please synchronize the Network Injector with new server."
                echo ""
	elif [ "$1" == '-l' -o "$1" == '--log' ]; then
		echo ""
		echo "Network Injector (Tactical Control Center)"
		echo ""
		echo "Log:"
		echo ""
		tail -f /var/log/syslog | grep RCS
	elif [ "$1" == '-s' -o "$1" == '--show-logs' ]; then
		echo ""
		echo "Network Injector (Tactical Control Center)"
		echo ""
		echo "The log directory is: /var/log/td-config/"
		echo ""
		echo "Current logs:"
		echo ""
		ls -l /var/log/td-config/
	elif [ "$1" == '-r' -o "$1" == '--report' ]; then
                if [ $USER != 'root' ]; then
                        echo "Root user privileges required."
			exit 0
                fi

                echo ""
                echo "Network Injector (Tactical Control Center)"
                echo ""
                echo "Build a complete report, please wait..." 
                cd $HOME
		rm -f tactical_report.tar.gz 2> /dev/null
		rm -Rf tactical_report/ 2> /dev/null
                mkdir tactical_report/
                cp -Rf /opt/td-config/ tactical_report/
                rm -f tactical_report/td-config/share/wordlist
                cp -Rf /var/log/td-config/* tactical_report/ 2> /dev/null
                tar -cvzf tactical_report.tar.gz tactical_report/ > /dev/null
                rm -Rf tactical_report/
                echo "Please send $HOME/tactical_report.tar.gz to support."
                echo ""
	elif [ "$1" == '-v' -o "$1" == '--version' ]; then
		echo ""
		echo "Network Injector (Tactical Control Center)"
		echo ""
		echo -n "Current system version: "
		cat /opt/td-config/VERSION | awk '{print $1}'
		echo -n "Current core version:   "
		cat /opt/td-config/VERSION | awk '{print $2}'
		echo ""
	else
		echo ""
		echo "Network Injector (Tactical Control Center)"
		echo ""
		echo "Usage: tactical [options]"
		echo ""
		echo "  -d, --desync         Desync from current server" 
		echo "  -l, --log            Show running log"
		echo "  -s, --show-logs      Show all logs"
		echo "  -r, --report         Build a complete report for support"
		echo "  -v, --version        Show current version"
		echo "  -h, --help           Show this help"
		echo ""
	fi
fi
