aboutsummaryrefslogtreecommitdiff
path: root/3.11/get_mail.rb
diff options
context:
space:
mode:
Diffstat (limited to '3.11/get_mail.rb')
-rwxr-xr-x3.11/get_mail.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/3.11/get_mail.rb b/3.11/get_mail.rb
new file mode 100755
index 0000000..679309e
--- /dev/null
+++ b/3.11/get_mail.rb
@@ -0,0 +1,60 @@
+#!/usr/bin/env ruby
+
+require 'net/http'
+require 'uri'
+require 'json'
+
+def get_ticket(un, tgt, sv)
+ uri = URI.parse("http://localhost:4567/ticket")
+ header = {'Content-Type': 'text/json'}
+
+ login = {
+ "username": un,
+ "ticket": tgt,
+ "service": sv
+ }
+
+ http = Net::HTTP.new(uri.host, uri.port)
+ request = Net::HTTP::Post.new(uri.request_uri, header)
+ request.body = login.to_json
+
+ response = http.request(request)
+ response.body
+end
+
+print "Username: "; un = gets.strip
+print "Mailserver: "; ms = gets.strip
+
+unless File.exist?(".keytab")
+ puts "No keytab, please kinit"
+ exit 1
+end
+
+Keys = File.readlines(".keytab").map{ |l| l.strip.split(?:) }.to_h
+
+if Keys.keys.include?(ms)
+ ticket = Keys[ms]
+elsif Keys.keys.include?("_TGS")
+ ticket = get_ticket(un, Keys["_TGS"], ms)
+ File.open(".keytab", ?a) do |f|
+ f.puts "#{ms}:#{ticket}"
+ end
+else
+ puts "No Ticket Granting Ticket, please kinit"
+ exit 1
+end
+
+uri = URI.parse("http://localhost:4568/login")
+header = {'Content-Type': 'text/json'}
+
+login = {
+ "username": un,
+ "ticket": ticket
+}
+
+http = Net::HTTP.new(uri.host, uri.port)
+request = Net::HTTP::Post.new(uri.request_uri, header)
+request.body = login.to_json
+
+response = http.request(request)
+puts response.body