PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/components/admin/extplorer/include/chmod.php

https://code.google.com/p/mwenhanced/
PHP | 227 lines | 170 code | 13 blank | 44 comment | 39 complexity | 443ebd5621b1c3c2a87e2b1e2f16e70e MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, AGPL-1.0, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. // ensure this file is being included by a parent file
  3. if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' );
  4. /**
  5. * @version $Id: chmod.php 109 2008-07-29 16:56:08Z soeren $
  6. * @package eXtplorer
  7. * @copyright soeren 2007
  8. * @author The eXtplorer project (http://sourceforge.net/projects/extplorer)
  9. * @author The The QuiX project (http://quixplorer.sourceforge.net)
  10. *
  11. * @license
  12. * The contents of this file are subject to the Mozilla Public License
  13. * Version 1.1 (the "License"); you may not use this file except in
  14. * compliance with the License. You may obtain a copy of the License at
  15. * http://www.mozilla.org/MPL/
  16. *
  17. * Software distributed under the License is distributed on an "AS IS"
  18. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  19. * License for the specific language governing rights and limitations
  20. * under the License.
  21. *
  22. * Alternatively, the contents of this file may be used under the terms
  23. * of the GNU General Public License Version 2 or later (the "GPL"), in
  24. * which case the provisions of the GPL are applicable instead of
  25. * those above. If you wish to allow use of your version of this file only
  26. * under the terms of the GPL and not to allow others to use
  27. * your version of this file under the MPL, indicate your decision by
  28. * deleting the provisions above and replace them with the notice and
  29. * other provisions required by the GPL. If you do not delete
  30. * the provisions above, a recipient may use your version of this file
  31. * under either the MPL or the GPL."
  32. *
  33. *
  34. */
  35. /**
  36. * Permission-Change Functions
  37. *
  38. */
  39. class ext_Chmod extends ext_Action {
  40. function execAction($dir, $item) { // change permissions
  41. if(($GLOBALS["permissions"]&01)!=01) ext_Result::sendResult( 'chmod', false, $GLOBALS["error_msg"]["accessfunc"]);
  42. if( !empty($GLOBALS['__POST']["selitems"])) {
  43. $cnt=count($GLOBALS['__POST']["selitems"]);
  44. }
  45. else {
  46. $GLOBALS['__POST']["selitems"][] = $item;
  47. $cnt = 1;
  48. }
  49. if( !empty($GLOBALS['__POST']['do_recurse'])) {
  50. $do_recurse = true;
  51. }
  52. else {
  53. $do_recurse = false;
  54. }
  55. // Execute
  56. if(isset($GLOBALS['__POST']["confirm"]) && $GLOBALS['__POST']["confirm"]=="true") {
  57. $bin='';
  58. for($i=0;$i<3;$i++) for($j=0;$j<3;$j++) {
  59. $tmp="r_".$i.$j;
  60. if(!empty($GLOBALS['__POST'][$tmp]) ) {
  61. $bin.='1';
  62. }
  63. else {
  64. $bin.='0';
  65. }
  66. }
  67. if( $bin == '0') { // Changing permissions to "none" is not allowed
  68. ext_Result::sendResult('chmod', false, $item.": ".ext_Lang::err('chmod_none_not_allowed'));
  69. }
  70. $old_bin = $bin;
  71. for($i=0;$i<$cnt;++$i) {
  72. if( ext_isFTPMode() ) {
  73. $mode = decoct(bindec($bin));
  74. } else {
  75. $mode = bindec($bin);
  76. }
  77. $item = $GLOBALS['__POST']["selitems"][$i];
  78. if( ext_isFTPMode() ) {
  79. $abs_item = get_item_info( $dir,$item);
  80. } else {
  81. $abs_item = get_abs_item($dir,$item);
  82. }
  83. if(!$GLOBALS['ext_File']->file_exists( $abs_item )) {
  84. ext_Result::sendResult('chmod', false, $item.": ".$GLOBALS["error_msg"]["fileexist"]);
  85. }
  86. if(!get_show_item($dir, $item)) {
  87. ext_Result::sendResult('chmod', false, $item.": ".$GLOBALS["error_msg"]["accessfile"]);
  88. }
  89. if( $do_recurse ) {
  90. $ok = $GLOBALS['ext_File']->chmodRecursive( $abs_item, $mode );
  91. }
  92. else {
  93. if( get_is_dir( $abs_item )) {
  94. // when we chmod a directory we must care for the permissions
  95. // to prevent that the directory becomes not readable (when the "execute bits" are removed)
  96. $bin = substr_replace( $bin, '1', 2, 1 ); // set 1st x bit to 1
  97. $bin = substr_replace( $bin, '1', 5, 1 );// set 2nd x bit to 1
  98. $bin = substr_replace( $bin, '1', 8, 1 );// set 3rd x bit to 1
  99. if( ext_isFTPMode() ) {
  100. $mode = decoct(bindec($bin));
  101. } else {
  102. $mode = bindec($bin);
  103. }
  104. }
  105. //ext_Result::sendResult('chmod', false, $GLOBALS['FTPCONNECTION']->pwd());
  106. $ok = @$GLOBALS['ext_File']->chmod( $abs_item, $mode );
  107. }
  108. $bin = $old_bin;
  109. }
  110. if($ok===false || PEAR::isError( $ok ) ) {
  111. $msg = $item.": ".$GLOBALS["error_msg"]["permchange"];
  112. $msg .= PEAR::isError( $ok ) ? ' [' . $ok->getMessage().']' : '';
  113. ext_Result::sendResult('chmod', false, $msg );
  114. }
  115. ext_Result::sendResult('chmod', true, ext_Lang::msg('permchange') );
  116. return;
  117. }
  118. if( ext_isFTPMode() ) {
  119. $abs_item = get_item_info( $dir, $GLOBALS['__POST']["selitems"][0]);
  120. } else {
  121. $abs_item = get_abs_item( $dir, $GLOBALS['__POST']["selitems"][0]);
  122. $abs_item = utf8_decode($abs_item);
  123. }
  124. $mode = parse_file_perms(get_file_perms( $abs_item ));
  125. if($mode===false) {
  126. ext_Result::sendResult('chmod', false, $item.": ".$GLOBALS["error_msg"]["permread"]);
  127. }
  128. $pos = "rwx";
  129. $text = "";
  130. for($i=0;$i<$cnt;++$i) {
  131. $s_item=get_rel_item($dir,$GLOBALS['__POST']["selitems"][$i]);
  132. if(strlen($s_item)>50) $s_item="...".substr($s_item,-47);
  133. $text .= $s_item.($i+1<$cnt ? ', ':'');
  134. }
  135. ?>
  136. <div style="width:auto;">
  137. <div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>
  138. <div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc">
  139. <h3 style="margin-bottom:5px;"><?php echo ext_Lang::msg('actperms') ?></h3>
  140. <?php echo $text ?>
  141. <div id="adminForm">
  142. </div>
  143. </div></div></div>
  144. <div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>
  145. </div>
  146. <script type="text/javascript">
  147. var form = new Ext.form.Form({
  148. labelWidth: 125, // label settings here cascade unless overridden
  149. url:'<?php echo basename( $GLOBALS['script_name']) ?>'
  150. });
  151. <?php
  152. // print table with current perms & checkboxes to change
  153. for($i=0;$i<3;++$i) {
  154. ?>
  155. form.column(
  156. {width:70, style:'margin-left:10px', clear:true}
  157. );
  158. form.fieldset(
  159. {legend:'<?php echo ext_Lang::msg(array('miscchmod'=> $i ), true ) ?>', hideLabels:true},
  160. <?php
  161. for($j=0;$j<3;++$j) {
  162. ?>
  163. new Ext.form.Checkbox({
  164. boxLabel:'<?php echo $pos{$j} ?>',
  165. <?php if($mode{(3*$i)+$j} != "-") echo 'checked:true,' ?>
  166. name:'<?php echo "r_". $i.$j ?>'
  167. }) <?php
  168. if( $j<2 ) echo ',';
  169. }
  170. ?> );
  171. form.end();
  172. <?php
  173. }
  174. ?>
  175. form.column(
  176. {width:400, style:'margin-left:10px', clear:true}
  177. );
  178. form.add(new Ext.form.Checkbox({
  179. fieldLabel:'<?php echo ext_Lang::msg('recurse_subdirs', true ) ?>',
  180. name:'do_recurse'
  181. }));
  182. form.end();
  183. form.addButton('<?php echo ext_Lang::msg( 'btnsave', true ) ?>', function() {
  184. statusBarMessage( '<?php echo ext_Lang::msg( 'permissions_processing', true ) ?>', true );
  185. form.submit({
  186. //reset: true,
  187. reset: false,
  188. success: function(form, action) {
  189. statusBarMessage( action.result.message, false, true );
  190. datastore.reload();
  191. dialog.hide();
  192. dialog.destroy();
  193. },
  194. failure: function(form, action) {
  195. statusBarMessage( action.result.error, false, false );
  196. Ext.MessageBox.alert('<?php echo ext_Lang::err( 'error', true ) ?>', action.result.error);
  197. },
  198. scope: form,
  199. // add some vars to the request, similar to hidden fields
  200. params: {option: 'com_extplorer',
  201. action: 'chmod',
  202. dir: '<?php echo stripslashes($GLOBALS['__POST']["dir"]) ?>',
  203. 'selitems[]': ['<?php echo implode("','", $GLOBALS['__POST']["selitems"]) ?>'],
  204. confirm: 'true'}
  205. });
  206. });
  207. form.addButton('<?php echo ext_Lang::msg( 'btncancel', true ) ?>', function() { dialog.hide();dialog.destroy(); } );
  208. form.render('adminForm');
  209. </script>
  210. <?php
  211. }
  212. }
  213. //------------------------------------------------------------------------------
  214. ?>