+<?php\r
+class wsSecureSWF {\r
+ public static $files = array('index.swf', 'player.swf');\r
+ public static $configOriginal;\r
+ public static $configLocal;\r
+ public static $protected;\r
+ public static $unprotected;\r
+\r
+ public static function checkProtectedSWF()\r
+ {\r
+ self::$protected = WS_COMPILE_ASSETS . '/';\r
+ self::$unprotected = WS_COMPILE_ASSETS . '/_unprotected/';\r
+ self::$configOriginal = WS_COMPILE_ASSETS . '/_protect/fluidbook.sspj';\r
+ self::$configLocal = WS_COMPILE_ASSETS . '/_protect/_fluidbook.sspj';\r
+\r
+ $protect = false;\r
+\r
+ self::checkConfigFile();\r
+\r
+ $configmtime = filemtime(self::$configLocal);\r
+\r
+ foreach(self::$files as $f) {\r
+ $p = self::$protected . '/' . $f;\r
+ $u = self::$unprotected . '/' . $f;\r
+ $pfilemtime = filemtime($p);\r
+ if (!file_exists($p) || $pfilemtime < filemtime($u) || $pfilemtime < $configmtime) {\r
+ $protect = true;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (!$protect) {\r
+ return;\r
+ }\r
+\r
+ self::protectFiles();\r
+ }\r
+\r
+ public static function checkConfigFile()\r
+ {\r
+ if (!file_exists(self::$configLocal) || filemtime(self::$configOriginal) > filemtime(self::$configLocal)) {\r
+ self::updateConfigFile();\r
+ }\r
+ }\r
+\r
+ protected static function updateConfigFile()\r
+ {\r
+ $x = simplexml_load_file(self::$configOriginal);\r
+ // Remplace les chemins par les chemins des fichiers sur le serveur\r
+ self::replacePathFiles($x, 'inputFiles', self::$unprotected);\r
+ self::replacePathFiles($x, 'outputFiles', self::$protected);\r
+\r
+ foreach($x->xpath("//void[@property='fileFullName']") as $f) {\r
+ $fname = trim((string)$f->string);\r
+ $fname = str_replace('\\', '/', $fname);\r
+\r
+ $e = explode('/', $fname);\r
+ $file = array_pop($e);\r
+ $r = simplexml_load_string('<void property="fileFullName"><string>' . self::$unprotected . $file . '</string></void>');\r
+ cubeXML::replace($f, $r);\r
+ }\r
+\r
+ file_put_contents(self::$configLocal, $x->asXML());\r
+ }\r
+\r
+ protected static function replacePathFiles($x, $property, $dir)\r
+ {\r
+ $o1 = $x->xpath("//void[@property='$property']");\r
+ $o = array_pop($o1);\r
+ $l = simplexml_load_string('<void property="' . $property . '" />');\r
+ $a = $l->addChild('array');\r
+ $a->addAttribute('class', 'java.lang.String');\r
+ $a->addAttribute('length', count(self::$files));\r
+ foreach(self::$files as $k => $f) {\r
+ $v = $a->addChild('void');\r
+ $v->addAttribute('index', $k);\r
+ $s = $v->addChild('string', $dir . $f);\r
+ }\r
+ cubeXML::replace($o, $l);\r
+ }\r
+\r
+ protected static function protectFiles()\r
+ {\r
+ $secureSWF = new cubeCommandLine('secureSWF', null, true);\r
+ $secureSWF->setPath(CONVERTER_PATH);\r
+ $secureSWF->setManualArg(self::$configLocal);\r
+ $secureSWF->setManualArg(self::$protected);\r
+ $secureSWF->execute();\r
+\r
+ file_put_contents(WS_COMPILE_ASSETS . '/_protect/secure.log', $secureSWF->commande . "\n\n\n" . $secureSWF->output);\r
+ }\r
+}\r
+\r
+?>
\ No newline at end of file