PageRenderTime 30ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/www/quixplorer/.include/chmod.php

https://bitbucket.org/cougar/nas4free.hg
PHP | 99 lines | 41 code | 10 blank | 48 comment | 17 complexity | ba232e11f1dff8f888567583e01fe0b1 MD5 | raw file
Possible License(s): Unlicense, MPL-2.0, GPL-2.0, GPL-3.0, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /*
  3. chmod.php
  4. Part of NAS4Free (http://www.nas4free.org).
  5. Copyright (C) 2012 by NAS4Free Team <info@nas4free.org>.
  6. All rights reserved.
  7. Portions of Quixplorer (http://quixplorer.sourceforge.net).
  8. Author: The QuiX project.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. 1. Redistributions of source code must retain the above copyright notice, this
  12. list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  20. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. The views and conclusions contained in the software and documentation are those
  27. of the authors and should not be interpreted as representing official policies,
  28. either expressed or implied, of the NAS4Free Project.
  29. */
  30. /*------------------------------------------------------------------------------
  31. Author: The QuiX project
  32. http://quixplorer.sourceforge.net
  33. Comment:
  34. QuiXplorer Version 2.3.2
  35. Permission-Change Functions
  36. ------------------------------------------------------------------------------*/
  37. //------------------------------------------------------------------------------
  38. function chmod_item($dir, $item) { // change permissions
  39. if(($GLOBALS["permissions"]&01)!=01) show_error($GLOBALS["error_msg"]["accessfunc"]);
  40. if(!file_exists(get_abs_item($dir, $item))) show_error($item.": ".$GLOBALS["error_msg"]["fileexist"]);
  41. if(!get_show_item($dir, $item)) show_error($item.": ".$GLOBALS["error_msg"]["accessfile"]);
  42. // Execute
  43. if(isset($GLOBALS['__POST']["confirm"]) && $GLOBALS['__POST']["confirm"]=="true") {
  44. $bin='';
  45. for($i=0;$i<3;$i++) for($j=0;$j<3;$j++) {
  46. $tmp="r_".$i.$j;
  47. if(isset($GLOBALS['__POST'][$tmp]) &&$GLOBALS['__POST'][$tmp]=="1" ) $bin.='1';
  48. else $bin.='0';
  49. if($bin=='0') show_error($item.": ".$GLOBALS["error_msg"]["chmod_not_allowed"]); // Remove permissions from owner is not allowed!
  50. }
  51. if(!@chmod(get_abs_item($dir,$item),bindec($bin))) {
  52. show_error($item.": ".$GLOBALS["error_msg"]["permchange"]);
  53. }
  54. header("Location: ".make_link("link",$dir,NULL));
  55. return;
  56. }
  57. $mode = parse_file_perms(get_file_perms($dir,$item));
  58. if($mode===false) show_error($item.": ".$GLOBALS["error_msg"]["permread"]);
  59. $pos = "rwx";
  60. $s_item=get_rel_item($dir,$item); if(strlen($s_item)>50) $s_item="...".substr($s_item,-47);
  61. show_header($GLOBALS["messages"]["actperms"].": /".$s_item);
  62. // Form
  63. echo "<CENTER><BR><TABLE width=\"175\"><FORM method=\"post\" action=\"";
  64. echo make_link("chmod",$dir,$item) . "\">\n";
  65. echo "<INPUT type=\"hidden\" name=\"confirm\" value=\"true\">\n";
  66. // print table with current perms & checkboxes to change
  67. for($i=0;$i<3;++$i) {
  68. echo "<TR><TD>" . $GLOBALS["messages"]["miscchmod"][$i] . "</TD>";
  69. for($j=0;$j<3;++$j) {
  70. echo "<TD>" . $pos{$j} . "&nbsp;<INPUT type=\"checkbox\"";
  71. if($mode{(3*$i)+$j} != "-") echo " checked";
  72. echo " name=\"r_" . $i.$j . "\" value=\"1\"></TD>";
  73. }
  74. echo "</TR>\n";
  75. }
  76. // Submit / Cancel
  77. echo "</TABLE>\n<BR><TABLE>\n<TR><TD>\n<INPUT type=\"submit\" value=\"".$GLOBALS["messages"]["btnchange"];
  78. echo "\"></TD>\n<TD><input type=\"button\" value=\"".$GLOBALS["messages"]["btncancel"];
  79. echo "\" onClick=\"javascript:location='".make_link("list",$dir,NULL)."';\">\n</TD></TR></FORM></TABLE><BR></CENTER>\n";
  80. }
  81. //------------------------------------------------------------------------------
  82. ?>