Browse Source

#73 - hash system files upon install

Alex Trofimov 12 years ago
parent
commit
871d33b8d7

+ 60 - 0
inc/classes/BxDolInstallerHasher.php

@@ -0,0 +1,60 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    DolphinCore Dolphin Core
+ * @{
+ */
+
+bx_import('BxDolInstallerUtils');
+
+class BxDolInstallerHasher extends BxDolInstallerUtils
+{
+    public function getSystemFilesHash () 
+    {
+        $this->_aNonHashableFiles = array(
+            'inc/header.inc.php',
+        );
+
+        $aFiles = array(
+
+            // slash at the end is necessary for directories
+            'inc/',   
+            'modules/base/',
+            'periodic/',
+            'studio/',
+            'template/',
+            
+            'cmts.php',
+            'conn.php',
+            'get_rss_feed.php',
+            'grid.php',
+            'gzip_loader.php',
+            'image_transcoder.php',
+            'index.php',
+            'logout.php',
+            'member.php',
+            'menu.php',
+            'page.php',
+            'searchKeyword.php',
+            'searchKeywordContent.php',
+            'splash.php',
+            'storage.php',
+            'storage_uploader.php',
+            'vote.php',
+            'modules/index.php',
+            'README.md',
+            'license.txt',
+        );
+        
+        $aFilesHashed = array();
+
+        foreach ($aFiles as $sFile)
+            $this->hashFiles(BX_DIRECTORY_PATH_ROOT . $sFile, $aFilesHashed);
+
+        return $aFilesHashed;
+    }
+}
+
+/** @} */

+ 2 - 7
inc/classes/BxDolInstallerUtils.php

@@ -122,11 +122,6 @@ class BxDolInstallerUtils extends BxDolIO
         }
     }
 
-    public function setNonHashableFiles($a)
-    {
-        $this->_aNonHashableFiles = $a;
-    }
-
     public function hashFiles($sPath, &$aFiles)
     {
         if (file_exists($sPath) && is_dir($sPath) && ($rSource = opendir($sPath))) {
@@ -143,8 +138,8 @@ class BxDolInstallerUtils extends BxDolIO
                     $aFiles[] = $this->hashInfo($sPath . $sFile);
             }
             closedir($rSource);
-        } else {
-            $aFiles[] = $this->hashInfo($sPath, $sFile);
+        } elseif (file_exists($sPath) && is_file($sPath)) {
+            $aFiles[] = $this->hashInfo($sPath);
         }
     }
 

+ 15 - 0
install/classes/BxDolInstallController.php

@@ -99,6 +99,8 @@ class BxDolInstallController
     {
         require_once(BX_INSTALL_PATH_HEADER);
 
+        $this->hashSystemFiles();
+
         $this->_oView->pageStart();
 
         $sPathToPhp = "/replace/it/with/path/to/php/binary";
@@ -133,6 +135,19 @@ class BxDolInstallController
     {
         return _t('_sys_inst_title', BX_DOL_VER);
     }
+
+    protected function hashSystemFiles()
+    {
+        bx_import('BxDolInstallerHasher');
+        $oHasher = new BxDolInstallerHasher();
+        $aFiles = $oHasher->getSystemFilesHash ();
+
+        bx_import('BxDolStudioInstallerQuery');
+        $oDb = new BxDolStudioInstallerQuery();
+
+        foreach($aFiles as $aFile)
+            $oDb->insertModuleTrack(0, $aFile);
+    }
 }
 
 /** @} */

+ 2 - 2
studio/classes/BxDolStudioInstaller.php

@@ -149,10 +149,10 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
             ),
         );
 
-        $this->setNonHashableFiles(array(
+        $this->_aNonHashableFiles = array(
             'install',
             'updates'
-        ));
+        );
     }
 
     public function install($aParams, $bAutoEnable = false)