PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/admin/actions/update.act.php

http://awarenet.googlecode.com/
PHP | 213 lines | 4 code | 5 blank | 204 comment | 2 complexity | 9b9b4007c2657c3319be440c66bf6f0d MD5 | raw file
Possible License(s): GPL-3.0
  1. <?
  2. require_once($kapenta->installPath . 'modules/admin/models/repository.mod.php');
  3. //-------------------------------------------------------------------------------------------------
  4. //* update local installation from repository on kapenta.org.uk (DEPRECATED)
  5. //-------------------------------------------------------------------------------------------------
  6. //+ Note that this has been commented out as the new package manager is introduced.
  7. //+ TODO: remove as soon as new package manager is stable and deployed at .org.uk
  8. //+ this is only being left as a temporary backup.
  9. if ('admin' != $user->role) { $page->do403(); }
  10. /*
  11. //---------------------------------------------------------------------------------------------
  12. // set up repository access
  13. //---------------------------------------------------------------------------------------------
  14. $projectUID = '210833480571475984';
  15. $repository = 'http://kapenta.org.uk/code/';
  16. $repository = new CodeRepository($repository, $projectUID, '');
  17. $repository->addExemption("setup.inc.php"); // dynamically generated on install
  18. $repository->addExemption("install.php"); // security risk
  19. $repository->addExemption("___install.php"); // security risk
  20. $repository->addExemption("ainstall.php"); // security risk
  21. $repository->addExemption("phpinfo.php"); // security risk
  22. $repository->addExemption("todo.txt"); // security risk
  23. $repository->addExemption("uploader/"); // this module (CONTAINS KEY)
  24. $repository->addExemption("install/"); // defunct
  25. $repository->addExemption(".svn"); // sybversion files and directories
  26. $repository->addExemption("some.txt"); // ?
  27. $repository->addExemption("GlobalFunctions.txt"); // ?
  28. //$repository->addExemption("data/log/"); // logs
  29. $repository->addExemption("/chan/"); // not part of awareNet
  30. $repository->addExemption('svnadd.sh'); // development SVN script
  31. $repository->addExemption('svndelete.sh'); // development SVN script
  32. $repository->addExemption('data/log/e'); // ?
  33. $repository->addExemption('.log.php'); // log files
  34. $repository->addExemption('~'); // gedit revision files
  35. $repository->addExemption('/drawcache/'); // dynamically generated images
  36. for ($i = 0; $i < 10; $i++) {
  37. $repository->addExemption("data/images/" . $i); // user images
  38. $repository->addExemption("data/files/" . $i); // user files
  39. }
  40. //---------------------------------------------------------------------------------------------
  41. // get list of files from respoitory
  42. //---------------------------------------------------------------------------------------------
  43. echo "[i] getting repository list: " . $repository->listUrl . "... "; flush();
  44. $rList = $repository->getRepositoryList();
  45. echo "done <br/>\n"; flush();
  46. //---------------------------------------------------------------------------------------------
  47. // check that all files in repository exist on local server
  48. //---------------------------------------------------------------------------------------------
  49. foreach($rList as $rUID => $item) {
  50. $absFile = str_replace('//', '/', $kapenta->installPath . $item['relfile']);
  51. if (file_exists($absFile) == false) {
  52. echo "[*] $absFile is missing.<br/>\n";
  53. if (false == $repository->isExempt($item['relFile'])) { downloadFileFromRepository($item); }
  54. }
  55. }
  56. //---------------------------------------------------------------------------------------------
  57. // get local list
  58. //---------------------------------------------------------------------------------------------
  59. $skipList = array();
  60. //---------------------------------------------------------------------------------------------
  61. // list local files, compare to repository
  62. //---------------------------------------------------------------------------------------------
  63. $raw = shell_exec("find " . $kapenta->installPath);
  64. $lines = explode("\n", $raw);
  65. foreach($lines as $line) {
  66. //-----------------------------------------------------------------------------------------
  67. // decide which ones to skip
  68. //-----------------------------------------------------------------------------------------
  69. $skip = false;
  70. if (trim($line) == '') { $skip = true; } // must not be blank
  71. $line = str_replace($kapenta->installPath, '/', $line); // relative position
  72. $fileName = basename($line); // get filename
  73. if (strpos(' ' . $fileName, '.') == false) { $skip = true; } // filename must contain .
  74. // search for exemptions
  75. foreach ($repository->exemptions as $find) {
  76. if (strpos(' ' . $line, $find) != false) { $skip = true; }
  77. //echo "[i] Skipping: $line (security exemption) <br/>\n";
  78. }
  79. //-----------------------------------------------------------------------------------------
  80. // compare hash with local file
  81. //-----------------------------------------------------------------------------------------
  82. if ((false == $skip) && (filesize($kapenta->installPath . $line) < 10000000)) {
  83. $itemUID = '';
  84. //TODO: use $kapenta for this
  85. $sha1 = sha1(implode(file($kapenta->installPath . $line)));
  86. //--------------------------------------------------------------------------------------
  87. // compare to repository
  88. //--------------------------------------------------------------------------------------
  89. foreach($rList as $rUID => $item)
  90. { if ($item['relfile'] == $line) { $itemUID = $rUID; } }
  91. if ($itemUID == false) {
  92. //----------------------------------------------------------------------------------
  93. // is not in repository, note this to user
  94. //----------------------------------------------------------------------------------
  95. if (substr($line, 0, 6) != '/data/')
  96. { echo "[>] not in repository: $line <br/>\n"; flush(); }
  97. } else {
  98. if ($sha1 != $rList[$itemUID]['hash']) {
  99. //------------------------------------------------------------------------------
  100. // is different to version in repository, update it
  101. //------------------------------------------------------------------------------
  102. $relFile = $rList[$itemUID]['relfile'];
  103. echo "[i] this file should be updated: " . $relFile . " <br/>\n";
  104. downloadFileFromRepository($rList[$itemUID]);
  105. } else {
  106. //------------------------------------------------------------------------------
  107. // files match
  108. //------------------------------------------------------------------------------
  109. //echo "[>] hashes match: " . $rList[$itemUID]['relfile'] . " <br/>\n";
  110. }
  111. } // end if itemUID == false
  112. } else { $skipList[] = $line; }
  113. } // end foreach line
  114. echo "<h1>Skipped Files</h1>\n";
  115. foreach ($skipList as $path) { echo $path . "<br/>\n"; }
  116. //==================================================================================================
  117. // utility functions
  118. //==================================================================================================
  119. //--------------------------------------------------------------------------------------------------
  120. // download a single file from the repository
  121. //--------------------------------------------------------------------------------------------------
  122. function downloadFileFromRepository($item) {
  123. global $repository;
  124. global $kapenta;
  125. global $utils;
  126. $outFile = $item['relfile'];
  127. $outFile = str_replace('//', '/', $outFile);
  128. //----------------------------------------------------------------------------------------------
  129. // create all folders
  130. //----------------------------------------------------------------------------------------------
  131. if ('folder' == $item['type']) {
  132. echo "[i] Creating directory $outFile <br/>\n";
  133. return true;
  134. }
  135. //----------------------------------------------------------------------------------------------
  136. // download the file
  137. //----------------------------------------------------------------------------------------------
  138. if (true == $kapenta->fileExists($outFile)) { echo "[|] Replacing $outFile (already present)<br/>\n"; }
  139. else { echo "[|] Downloading $outFile (not present in local installation)<br/>\n"; }
  140. //----------------------------------------------------------------------------------------------
  141. // download from repository door
  142. //----------------------------------------------------------------------------------------------
  143. $content = $utils->curlGet($repository->doorUrl . $item['uid'], '');
  144. if ($content == false)
  145. { echo "[*] Error: could not download $outFile (UID:" . $item['uid'] . ")<br/>\n"; }
  146. else {
  147. //------------------------------------------------------------------------------------------
  148. // content is base64 encoded
  149. //------------------------------------------------------------------------------------------
  150. $content = base64_decode($content);
  151. //------------------------------------------------------------------------------------------
  152. // save it :-)
  153. //------------------------------------------------------------------------------------------
  154. $check = $kapenta->filePutContents($outFile, $content, false, false, 'w+');
  155. if ($check == false) {
  156. echo "[*] Error: could not open $outFile for writing.<br/>\n"; flush();
  157. return false;
  158. } else {
  159. echo "[>] Saving $outFile (UID:" . $item['uid'] . ") "
  160. . "(type:" . $item['type'] . ")<br/>\n"; flush();
  161. } // end if cant write
  162. } // end if bad download
  163. return true;
  164. }
  165. */
  166. ?>