daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest May 23rd, 2018 213 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Copyright (c) 2012 Joji Antony
  3. All rights reserved
  4. License : Affero GPL V3
  5. */
  6. #include <stdio.h>
  7. #include <unistd.h>
  8. #include <stdlib.h>
  9. #include "spectranet.h"
  10.  
  11. #define _GNU_SOURCE
  12. #define _XOPEN_SOURCE
  13.  
  14. #define SLEEP_TIME 1800
  15. #define CONN_WAIT 5
  16. static char *username = "YOUR_USERNAME";
  17. static char *password = "YOUR_PASSWORD";
  18. static char *serv_command = "/media/usb/router/packages/usr/sbin/lighttpd -f /media/usb/router/packages/etc/lighttpd/lighttpd.conf";
  19. static char *check_ssh_command = "ps aux|grep ssh|grep localhost|grep -v \'sh -c\' >/dev/null";
  20. static char *check_http_command = "ps aux|grep ssh|grep 0.0.0.0 |grep -v \'sh -c\' > /dev/null";
  21. static char *ssh_command = "ssh -f -N -R 10000:localhost:22 ec2-user@ec2-75-101-209-183.compute-1.amazonaws.com -i /media/usb/router/scripts/id_rsa";
  22. static char *http_command = "ssh -f -N -R *:2500:0.0.0.0:81 ec2-user@ec2-75-101-209-183.compute-1.amazonaws.com -i /media/usb/router/scripts/id_rsa";
  23. int
  24. main(int argc,char *argv)
  25. {
  26.   /* Daemonize */
  27.   if( fork() != 0 )
  28.     exit(0);
  29.   int not_found_ssh,not_found_http;
  30.   /* Start HTTP Server */
  31.   fprintf(stderr, "Starting HTTP Server\n");
  32.   system(serv_command);
  33.   while( 1 ) {
  34.     if( check_internet_connection() ) {
  35.       fprintf(stderr,"Connection exists.\n");
  36.  
  37.       /* Check for existing ssh tunnels */
  38.       not_found_ssh = system(check_ssh_command);
  39.       if( not_found_ssh ) {
  40.         fprintf(stderr, "No connection found for ssh. Connecting...\n");
  41.         system(ssh_command);
  42.       }
  43.       /* Check for existing http tunnels */
  44.       not_found_http = system(check_http_command);
  45.       if( not_found_http ) {
  46.         fprintf(stderr, "No connection found for http. Connecting...\n");
  47.         system(http_command);
  48.       }
  49.       if( not_found_ssh || not_found_http ) {
  50.           sleep ( CONN_WAIT );
  51.           continue;
  52.       }
  53.       else {
  54.           fprintf(stderr, "All connections found...\nSleeping...\n");
  55.           sleep( SLEEP_TIME );
  56.       }  
  57.     }
  58.     /* No Internet connection */
  59.     else {
  60.       connect_to_internet(username,password);
  61.       sleep( CONN_WAIT );
  62.     }
  63.    
  64.   }
  65.   fprintf(stderr,"Something wrong\n");
  66.   fprintf(stderr,"Exited out of infinite loop\n");
  67.   return 1;
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top