PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/admin/actions/txtedit.act.php

http://awarenet.googlecode.com/
PHP | 147 lines | 95 code | 24 blank | 28 comment | 36 complexity | da724f29df90ae3e65ab4309468867b8 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?
  2. //-------------------------------------------------------------------------------------------------
  3. //* for editing text files on the server
  4. //-------------------------------------------------------------------------------------------------
  5. //---------------------------------------------------------------------------------------------
  6. // authorization
  7. //---------------------------------------------------------------------------------------------
  8. if ('admin' != $user->role) { $page->do403(); }
  9. //---------------------------------------------------------------------------------------------
  10. // handle submissions
  11. //---------------------------------------------------------------------------------------------
  12. if ((true == array_key_exists('action', $_POST)) && ('saveFile' == $_POST['action'])) {
  13. $fileName = stripslashes($_POST['fileName']);
  14. $fileName = str_replace('..', '', $fileName);
  15. $fileName = str_replace('//', '/', $fileName);
  16. $contents = stripslashes($_POST['fileContents']);
  17. $kapenta->filePutContents($fileName, $contents, false, false);
  18. $req->args['path'] = '';
  19. }
  20. //---------------------------------------------------------------------------------------------
  21. // working directory
  22. //---------------------------------------------------------------------------------------------
  23. $browsePath = '';
  24. if (true == array_key_exists('path', $req->args)) {
  25. $browsePath = 'path_' . $req->args['path'];
  26. }
  27. //---------------------------------------------------------------------------------------------
  28. // confirm file deletion (if specified)
  29. //---------------------------------------------------------------------------------------------
  30. if ((true == array_key_exists('action', $_POST)) && ('confirmDeleteFile' == $_POST['action'])) {
  31. if (true == array_key_exists('delfile', $_POST)) {
  32. $msg = "<b>Confirm: you wish to delete " . $_POST['delfile'] . "?</b><br/>
  33. <p>Note that this action cannot be undone and may affect the functioning of this website.</p>
  34. <table noborder>
  35. <tr>
  36. <td valign='top'>
  37. <form name='confirmDelete' method='POST' action='%%serverPath%%admin/txtedit/'>
  38. <input type='hidden' name='action' value='deleteFile' />
  39. <input type='hidden' name='delfile' value='" . $_POST['delfile'] . "' />
  40. <input type='submit' value='Yes: Delete it' />
  41. </form>
  42. </td>
  43. <td valign='top'>
  44. <form name='cancelDelete' method='POST' action='%%serverPath%%admin/txtedit/'>
  45. <input type='submit' value='No: Cancel' />
  46. </form>
  47. </td>
  48. </tr>
  49. </table>\n";
  50. $session->msg($msg, 'warn');
  51. }
  52. }
  53. //---------------------------------------------------------------------------------------------
  54. // delete a file (if specified)
  55. //---------------------------------------------------------------------------------------------
  56. if ((true == array_key_exists('action', $_POST)) && ('deleteFile' == $_POST['action'])) {
  57. if (true == array_key_exists('delfile', $_POST)) {
  58. $fileName = $_POST['delfile'];
  59. if (substr($fileName,0, 1) == '/') { $fileName = substr($fileName, 1); }
  60. if (true == $kapenta->fileExists($fileName)) {
  61. unlink($kapenta->installPath . $fileName);
  62. if (false == $kapenta->fileExists($fileName)) {
  63. $session->msg("Deleted: " . $fileName, 'ok');
  64. } else {
  65. $session->msg("Could not delete: " . $fileName, 'bad');
  66. }
  67. } else { $session->msg("Could not delete: " . $fileName, 'bad'); }
  68. }
  69. }
  70. //---------------------------------------------------------------------------------------------
  71. // load file (if specified)
  72. //---------------------------------------------------------------------------------------------
  73. $editFile = '';
  74. if (true == array_key_exists('file', $req->args)) {
  75. $editFile = base64_decode($req->args['file']);
  76. if (true == array_key_exists('path', $req->args)) {
  77. $editFile = base64_decode($req->args['path']) . $editFile;
  78. }
  79. if (false == $kapenta->fileExists($editFile)) {
  80. $session->msg("file does not exist.<br/>" . $editFile, 'bad');
  81. $editFile = '';
  82. }
  83. }
  84. //---------------------------------------------------------------------------------------------
  85. // make the edit form
  86. //---------------------------------------------------------------------------------------------
  87. $editorForm = '';
  88. if ($editFile != '') {
  89. $editorFormAction = $kapenta->serverPath
  90. . 'admin/txtedit/'
  91. . '/file_' . base64_encode($editFile)
  92. . '/' . $browsePath;
  93. $raw = $kapenta->fileGetContents($editFile); // TODO: use $kapenta
  94. $rawJs = $utils->base64EncodeJs('contentJs', $raw, false);
  95. $editorForm = "<form name='editTxtFile' method='POST' action='" . $editorFormAction . "'>
  96. <input type='hidden' name='action' value='saveFile' />
  97. <b>File: $editFile</b>
  98. <input type='text' name='fileName' size='40' value='" . $editFile . "' style='width: 100%;' /><br/>
  99. <textarea name='fileContents' id='taFileContents' rows='30' cols='50' style='width: 100%;'></textarea>
  100. <input type='submit' value='save' />
  101. </form><br/>
  102. <script language='javascript'>
  103. $rawJs
  104. base64_loadTextArea('taFileContents', contentJs);
  105. </script>\n
  106. <hr/>
  107. <form name='delTxtFile' method='POST' action='" . $editorFormAction . "'>
  108. <input type='hidden' name='action' value='confirmDeleteFile' />
  109. <input type='hidden' name='delfile' value='" . $editFile . "' />
  110. <input type='submit' value='Delete this file' />
  111. </form>
  112. ";
  113. }
  114. //---------------------------------------------------------------------------------------------
  115. // render the page
  116. //---------------------------------------------------------------------------------------------
  117. $page->load('modules/admin/actions/txtedit.page.php');
  118. $page->blockArgs['editFile'] = $editFile;
  119. $page->blockArgs['editorForm'] = $editorForm;
  120. //$page->blockArgs['editorList'] = $editorList;
  121. $page->blockArgs['browsePath'] = $browsePath;
  122. $page->render();
  123. ?>