Projekt: Joomla! Dateirechte
Dienstag, 10. Oktober 2006
Die Idee ist, die Schreibrechte "wichtiger" Dateien in einer Joomla!installation übersichtlich anzuzeigen, und bei Bedarf zu ändern. Das ganze könnte dann so aussehen:
Screenshot:
Screenshot

Ein Screenshot aus dem Joomla!backend.
Das Ganze ist im Moment als Komponente nur für SuperAdmins ausgelegt.
Wäre natürlich schön, wenn sich so etwas etwas fester in J! integrieren könnte :)

Download: Hier...

Basierend auf folgendem Code:

<?php
/**
 * @version $Id: admin.j!secure.php 2006-09-15 elkuku $
 * @package J!Secure
 * @copyright 
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 */
defined( '_VALID_MOS' ) or die( 'Foolproofed.. !' );
if ($my->usertype != "Super Administrator") {
  echo "Sorry, Supis only..";
} else {
  switch ($act) {
    case 'chmod':
      $mod = intval(mosGetParam( $_GET, 'mod', '' ));
      $file = $GLOBALS['mosConfig_absolute_path']
          . '/' . mosGetParam( $_GET, 'file', '' );
      $erfolg = false;
      switch ($mod) {
        case 444:
          $erfolg = chmod($file, 0444);
          break;
        case 644:
          $erfolg = chmod($file, 0644);
          break;
        case 664:
          $erfolg = chmod($file, 0664);
          break;
      }
      if (!$erfolg) {
        echo '
        <strong>Schreibrechte konnten NICHT geändert werden !!!
        benutzen Sie Ihr FTP-Programm</strong>';
      }
  }
 
  $query = "SELECT template"
           . "\n FROM #__templates_menu"
           . "\n WHERE client_id = 0"
           . "\n AND menuid = 0";
 
  $database->setQuery( $query );
 
  $tmp_cur_template = $database->loadResult();
 
  echo '
  <h3>J! DateiRechte</h3>
  <p>Zu Ihrem Schutz sollten die folgenden Dateien nicht beschreibbar sein.</p>';
  
  if (!ext_mosIsChmodable($GLOBALS['mosConfig_absolute_path'] . '/index.php')) {
    echo '
    <h3><font color="red">Zum ändern der Schreibrechte
    müssen Sie ein FTP-Programm benutzen !</font></h3>';
}
  else {
    echo '<font color="red">Das Programm kann die Schreibrechte ändern.<br />
    Sollte dies nicht funktionieren, benutzen Sie bitte Ihr FTP-Programm !</font>
';
  }
  echo '
  <table border="1">
    <tr>
      <td colspan="8" align="center" bgcolor="#CCCCCC">
        <strong>Coredateien</strong>
      </td>
    </tr>
      <tr>
  <td colspan="8">
          <strong>$mosConfig_absolute_path : </strong>
          ' . $mosConfig_absolute_path . '</td>
      </tr>
      <tr>
        <td>File</td>
        <td colspan="2" align="center">Rechte</td>
        <td colspan="2"align="center">Status</td>
        <td colspan="3" align="center">Aktion</td>
      </tr>';
/**
 * Hier können weitere wichtige Dateien eingefügt werden
 */
      writableCell( 'configuration.php' );
      writableCell( 'index.php' );
      writableCell( 'index2.php' );
      writableCell( 'administrator/index.php' );
 
echo '
      <tr>
        <td colspan="8" align="center" bgcolor="#CCCCCC"><strong>Template</strong></td>
      </tr>
      <tr>  
        <td colspan="8">
          <strong>Current Template : </strong>
          ' . $tmp_cur_template . '
        </td>
      </tr>
      <tr>
        <td>File</td>
        <td colspan="2" align="center">Rechte</td>
        <td colspan="2"align="center">Status</td>
        <td colspan="3" align="center">Aktion</td>
      </tr>';
/**
 * Hier stehen die Templatedateien
 */
      writableCell( 'templates/'.$tmp_cur_template.'/index.php' );
      writableCell( 'templates/'.$tmp_cur_template.'/css/template_css.css' );
  
echo '
</table>';
 
echo '
<hr />by <a href="http://www.nik-it.de" class="internal">NiK-IT.de</a> 2006<hr />';
}
 
