Beispiel #1
0
int main(int argc, char **argv) {
  char pbuffer[64000];
  struct pk_conn pkc;
  struct pk_parser* pkp;
  struct pk_pagekite kite;
  struct pk_kite_request kite_r;
  struct pk_kite_request* kite_rp;
  SSL_CTX* ctx;

  if (argc < 3) {
    usage();
    exit(1);
  }

  pks_global_init(PK_LOG_ALL);
  pk_state.log_file = NULL;
  PKS_SSL_INIT(ctx);

  kite_r.kite = &kite;
  strcpy(kite.protocol, "http");
  strncpyz(kite.public_domain, argv[1], PK_DOMAIN_LENGTH);
  kite.public_port = 0;
  strncpyz(kite.auth_secret, argv[2], PK_SECRET_LENGTH);

  kite_r.bsalt[0] = '\0';
  kite_r.fsalt[0] = '\0';
  kite_rp = &kite_r;

  srand(time(0) ^ getpid());
  if (0 > pk_connect(&pkc, argv[1], 443, 1, &kite_r, NULL, ctx)) {
    pk_perror(argv[1]);
    usage();
    return 1;
  }

  pkp = pk_parser_init(sizeof(pbuffer), pbuffer, &handle_request, &pkc);
  if (NULL == pkp) {
    pk_perror(argv[1]);
    usage();
    return 1;
  }

  fprintf(stderr, "*** Connected! ***\n");
  while (pkc_wait(&pkc, -1)) {
    pkc_read(&pkc);
    pk_parser_parse(pkp, pkc.in_buffer_pos, (char *) pkc.in_buffer);
    pkc.in_buffer_pos = 0;
  }
  pkc_reset_conn(&pkc, 0);

  return 0;
}
Beispiel #2
0
int main(int argc, char **argv) {
  struct pk_manager *m;
  unsigned int tmp_uint;
  char* proto;
  char* kitename;
  char* secret;
  int gotargs = 0;
  int verbosity = 0;
  int use_ipv4 = 1;
  int fes_v4 = 0;
#ifdef HAVE_IPV6
  int use_ipv6 = 1;
  int fes_v6 = 0;
#endif
  int use_current = 1;
  int use_ssl = 1;
  int use_evil = 0;
  int use_watchdog = 0;
  int max_conns = 25;
  int spare_frontends = 0;
  char* fe_hostname = NULL;
  char* ddns_url = PAGEKITE_NET_DDNS;
  int ac;
  int pport;
  int lport;
  SSL_CTX* ssl_ctx;

  /* FIXME: Is this too lame? */
  srand(time(0) ^ getpid());
  pks_global_init(PK_LOG_NORMAL);

  while (-1 != (ac = getopt(argc, argv, "46c:B:CE:F:In:qRSvWZ"))) {
    switch (ac) {
      case '4':
        use_ipv4 = 0;
        break;
      case '6':
#ifdef HAVE_IPV6
        use_ipv6 = 0;
#endif
        break;
      case 'C':
        use_current = 0;
        break;
      case 'v':
        verbosity++;
        break;
      case 'q':
        verbosity--;
        break;
      case 'I':
        use_ssl = 0;
        break;
      case 'R':
        pk_state.fake_ping = 1;
        break;
      case 'S':
        ddns_url = NULL;
        break;
      case 'W':
        use_watchdog = 1;
        break;
      case 'Z':
        use_evil = 1;
        break;
      case 'F':
        gotargs++;
        fe_hostname = strdup(optarg);
        break;
      case 'B':
        gotargs++;
        if (1 == sscanf(optarg, "%u", &pk_state.bail_on_errors)) break;
        usage(1);
      case 'c':
        gotargs++;
        if (1 == sscanf(optarg, "%d", &max_conns)) break;
        usage(1);
      case 'E':
        gotargs++;
        if (1 == sscanf(optarg, "%u", &tmp_uint)) {
          pk_state.conn_eviction_idle_s = tmp_uint;
          break;
        }
        usage(1);
      case 'n':
        gotargs++;
        if (1 == sscanf(optarg, "%d", &spare_frontends)) break;
        usage(1);
      default:
        usage(1);
    }
    gotargs++;
  }

  if ((argc-1-gotargs) < 5 || ((argc-1-gotargs) % 5) != 0) usage(1);

  signal(SIGUSR1, &raise_log_level);
  pk_state.log_mask = ((verbosity < 0) ? PK_LOG_ERRORS :
                      ((verbosity < 1) ? PK_LOG_NORMAL :
                      ((verbosity < 2) ? PK_LOG_DEBUG : PK_LOG_ALL)));

  if (use_ssl) {
    PKS_SSL_INIT(ssl_ctx);
  }
  else {
    ssl_ctx = NULL;
  }

  if (NULL == (m = pkm_manager_init(NULL, 0, NULL,
                                    1 + (argc-1-gotargs)/5, /* Kites */
                                    PAGEKITE_NET_FE_MAX,
                                    max_conns, ddns_url, ssl_ctx))) {
    pk_perror(argv[0]);
    exit(1);
  }
  m->want_spare_frontends = spare_frontends;
  if (use_evil) {
    m->housekeeping_interval_min = 5;
    m->housekeeping_interval_max = 20;
    m->check_world_interval = 30;
  }
  if (use_watchdog)
    m->enable_watchdog = 1;

  for (ac = gotargs; ac+5 < argc; ac += 5) {
    if ((1 != sscanf(argv[ac+1], "%d", &lport)) ||
        (1 != sscanf(argv[ac+4], "%d", &pport))) {
      usage(2);
    }
    proto = argv[ac+2];
    kitename = argv[ac+3];
    secret = argv[ac+5];
    if ((NULL == (pkm_add_kite(m, proto, kitename, 0, secret,
                               "localhost", lport))) ||
        (use_current &&
         (0 > (pkm_add_frontend(m, kitename, pport, FE_STATUS_AUTO))))) {
      pk_perror(argv[0]);
      exit(3);
    }
  }

  if (ddns_url != NULL) {
    if (fe_hostname) {
      if (0 > (fes_v4 = pkm_add_frontend(m, fe_hostname, 443, FE_STATUS_AUTO))) {
        pk_perror(argv[0]);
        exit(4);
      }
    }
    else if (((use_ipv4) &&
              (0 >= (fes_v4 = pkm_add_frontend(m, PAGEKITE_NET_V4FRONTENDS, FE_STATUS_AUTO))))
#ifdef HAVE_IPV6
         ||  ((use_ipv6) &&
              (0 >= (fes_v6 = pkm_add_frontend(m, PAGEKITE_NET_V6FRONTENDS, FE_STATUS_AUTO))))
#endif
             ) {
      pk_perror(argv[0]);
      exit(4);
    }
  }
  if (0 == (fes_v4 + fes_v6)) {
    pk_error = ERR_NO_FRONTENDS;
    pk_perror(argv[0]);
    exit(4);
  }

  if (0 > pkm_run_in_thread(m)) {
    pk_perror(argv[0]);
    exit(5);
  }

  pkm_wait_thread(m);
  return 0;
}
Beispiel #3
0
int main(int argc, char **argv) {
  struct pk_manager *m;
  unsigned int tmp_uint;
  int gotargs = 0;
  int verbosity = 0;
  int use_ipv4 = 1;
#ifdef HAVE_IPV6
  int use_ipv6 = 1;
#endif
  int use_evil = 0;
  int use_watchdog = 0;
  int max_conns = 25;
  int lport;
  int ac;
  SSL_CTX* ssl_ctx;

  /* FIXME: Is this too lame? */
  srand(time(0) ^ getpid());
  pks_global_init(PK_LOG_NORMAL);

  while (-1 != (ac = getopt(argc, argv, "46a:c:B:E:qvWZ"))) {
    switch (ac) {
      case '4':
        use_ipv4 = 0;
        break;
      case '6':
#ifdef HAVE_IPV6
        use_ipv6 = 0;
#endif
        break;
      case 'v':
        verbosity++;
        break;
      case 'q':
        verbosity--;
        break;
      case 'W':
        use_watchdog = 1;
        break;
      case 'Z':
        use_evil = 1;
        break;
      case 'B':
        gotargs++;
        if (1 == sscanf(optarg, "%u", &pk_state.bail_on_errors)) break;
        usage(EXIT_ERR_USAGE);
      case 'c':
        gotargs++;
        if (1 == sscanf(optarg, "%d", &max_conns)) break;
        usage(EXIT_ERR_USAGE);
      case 'E':
        gotargs++;
        if (1 == sscanf(optarg, "%u", &tmp_uint)) {
          pk_state.conn_eviction_idle_s = tmp_uint;
          break;
        }
        usage(EXIT_ERR_USAGE);
      default:
        usage(EXIT_ERR_USAGE);
    }
    gotargs++;
  }

  if ((argc-1-gotargs) < 5 || ((argc-1-gotargs) % 5) != 0) {
    usage(EXIT_ERR_USAGE);
  }

  signal(SIGUSR1, &raise_log_level);

  pk_state.log_mask = ((verbosity < 0) ? PK_LOG_ERRORS :
                      ((verbosity < 1) ? PK_LOG_NORMAL :
                      ((verbosity < 2) ? PK_LOG_DEBUG : PK_LOG_ALL)));

  PKS_SSL_INIT(ssl_ctx);

  if (NULL == (m = pkm_manager_init(NULL, 0, NULL, 0,
                                    PAGEKITE_NET_CLIENT_MAX,
                                    max_conns, NULL, ssl_ctx))) {
    pk_perror(argv[0]);
    exit(EXIT_ERR_MANAGER_INIT);
  }
  if (use_evil) {
    m->housekeeping_interval_min = 5;
    m->housekeeping_interval_max = 20;
    m->check_world_interval = 30;
  }
  if (use_watchdog)
    m->enable_watchdog = 1;

  for (ac = gotargs; ac < argc; ac += 1) {
    if (1 == sscanf(argv[ac+1], "%d", &lport)) {
      if (use_ipv4)
        if (NULL == (pkr_add_listener(m, lport))) {
          pk_perror(argv[0]);
          exit(EXIT_ERR_ADD_LPORT);
        }
#ifdef HAVE_IPV6
      if (use_ipv6)
        if (NULL == (pkr_add_listener_v6(m, lport))) {
          pk_perror(argv[0]);
          exit(EXIT_ERR_ADD_LPORT);
        }
#endif
    } else {
      break;
    }
  }

  for (; ac+2 < argc; ac += 2) {
    if (NULL == (pkm_add_kite(m, NULL, argv[ac+1], 0, argv[ac+2], NULL, 0))) {
      pk_perror(argv[0]);
      exit(EXIT_ERR_ADD_KITE);
    }
  }

  if (0 > pkm_run_in_thread(m)) {
    pk_perror(argv[0]);
    exit(EXIT_ERR_START_THREAD);
  }

  pkm_wait_thread(m);

  return 0;
}