Esempio n. 1
0
/* This function reads the type_c contexts.  */
gboolean 
read_types (tclient_c *tclient)
{
    GKeyFile *keys = 0;
    gint i = 0;
    gchar *buf = 0;
    gint buf_size = 0;

    buf = (gchar *)load_remote_file(tclient, "types.conf");
    if (!buf)
    {
        start_error_dialog(tclient, __FUNCTION__, "Could not load the types file");
        return FALSE;
    }

    buf_size = strlen(buf);

    /* Parse the keys */
    keys = g_key_file_new();
    if(g_key_file_load_from_data(keys, buf, buf_size, G_KEY_FILE_NONE, NULL))
    {
        gchar **group = 0;
        gsize group_size = 0;

        group = g_key_file_get_groups(keys, &group_size);

        /* Go through the groups and create connections for them */
        for (i = 0; i < group_size; i++)
        {
            type_c *type;

            type = g_malloc0 (sizeof (type_c));

            type->alias = g_strdup(group[i]);
            type->program = g_key_file_get_value(keys, group[i], "program", NULL);
            type->arguments = g_key_file_get_value(keys, group[i], "arguments", NULL);
            type->description = g_key_file_get_value(keys, group[i], "description", NULL);

            tclient->connection_type = g_list_append(tclient->connection_type, type);
        }

        g_strfreev(group);
    }

    g_key_file_free(keys);

    return TRUE;
}
Esempio n. 2
0
gboolean
read_settings (tclient_c *tclient)
{
    GKeyFile *keys = 0;
    gchar *buf;
    gint buf_size = 0;
    gchar hostname[_POSIX_HOST_NAME_MAX + 1] = {0};
    gchar *filename = 0;

    gethostname(hostname, _POSIX_HOST_NAME_MAX);

    filename = g_strdup_printf("clients/%s.conf", &hostname[0]);

    buf = (gchar *)load_remote_file(tclient, filename);

    if (!buf || strlen(buf) <= 1)
    {
        /* Client settings can be blank, just return true */
        return TRUE;
    }

    buf_size = strlen(buf);
    if (buf_size < 1)
        return TRUE;

    /* Parse the keys */
    keys = g_key_file_new();
    if(g_key_file_load_from_data(keys, buf, buf_size, G_KEY_FILE_NONE, NULL))
    {
        gchar **group = 0;
        gsize group_size = 0;

        group = g_key_file_get_groups(keys, &group_size);

        tclient->settings.connection = g_key_file_get_value(keys, group[0], "server", NULL);
        tclient->settings.resolution = g_key_file_get_value(keys, group[0], "resolution", NULL);

        g_strfreev(group);
    }

    g_free(filename);
    g_key_file_free(keys);

    return TRUE;
}
Esempio n. 3
0
static int
__load_file(hcq_handle_t hcq,
	    uint64_t     cmd)
{
    uint32_t   data_size = 0;
    char     * xml_str   = NULL;
    pet_xml_t  xml       = NULL;
    char     * err_str   = NULL;

    char     * src_file  = NULL;
    char     * dst_file  = NULL;

    int ret = -1;

    xml_str = (char *)hcq_get_cmd_data(hcq, cmd, &data_size);

    if (xml_str == NULL) {
	err_str = "Could not read File spec";
	goto out;
    }


    xml = pet_xml_parse_str(xml_str);

    if (xml == PET_INVALID_XML) {
	err_str = "XML Syntax Error";
	goto out;
    }

    src_file = pet_xml_get_val(xml, "src_file");
    dst_file = pet_xml_get_val(xml, "dst_file");
    
    if ((src_file == NULL) || (dst_file == NULL)) {
	err_str = "Invalid File spec";
 	goto out;
    }
    
    ret = load_remote_file(src_file, dst_file);

 out:
    if (err_str) ERROR("%s\n", err_str);

    hcq_cmd_return(hcq, cmd, ret, smart_strlen(err_str) + 1, err_str);
    return 0;
}
Esempio n. 4
0
/* This function updates the connection_c contexts.  */
gboolean
read_connections (tclient_c *tclient)
{
    GKeyFile *keys = 0;
    gint i = 0;
    gchar *buf = 0;
    gint buf_size = 0;

    tclient->connection = 0;

    buf = (gchar *)load_remote_file(tclient, "connections.conf");
    if (!buf)
    {
        start_error_dialog(tclient, __FUNCTION__, "Couldn't read connections\n");
        return FALSE;
    }
    buf_size = strlen(buf);

    /* Parse the keys */
    keys = g_key_file_new();
    if(g_key_file_load_from_data(keys, buf, buf_size, G_KEY_FILE_NONE, NULL))
    {
        gchar **group = 0;
        gsize group_size = 0;

        group = g_key_file_get_groups(keys, &group_size);

        /* Go through the groups and create connections for them */
        for (i = 0; i < group_size; i++)
        {
            connection_c *connection;
            connection = g_malloc0 (sizeof (connection_c));

			/* conf file reads like this
			 * [connection alias]
			 * host=127.0.0.1 #any resolvable IP/DNS
			 * icon=windows.png #Loaded from %server%/tclient/icons/
			 * type=RDP # Type of conneciton, must be defined in connections
			 * description=Test Station # This will show as a tooltip
			 * username=root #This is the default username to try
			 * retry=false #retry the connection or not
			 * hidden=true #Whether or not it shows up in the list */

            connection->alias = g_strdup(group[i]);
			
			/* Get the hostname/ip.  Verify that there is text there.  Fail
			 * if this is not there */
			if(!(connection->host = g_key_file_get_value(keys, group[i], "host", NULL)))
			{
				gchar *error_str = 0;
					
				error_str = g_strdup_printf("Malformed connection.conf: Error in group \"%s\".  You must provide a valid host to connect to.", group[i]);
				start_error_dialog(tclient, __FUNCTION__, error_str);
				
				g_free(error_str);
				g_free(connection);
				continue;
			}
			if (strlen(connection->host) <= 0)
			{
				gchar *error_str = 0;
				
				error_str = g_strdup_printf("Malformed connection.conf: Error in group \"%s\".  You must provide a valid host to connect to.", group[i]);
				start_error_dialog(tclient, __FUNCTION__, error_str);
				
				g_free(error_str);
				g_free(connection);
				continue;
			}
			
			/* Default username.  This can be empty */
			connection->username = g_key_file_get_value(keys, group[i], "username", NULL);
			
			/* Type to use.  This must exist in the types.conf file.  Fail if this
			 * entry is blank */
			if (!(connection->type = g_key_file_get_value(keys, group[i], "type", NULL)))
			{
				gchar *error_str = 0;
				
				error_str = g_strdup_printf("Malformed connection.conf: Error in group \"%s\".  \"%s\" must be set in types.conf", group[i], connection->type);
				start_error_dialog(tclient, __FUNCTION__, error_str);
				
				g_free(error_str);
				g_free(connection);
				continue;
			}
			if (connection->type == NULL)
			{
				gchar *error_str = 0;
				
				error_str = g_strdup_printf("Malformed connection.conf: Error in group \"%s\".  Type must be set", group[i]);
				start_error_dialog(tclient, __FUNCTION__, error_str);
				
				g_free(error_str);
				g_free(connection);
				continue;
			}
			
			/* Set retry setting.  If nothing else, say true */
			if (g_ascii_strncasecmp(g_key_file_get_value(keys, group[i], "retry", NULL), "true", strlen("true")) == 0)
			{
				connection->retry = TRUE;
			} 
			else if (g_ascii_strncasecmp(g_key_file_get_value(keys, group[i], "retry", NULL), "false", strlen("false")) == 0)
			{
				connection->retry = FALSE;
			} 
			else
			{
				connection->retry = TRUE;
			}
			
			/* Get this hidden setting.  Set to false by default */
			if(g_key_file_get_value(keys, group[i], "hidden", NULL) != NULL)
			{
				if (g_ascii_strncasecmp(g_key_file_get_value(keys, group[i], "hidden", NULL), "true", strlen("true")) == 0)
				{
					connection->hidden = TRUE;
				} 
				else if (g_ascii_strncasecmp(g_key_file_get_value(keys, group[i], "hidden", NULL), "false", strlen("false")) == 0)
				{
					connection->hidden = FALSE;
				}
			}
			else
			{
				connection->hidden = FALSE;
			}
			
			/* Get the icon name, this is optional */
            connection->icon = g_key_file_get_value(keys, group[i], "icon", NULL);
			
			/* Get the description, this is optional */
            connection->description = g_key_file_get_value(keys, group[i], "description", NULL);
			
            tclient->connection = g_list_append(tclient->connection, connection);
        }

        g_strfreev(group);
    }

    g_key_file_free(keys);

    return TRUE;
}