[Fusionforge-commits] r12054 - in branches/Branch_5_1/src/common: docman/engine include

Roland Mas lolando at libremir.placard.fr.eu.org
Fri Jan 21 14:59:55 CET 2011


Author: lolando
Date: 2011-01-21 14:59:55 +0100 (Fri, 21 Jan 2011)
New Revision: 12054

Modified:
   branches/Branch_5_1/src/common/docman/engine/parser_doc.php
   branches/Branch_5_1/src/common/include/utils.php
Log:
Merged from Evolvis: random number generator using entropy provided by the kernel

Modified: branches/Branch_5_1/src/common/docman/engine/parser_doc.php
===================================================================
--- branches/Branch_5_1/src/common/docman/engine/parser_doc.php	2011-01-21 13:20:06 UTC (rev 12053)
+++ branches/Branch_5_1/src/common/docman/engine/parser_doc.php	2011-01-21 13:59:55 UTC (rev 12054)
@@ -38,11 +38,10 @@
 if (!is_file($fichin))
 	exit (1);
 
-$fichout = "/tmp/gfo".rand(10000, 99999).".tmp";
+$fichout = tempnam("/tmp/","tmp");
 $cmd = "/usr/bin/antiword -i1 -t $fichin > $fichout";
 $res = shell_exec($cmd);
 
-
 echo parser_text($fichout);
 unlink ($fichout);
 

Modified: branches/Branch_5_1/src/common/include/utils.php
===================================================================
--- branches/Branch_5_1/src/common/include/utils.php	2011-01-21 13:20:06 UTC (rev 12053)
+++ branches/Branch_5_1/src/common/include/utils.php	2011-01-21 13:59:55 UTC (rev 12054)
@@ -1361,6 +1361,26 @@
 	return $postfile;
 }
 
+function util_randbytes($num=6) {
+	$f = fopen("/dev/urandom", "rb");
+	$b = fread($f, $num);
+	fclose($f);
+
+	if (strlen($b) != $num)
+		exit_error(_('Internal Error'),
+			   _('Could not read from random device'));
+
+	return ($b);
+}
+
+/* maximum: 2^31 - 1 due to PHP weakness */
+function util_randnum($min=0,$max=32767) {
+	$ta = unpack("L", util_randbytes(4));
+	$n = $ta[0] & 0x7FFFFFFF;
+	$v = $n % (1 + $max - $min);
+	return ($min + $v);
+}
+
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"




More information about the Fusionforge-commits mailing list