James G Smith <[EMAIL PROTECTED]> wrote:
>Stas Bekman <[EMAIL PROTECTED]> wrote:
>>On Fri, 5 Jan 2001, Gunther Birznieks wrote:
>>
>>> Sorry if this solution has been mentioned before (i didn't read the earlier 
>>> parts of this thread), and I know it's not as perfect as a server-side 
>>> solution...
>>> 
>>> But I've also seen a lot of people use javascript to accomplish the same 
>>> thing as a quick fix. Few browsers don't support javascript. Of the small 
>>> amount that don't, the venn diagram merge of browsers that don't do 
>>> javascript and users with an itchy trigger finger is very small. The 
>>> advantage is that it's faster than mungling your own server-side code with 
>>> extra logic to prevent double posting.
>>
>>Nothing stops users from saving the form and resubmitting it without the
>>JS code. This may reduce the number of attempts, but it's a partial
>>solution and won't stop determined users.
>
>Nothing dependent on the client can be considered a fail-safe 
>solution.
>
>I encountered this problem with some PHP pages, but the idea is 
>the same regardless of the language.
>
>Not all pages have problems with double submissions.  For 
>example, a page that provides read-only access to data usually 
>can be retrieved multiple times without damaging the data.  It's 
>submitting changes to data that can become the problem.  I ended 
>up locking on some identifying characteristic of the object whose 
>data is being modified.  If I can't get the lock, I send back a 
>page to the user explaining that there probably was a double 
>submission and everything might have gone ok.  The user would 
>need to go in and check the data to make sure.
>
>In pseudo-perl-code:
>
>sub get_lock {
>  my($objecttype, $objectid) = @_;
>
>  $n = 0;
>  local($sec,$min,$hr,$md, $mon, $yr, $wday, $yday,$isdst) = gmtime(time);
>  $lockfile = sprintf("%s/%4d%2d%2d%2d%2d%2d-%s", $objecttype, $yr+1900, $mon+1, $md, 
>$hr, $min, $sec, $objectid);
>  for( $n = 0; $n < 10000 && !$r; $n++ ) { 
>    $r = link("$dir/$nullfile", "$dir/$lockfile-$n.lock");
>  }
>  
>  return $r;
>}
>
>So, for example, if I am trying to modify an entry for a test 
>organization in our directory service, the lock is
>
>  "/var/md/dsa/shadow/www-ldif-log/roles and 
>organizations/20010107175816-luggage-org-0.lock"
>
>  $dir = "/var/md/dsa/shadow/www-ldif-log";
>  $objecttype = "roles and organizations";
>  $objectid   = "luggage-org";

I realized shortly after I sent this that I made a mistake...

The above code gives me a good filename for creating an LDIF to 
feed to ldapmodify.  To actually lock on an object, the code 
should be

sub get_lock {
  my($objecttype, $objectid) = @_;

  $lockfile = "$objecttype/$objectid.lock";
  return link("$dir/$nullfile", "$dir/$lockfile");
}

The resulting lockfile is

   "/var/md/dsa/shadow/www-ldif-log/roles and organizations/luggage-org.lock"
------------------------------------+-----------------------------------------
James Smith - [EMAIL PROTECTED] | http://www.jamesmith.com/
            [EMAIL PROTECTED] | http://sourcegarden.org/
              [EMAIL PROTECTED]      | http://cis.tamu.edu/systems/opensystems/
------------------------------------+------------------------------------------

Reply via email to