Skip to content

File Permissions overview #5

Description

@bueltge
       <table class="widefat">
         <thead>
          <tr>
            <tr>
              <th>File</th>
          <th>Permission</th>
          <th>Size</th>
            </tr>
         </thead>
       <tbody>

<?php  // ----  Root folder


       $iterator = new DirectoryIterator( ABSPATH );

       // don't scan for these files types
       $filetypes = array("jpg", "png", "gif", "jpeg", "ico", "css", "txt");


        foreach ($iterator as $fileinfo) {
           if (!$fileinfo->isDot()) {

                    //get file extension
                    $filetype = pathinfo($fileinfo, PATHINFO_EXTENSION);

            // get permissions in octal
            $stringy = substr(sprintf('%o', $fileinfo->getPerms()), -4);
            ?>

                    </tr>
                   <?php if (!in_array(strtolower($filetype), $filetypes)) {

              //output file name
            echo "<td>" . $fileinfo . "</td>";


                  //check for 777 ! and outputs perms

                   if  ($stringy == '0777'){
                        echo "<td>" . substr(sprintf('%o', $fileinfo->getPerms()), -4) .
                "<span class='red'> &#215; </span>" . "</td>" ;
                   }else{
                    echo "<td>" . substr(sprintf('%o', $fileinfo->getPerms()), -4) .  "</td>" ;
                   }


                 //output file sizes
                     echo "<td>" . number_format($fileinfo->getSize()/1024, 2) . " KB" . "</td>";


           }
        }
    }?>

        </tbody>
      </table>
    </div>

  <!--TAB TWO   -->

  <div>
   <table class="widefat">
    <thead>
      <tr>
        <tr>
         <th>File</th>
         <th>Permission</th>
     <th>Size</th>
        </tr>
    </thead>
  <tbody>

<?php  // ----  wp-admin folder

      $it = new RecursiveDirectoryIterator( ABSPATH . "wp-admin");

           foreach(new RecursiveIteratorIterator($it) as $file) {

        $filetype = pathinfo($file, PATHINFO_EXTENSION);
        $stringy = substr(sprintf('%o', $fileinfo->getPerms()), -4);
        ?>

            </tr>

              <?php if (!in_array(strtolower($filetype), $filetypes)) {

                 echo "<td>" . $file . "</td>";

         //check for 777 !

                   if  ($stringy == '0777'){
                        echo "<td>" . substr(sprintf('%o', $fileinfo->getPerms()), -4) .
                "<span class='red'> &#215; </span>" . "</td>" ;
                   }else{
                    echo "<td>" . substr(sprintf('%o', $fileinfo->getPerms()), -4) .  "</td>" ;
                   }

                        echo "<td>" . number_format($file->getSize()/1024, 2) . " KB" . "</td>";

          }
       }?>


    </tbody>
   </table>
 </div>

  <!--TAB THREE-->

 <div>
   <table class="widefat">
     <thead>
       <tr>
        <tr>
         <th>File</th>
         <th>Permission</th>
     <th>Size</th>
        </tr>
    </thead>
 <tbody>

<?php  // ----  wp-content folder

      $it = new RecursiveDirectoryIterator( ABSPATH . "wp-content" );

           foreach(new RecursiveIteratorIterator($it) as $file) {

        $filetype = pathinfo($file, PATHINFO_EXTENSION);
        $stringy = substr(sprintf('%o', $fileinfo->getPerms()), -4);
        ?>

            </tr>

              <?php if (!in_array(strtolower($filetype), $filetypes)) {

                 echo "<td>" . $file . "</td>";

         //check for 777 !

                   if  ($stringy == '0777'){
                        echo "<td>" . substr(sprintf('%o', $fileinfo->getPerms()), -4) .
                "<span class='red'> &#215; </span>" . "</td>" ;
                   }else{
                    echo "<td>" . substr(sprintf('%o', $fileinfo->getPerms()), -4) .  "</td>" ;
                   }

                        echo "<td>" . number_format($file->getSize()/1024, 2) . " KB" . "</td>";

          }
       }?>

   </tbody>
  </table>
 </div>

  <!--TAB FOUR-->

 <div>
  <table class="widefat">
   <thead>
     <tr>
        <tr>
         <th>File</th>
         <th>Permission</th>
     <th>Size</th>
        </tr>
    </thead>
  <tbody>

   <?php  // ----  wp-includes folder

      $it = new RecursiveDirectoryIterator( ABSPATH . "wp-includes" );

           foreach(new RecursiveIteratorIterator($it) as $file) {

        $filetype = pathinfo($file, PATHINFO_EXTENSION);
        $stringy = substr(sprintf('%o', $fileinfo->getPerms()), -4); ?>

            </tr>

              <?php if (!in_array(strtolower($filetype), $filetypes)) {

                 echo "<td>" . $file . "</td>";

         //check for 777 !

                   if  ($stringy == '0777'){
                        echo "<td>" . substr(sprintf('%o', $fileinfo->getPerms()), -4) .
                "<span class='red'> &#215; </span>" . "</td>" ;
                   }else{
                    echo "<td>" . substr(sprintf('%o', $fileinfo->getPerms()), -4) .  "</td>" ;
                   }


         echo "<td>" . number_format($file->getSize()/1024, 2) . " KB" . "</td>";

          }
       }?>

    </tbody>
   </table>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions