Advertisement
Guest User

Untitled

a guest
Jan 16th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.14 KB | None | 0 0
  1. /*
  2. Copyright (c) 2012 Joji Antony
  3. All right reserved
  4. Licensce 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-72-110-212-185.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-72-110-212-185.compute-1.amazonaws.com -i /media/usb/router/scripts/id_rsa";
  23. int
  24. main(int argc,char *argv)
  25. {
  26.   int not_found_ssh,not_found_http;
  27.   /* Start HTTP Server */
  28.   fprintf(stderr, "Starting HTTP Server\n");
  29.   system(serv_command);
  30.   while( 1 ) {
  31.     if( check_internet_connection() ) {
  32.       fprintf(stderr,"Connection exists.\n");
  33.      
  34.       /* Check for existing ssh tunnels */
  35.       not_found_ssh = system(check_ssh_command);
  36.       if( not_found_ssh ) {
  37.         fprintf(stderr, "No connection found for ssh. Connecting...\n");
  38.         system(ssh_command);
  39.       }
  40.       /* Check for existing http tunnels */
  41.       not_found_http = system(check_http_command);
  42.       if( not_found_http ) {
  43.             fprintf(stderr, "No connection found for http. Connecting...\n");
  44.         system(http_command);
  45.       }
  46.       if( not_found_ssh || not_found_http ) {
  47.               sleep ( CONN_WAIT );
  48.           continue;
  49.       }
  50.       else {
  51.     fprintf(stderr, "All connections found...\nSleeping...\n");
  52.     sleep( SLEEP_TIME );
  53.       }  
  54.     }
  55.     /* No Internet connection */
  56.     else {
  57.       connect_to_internet(username,password);
  58.       sleep( CONN_WAIT );
  59.     }
  60.    
  61.   }
  62.   fprintf(stderr,"Something wrong\n");
  63.   fprintf(stderr,"Exited out of infinite loop\n");
  64.   return 1;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement