#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <stddef.h>
#include <dlfcn.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/time.h>

#include "gsw_sys_interface.h"
#include "gsw_log_interface.h"
#define  LOG_LEVLE_CONFIG_FILE "/etc/telinit"

#define GSW_SYS "[HAL][GSW_SYS]"

#define SERVER_IP "127.0.0.1"
#define TIMEOUT_SEC 3

#define SSH_PORT 22
#define FTP_PORT 21

static int check_local_port(int port)
{
    int sockfd;
    struct sockaddr_in server_addr;
    struct timeval timeout;

    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        return 1;
    }

    timeout.tv_sec = TIMEOUT_SEC;
    timeout.tv_usec = 0;
    setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
    setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));

    memset(&server_addr, 0, sizeof(server_addr));
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(port);
    inet_pton(AF_INET, SERVER_IP, &server_addr.sin_addr);

    int ret = connect(sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr));
    close(sockfd);

    return ret == 0 ? 0 : 1;
}

int gsw_sys_svr_ftp_start(const char *cfg)
{
	int ret = GSW_HAL_SUCCESS;
	char command[128];

	if(check_local_port(FTP_PORT) == 0)
	{
		
		LOGI(GSW_SYS, "ftp service is running");
		gsw_sys_svr_ftp_stop();
	}

	if(NULL == cfg)
	{
		strcpy(command, "/etc/init.d/vsftpd start");
	}
	else
	{
		snprintf(command, sizeof(command), "vsftpd %s &", cfg);
	}
	ret = system(command);
	if(ret != 0) {
		LOGE(GSW_SYS, "command execution failed command:%s.\n", command);
		goto exit;
	}
exit:
	return ret;
}
int gsw_sys_svr_ftp_stop()
{
	int ret = GSW_HAL_SUCCESS;

	if(check_local_port(FTP_PORT))
	{
		LOGI(GSW_SYS, "ftp service is not running");
		return GSW_HAL_SUCCESS;
	}
	
	ret = system("/etc/init.d/vsftpd stop 2>/dev/null");
	LOGI(GSW_SYS, "execute command etc/init.d/vsftpd stop 2>/dev/null  ret:%d", ret);
		
	ret = system("killall -TERM vsftpd 2>/dev/null");
	LOGI(GSW_SYS, "execute command killall -TERM vsftpd 2>/dev/null  ret:%d", ret);
		
	return GSW_HAL_SUCCESS;
}
int gsw_sys_svr_ssh_start(const char *cfg)
{
	int ret= GSW_HAL_SUCCESS;
	char command[128];

	if(check_local_port(SSH_PORT) == 0)
	{
		LOGI(GSW_SYS, "ssh service is running");
		gsw_sys_svr_ssh_stop();
	}
	
	if(NULL == cfg)
	{			
		strcpy(command, "/etc/init.d/sshd start");
	}
	else
	{
		snprintf(command, sizeof(command), "/usr/sbin/sshd -f %s &", cfg);
	}
	
	ret = system(command);
	if(ret != 0)
	{
		LOGE(GSW_SYS, "command execution failed command:%s.\n", command);
		goto exit;
	}
	
exit:
	return ret;
}
int gsw_sys_svr_ssh_stop()
{
	int ret = GSW_HAL_SUCCESS;

	if(check_local_port(SSH_PORT))
	{
		LOGI(GSW_SYS, "ssh service is not running");
		return GSW_HAL_SUCCESS;
	}
	
	ret = system("/etc/init.d/sshd stop 2>/dev/null");
	LOGI(GSW_SYS, "execute command /etc/init.d/sshd stop 2>/dev/null  ret:%d", ret);
	
	ret = system("killall sshd 2>/dev/null");
	LOGI(GSW_SYS, "execute command killall sshd 2>/dev/null  ret:%d", ret);
	
	return GSW_HAL_SUCCESS;
}
int gsw_sys_svr_syslog_restart(const char *log_lvl)
{
	(void)log_lvl;
	int 	ret = GSW_HAL_SUCCESS;
	char command[256] = {0};
	int level = 0;
	char *log_level_params[8] = {"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"};
	char *log_level_values[8] = {"1", "2", "3", "4", "5", "6", "7", "8"};


	snprintf(command, sizeof(command), 
			 "grep -q 'setprop sys.default.loglevel' %s", LOG_LEVLE_CONFIG_FILE);
	for(level = 0; level < 8; level++)
	{
		if(0 == strcmp(log_lvl, log_level_params[level]))
			break;
	}
	if(8 == level)
	{
		LOGE(GSW_SYS, "Parameter error\n");
		ret = GSW_HAL_NORMAL_FAIL;
	    goto exit;
	}
	
	ret = system(command);
	if (ret != 0)
	{
		LOGE(GSW_SYS, "config option not exist.\n");
	    goto exit;
	}
	snprintf(command, sizeof(command), 
	         "sed -i 's/\\(setprop sys.default.loglevel \\)\\S*/\\1%s/' %s",
	         log_level_values[level], LOG_LEVLE_CONFIG_FILE);
	
	ret = system(command);
	if (ret != 0)
	{
	    LOGE(GSW_SYS, "command execution failed.\n");
	    goto exit;
	}
exit:
	return ret;
}

