Skip to content
Browse files

add github upload target, fix typo

  • Loading branch information...
1 parent 6314112 commit aa2053559bcbf361c1c5d2f025267f0e3fe23d7a @mhils committed Sep 18, 2012
Showing with 3,952 additions and 1 deletion.
  1. +2 −1 .gitignore
  2. +9 −0 build/build.xml
  3. +3,849 −0 build/cacert.pem
  4. +70 −0 build/deploy-snapshot.py
  5. +22 −0 build/github-auth.py
  6. 0 gui/js/HoneyProxy/{Config.js → config.js}
View
3 .gitignore
@@ -4,4 +4,5 @@ dist/
outfile
dump/
build/dojo/
-web/build/
+web/build/
+build/github_oauth_token.txt
View
9 build/build.xml
@@ -24,6 +24,15 @@
/>
<!-- <move file="${dist}/snapshot.zip" todir="dir/to/move/to"/> -->
</target>
+
+ <target name="deploy-snapshot" depends="pack" description="deploy to github! :)">
+ <exec dir="build/" executable="python">
+ <arg line='-u' />
+ <arg line='deploy-snapshot.py' />
+ </exec>
+ </target>
+
+
<target name="clean" description="clean up" >
<!-- Delete the ${dist} directory trees -->
View
3,849 build/cacert.pem
3,849 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
70 build/deploy-snapshot.py
@@ -0,0 +1,70 @@
+import os.path, urllib, pycurl as curl, cStringIO, json
+from datetime import date
+config = {
+ "user": "mhils",
+ "repo": "HoneyProxy"
+}
+filename = "snapshot-%(date)s.zip" % {"date": date.today().strftime("%Y%m%d")}
+filepath = os.path.abspath("../dist/"+filename)
+assert os.path.isfile(filepath)
+filesize = os.path.getsize(filepath)
+
+def common_curl_options(c):
+
+ c.setopt(curl.CAINFO, os.path.abspath("cacert.pem"))
+ #c.setopt(curl.FAILONERROR, True)
+ #c.setopt(curl.VERBOSE, True)
+ #c.setopt(curl.SSL_VERIFYPEER, 0)
+ #c.setopt(curl.SSL_VERIFYHOST, 0)
+ #c.setopt(curl.PROXY, 'http://localhost:8080')
+
+buf = cStringIO.StringIO()
+c = curl.Curl()
+common_curl_options(c)
+c.setopt(curl.URL, 'https://api.github.com/repos/%(user)s/%(repo)s/downloads' % config)
+c.setopt(curl.WRITEFUNCTION, buf.write)
+
+with open("github_oauth_token.txt","r") as f:
+ c.setopt(curl.HTTPHEADER, ['Authorization: token ' + f.read()])
+
+params = {"name":filename, "size":filesize}
+c.setopt(curl.POSTFIELDS,json.dumps(params))
+print "Create Download @ GitHub..."
+c.perform()
+data = json.loads(buf.getvalue())
+buf.close()
+c.close()
+print "Download created."
+
+#s3 upload
+c = curl.Curl()
+common_curl_options(c)
+c.setopt(curl.URL,str(data.get("s3_url")))
+class ProgressDisplay:
+ last_progress = -1
+ def progress(self,download_t, download_d, upload_t, upload_d):
+ if(upload_t > 0):
+ progress = int(100 * upload_d / upload_t)
+ if(progress - self.last_progress > 0):
+ print "%02d%%" % progress
+ self.last_progress = progress
+
+c.setopt(c.NOPROGRESS, 0)
+c.setopt(curl.WRITEFUNCTION, cStringIO.StringIO().write)
+c.setopt(curl.PROGRESSFUNCTION, ProgressDisplay().progress)
+values = [
+ ("key", str(data.get("path"))),
+ ("acl",str(data.get("acl"))),
+ ("success_action_status","201"),
+ ("Filename",str(data.get("name"))),
+ ("AWSAccessKeyId",str(data.get("accesskeyid"))),
+ ("Policy",str(data.get("policy"))),
+ ("Signature",str(data.get("signature"))),
+ ("Content-Type",str(data.get("mime_type"))),
+ ("file", (curl.FORM_FILE, filepath))
+]
+c.setopt(curl.HTTPPOST, values)
+print "Start Upload..."
+c.perform()
+c.close()
+print "Finished!"
View
22 build/github-auth.py
@@ -0,0 +1,22 @@
+import urllib2, json, getpass, base64
+
+username = raw_input("User:")
+password = getpass.getpass("Password:")
+
+params = {"scopes":["repo"],"note":"download-deploy"}
+request = urllib2.Request(
+ url="https://api.github.com/authorizations",
+ data=json.dumps(params))
+#basic auth
+base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
+request.add_header("Authorization", "Basic %s" % base64string)
+
+result = urllib2.urlopen(request)
+
+token = json.loads(result.read()).get("token")
+
+with open("github_oauth_token.txt","w") as f:
+ f.write(token)
+
+print "Token saved to github_oauth_token.txt!"
+raw_input("Press any key to continue...")
View
0 gui/js/HoneyProxy/Config.js → gui/js/HoneyProxy/config.js
File renamed without changes.

0 comments on commit aa20535

Please sign in to comment.
Something went wrong with that request. Please try again.