PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/properties.php

https://github.com/Amsoft-Systems/ICEcoder
PHP | 147 lines | 129 code | 11 blank | 7 comment | 26 complexity | 1c15a8fdb2132222cd752ebb34822279 MD5 | raw file
  1. <?php include("settings.php");?>
  2. <!DOCTYPE html>
  3. <html onContextMenu="return false">
  4. <head>
  5. <title>ICEcoder <?php echo $ICEcoder["versionNo"];?> file/folder properties</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  7. <link rel="stylesheet" type="text/css" href="properties.css">
  8. </head>
  9. <body class="properties">
  10. <h1 id="title">properties</h1>
  11. <?php
  12. $fileName=$docRoot.$iceRoot.str_replace("|","/",strClean($_GET['fileName']));
  13. ?>
  14. <h2><?php echo basename($fileName); ?></h2><br>
  15. <span class="column" style="width: 180px">Size: <?php
  16. $bytes = filesize($fileName);
  17. // If it's a dir, get the dir size
  18. if (is_dir($fileName)) {
  19. $io = popen('/usr/bin/du -sb '.$fileName, 'r');
  20. $bytes = intval(fgets($io,80));
  21. pclose($io);
  22. }
  23. // Change into kilobytes
  24. $outputSize = ($bytes/1024);
  25. $outputUnit = "kb";
  26. // Maybe we should show in megabytes?
  27. if ($outputSize >= 1024) {
  28. $outputSize = ($outputSize/1024);
  29. $outputUnit = "mb";
  30. }
  31. echo number_format($outputSize, 2, '.', '').$outputUnit." (".number_format($bytes)." bytes)";
  32. ?></span>
  33. <span class="column" style="margin: 0 10px">Modified: <?php echo date( "D d M Y g:i:sa", filemtime($fileName)); ?></span>
  34. <span class="column">Last access: <?php echo date( "D d M Y g:i:sa", fileatime($fileName)); ?></span>
  35. <br><br>
  36. <span class="column" style="width: 180px">Type: <?php echo is_dir($fileName) ? "Folder" : "File"; ?></span>
  37. <span class="column" style="margin: 0 10px">Readable / Writeable:
  38. <?php echo is_readable($fileName) ? "Yes" : "No"; ?> / <?php echo is_writeable($fileName) ? "Yes" : "No";?>
  39. </span>
  40. <span class="column">Relative path: <?php echo str_replace($docRoot,"",$fileName);?></span>
  41. <span style="font-size:10px">
  42. <br><br>
  43. Absolute path:<br><?php echo $fileName;?>
  44. <br><br>
  45. </span>
  46. <span class="column" style="width: 180px">
  47. Permissions:
  48. <?php
  49. $chmodInfo = substr(sprintf('%o', fileperms($fileName)), -4);
  50. echo $chmodInfo;
  51. ?>
  52. </span>
  53. <span class="column" style="margin: 0 10px">
  54. <?php
  55. $perms = str_split(substr($chmodInfo,1,3)); // reduces 0705 down to 705
  56. $readVars = array(4,5,6,7);
  57. $writeVars = array(2,3,6,7);
  58. $execVars = array(1,3,5,7);
  59. ?>
  60. <table>
  61. <tr><th>Owner</th><th>Group</th><th>Public</th></tr>
  62. <tr>
  63. <td><input type="checkbox" name="ownerR" id="owner4"<?php if(in_array($perms[0],$readVars)!="") {echo ' checked';};?> onClick="changePerms();showButton()"> Read</td>
  64. <td><input type="checkbox" name="groupR" id="group4"<?php if(in_array($perms[1],$readVars)!="") {echo ' checked';};?> onClick="changePerms();showButton()"> Read</td>
  65. <td><input type="checkbox" name="publicR" id="public4"<?php if(in_array($perms[2],$readVars)!="") {echo ' checked';};?> onClick="changePerms();showButton()"> Read</td>
  66. </tr>
  67. <tr>
  68. <td><input type="checkbox" name="ownerW" id="owner2"<?php if(in_array($perms[0],$writeVars)!="") {echo ' checked';};?> onClick="changePerms();showButton()"> Write</td>
  69. <td><input type="checkbox" name="groupW" id="group2"<?php if(in_array($perms[1],$writeVars)!="") {echo ' checked';};?> onClick="changePerms();showButton()"> Write</td>
  70. <td><input type="checkbox" name="publicW" id="public2"<?php if(in_array($perms[2],$writeVars)!="") {echo ' checked';};?> onClick="changePerms();showButton()"> Write</td>
  71. </tr>
  72. <tr>
  73. <td><input type="checkbox" name="ownerE" id="owner1"<?php if(in_array($perms[0],$execVars)!="") {echo ' checked';};?> onClick="changePerms();showButton()"> Execute</td>
  74. <td><input type="checkbox" name="groupE" id="group1"<?php if(in_array($perms[1],$execVars)!="") {echo ' checked';};?> onClick="changePerms();showButton()"> Execute</td>
  75. <td><input type="checkbox" name="publicE" id="public1"<?php if(in_array($perms[2],$execVars)!="") {echo ' checked';};?> onClick="changePerms();showButton()"> Execute</td>
  76. </tr>
  77. </table>
  78. </span>
  79. <span class="column">
  80. Change to:<br>
  81. <form name="chmod" action="#" method="GET">
  82. <input type="text" name="chmod" id="permText" style="width: 30px; border: 0; background-color: #444; font-size: 10px; color: #fff" maxlength="3" value="<?php echo substr($chmodInfo,1,3); ?>" onKeyUp="changePerms(this.value);showButton()" onChange="changePerms(this.value);showButton()">
  83. </form>
  84. </span>
  85. <div class="update" id="updateButton" onClick="validatePerms()">update</div>
  86. <script>
  87. readVars = [4,5,6,7];
  88. writeVars = [2,3,6,7];
  89. execVars = [1,3,5,7];
  90. permGroups = ['owner','group','public'];
  91. permValues = [4,2,1];
  92. permTypes = ['read','write','exec'];
  93. function changePerms(val) {
  94. var permText = document.getElementById('permText').value;
  95. // change checkboxes
  96. if (val) {
  97. // set values
  98. if (permText.length==3) {
  99. for (var i=0;i<=2;i++) {
  100. for (var j=0;j<=2;j++) {
  101. document.getElementById(permGroups[i]+permValues[j]).checked = window[permTypes[j]+'Vars'].indexOf(permText.split("")[i]*1)>-1;
  102. }
  103. }
  104. // clear values
  105. } else {
  106. for (var i=0;i<=2;i++) {
  107. for (var j=0;j<=2;j++) {
  108. document.getElementById(permGroups[i]+permValues[j]).checked = false;
  109. }
  110. }
  111. }
  112. // change text value
  113. } else {
  114. ownerPerms = (document.getElementById('owner4').checked*4)+(document.getElementById('owner2').checked*2)+(document.getElementById('owner1').checked*1);
  115. groupPerms = (document.getElementById('group4').checked*4)+(document.getElementById('group2').checked*2)+(document.getElementById('group1').checked*1);
  116. publicPerms = (document.getElementById('public4').checked*4)+(document.getElementById('public2').checked*2)+(document.getElementById('public1').checked*1);
  117. document.getElementById('permText').value = ownerPerms.toString() + groupPerms.toString() + publicPerms.toString();
  118. }
  119. }
  120. var showButton = function() {
  121. document.getElementById('updateButton').style.opacity = 1;
  122. }
  123. var validatePerms = function() {
  124. var permText = document.getElementById('permText').value;
  125. canUpdate = true;
  126. if (permText.length!=3 || isNaN(permText)) {canUpdate = false};
  127. if ( permText.split("")[0]*1 <0 || permText.split("")[0]*1 >7 ||
  128. permText.split("")[1]*1 <0 || permText.split("")[1]*1 >7 ||
  129. permText.split("")[2]*1 <0 || permText.split("")[2]*1 >7) {
  130. canUpdate = false;
  131. }
  132. if (canUpdate) {top.ICEcoder.chmod('<?php echo str_replace($docRoot,"",$fileName);?>',permText)};
  133. }
  134. </script>
  135. </body>
  136. </html>