PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_extplorer/include/chmod.php

https://github.com/cavila/Astica
PHP | 227 lines | 174 code | 10 blank | 43 comment | 40 complexity | 9c276d5790c0d95018c767ba8fb7f77c MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, Apache-2.0, BSD-3-Clause
  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 201 2011-06-27 09:45:09Z soeren $
  6. * @package eXtplorer
  7. * @copyright soeren 2007-2009
  8. * @author The eXtplorer project (http://extplorer.net)
  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. } else {
  63. $bin.='0';
  64. }
  65. }
  66. if( $bin == '0') { // Changing permissions to "none" is not allowed
  67. ext_Result::sendResult('chmod', false, $item.": ".ext_Lang::err('chmod_none_not_allowed'));
  68. }
  69. $old_bin = $bin;
  70. for($i=0;$i<$cnt;++$i) {
  71. if( ext_isFTPMode() ) {
  72. $mode = decoct(bindec($bin));
  73. } else {
  74. $mode = bindec($bin);
  75. }
  76. $item = $GLOBALS['__POST']["selitems"][$i];
  77. if( ext_isFTPMode() ) {
  78. $abs_item = get_item_info( $dir,$item);
  79. } else {
  80. $abs_item = get_abs_item($dir,$item);
  81. }
  82. if(!$GLOBALS['ext_File']->file_exists( $abs_item )) {
  83. ext_Result::sendResult('chmod', false, $item.": ".$GLOBALS["error_msg"]["fileexist"]);
  84. }
  85. if(!get_show_item($dir, $item)) {
  86. ext_Result::sendResult('chmod', false, $item.": ".$GLOBALS["error_msg"]["accessfile"]);
  87. }
  88. if( $do_recurse ) {
  89. $ok = $GLOBALS['ext_File']->chmodRecursive( $abs_item, $mode );
  90. }
  91. else {
  92. if( get_is_dir( $abs_item )) {
  93. // when we chmod a directory we must care for the permissions
  94. // to prevent that the directory becomes not readable (when the "execute bits" are removed)
  95. $bin = substr_replace( $bin, '1', 2, 1 ); // set 1st x bit to 1
  96. $bin = substr_replace( $bin, '1', 5, 1 );// set 2nd x bit to 1
  97. $bin = substr_replace( $bin, '1', 8, 1 );// set 3rd x bit to 1
  98. if( ext_isFTPMode() ) {
  99. $mode = decoct(bindec($bin));
  100. } else {
  101. $mode = bindec($bin);
  102. }
  103. }
  104. //ext_Result::sendResult('chmod', false, $GLOBALS['FTPCONNECTION']->pwd());
  105. $ok = @$GLOBALS['ext_File']->chmod( $abs_item, $mode );
  106. }
  107. $bin = $old_bin;
  108. }
  109. if($ok===false || PEAR::isError( $ok ) ) {
  110. $msg = $item.": ".$GLOBALS["error_msg"]["permchange"];
  111. $msg .= PEAR::isError( $ok ) ? ' [' . $ok->getMessage().']' : '';
  112. ext_Result::sendResult('chmod', false, $msg );
  113. }
  114. ext_Result::sendResult('chmod', true, ext_Lang::msg('permchange') );
  115. return;
  116. }
  117. if( ext_isFTPMode() ) {
  118. $abs_item = get_item_info( $dir, $GLOBALS['__POST']["selitems"][0]);
  119. } else {
  120. $abs_item = get_abs_item( $dir, $GLOBALS['__POST']["selitems"][0]);
  121. $abs_item = utf8_decode($abs_item);
  122. }
  123. $mode = parse_file_perms(get_file_perms( $abs_item ));
  124. if($mode===false) {
  125. ext_Result::sendResult('chmod', false, $item.": ".$GLOBALS["error_msg"]["permread"]);
  126. }
  127. $pos = "rwx";
  128. $text = "";
  129. for($i=0;$i<$cnt;++$i) {
  130. $s_item=get_rel_item($dir,$GLOBALS['__POST']["selitems"][$i]);
  131. if(strlen($s_item)>50) $s_item="...".substr($s_item,-47);
  132. $text .= $s_item.($i+1<$cnt ? ', ':'');
  133. }
  134. ?>
  135. {
  136. "xtype": "form",
  137. "id": "simpleform",
  138. "width": "300",
  139. "labelWidth": 125,
  140. "url":"<?php echo basename( $GLOBALS['script_name']) ?>",
  141. "dialogtitle": "<?php echo ext_Lang::msg('actperms') ?>",
  142. "title" : "<?php echo $text ?>",
  143. "frame": true,
  144. "items": [{
  145. "layout": "column",
  146. "items": [{
  147. <?php
  148. // print table with current perms & checkboxes to change
  149. for($i=0;$i<3;++$i) {
  150. ?>
  151. "width":80,
  152. "title":"<?php echo ext_Lang::msg(array('miscchmod'=> $i ), true ) ?>",
  153. "items": [{
  154. <?php
  155. for($j=0;$j<3;++$j) {
  156. ?>
  157. "xtype": "checkbox",
  158. "boxLabel":"<?php echo $pos{$j} ?>",
  159. <?php if($mode{(3*$i)+$j} != "-") echo '"checked":true,' ?>
  160. "name":"<?php echo "r_". $i.$j ?>"
  161. } <?php
  162. if( $j<2 ) echo ',{';
  163. }
  164. ?>
  165. ]
  166. }
  167. <?php
  168. if( $i<2 ) echo ',{';
  169. }
  170. ?>,{
  171. "width":400,
  172. "style":"margin-left:10px",
  173. "clear":true,
  174. "html": "&nbsp;"
  175. }]
  176. },{
  177. "xtype": "checkbox",
  178. "fieldLabel":"<?php echo ext_Lang::msg('recurse_subdirs', true ) ?>",
  179. "name":"do_recurse"
  180. }],
  181. "buttons": [{
  182. "text": "<?php echo ext_Lang::msg( 'btnsave', true ) ?>",
  183. "handler": function() {
  184. statusBarMessage( '<?php echo ext_Lang::msg( 'permissions_processing', true ) ?>', true );
  185. form = Ext.getCmp("simpleform").getForm();
  186. form.submit({
  187. //reset: true,
  188. reset: false,
  189. success: function(form, action) {
  190. statusBarMessage( action.result.message, false, true );
  191. datastore.reload();
  192. Ext.getCmp("dialog").destroy();
  193. },
  194. failure: function(form, action) {
  195. statusBarMessage( action.result.error, false, false );
  196. Ext.Msg.alert('<?php echo ext_Lang::err( 'error', true ) ?>', action.result.error);
  197. },
  198. scope: form,
  199. params: {
  200. "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. }
  208. },{
  209. "text": "<?php echo ext_Lang::msg( 'btncancel', true ) ?>",
  210. "handler": function() { Ext.getCmp("dialog").destroy(); }
  211. }]
  212. }
  213. <?php
  214. }
  215. }
  216. //------------------------------------------------------------------------------
  217. ?>