changeset 2180:428be07823ba

entry.rb md5 => digest
author SUZUKI Takehisa <c110128@e.koeki-u.ac.jp>
date Fri, 24 Jan 2014 15:32:35 +0900
parents 5c4a6399edf8
children 3e0c1405756b
files coop/entry.rb coop/entry2.rb
diffstat 2 files changed, 21 insertions(+), 95 deletions(-) [+]
line wrap: on
line diff
--- a/coop/entry.rb	Fri Jan 24 15:26:44 2014 +0900
+++ b/coop/entry.rb	Fri Jan 24 15:32:35 2014 +0900
@@ -1,73 +1,41 @@
 #!/usr/bin/env ruby
-#coding: euc-jp
+# coding: euc-jp
 
 require 'cgi'
-require 'md5'
-
-#m = MD5.hexdigest('hatsunemiku')
-def generate_session_id
-  m = MD5.new
-  m.update(Time.now.to_s)
-  m.update($$.to_s)
-  m.update(rand.to_s)
-  m.update('secret words')
-  m.hexdigest
-end
+#require 'digest'
 
 c = CGI.new('html4Tr')
 me = File.basename(c.script_name)
 
-cookie = c.cookies['id']
+c0 = c.cookies['id']
+ip = ENV['REMOTE_ADDR']
+i = 0
+
 
-if !cookie.empty?
-  if /^[a-z0-f]{32}$/i =~ cookie.first
-    session_id = cookie.first
-  else
-    session_id = generate_session_id
-#    session_id = m
-  end
-else
-#  session_id = m
-  session_id = generate_session_id
-  cookie = CGI::Cookie.new({'name' => 'id',
-                             'value' => session_id,
-                             'domain' => cgi.server_name,
-                             'path' => cgi.script_name})
-end
+srand(56384679263254687)
+10000.times {rand(1000000)}
+idlist = (1..100).collect{rand(10000000)}
+
+cookie = CGI::Cookie.new({'name' => 'id',
+                           'value' => "#{ip}",
+                           'domain' => c.server_name,
+                           'path' => c.script_name})
+
 cookie.expires = Time.now + 10
 
-datafile = File.join('/tmp',session_id)
-
-begin
-  if File.exist?(datafile)
-    f = open(datafile,'r+')
-    i = f.read.to_i
-    f.rewind
-  else
-    i = 1
-    f = open(datafile,'w')
-  end
-  f.puts(i+1).to_s
-  f.truncate(f.pos)
-ensure
-  f.close
-end
-
-
 c.out({'cookie' => cookie}) do
   c.html({'PRETTY' => ' '}) do
     c.head do
       c.title {'サンプル'}
     end + c.body do
-      srand(56384679263254687)
-      10000.times {rand(1000000)}
-      idlist = (1..100).collect{rand(10000000)}      
       if idlist.index(ARGV[0].to_i)
-        c.p{'おめでとう'} + c.p{
-          c.code {cookie}
-        }
-      else
+        c.p{'おめでとう'} +
+          c.p{
+          c.code{cookie[0]}}
+      elsif i >= 50
         c.p{'ごめんなさい'}
+      else 
+        c.p{'error'}
       end
     end
   end
--- a/coop/entry2.rb	Fri Jan 24 15:26:44 2014 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-#!/usr/bin/env ruby
-# coding: euc-jp
-
-require 'cgi'
-#require 'digest'
-
-c = CGI.new('html4Tr')
-me = File.basename(c.script_name)
-
-c0 = c.cookies['id']
-ip = ENV['REMOTE_ADDR']
-i = 0
-
-
-srand(56384679263254687)
-10000.times {rand(1000000)}
-idlist = (1..100).collect{rand(10000000)}
-
-cookie = CGI::Cookie.new({'name' => 'id',
-                           'value' => "#{ip}",
-                           'domain' => c.server_name,
-                           'path' => c.script_name})
-
-cookie.expires = Time.now + 10
-
-c.out({'cookie' => cookie}) do
-  c.html({'PRETTY' => ' '}) do
-    c.head do
-      c.title {'サンプル'}
-    end + c.body do
-      if idlist.index(ARGV[0].to_i)
-        c.p{'おめでとう'} +
-          c.p{
-          c.code{cookie[0]}}
-      elsif i >= 50
-        c.p{'ごめんなさい'}
-      else 
-        c.p{'error'}
-      end
-    end
-  end
-end

yatex.org