Ejemplo n.º 1
0
int sort_redirect(sieve2_context_t *s, void *my)
{
	struct sort_context *m = (struct sort_context *)my;
	const char *to;
	const char *from;

	to = sieve2_getvalue_string(s, "address");

	TRACE(TRACE_INFO, "Action is REDIRECT: REDIRECT destination is [%s].",
		to);

	/* According to a clarification from the ietf-mta-filter mailing list,
	 * the redirect is supposed to be absolutely transparent: the envelope
	 * sender is the original envelope sender, with only the envelope
	 * recipient changed. As a fallback, we'll use the redirecting user. */
	from = dbmail_message_get_header(m->message, "Return-Path");
	if (!from)
		from = m->message->envelope_recipient->str;

	if (send_redirect(m->message, to, from) != 0) {
		return SIEVE2_ERROR_FAIL;
	}

	m->result->cancelkeep = 1;
	return SIEVE2_OK;
}
Ejemplo n.º 2
0
void http_redirect(char *location)
{
  char buf[192];
  int n = sprintf(buf,
   "HTTP/1.1 303 See Other\r\n"
     "Location: http://%s%s\r\n"
     "Connection: Close\r\n\r\n",
      req_host,
      location);
  send_redirect(buf, n);
}
Ejemplo n.º 3
0
void http_redirect_to_addr(unsigned char *ip, unsigned short port, char *location)
{
  char buf[256];
  int n;
  n = sprintf(buf,
   "HTTP/1.1 303 See Other\r\n"
   "Location: http://%d.%d.%d.%d:%d%s\r\n"
   "Connection: Close\r\n\r\n",
   sys_setup.ip[0], sys_setup.ip[1], sys_setup.ip[2], sys_setup.ip[3],
   sys_setup.http_port,
   location
  );
  send_redirect(buf, n);
}
Ejemplo n.º 4
0
static void
answer_file(struct vmod_fsdirector_file_system *fs, struct stat *stat_buf,
    const char *path)
{
	mode_t mode = stat_buf->st_mode;

	if (S_ISREG(mode)) {
		if (stat_buf->st_size) {
			send_response(fs, stat_buf, path);
		}
		else {
			prepare_answer(&fs->htc, 204);
			prepare_body(&fs->htc);
		}
	}
	else if (S_ISLNK(mode)) {
		send_redirect(fs, path);
	}
	else {
		prepare_answer(&fs->htc, 404);
		prepare_body(&fs->htc);
	}
}
Ejemplo n.º 5
0
int main(int argc, char *argv)
{
  char *s, *p, *action = "", *uid, *path_info;
  struct event x, y;
  FILE *events;

  memset(&x, 0, sizeof(x));
  memset(&y, 0, sizeof(y));

  path_info = getenv("PATH_INFO");
  if (path_info)
    {
      snprintf(data_path, sizeof(data_path), "/pf%s.ics", path_info);
      snprintf(backup_path, sizeof(backup_path), "/pf%s.bak", path_info);
    }
  else
    {
      strcpy(data_path, DATA_FILE);
      strcpy(backup_path, BACKUP_FILE);
    }
    
  s = getenv("QUERY_STRING");
  for (; p = strtok(s, "&"); s = 0)
  {
    if (strncmp(p, "action=", 7) == 0)
      action = p + 7;
    else if (strncmp(p, "uid=", 4) == 0)
      uid = p + 4;
  }

  if (strcmp(action, "create") == 0)
  {
    printf("Content-type: text/html\n\n");
    printf("<html>");
    printf("<title>Create Event</title>");
    printf("<body>");
    printf("<h1>Create Event</h1>");
    if (strcasecmp(getenv("REQUEST_METHOD"), "POST") == 0)
    {
      bind_request_params(&x);
      create_event(&x);
      printf("<div>Event created.</div>");
    }
    edit_event_form(&x);
    printf("</html>");
  }
  else if (strcmp(action, "quickedit") == 0)
    {
      if (strcasecmp(getenv("REQUEST_METHOD"), "POST") == 0)
	{
	  bind_request_params(&x);
	  create_event(&x);
	}
      send_redirect();
    }
  else if (strcmp(action, "copy") == 0)
  {
    if (strcasecmp(getenv("REQUEST_METHOD"), "POST") == 0)
    {
      bind_request_params(&x);
      create_event(&x);
      send_redirect();
    }
    else /* REQUEST_METHOD == "GET" */
    {
      const char *title = "Copy Event";
      printf("Content-type: text/html\n\n");
      printf("<html>");
      printf("<title>%s</title>", title);
      printf("<h1>%s</h1>", title);
      events = fopen(data_path, "r");
      while (getical(events, &x))
      {
        if (strcmp(x.uid, uid) == 0)
        {
          x.uid[0] = 0;
          edit_event_form(&x);
        }
      }
      fclose(events);
    }
  }
  else if (strcmp(action, "edit") == 0)
  {
    if (strcasecmp(getenv("REQUEST_METHOD"), "POST") == 0)
    {
      bind_request_params(&y);
      char tmpnam[PATH_MAX];
      strcpy(tmpnam, "/tmp/events.XXXXXX");
      FILE *tmp = fdopen(mkstemp(tmpnam), "a");
      events = fopen(data_path, "r");
      while (getical(events, &x))
      {
        if (strcmp(x.uid, uid) == 0)
          putical(tmp, &y);
        else
          putical(tmp, &x);
      }
      fclose(events);
      unlink(backup_path);
      rename(data_path, backup_path);
      rename(tmpnam, data_path);
      printf("Status: 301\n");
      printf("Location: %s%s\n\n", getenv("SCRIPT_NAME"), getenv("PATH_INFO"));
    }
    else
    {
      const char *title = "Edit Event";
      printf("Content-type: text/html\n\n");
      printf("<html>");
      printf("<title>%s</title>", title);
      printf("<h1>%s</h1>", title);
      events = fopen(data_path, "r");
      while (getical(events, &x))
      {
        if (strcmp(x.uid, uid) == 0)
        {
          edit_event_form(&x);
        }
      }
      fclose(events);
      printf("</html>");
    }
  }
  else if (strcmp(action, "delete") == 0)
    {
      if (strcasecmp(getenv("REQUEST_METHOD"), "POST") == 0)
	{
	  bind_request_params(&y);
	  char tmpnam[PATH_MAX];
	  strcpy(tmpnam, "/tmp/events.XXXXXX");
	  FILE *tmp = fdopen(mkstemp(tmpnam), "a");
	  events = fopen(data_path, "r");
	  while (getical(events, &x))
	    {
	      if (strcmp(x.uid, uid) == 0)
		/* skip */;
	      else
		putical(tmp, &x);
	    }
	  fclose(events);
	  unlink(backup_path);
	  rename(data_path, backup_path);
	  rename(tmpnam, data_path);
	  printf("Status: 301\n");
	  printf("Location: %s\n\n", getenv("SCRIPT_NAME"));
	}
      else
	{
	  const char *title = "Delete Event";
	  printf("Content-type: text/html\n\n");
	  printf("<html>");
	  printf("<title>%s</title>", title);
	  printf("<h1>%s</h1>", title);
	  events = fopen(data_path, "r");
	  while (getical(events, &x))
	    {
	      if (strcmp(x.uid, uid) == 0)
		{
		  delete_event_form(&x);
		}
	    }
	  fclose(events);
	  printf("</html>");
	}
    }
  else
  {
    printf("Content-type: text/html\n\n");
    printf("<style>table,th,td { border: thin solid gray }</style>");
    printf("<title>Index</title>");
    printf("<table>");
    printf("<tr>");
    printf("<th>Summary</th>");
    printf("<th>Location</th>");
    printf("<th>Geo</th>");
    printf("<th>From</th>");
    printf("<th>To</th>");
    printf("<th>Start</th>");
    printf("<th>End</th>");
    printf("<th>Byday</th>");
    printf("<th>Exdate</th>");
    printf("<th>Actions</th>");
    printf("</tr>");
    events = fopen(data_path, "r");
    if (events != NULL)
      {
	while (getical(events, &x))
	  {
	    printf("<tr>");
	    printf("<td>%s</td>", x.summary);
	    printf("<td>%s</td>", x.location);
	    printf("<td>%s</td>", x.geo);
	    printf("<td>%s</td>", x.from);
	    printf("<td>%s</td>", x.to);
	    printf("<td>%s</td>", x.start);
	    printf("<td>%s</td>", x.end);
	    printf("<td>%s</td>", x.byday);
	    printf("<td>%s</td>", x.exdate);
	    printf("<td>");
	    printf("<a href='?action=copy&uid=%s'>Copy</a> ", x.uid);
	    printf("<a href='?action=edit&uid=%s'>Edit</a> ", x.uid);
	    printf("<a href='?action=delete&uid=%s'>Delete</a>", x.uid);
	    printf("</td>");
	    printf("</tr>");
	  }
	fclose(events);
      }
    bind_request_params(&x);
    quickedit_event_form(&x);
    printf("</table>");
    printf("<hr/>");
    printf("<div><a href='?action=create'>Create</a></div>");
  }

  exit(EXIT_SUCCESS);
}