OpenDCIM

OpenDCIM - PHP - Programmation

Marsh Posté le 25-03-2020 à 17:44:39    

Hello à tous,  
 
Tout d'abord j'espère être dans la bonne catégorie.
 
Je suis en train de tester la mise en place d'un serveur opendcim (https://www.opendcim.org/) en version 19.10 sous CentOS.
J'ai suivi le wiki mis à dispo par les devs (https://wiki.opendcim.org/wiki/index.php/Installation), à une vache près qu'il faut effectuer l'étape Enable User Authentication après avoir installé les fichiers opendcim.
 
Bref, le site fonctionne mais j'ai un léger souci de droits lors de l'affichage d'une page php https://opendcim/rightscheck.php :  
https://i.postimg.cc/P5kHB4K4/Screen-Shot-03-25-20-at-05-42-PM.png
D'après le script php, il effectue un test d'écriture dans les répertoires du site... Normalement au vu des droits affecter ça devrait fonctionner, mais visiblement non, il continue de me dire que c'est pas bon.
Apparemment il exécute le script en tant que user Apache.
J'ai même fait un test en passant les répertoires en 777, rien n'y fait.
 
A moins que le fichier rightscheck.php soit daubé mais ça me surprendrait :  

<!doctype html>
<html>
<head>
<title>openDCIM rights check</title>
<style type="text/css">
.wanted { background-color: forestgreen; }
.warning { background-color: orange; }
table { background-color: azure; border-collapse: collapse; border: 1px solid black; display: inline-flex; }
td, th { padding: 0 8px; }
</style>
</head>
<body>
 
<?php
 
$userid=exec('id -u');
$grpid=exec('id -g');
 
// The directories we want writable for uploads
$wantedpaths=array('drawings', 'pictures','vendor'.DIRECTORY_SEPARATOR.'mpdf'.DIRECTORY_SEPARATOR.'mpdf'.DIRECTORY_SEPARATOR.'ttfontdata');
 
print "<table>
 <tr>
  <th>Directory</th>
  <th>Writable</th>
  <th colspan=2>Rights</th>
  <th>Owner:Group</th>
 </tr>";
function matches(&$check,$const){
 if($check==$const){
  $check="<font color=\"LimeGreen\">$check</font>";
 }
}
 
function printrow($file,&$wantedpaths,$userid,$grpid){
 $uploadDir=$file;
 $not=(is_writable('.'.DIRECTORY_SEPARATOR.$uploadDir))?'<font color="LimeGreen">Yes</font>':'<font color="red">No</font>';
 $perms = fileperms('.'.DIRECTORY_SEPARATOR.$uploadDir);
 
 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' : '-'));
 
 $owner=fileowner($uploadDir);
 $group=filegroup($uploadDir);
 $perms=substr(sprintf('%o', $perms), -4);
 matches($owner,$userid);
 matches($group,$grpid);
 
 $class=(in_array($uploadDir,$wantedpaths))?' class="wanted"':'';
 $class=(preg_match('/LimeGreen/',$not) && !in_array($uploadDir,$wantedpaths))?' class="warning"':$class;
 
 print "\n\t<tr$class>\n\t\t<td>$uploadDir</td><td>$not</td><td>$info</td><td>$perms</td><td>$owner:$group</td></tr>";
}
 
$directory=".";
$scanned_directory = array_diff(scandir($directory), array('..', '.'));
foreach($scanned_directory as $i => $file){
 if(!is_dir($file)){
  continue;
 }
 
 printrow($file,$wantedpaths,$userid,$grpid);
}
 
# Add in extra paths here that aren't part of the root loop.
printrow('vendor'.DIRECTORY_SEPARATOR.'mpdf'.DIRECTORY_SEPARATOR.'mpdf'.DIRECTORY_SEPARATOR.'ttfontdata',$wantedpaths,$userid,$grpid);
 
# Handle paths that may or may not be set in the configuration screen for docker
# clowns.
if(file_exists("db.inc.php" )){
 require_once("db.inc.php" );
 foreach($config->ParameterArray as $option => $value){
  if(preg_match('/path$/',$option)){
   array_push($wantedpaths,$value);
   printrow($value,$wantedpaths,$userid,$grpid);
  }
 }
}
 
print "\n</table>
<table>
 <tr>
  <th>Legend</th>
 </tr>
 <tr class=\"wanted\"><td>Directory that should be writable</td></tr>
 <tr class=\"warning\"><td>Directory is writable and unexpected</td></tr>
 <tr><td>Normal and expected rights</td></tr>
</table>
<p>Script is being executed as owner: $userid group: $grpid</p>";
 


 
Bref si vous avez une idée de pourquoi ça fonctionne pas ça m'intéresse.
Est-ce que ça pourrait venir du package complet qui fonctionnerait pas bien sous CentOS (j'ai l'impression que les devs tournent plutôt sur du noyau debian/ubuntu) ?


---------------
I'll feed your skin snacks to my cockatiel!
Reply

Marsh Posté le 25-03-2020 à 17:44:39   

Reply

Marsh Posté le 26-03-2020 à 09:37:34    

Code :
  1. function printrow($file,&$wantedpaths,$userid,$grpid){
  2. $uploadDir=$file;
  3. $not=(is_writable('.'.DIRECTORY_SEPARATOR.$uploadDir))?'<font color="LimeGreen">Yes</font>':'<font color="red">No</font>';
  4. [...]


https://www.php.net/manual/fr/function.is-writable.php
Essaye de découvrir pourquoi cette fonction te renvoie le No...
 
Peut être que tu as une limitation de sécurité sur l'utilisateur.
 
Essaye aussi un :

Code :
  1. echo shell_exec('whoami');


---------------
D3
Reply

Marsh Posté le 26-03-2020 à 10:12:05    

Hello,
 
Merci pour ton retour.  
D'après les tests que j'ai fait hier soir, le script est correct : quand j'essaie d'écrire un fichier dans le répertoire, ça n'écrit pas.  
 
J'ai fait un whoami, il renvoie bien apache. Donc c'est bien le user apache qui est sensé écrire dans ces répertoires.  
 
J'en perds mon latin  :pt1cable: .
 
Je continue de gratter.


---------------
I'll feed your skin snacks to my cockatiel!
Reply

Marsh Posté le 26-03-2020 à 10:28:18    

Et ton file owner c'est bien apache ?
https://www.php.net/manual/fr/function.fileowner.php
Bon en 777, ça ne devrait rien changer...
 
Sinon tu as regardé du coté de SELinux, je sais que parfois il a tendance à faire du Zéle.


---------------
D3
Reply

Marsh Posté le 26-03-2020 à 10:34:43    

Justement j'ai un collègue qui m'a orienté vers la problématique SELinux (que je ne connaissais pas, je manque cruellement d'expérience sur Linux en général).
 
Donc j'ai commencé par vérifier si SELinux était activé :  

#sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      31


 
Donc en suivant les recommandation de cette page : https://blog.lysender.com/2015/07/c [...] tter-what/
J'ai passé la commande suivante :  

chcon -t httpd_sys_rw_content_t drawings/ -R


 
Et ça règle le souci.
Merci mechkurt pour tes retours. :jap:


---------------
I'll feed your skin snacks to my cockatiel!
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed