lots of new changes.  menu based functions are working, lots of error checking.

diff --git a/controller/usercontrol.rb b/controller/usercontrol.rb
index dfaf160..3c5e05f 100644
--- a/controller/usercontrol.rb
+++ b/controller/usercontrol.rb
@@ -1,6 +1,7 @@
 require 'rubygems'
 require 'aws-sdk'
 require 'open-uri'
+require 'net/scp'

 tcvolume = "#{ENV['HOME']}/Dropbox/newdropbox"
 cfnpath = "/opt/aws-cloudformatino-tools/"
@@ -9,6 +10,7 @@ templatefile = "#{ENV['HOME']}/src/setec-astronomy/aws/setec-astronomy.template"
 stack = "setec-astronomy"
 keyname = "setec-astronomy"
 webport = 1234
+localkeys = "#{ENV['HOME']}/Downloads/"

 def readcreds(credfile)
   puts "Reading EC2 credentials file, #{credfile}"
@@ -44,11 +46,12 @@ def check4stack(cfm, stack)
   puts "Checking for existing stack"
   if !cfm.stacks[stack].exists?
     puts "doesn't exist"
+    stackstatus = "not running"
   else
     puts "it exists"
-    hasstack = true
+    stackstatus = "running"
   end
-  return hasstack
+  return stackstatus
 end

 def killstack(cfm, stack)
@@ -63,7 +66,7 @@ def killstack(cfm, stack)
     # this is causing an error
     #
     #while setecstatus == "DELETE_IN_PROGRESS" do
-    while setecstatus
+    while setecstatus == "running"
       puts "Deletion still in progress, waiting..."
       sleep 3
       setecstatus = check4stack(cfm, stack)
@@ -148,7 +151,7 @@ def checkservices(stackip, webport)
       when "not running"
         puts "service #{service} is not running, starting"
         runresult = open("http://#{stackip}:#{webport}/services/#{service}/start")
-        puts "result was #{runresult}"
+        open("http://#{stackip}:#{webport}/services/vpn/process")
       when "start"
         puts "service #{service} is running"
       end
@@ -159,12 +162,15 @@ def checkservices(stackip, webport)
   end
 end

-def printmenu1()
+def printmenu1(stackstatus, stackip)
 puts %{
 *************
 * Main Menu *
 *************

+Existing stack: #{stackstatus}
+Stack ip: #{stackip}
+
 [1] Create Stack

 [2] Delete Stack
@@ -173,23 +179,85 @@ puts %{

 [4] Check Services

-[5] Exit
+[5] Copy vpn files
+
+[6] Exit

 }
 end

+def pullkeys(stackip, localkeys, webport)
+  begin
+    puts "pulling ca.crt"
+    Net::SCP::download!(stackip, "ec2-user", "/home/ec2-user/ca.crt", "#{localkeys}/ca.crt")
+    puts "pulling client1.crt"
+    Net::SCP::download!(stackip, "ec2-user", "/home/ec2-user/client1.crt", "#{localkeys}/client1.crt")
+    puts "pulling client1.key"
+    Net::SCP::download!(stackip, "ec2-user", "/home/ec2-user/client1.key", "#{localkeys}/client1.key")
+    open("http://#{stackip}:#{webport}/services/vpn/cleanup")
+    puts "remote files cleaned"
+  rescue Net::SSH::AuthenticationFailed
+    puts "authentication error, ensure you're setting SSHKEYS and that ssh-add is working.  if you have to just manually ssh-add your aws pem before running usercontrol.sh"
+  rescue
+    puts "an error occured while downloading keys"
+  end
+end
+
 #mounttc(tcvolume)
+
 awsaccesskey, awssecretkey = readcreds(credfile)
+
 cfm = AWS::CloudFormation.new( :access_key_id => awsaccesskey, :secret_access_key => awssecretkey)
+
+stackstatus = check4stack(cfm, stack)
+if stackstatus == "running"
+  stackip = getip(cfm, stack)
+else
+  stackip = "notset"
+end
+
 menu1in = ""
-until menu1in == "5"
-  printmenu1()
+until menu1in == "6"
+  printmenu1(stackstatus, stackip)
   print " > "
   menu1in = gets.strip
+  case menu1in
+  when "1"
+    if stackstatus == "running"
+      killstack(cfm, stack)
+    end
+    puts "execute createstack()"
+    createstack(cfm, stack, templatefile, keyname)
+    stackstatus = "running"
+  when "2"
+    stackstatus = check4stack(cfm, stack)
+    if stackstatus == "running"
+      killstack(cfm, stack)
+    else
+      puts "no stack to delete"
+    end
+    stackip = "notset"
+  when "3"
+    stackip = getip(cfm, stack)
+  when "4"
+    hasweb = check4web(stackip, webport)
+    until hasweb do
+      puts "Web port not available yet, waiting..."
+      sleep 10
+      hasweb = check4web(stackip, webport)
+    end
+    checkservices(stackip, webport)
+  when "5"
+    if stackip == "notset"
+      puts "no stack ip set, start a stack"
+    else
+      pullkeys(stackip, localkeys, webport)
+    end
+  end
 end

-#hasstack = check4stack(cfm, stack)
-#if hasstack
+#stackstatus = check4stack(cfm, stack)
+#if stackstatus
 #  killstack(cfm, stack)
 #end
 #createstack(cfm, stack, templatefile, keyname)