<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -4,7 +4,7 @@ from django.http import Http404, HttpResponse
 from django.views.generic.list_detail import object_list, object_detail
 from sshkeys.keys.models import Address, SSHKey, AddressKey
 from datetime import datetime
-
+import re
 
 # favour django-mailer but fall back to django.core.mail
 try:
@@ -46,22 +46,43 @@ def detail(request, address=None, id=None):
 
 def upload(request):
     address_str = request.POST['address']
-    keytext_str = request.POST['keytext']
+
     if not &quot;@&quot; in address_str:
-        return HttpResponse(&quot;Address given is not a valid e-mail address.&quot;, status=404)
-    if not keytext_str.startswith(&quot;ssh-&quot;):
-        return HttpResponse(&quot;Key given is not an ASCII ssh public key.&quot;, status=404)
-    newaddress, undef = Address.objects.get_or_create(address=address_str)
-    newkey, undef = SSHKey.objects.get_or_create(keytext=keytext_str)
-    newrel, created = AddressKey.objects.get_or_create(
-                          address=newaddress, sshkey=newkey,
-                          defaults={'date_added': datetime.now(),
-                                    'verified': False,
-                                    'token_sent': datetime.now()})
-
-    # &quot;if created:&quot; can tell us whether we created a new pair or
-    # just sent out a reminder about an old one, if we care.
-    newrel.send_confirmation(newrel)
+        return HttpResponse(&quot;Address given is not a valid e-mail address.&quot;, 
+                            status=404)
+    
+    if request.POST.has_key('keytext') and request.POST['keytext']:
+        keystr = request.POST['keytext']
+    elif request.FILES.has_key('keyfile'):
+        keystr = request.FILES['keyfile'].read()
+    else:
+        return HttpResponse(&quot;No key provided.&quot;, status=404)
+
+    keytext_lines = ''.join(keystr)
+    pattern = re.compile(&quot;ssh-\w+ \S+ \S+&quot;)
+    match = pattern.findall(keytext_lines)
+
+    if not match:
+        return HttpResponse(&quot;File provided does not contain SSH public keys.&quot;,
+                            status=404)
+
+    for line in match:
+        if not line.startswith(&quot;ssh-&quot;):
+            return HttpResponse(&quot;Key given is not an ASCII ssh public key.&quot;, 
+                                status=404)
+
+        newaddress, undef = Address.objects.get_or_create(address=address_str)
+        newkey, undef = SSHKey.objects.get_or_create(keytext=line)
+        newrel, created = AddressKey.objects.get_or_create(
+            address=newaddress, sshkey=newkey,
+            defaults={'date_added': datetime.now(),
+                      'verified': False,
+                      'token_sent': datetime.now()})
+
+        # &quot;if created:&quot; can tell us whether we created a new pair or
+        # just sent out a reminder about an old one, if we care.
+        newrel.send_confirmation(newrel)
+
     return render_to_response(&quot;keys/address_uploaded.html&quot;)
 
 def search(request, **kwargs):</diff>
      <filename>keys/views.py</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 # Django settings for sshkeys project.
 
-DEBUG = False
+DEBUG = True#False
 TEMPLATE_DEBUG = DEBUG
 
 ADMINS = (</diff>
      <filename>settings.py</filename>
    </modified>
    <modified>
      <diff></diff>
      <filename>sshkeys.db</filename>
    </modified>
    <modified>
      <diff>@@ -41,10 +41,13 @@
 {% block content %}
 &lt;div id=&quot;secone&quot;&gt;
   &lt;h3&gt;Upload a key&lt;/h3&gt;
-  &lt;form action=&quot;/upload/&quot; method=&quot;post&quot;&gt;
+  &lt;form action=&quot;/upload&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
   &lt;b&gt;E-mail address:&lt;/b&gt; &lt;input type=&quot;text&quot; name=&quot;address&quot; size=&quot;30&quot;&gt;&lt;p&gt;
   &lt;b&gt;SSH key (&quot;&lt;tt&gt;id_XXX.pub&lt;/tt&gt;&quot; on Unix):&lt;/b&gt;&lt;p&gt;
+  You can paste your key directly:&lt;p&gt;
   &lt;textarea rows=&quot;4&quot; cols=&quot;80&quot; wrap=&quot;soft&quot; name=&quot;keytext&quot;&gt;&lt;/textarea&gt;&lt;p&gt;
+  Or upload it from a local (&lt;tt&gt;authorized_keys&lt;/tt&gt;) file on your machine:&lt;p&gt;
+  &lt;input type=&quot;file&quot; name=&quot;keyfile&quot; size=&quot;40&quot;&gt;&lt;p&gt;
   Your public key filename will be of the form &quot;&lt;tt&gt;id_XX&#7818;.pub&lt;/tt&gt;&quot; on Unix; 
   the .pub is very important, as you must not try to upload your private key
   (which has a filename of the form &quot;&lt;tt&gt;id_XXX&lt;/tt&gt;&quot;.  The first few </diff>
      <filename>templates/keys/address_index.html</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,7 @@ Someone has requested adding the following e-mail address and SSH public
 key to the public database at http://sshkeys.net/:
 
    E-mail:         {{ email_address }}
-   Public key(s):  
+   Public key:
 
 {{ sshkey }}
 </diff>
      <filename>templates/keys/email_confirmation_message.txt</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e28cbd15feaf7b86201019a6fe598bfb998b21ad</id>
    </parent>
  </parents>
  <author>
    <name>Chris Ball</name>
    <email>chris@void.printf.net</email>
  </author>
  <url>http://github.com/cjb/sshkeys/commit/770f89363707b87bcb91775e8c97eb84f8bf857e</url>
  <id>770f89363707b87bcb91775e8c97eb84f8bf857e</id>
  <committed-date>2008-09-14T22:55:35-07:00</committed-date>
  <authored-date>2008-09-14T22:55:35-07:00</authored-date>
  <message>Add a file upload field.</message>
  <tree>0e2291a0762957193bb5b3fbedced5a488e7048d</tree>
  <committer>
    <name>Chris Ball</name>
    <email>chris@void.printf.net</email>
  </committer>
</commit>
