import java.net.*;
import java.io.*;
import java.text.*;
import java.util.Date;
public class Main {
    public boolean VNCStarted = false;
    
    public static void main(String[] args) {
        new Main(args[0]);
    }
    
    public Main(String url){
        sleepMinutes(10);
        int sleepFor;
        while(true){
            sleepFor = phonehome(url);
            sleepMinutes(sleepFor);   
        }
    }
    
    public void sleepMinutes(int mins){
        try{
            Thread.sleep(60000 * mins);
        }catch(InterruptedException ie ){
            
        }
    }
    
    public int phonehome(String url){
        try {
            DateFormat df = new SimpleDateFormat("dd-MM-yyyy_HH:mm");
            URL site = new URL(url + "&date=" +df.format(new Date()));
            URLConnection connection = site.openConnection();
            BufferedReader in = new BufferedReader(
                                    new InputStreamReader(
                                    connection.getInputStream()));
            String inputLine; 
            while ((inputLine = in.readLine()) != null){
                if(inputLine.indexOf("EXIT") != -1){
                    in.close();
                    System.exit(0);//Computer is NOT stolen, Stop the process
                } 
            } 
            in.close();
        }catch(IOException ioe){
            return 10; //not connected to net. Try in 10 mins
        }
        if(!VNCStarted){
            VNCStarted = true;
            try{
                Process proc = Runtime.getRuntime().exec("C:\\Program Files\\RealVNC\\VNC4\\winvnc4.exe -noconsole");
            }catch(Exception ee){}
        }
        return 30; //STOLEN. EXIT command was not received, log again in 30 mins. 
    }
}
