#!/bin/bash
#
#Copyright 2012 CurlyMo <development@xbian.org>
#
#This file is part of XBian - XBMC on the Raspberry Pi.
#
#XBian is free software: you can redistribute it and/or modify it under the
#terms of the GNU General Public License as published by the Free Software
#Foundation, either version 3 of the License, or (at your option) any later
#version.
#
#XBian is distributed in the hope that it will be useful, but WITHOUT ANY
#WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
#FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
#details.
#
#You should have received a copy of the GNU General Public License along
#with XBian. If not, see <http://www.gnu.org/licenses/>

#|------------------------------------|
#|          Global variables          |
#|------------------------------------|

# The arguments this module accepts
ARGUMENTS=(status rootpass enable disable);

#|------------------------------------|
#|          Include files             |
#|------------------------------------|

source $BASEPATH/modules/sshroot/functions
if [ $GUIMODE -eq 1 ]; then
	source $BASEPATH/modules/sshroot/dialogs
fi

#|------------------------------------|
#|           Main program             |
#|------------------------------------|

# Executes the GUI version of this module
function showGUIFn() {
	rootPasswordSetFn
	if [ $? -eq 0 ]; then
		showEmptyRootPasswordDlg
	fi
	
	enableDisableSSHRootLoginDlg
	CODE=$?
	if [ $CODE -eq 0 ]; then
		enableSSHRootLoginFn
		if [ $? -eq 0 ]; then
			showErrorDlg;
		else
			showSSHRootEnabledDlg
		fi
	elif [ $CODE -eq 1 ]; then
		disableSSHRootLoginFn
		if [ $? -eq 0 ]; then
			showErrorDlg;
		else
			showSSHRootDisabledDlg
		fi
	fi
}

# Executes the command line version of this module
#  $1 Argument [String]
# Returns
#  *Status [Integer]
#  - 1: Enabled
#  - 0: Disabled
#  *Rootpass [Integer]
#  - 1: Set
#  - 0: Empty
#  *Enable [Integer]
#  - 1: Succes
#  - 0: Failed
#  *Disable [Integer]
#  - 1: Succes
#  - 0: Failed
function showCMDFn() {
	case $1 in
		"status")
			isSSHRootLoginEnabledFn;
			echo $?;
		;;
		"rootpass")
			rootPasswordSetFn;
			echo $?;
		;;
		"enable")
			enableSSHRootLoginFn;
			echo $?;
		;;
		"disable")
			disableSSHRootLoginFn;
			echo $?;
		;;
	esac
}