Exemplo n.º 1
0
static gboolean
pcp_filter (CockpitPortal *self,
            const gchar *command,
            const gchar *channel,
            JsonObject *options,
            GBytes *payload)
{
  const gchar *type;
  const gchar *source;

  if (g_str_equal (command, "open") && channel)
    {
      if (!cockpit_json_get_string (options, "payload", NULL, &type))
        type = NULL;
      if (!cockpit_json_get_string (options, "source", NULL, &source))
        source = NULL;

      if (g_strcmp0 (type, "metrics1") != 0 ||
          g_strcmp0 (source, "internal") == 0)
        {
          return FALSE;
        }

      g_debug ("pcp portal channel: %s", channel);
      cockpit_portal_add_channel (self, channel, COCKPIT_PORTAL_NORMAL);
      return TRUE;
    }

  return FALSE;
}
Exemplo n.º 2
0
static gboolean
superuser_filter (CockpitPortal *self,
                  const gchar *command,
                  const gchar *channel,
                  JsonObject *options,
                  GBytes *payload)
{
  CockpitPortalFlags flags = COCKPIT_PORTAL_NORMAL;
  gboolean privileged = FALSE;
  const gchar *superuser;

  if (g_str_equal (command, "logout"))
    {
      g_debug ("got logout at super proxy");
      transition_none (self);
      return FALSE;
    }

  if (g_str_equal (command, "open") && channel)
    {
      if (!cockpit_json_get_bool (options, "superuser", FALSE, &privileged))
        {
          if (!cockpit_json_get_string (options, "superuser", NULL, &superuser))
            {
              g_warning ("invalid value for \"superuser\" channel open option");
              send_close_channel (self, channel, "protocol-error");
              return TRUE;
            }
          else if (g_strcmp0 (superuser, "try") == 0)
            {
              privileged = TRUE;
              flags = COCKPIT_PORTAL_FALLBACK;
            }
          else if (g_strcmp0 (superuser, "require") == 0)
            {
              privileged = TRUE;
            }
          else if (superuser)
            {
              g_warning ("invalid value for \"superuser\" channel open option: %s", superuser);
              send_close_channel (self, channel, "protocol-error");
              return TRUE;
            }
        }

      if (!privileged)
        return FALSE;

      g_debug ("superuser channel open: %s", channel);
      cockpit_portal_add_channel (self, channel, flags);
      return TRUE;
    }

  return FALSE;
}
Exemplo n.º 3
0
static gboolean
mock_filter_lower (CockpitPortal *portal,
                   const gchar *command,
                   const gchar *channel,
                   JsonObject *options)
{
  const gchar *payload = NULL;

  if (channel && g_str_equal (command, "open") &&
      cockpit_json_get_string (options, "payload", NULL, &payload) &&
      g_strcmp0 (payload, "lower") == 0)
    {
      cockpit_portal_add_channel (portal, channel, COCKPIT_PORTAL_NORMAL);
      return TRUE;
    }

  return FALSE;
}