creation of spamassassin directory and user_prefs

Discussion in 'Installation/Configuration' started by jmroth, Aug 28, 2007.

  1. jmroth

    jmroth New Member

    Ehm... this new piece of code
    Code:
      // Spamassassin directory anlegen
      if(!is_dir($web_path."/user/".$user_username."/.spamassassin")) {
            mkdir($web_path."/user/".$user_username."/.spamassassin", 0700);
            $mod->log->caselog("chown ".$user_username.":web".$web_doc_id." ".$web_path."/user/"
    .$user_username."/.spamassassin");
      }
      if(!is_link($web_path."/user/".$user_username."/.spamassassin/user_prefs")) {
            symlink($web_path."/user/".$user_username."/.user_prefs",$web_path."/user/".$user_us
    ername."/.spamassassin/user_prefs");
      }
    
    I don't think this also works correctly the "admin user" where the homedir is not /home/www/webXX/user/webXX_user/ but only /home/www/webXX/
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Yes, the current implementation is only for non admin users.
     
  3. jmroth

    jmroth New Member

    Why did you do that?
    I like your software, and I mean no disrespect at all. By why put a feature/hack in there that does not apply to all the cases (here: users). I now know its behavior but either do it completely or just leave it would be my way to do it...
     
  4. jmroth

    jmroth New Member

    Oh well but instead of complaining why don't you just add code similar to this to your own from above :)

    Code:
      if($user["user_admin"]) {
        @unlink($web_path."/.spamassassin");
        symlink($web_path."/user/".$user_username."/.spamassassin/",
                $web_path."/.spamassassin");
      }
    
     
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    The faeture is experimental, ISPConfig 2.2.16 had to be released instantly due to a bug in Clamav, so there was no time for further testing it and I do not add any additional code that I'am not able to test extensively.
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Thanks, I will test it.
     
  7. Ben

    Ben Active Member Moderator

    So this bug / hack is not included in versions prior to 2.2.16?
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    Its neither a bug nor a hack. Its a experimental function in 2.2.16 to implement links for spamd for non admin users.
     
  9. Ben

    Ben Active Member Moderator

    Ah ok, so if I do not make use of that exp. feature there won't be any problems?
     
  10. till

    till Super Moderator Staff Member ISPConfig Developer

    No. Even if you use this function, there are no problems. What jmroth pointed out is, that the function is just implemented for normal users and not administrators.

    I agree with him that this was not a good solution to implement this for users only.
     
  11. jmroth

    jmroth New Member

    My previous snippet doesn't work! (unlink doesnt delete (empty) directories!)

    I have added recursive delete to the file class (i hate using "exec")

    Code:
      /**
       * Delete a file, or a folder and its contents
       *
       * @author      Aidan Lister <[email protected]>
       * @version     1.0.3
       * @link        http://aidanlister.com/repos/v/function.rmdirr.php
       * @param       string   $dirname    Directory to delete
       * @return      bool     Returns TRUE on success, FALSE on failure
       */
      function rmdirr($dirname)
      {
        // Sanity check
        if (!file_exists($dirname)) {
          return false;
        }
    
        // Simple delete for a file
        if (is_file($dirname) || is_link($dirname)) {
          return unlink($dirname);
        }
    
        // Loop through the folder
        $dir = dir($dirname);
        while (false !== $entry = $dir->read()) {
          // Skip pointers
          if ($entry == '.' || $entry == '..') {
            continue;
          }
    
          // Recurse
          $this->rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
        }
    
        // Clean up
        $dir->close();
        return rmdir($dirname);
      }
    
    Then I have added to config.lib.php around lines 745 (user insert) and 930 (user update)

    Code:
      // Spamassassin directory anlegen
      if(!is_dir($web_path."/user/".$user_username."/.spamassassin")) {
        mkdir($web_path."/user/".$user_username."/.spamassassin", 0700);
        $mod->log->caselog("chown ".$user_username.":web".$web_doc_id." ".$web_path\
    ."/user/".$user_username."/.spamassassin");
      }
      if(!is_link($web_path."/user/".$user_username."/.spamassassin/user_prefs")) {
        symlink($web_path."/user/".$user_username."/.user_prefs",
                $web_path."/user/".$user_username."/.spamassassin/user_prefs");
      }
    +  if($user["user_admin"]) {
    +    $mod->file->rmdirr($web_path."/.spamassassin");
    +    symlink($web_path."/user/".$user_username."/.spamassassin/",
    +            $web_path."/.spamassassin");
    +  }
    
    
    Maybe one could put that in an extra function, as it is completely the same twice. Not sure how you handle code reuse in ispconfig ;)
     
  12. jmroth

    jmroth New Member

    There was another unhandled case when user_prefs already existed but was not a link... What follows is the new updated code around lines 741 and 928

    Code:
      if(!is_link($web_path."/user/".$user_username."/.spamassassin/user_prefs")) {
            if (is_file($web_path."/user/".$user_username."/.spamassassin/user_prefs")) @unlink($web_path."/user/".$user_username."/.spamassassin/user_prefs");
            symlink($web_path."/user/".$user_username."/.user_prefs",$web_path."/user/".$user_username."/.spamassassin/user_prefs");
      }
      if($user["user_admin"]) {
        $mod->file->rmdirr($web_path."/.spamassassin");
        symlink($web_path."/user/".$user_username."/.spamassassin/",
                $web_path."/.spamassassin");
      }
    
    
     

Share This Page