Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Copyright (c) 2012 Joji Antony
- All right reserved
- Licensce Affero GPL v3
- */
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include "spectranet.h"
- #define _GNU_SOURCE
- #define _XOPEN_SOURCE
- #define SLEEP_TIME 1800
- #define CONN_WAIT 5
- static char *username = "YOUR_USERNAME";
- static char *password = "YOUR_PASSWORD";
- static char *serv_command = "/media/usb/router/packages/usr/sbin/lighttpd -f /media/usb/router/packages/etc/lighttpd/lighttpd.conf";
- static char *check_ssh_command = "ps aux|grep ssh|grep localhost|grep -v \'sh -c\' >/dev/null";
- static char *check_http_command = "ps aux|grep ssh|grep 0.0.0.0 |grep -v \'sh -c\' > /dev/null";
- 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";
- 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";
- int
- main(int argc,char *argv)
- {
- /* Daemonize */
- if( fork() != 0 )
- exit(0);
- int not_found_ssh,not_found_http;
- /* Start HTTP Server */
- fprintf(stderr, "Starting HTTP Server\n");
- system(serv_command);
- while( 1 ) {
- if( check_internet_connection() ) {
- fprintf(stderr,"Connection exists.\n");
- /* Check for existing ssh tunnels */
- not_found_ssh = system(check_ssh_command);
- if( not_found_ssh ) {
- fprintf(stderr, "No connection found for ssh. Connecting...\n");
- system(ssh_command);
- }
- /* Check for existing http tunnels */
- not_found_http = system(check_http_command);
- if( not_found_http ) {
- fprintf(stderr, "No connection found for http. Connecting...\n");
- system(http_command);
- }
- if( not_found_ssh || not_found_http ) {
- sleep ( CONN_WAIT );
- continue;
- }
- else {
- fprintf(stderr, "All connections found...\nSleeping...\n");
- sleep( SLEEP_TIME );
- }
- }
- /* No Internet connection */
- else {
- connect_to_internet(username,password);
- sleep( CONN_WAIT );
- }
- }
- fprintf(stderr,"Something wrong\n");
- fprintf(stderr,"Exited out of infinite loop\n");
- return 1;
- }
Add Comment
Please, Sign In to add comment