Guest User

Untitled

a guest
Feb 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1.  
  2. <?php
  3. /*
  4. * This is just a test. Code could be written in much fewer lines :).
  5. */
  6. function findPerms() {
  7. $fstat = $dstat = array('uid' => 0, 'gid' => 0);
  8.  
  9. // Get information about newly created directory
  10. if (!mkdir('test')) {
  11. // TODO: throw error here?
  12. echo "ERROR: could not create test directory. Make sure that Symphony can create child directories, at least while installing/updating itself.";
  13. return array();
  14. }
  15. $dstat = stat('test');
  16.  
  17. // Get information about newly created file
  18. if (file_put_contents('test/test.txt', 'test')) {
  19. $fstat = stat('test/test.txt');
  20. unlink('test/test.txt');
  21. }
  22.  
  23. // Cleanup
  24. rmdir('test');
  25.  
  26. // Get iformation about FTP uploaded directory
  27. $ftpdstat = stat('symphony');
  28.  
  29. // Get information about FTP uploaded file
  30. $ftpfstat = stat(__FILE__);
  31.  
  32. // TODO: throw error if $ftp* are not arrays?
  33.  
  34. $result = array();
  35. if ($ftpfstat['uid'] == $fstat['uid']) {
  36. $result['file'] = '644';
  37. }
  38. else if ($ftpfstat['gid'] == $fstat['gid']) {
  39. $result['file'] = '664';
  40. }
  41. else if (isset($fstat['mode'])) {
  42. // TODO: we could check if PHP needs executable flag,
  43. // by creating test.php instead of test.txt,
  44. // and using Gateway to check if it returns correct output.
  45. $result['file'] = substr(decoct($fstat['mode']), -3);
  46. }
  47. else {
  48. // Everything failed, so return "default" defaults ;(.
  49. $result['file'] = '644';
  50. }
  51.  
  52. if ($ftpdstat['uid'] == $dstat['uid']) {
  53. $result['directory'] = '755';
  54. }
  55. else if ($ftpdstat['gid'] == $dstat['gid']) {
  56. $result['directory'] = '775';
  57. }
  58. else if (isset($dstat['mode'])) {
  59. // TODO: we could check if PHP needs executable flag,
  60. // by creating test.php instead of test.txt,
  61. // and using Gateway to check if it returns correct output.
  62. $result['directory'] = substr(decoct($dstat['mode']), -3);
  63. }
  64. else {
  65. // Everything failed, so return "default" defaults ;(.
  66. $result['directory'] = '755';
  67. }
  68.  
  69. return $result;
  70. }
  71.  
  72. var_dump(findPerms());
Add Comment
Please, Sign In to add comment