///////////////////////////////////////
/////////////////////FUNKTIONEN///////////
///////////////////////////////////////
 
/**
 * Die Corefunktion writableCell - umgedreht und etwas erweitert :-)
 */
function writableCell( $file ) {
  echo '
  <tr>
    <td bgcolor="#EEEEEE">' . $file . '</td>
    <td>' . show_fileperms($file) . '</td>
    <td>' . showFullFileperms($file) . '</td>';
 
  if (is_writable( $GLOBALS['mosConfig_absolute_path'] . '/' . $file )) {
    echo '
    <td bgcolor="#FFCCCC">
      <b><font color="red">Beschreibbar</font></b>
    </td>
    <td bgcolor="#FFCCCC">
      <strong>Rechte ändern !! (644/444)</strong>
    </td>' ;
  }else {
    echo '
    <td bgcolor="#CCFFCC">
      <b><font color="green">Nicht beschreibbar</font></b>
    </td>
    <td bgcolor="#CCFFCC">OK</td>';
  }
  if (!ext_mosIsChmodable($GLOBALS['mosConfig_absolute_path'] . '/index.php')) {
    //kann nicht geändert werden
    echo '
    <td colspan="2"> </td>';
  }
  else {
    //kann geändert werden
    echo '
    <td>
      <a href="index2.php?option=com_j!secure&act=chmod&mod=664&file='.$file.'">
      664</a>
    </td>
    <td>
      <a href="index2.php?option=com_j!secure&act=chmod&mod=644&file='.$file.'">
      644</a>
    </td>
    <td>
      <a href="index2.php?option=com_j!secure&act=chmod&mod=444&file='.$file.'">
      444</a>
    </td>';
  }
  echo '</tr>';
}
 
/**
 * Zeigt Schreibrechte xxxx
 */
function show_fileperms ($file) {
  $f_perms = substr(sprintf('%o', fileperms($GLOBALS['mosConfig_absolute_path'] .
        '/' . $file)), -4);
  return $f_perms;
}
 
/**
 * Zeigt detaillierte Schreibrechte xxxxxxxxxx
 */
function showFullFileperms ($file) {
  $perms = fileperms($GLOBALS['mosConfig_absolute_path'] . '/' . $file);
 
if (($perms & 0xC000) == 0xC000) {
    // Socket
    $info = 's';
} elseif (($perms & 0xA000) == 0xA000) {
    // Symbolic Link
    $info = 'l';
} elseif (($perms & 0x8000) == 0x8000) {
    // Regular
    $info = '-';
} elseif (($perms & 0x6000) == 0x6000) {
    // Block special
    $info = 'b';
} elseif (($perms & 0x4000) == 0x4000) {
    // Directory
    $info = 'd';
} elseif (($perms & 0x2000) == 0x2000) {
    // Character special
    $info = 'c';
} elseif (($perms & 0x1000) == 0x1000) {
    // FIFO pipe
    $info = 'p';
} else {
    // Unknown
    $info = 'u';
}
 
// Owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
            (($perms & 0x0800) ? 's' : 'x' ) :
            (($perms & 0x0800) ? 'S' : '-'));
 
// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
            (($perms & 0x0400) ? 's' : 'x' ) :
            (($perms & 0x0400) ? 'S' : '-'));
 
// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
            (($perms & 0x0200) ? 't' : 'x' ) :
            (($perms & 0x0200) ? 'T' : '-'));
 
return $info;
}
 
/**
 * Prüft auf Beschreibbarkeit
 */
function ext_mosIsChmodable($file) {
  $perms = fileperms($file);
  if ( $perms !== FALSE ) {
    if (@chmod($file, $perms ^ 0001)) {
      @chmod($file, $perms);
      return TRUE;
    }
  }
  return FALSE;
}
 
?>