daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest May 23rd, 2018 208 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include "spectranet.h"
  5.  
  6. #define _GNU_SOURCE
  7. #define _XOPEN_SOURCE
  8.  
  9. #define SLEEP_TIME 1800
  10. #define CONN_WAIT 5
  11. static char *username = "YOUR_USERNAME";
  12. static char *password = "YOUR_PASSWORD";
  13. static char *serv_command = "/media/usb/router/packages/usr/sbin/lighttpd -f /media/usb/router/packages/etc/lighttpd/lighttpd.conf";
  14. static char *check_ssh_command = "ps aux|grep ssh|grep localhost|grep -v \'sh -c\' >/dev/null";
  15. static char *check_http_command = "ps aux|grep ssh|grep 0.0.0.0 |grep -v \'sh -c\' > /dev/null";
  16. 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";
  17. 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";
  18. int
  19. main(int argc,char *argv)
  20. {
  21.   /* Daemonize */
  22.   if( fork() != 0 )
  23.     exit(0);
  24.   int not_found_ssh,not_found_http;
  25.   /* Start HTTP Server */
  26.   fprintf(stderr, "Starting HTTP Server\n");
  27.   system(serv_command);
  28.   while( 1 ) {
  29.     if( check_internet_connection() ) {
  30.       fprintf(stderr,"Connection exists.\n");
  31.  
  32.       /* Check for existing ssh tunnels */
  33.       not_found_ssh = system(check_ssh_command);
  34.       if( not_found_ssh ) {
  35.         fprintf(stderr, "No connection found for ssh. Connecting...\n");
  36.         system(ssh_command);
  37.       }
  38.       /* Check for existing http tunnels */
  39.       not_found_http = system(check_http_command);
  40.       if( not_found_http ) {
  41.         fprintf(stderr, "No connection found for http. Connecting...\n");
  42.         system(http_command);
  43.       }
  44.       if( not_found_ssh || not_found_http ) {
  45.           sleep ( CONN_WAIT );
  46.           continue;
  47.       }
  48.       else {
  49.           fprintf(stderr, "All connections found...\nSleeping...\n");
  50.           sleep( SLEEP_TIME );
  51.       }  
  52.     }
  53.     /* No Internet connection */
  54.     else {
  55.       connect_to_internet(username,password);
  56.       sleep( CONN_WAIT );
  57.     }
  58.    
  59.   }
  60.   fprintf(stderr,"Something wrong\n");
  61.   fprintf(stderr,"Exited out of infinite loop\n");
  62.   return 1;
  63. }
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