function ReloadMacHelpers($output = false)
{
    @mkdir("/var/log/squid/reload", 0755, true);
    $unix = new unix();
    $pgrep = $unix->find_program("pgrep");
    $rm = $unix->find_program("rm");
    shell_exec("{$rm} /var/log/squid/reload/*.ufdbgclient.php");
    if (is_file("/var/log/squid/UfdbguardCache.db")) {
        @unlink("/var/log/squid/UfdbguardCache.db");
    }
    exec("{$pgrep} -l -f \"ufdbgclient.php\" 2>&1", $results);
    while (list($index, $ligne) = each($results)) {
        if (preg_match("#pgrep#", $ligne)) {
            continue;
        }
        if (!preg_match("#^([0-9]+)\\s+#", $ligne, $re)) {
            continue;
        }
        $PIDS[] = $re[1];
        echo "Starting......: " . date("H:i:s") . " [INIT]: Webfilter client reloading PID {$re[1]}\n";
        @touch("/var/log/squid/reload/{$re[1]}.ufdbgclient.php");
        @chown("/var/log/squid/reload/{$re[1]}.ufdbgclient.php", "squid");
        @chgrp("/var/log/squid/reload/{$re[1]}.ufdbgclient.php", "squid");
    }
    squid_admin_mysql(2, count($PIDS) . " Artica helper(s) was reloaded", null, __FILE__, __LINE__);
}
Example #2
0
 /**
  * Called when socket is bound
  * @return boolean Success
  */
 protected function onBound()
 {
     touch($this->path);
     chmod($this->path, 0770);
     if ($this->group === null && !empty($this->uri['pass'])) {
         $this->group = $this->uri['pass'];
     }
     if ($this->group === null && isset(Daemon::$config->group->value)) {
         $this->group = Daemon::$config->group->value;
     }
     if ($this->group !== null) {
         if (!@chgrp($this->path, $this->group)) {
             unlink($this->path);
             Daemon::log('Couldn\'t change group of the socket \'' . $this->path . '\' to \'' . $this->group . '\'.');
             return false;
         }
     }
     if ($this->user === null && !empty($this->uri['user'])) {
         $this->user = $this->uri['user'];
     }
     if ($this->user === null && isset(Daemon::$config->user->value)) {
         $this->user = Daemon::$config->user->value;
     }
     if ($this->user !== null) {
         if (!@chown($this->path, $this->user)) {
             unlink($this->path);
             Daemon::log('Couldn\'t change owner of the socket \'' . $this->path . '\' to \'' . $this->user . '\'.');
             return false;
         }
     }
     return true;
 }
Example #3
0
 /**
  * 尝试建立目录
  * @param $url	文件路径
  * @param $mode	目录权限
  * @param $maxloop	最大尝试次数
  * @return true or false
  */
 public function tryMakedir($url, $mode = 0777, $maxloop = 5)
 {
     $urlarr = explode('/', $url);
     $urlstr = '';
     foreach ($urlarr as $key => $value) {
         $urlstr .= $value . '/';
         if (!is_dir($urlstr)) {
             $loop = 0;
             $makeok = false;
             while ($loop < $maxloop) {
                 if (@mkdir($urlstr, $mode)) {
                     chown($urlstr, 'nobody');
                     chgrp($urlstr, 'nobody');
                     chmod($urlstr, $mode);
                     $makeok = true;
                     break;
                 } else {
                     $loop++;
                 }
             }
             if (!$makeok) {
                 return false;
             }
         }
     }
     return true;
 }
Example #4
0
 public function run(InputInterface $input = null, OutputInterface $output = null)
 {
     $fp = fopen($this->config['lockfile'], "w");
     // if you run this script as root - change user/group
     if (file_exists($this->config['lockfile'])) {
         chown($this->config['lockfile'], $this->config['file-user']);
         chgrp($this->config['lockfile'], $this->config['file-group']);
     }
     $exitCode = 0;
     if (flock($fp, LOCK_EX | LOCK_NB)) {
         // acquire an exclusive lock
         ftruncate($fp, 0);
         $exitCode = parent::run($input, $output);
         fflush($fp);
         // flush output before releasing the lock
         flock($fp, LOCK_UN);
         // release the lock
     } else {
         //throw new DNSSyncException("Running multiple instances is not allowed."); - nezachytí applikace error
         //$output->writeln() - null v této chvíli
         $message = "Running multiple instances is not allowed.";
         echo $message . PHP_EOL;
         mail($this->config['admin-email'], $message, $message);
         $exitCode = 500;
     }
     fclose($fp);
     return $exitCode;
 }
 public function run()
 {
     if (is_array($this->conf['init-system']['dirs']) && count($this->conf['init-system']['dirs'])) {
         foreach ($this->conf['init-system']['dirs'] as $dir) {
             if (file_exists($dir)) {
                 $this->msg('Directory ' . $dir . ' already exists.');
             } else {
                 $this->msg('Creating directory ' . $dir);
                 mkdir($dir, 0775, TRUE);
             }
         }
     }
     if (!empty($this->conf['init-system']['packages'])) {
         $this->msg('Install linux packages...');
         $rc = $this->system('apt-get install -y ' . $this->conf['init-system']['packages']);
         if ($rc['rc']) {
             $this->msg('An error occured while installing packages:');
             foreach ($rc['output'] as $line) {
                 $this->msg($line);
             }
             exit(2);
         }
         $this->system('apt-get clean');
         chown('/var/log/php_errors', 'www-data');
         chgrp('/var/log/php_errors', 'www-data');
     }
 }
Example #6
0
 function create($domain)
 {
     $server_setting = $this->load_server_setting();
     $vhost_setting = $this->load_vhost_setting();
     #生成web空间
     $htdocs = $server_setting['http']['htdocs'] . '/' . $vhost_setting['domain'];
     $server_setting['http']['htdocs'] = $htdocs;
     $htdocs_owner = $server_setting['ftp']['user'];
     mkdir($htdocs);
     chown($htdocs, $htdocs_owner);
     #生成http服务配置
     if ($server_setting['http']['name'] == 'nginx') {
         $nginx = new svhost_server_nginx($server_setting['http']);
         $server_ip = $server_setting['server']['ip'];
         $nginx->create($domain, $server_ip);
     }
     #生成ftp帐号
     if ($server_setting['ftp']['name'] == 'proftpd') {
         $proftpd = new svhost_server_proftpd($server_setting['ftp']);
         $ftp['user'] = $vhost_setting['ftp']['user'];
         $ftp['password'] = $vhost_setting['ftp']['password'];
         $ftp['home'] = $htdocs;
         $proftpd->create($ftp);
     }
     #生成mysql帐号
     if ($server_setting['database']['name'] == 'mysql') {
         $database = new svhost_server_mysql($server_setting['database']);
         $mysql['db_name'] = $vhost_setting['db']['name'];
         $mysql['db_user'] = $vhost_setting['db']['user'];
         $mysql['db_host'] = $vhost_setting['db']['host'];
         $mysql['db_password'] = $vhost_setting['db']['password'];
         $database->create($mysql);
     }
     return true;
 }
Example #7
0
 private function renderRelativeImagePath($imageType, $imageFilename, $imageWidth = 0, $imageHeight = 0, $flagStamp = false)
 {
     $imageFilename = trim($imageFilename);
     $imageWidth = intval($imageWidth);
     $imageHeight = intval($imageHeight);
     if (!is_bool($flagStamp)) {
         $flagStamp = false;
     }
     if (!in_array($imageType, array('orig', 'crop', 'scale')) || !strlen($imageFilename)) {
         return '';
     }
     $postfix = '';
     if ($imageWidth && $imageHeight) {
         $postfix .= '_' . $imageWidth . '_' . $imageHeight;
     }
     if ($flagStamp) {
         $postfix .= '_stamp';
     }
     $path = '/' . $imageType . '/' . substr($imageFilename, 0, 2) . '/' . substr($imageFilename, 2, 2);
     if (!file_exists($this->pathImage . $path)) {
         mkdir($this->pathImage . $path, 0775, true);
         $folderOwnerInfo = posix_getpwuid(fileowner($this->pathImage . $path));
         if ($folderOwnerInfo['name'] == Cfg::FILE_SYSTEM_SUPERUSER) {
             chown($this->pathImage . $path, Cfg::FILE_SYSTEM_USERNAME);
             chgrp($this->pathImage . $path, Cfg::FILE_SYSTEM_USERNAME);
         }
     }
     return $path . '/' . $imageFilename . $postfix . '.jpg';
 }
 public static function fixPermissions($item, $owner, $filePrivileges, $dirPrivileges)
 {
     if (is_dir($item)) {
         if (!@chmod($item, $dirPrivileges)) {
             return false;
         }
     } elseif (!@chmod($item, $filePrivileges)) {
         return false;
     }
     if (!@chown($item, $owner)) {
         return false;
     }
     if (!is_dir($item)) {
         return true;
     }
     $dir = $item;
     $dirResource = opendir($dir);
     while ($file = readdir($dirResource)) {
         if ($file == "." || $file == "..") {
             continue;
         }
         if (in_array($file, self::$_excludeUpdateFiles)) {
             continue;
         }
         if (!self::fixPermissions($dir . "/" . $file, $owner, $filePrivileges, $dirPrivileges)) {
             return false;
         }
     }
     closedir($dirResource);
     return true;
 }
Example #9
0
function _match_owners_if_possible($target_filename, $match_from_filename)
{
    try {
        if (false === ($intended_uid = fileowner($match_from_filename))) {
            throw new Exception("fileowner failed on source");
        }
        if (false === ($intended_gid = filegroup($match_from_filename))) {
            throw new Exception("filegroup failed on source");
        }
        if (false === ($uid = fileowner($target_filename))) {
            throw new Exception("fileowner failed on target");
        }
        if (false === ($gid = filegroup($target_filename))) {
            throw new Exception("filegroup failed on target");
        }
        if ($intended_uid != $uid && !chown($target_filename, $intended_uid)) {
            throw new Exception("chown failed on target");
        }
        if ($intended_gid != $gid && !chgrp($target_filename, $intended_gid)) {
            throw new Exception("chgrp failed on target");
        }
    } catch (Exception $e) {
        error_log("Cannot assign ownership of [{$target_filename}] to owner of [{$match_from_filename}]: " . $e->getMessage());
    }
}
Example #10
0
 /**
  * 
  */
 public function reset()
 {
     \file_put_contents(ROOT . '/tmp/installing.json', \json_encode(['step' => 0], JSON_PRETTY_PRINT));
     \chmod(ROOT . '/tmp/installing.json', 0777);
     \chown(ROOT . '/tmp/installing.json', 'www-data');
     \symlink(ROOT . '/Installer/launch.php', ROOT . '/public/launch.php');
 }
Example #11
0
 public static function chunk($_log = '')
 {
     $maxLineLog = config::byKey('maxLineLog');
     if ($maxLineLog < 200) {
         $maxLineLog = 200;
     }
     if ($_log != '') {
         $path = self::getPathToLog($_log);
         shell_exec('echo "$(tail -n ' . $maxLineLog . ' ' . $path . ')" > ' . $path);
         @chown($path, 'www-data');
         @chgrp($path, 'www-data');
         @chmod($path, 0777);
     } else {
         $logs = ls(dirname(__FILE__) . '/../../log/', '*');
         foreach ($logs as $log) {
             $path = dirname(__FILE__) . '/../../log/' . $log;
             if (is_file($path)) {
                 shell_exec('echo "$(tail -n ' . $maxLineLog . ' ' . $path . ')" > ' . $path);
                 @chown($path, 'www-data');
                 @chgrp($path, 'www-data');
                 @chmod($path, 0777);
             }
         }
         $logs = ls(dirname(__FILE__) . '/../../log/scenarioLog', '*');
         foreach ($logs as $log) {
             $path = dirname(__FILE__) . '/../../log/scenarioLog/' . $log;
             if (is_file($path)) {
                 shell_exec('echo "$(head -n ' . $maxLineLog . ' ' . $path . ')" > ' . $path);
                 @chown($path, 'www-data');
                 @chgrp($path, 'www-data');
                 @chmod($path, 0777);
             }
         }
     }
 }
 protected function setRights($path)
 {
     if ($path == '' || $path == '/' || $path == DIRECTORY_SEPARATOR || !file_exists($path)) {
         return false;
     }
     if (is_file($path)) {
         if ($this->config->doChmod) {
             chmod($path, intval($this->config->chmodFileValue, 8));
         }
         if ($this->config->doChown) {
             chown($path, $this->config->chownUser);
             chgrp($path, $this->config->chownGroup);
         }
         return true;
     }
     if (!is_dir($path)) {
         return false;
     }
     if ($this->config->doChmod) {
         chmod($path, intval($this->config->chmodDirValue, 8));
     }
     if ($this->config->doChown) {
         chown($path, $this->config->chownUser);
         chgrp($path, $this->config->chownGroup);
     }
     $dir = new DirectoryIterator($path);
     foreach ($dir as $dirContent) {
         if (!$dirContent->isDot()) {
             $this->setRights($dirContent->getPathName());
         }
     }
     unset($dir);
     unset($dirContent);
 }
function createLocalImage($url, $unique)
{
    $extension = ".png";
    $filename = $unique . $extension;
    $path = "images/";
    $img = @imagecreatefrompng($url);
    imagepng($img, $path . $filename);
    chown($path . $filename, "apache");
}
Example #14
0
 /**
  * 
  * @param type $filename
  */
 function fixPerms($filename)
 {
     if (!is_file($filename)) {
         echo "{$filename} is not a file\n";
     }
     chown($filename, "www-data");
     chmod($filename, 0666);
     return $filename;
 }
Example #15
0
function cron_welcome($entry, $fullpath, $args = NULL)
{
    $source = '/etc/skel/WELCOME.txt';
    $destin = $fullpath . '/WELCOME.txt';
    copy($source, $destin);
    chown($destin, 'root');
    chgrp($destin, 'root');
    chmod($destin, 0444);
}
Example #16
0
function prepareDir($dir){
  if (strlen($dir)){
    if ( ! is_dir($dir) && ! is_file($dir)){
      mkdir($dir, 0777, true);
      chown($dir, 'nobody');
      chgrp($dir, 'users');
      sleep(1);
    }
  }
}
Example #17
0
 /**
  * Set the user for a given directory or file
  *
  * @param $path
  * @param $user
  * @param boolean $recursive
  */
 public function setUser($path, $user, $recursive)
 {
     chown($path, $user);
     if (!$recursive || !is_dir($path)) {
         return;
     }
     foreach ($this->getIterator($path) as $file) {
         chown($file, $user);
     }
 }
Example #18
0
 /**
  * @return $this
  */
 protected function cleanUp()
 {
     if (!is_dir($this->tmpDir)) {
         return $this;
     }
     chown($this->tmpDir, 0777);
     $this->deleteContent($this->tmpDir);
     rmdir($this->tmpDir);
     return $this;
 }
 private function forceFileOwnershipToAppUser()
 {
     $manifest_directory = $this->generator->getManifestDirectory();
     if (is_dir($manifest_directory)) {
         foreach (glob($manifest_directory . '/' . Git_Mirror_ManifestFileGenerator::FILE_PREFIX . '*') as $file) {
             chown($file, ForgeConfig::get('sys_http_user'));
             chgrp($file, ForgeConfig::get('sys_http_user'));
         }
     }
 }
Example #20
0
 /**
  * 递归建目录函数
  *
  * @param string $dir 目录
  * @param string $mode
  * @return boolean
  */
 private static function m_MakeDirs($dir, $mode = 0777)
 {
     if (!is_dir($dir)) {
         self::m_MakeDirs(dirname($dir), $mode);
         $result = mkdir($dir, $mode);
         $result = chown($dir, "www");
         $result = chgrp($dir, "www");
         return $result;
     }
     return true;
 }
 /**
  * Solve a HTTP-01 challenge
  *
  * @return bool
  */
 public function solve()
 {
     $payload = $this->domain->account->acme->generateHttp01Payload($this->token);
     $wwwCheck = explode('.', $this->challengeDomain, 2);
     if ($wwwCheck[0] === 'www') {
         // WWW, so use the path to without www
         $domainPath = $this->challengeDomain[1];
     } else {
         // without WWW, so use the normal domain
         $domainPath = $this->challengeDomain;
     }
     $subdomainCheck = explode('.', $domainPath, 2);
     if ($subdomainCheck[1] === $this->domain->getDomain()) {
         // The second key is the same as the domain, so we're on a subdomain
         $challengePath = $this->domain->getPath() . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . $subdomainCheck[0] . DIRECTORY_SEPARATOR . '.well-known';
     } else {
         // Were not on a subdomain, use main domain
         $challengePath = $this->domain->getPath() . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . '.well-known';
     }
     if (!file_exists($challengePath)) {
         mkdir($challengePath);
         if (defined('CRON')) {
             chown($challengePath, $this->domain->account->getUsername());
             chgrp($challengePath, $this->domain->account->getUsername());
         }
     }
     $challengePath .= DIRECTORY_SEPARATOR . 'acme-challenge';
     if (!file_exists($challengePath)) {
         mkdir($challengePath);
         if (defined('CRON')) {
             chown($challengePath, $this->domain->account->getUsername());
             chgrp($challengePath, $this->domain->account->getUsername());
         }
     }
     file_put_contents($challengePath . DIRECTORY_SEPARATOR . $this->token, $payload);
     if (defined('CRON')) {
         chown($challengePath . DIRECTORY_SEPARATOR . $this->token, $this->domain->account->getUsername());
         chgrp($challengePath . DIRECTORY_SEPARATOR . $this->token, $this->domain->account->getUsername());
     }
     $this->domain->account->acme->selfVerify($this->challengeDomain, $this->token, $payload);
     $this->domain->account->acme->answerChallenge($this->uri, $payload);
     $this->domain->account->acme->pollForChallenge($this->location);
     unlink($challengePath . DIRECTORY_SEPARATOR . $this->token);
     $isChallengePathEmpty = !(new \FilesystemIterator($challengePath))->valid();
     if ($isChallengePathEmpty) {
         rmdir($challengePath);
         $challengePath = dirname($challengePath);
         $isChallengePathEmpty = !(new \FilesystemIterator($challengePath))->valid();
         if ($isChallengePathEmpty) {
             rmdir($challengePath);
         }
     }
     return true;
 }
Example #22
0
 /**
  * Run the installer
  *
  * @param string[] $args
  * @return bool
  */
 public function run($args = null)
 {
     if ($args !== null) {
         $this->setArgs($args);
     }
     $force = $this->hasOption('-f');
     // non-interactive mode
     // Check the user exists
     if (!file_exists($this->getHomeDir())) {
         $this->log("User directory does not exist '" . $this->getHomeDir() . "' - have you created the test user?");
         $this->log("Add a user `" . properties::$user . "` with password `" . properties::$pass . "`");
         return false;
     }
     // Check you are root
     if (trim(`whoami`) != 'root') {
         $this->log("You need to be root to do this");
         return false;
     }
     // User confirmation
     if (!$force && !$this->confirm()) {
         $this->log("Aborting");
         return false;
     }
     $this->log("Installing.. ", false);
     // Pub keys to install
     $files = ['dsa-nopw.pem.pub', 'dsa-pw.pem.pub', 'rsa-nopw.pem.pub', 'rsa-pw.pem.pub'];
     // Check ~/.ssh/ directory exists
     $ssh_dir = $this->getHomeDir() . '/.ssh';
     if (!file_exists($ssh_dir)) {
         mkdir($ssh_dir, 0700, true);
         chown($ssh_dir, properties::$user);
         chgrp($ssh_dir, properties::$user);
     }
     // Check authorized_keys file exists
     $key_file = $this->getKeyFile();
     if (!file_exists($key_file)) {
         touch($key_file);
         chmod($key_file, 0600);
         chown($key_file, properties::$user);
         chgrp($key_file, properties::$user);
     }
     if (!is_writable($key_file)) {
         $this->log("No write access to key file, aborting");
         return false;
     }
     $base = __DIR__ . '/';
     $fp = fopen($key_file, 'a');
     foreach ($files as $file) {
         fwrite($fp, trim(file_get_contents($base . $file)) . "\n");
     }
     fclose($fp);
     $this->log("done");
     return false;
 }
Example #23
0
 /**
  * @param  \SplFileInfo  $file
  * @return bool
  */
 public function apply(\SplFileInfo $file)
 {
     if (!$this->checkType($file)) {
         return FALSE;
     }
     if (!preg_match($this->pattern, $file->getFilename())) {
         return FALSE;
     }
     chmod($file, $this->getMode($file));
     chown($file, $this->getOwner());
     return TRUE;
 }
Example #24
0
 public function Duplicados($nombre)
 {
     $msg;
     //Leer la carpeta y verificar que no exista
     if (mkdir(WWW_ROOT . DS . $nombre . "/", 0777, true)) {
         chown(WWW_ROOT . DS . $nombre . "/", "edgar");
         $msg = "Carpeta Creada: " . $nombre;
     } else {
         $msg = "El carpeta ya existe";
     }
     header("Location: ../operator/carpeta.php?msg=" . $msg);
 }
Example #25
0
 private function createDirectory($pathname, $mode, $user, $group)
 {
     if (!mkdir($pathname, $mode, TRUE)) {
         throw new \Exception('Failed to create folder: ' . $pathname);
     }
     if (!chown($pathname, $user)) {
         throw new \Exception('Failed to set owner for folder: ' . $pathname);
     }
     if (!chgrp($pathname, $group)) {
         throw new \Exception('Failed to set group for folder: ' . $pathname);
     }
 }
 function changeWidgetDir($newDir)
 {
     $defaultDir = str_replace('//', '/', str_replace('\\', '/', dirname(plugin_dir_path(__FILE__)))) . '/custom-widgets/';
     if (empty($newDir) || get_option('preset-cdwd') == TRUE || get_option('widgetdir') == '/') {
         $newDir = $defaultDir;
         $dirchange = TRUE;
     }
     $newDir = str_replace('//', '/', str_replace('\\', '/', $newDir));
     $wpdir = str_replace('//', '/', str_replace('\\', '/', wp_upload_dir()));
     $plugindir = str_replace('//', '/', str_replace('\\', '/', dirname(plugin_dir_path(__FILE__))));
     if (WPWM_DEBUG == 1) {
         $error = TRUE;
         $errmsg = "Debug Mode enabled, unrestricted  directory changes permitted";
     } else {
         if (strstr($newDir, $plugindir) == FALSE) {
             $error = TRUE;
             $errmsg = " ERROR-Custom Widget Directory must be within Wordpress manager plugin directory. The default had been set instead of " . $newDir . '<br/>';
             $newDir = dirname(plugin_dir_path(__FILE__)) . '/custom-widgets/';
             $dirchange = TRUE;
         }
     }
     $dirchange = TRUE;
     $newDir = str_replace('//', '/', str_replace('\\', '/', $newDir));
     if (file_exists($newDir) == FALSE) {
         $dirDiff = true;
         mkdir($newDir, 0755);
         $user = exec(whoami);
         chown($newDir, $user);
     }
     $sourceDir = get_option('widgetdir');
     if (file_exists($sourceDir)) {
         $sourceDir = str_replace('//', '/', str_replace('\\', '/', $sourceDir));
         if (strcmp($sourceDir, $wpdir['basedir']) != 0) {
             $contents = scandir($sourceDir);
             if (SUBSTR($newDir, -1) != '/') {
                 $newDir .= '/';
             }
             foreach ($contents as $widgets) {
                 if ($widgets != "." && $widgets != "..") {
                     recurse_copy($sourceDir, $newDir);
                 }
             }
             if ($sourceDir != $newDir) {
                 if ($sourceDir != $defaultDir) {
                     $check = recursiveRemove($sourceDir);
                 }
             }
         }
     }
     update_option('widgetdir', $newDir);
     msgDisplay($error, $errmsg, $dirchange, $dirDiff);
 }
 function update($event_name, $data)
 {
     global $app, $conf;
     // get the config
     $app->uses("getconf");
     $old_ini_data = $app->ini_parser->parse_ini_string($data['old']['config']);
     $mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
     copy('/etc/postfix/main.cf', '/etc/postfix/main.cf~');
     if ($mail_config['relayhost'] != '') {
         exec("postconf -e 'relayhost = " . $mail_config['relayhost'] . "'");
         if ($mail_config['relayhost_user'] != '' && $mail_config['relayhost_password'] != '') {
             exec("postconf -e 'smtp_sasl_auth_enable = yes'");
         } else {
             exec("postconf -e 'smtp_sasl_auth_enable = no'");
         }
         exec("postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'");
         exec("postconf -e 'smtp_sasl_security_options ='");
         // Store the sasl passwd
         $content = $mail_config['relayhost'] . '   ' . $mail_config['relayhost_user'] . ':' . $mail_config['relayhost_password'];
         file_put_contents('/etc/postfix/sasl_passwd', $content);
         chmod('/etc/postfix/sasl_passwd', 0600);
         chown('/etc/postfix/sasl_passwd', 'root');
         chgrp('/etc/postfix/sasl_passwd', 'root');
         exec('postmap /etc/postfix/sasl_passwd');
         exec($conf['init_scripts'] . '/' . 'postfix restart');
     } else {
         exec("postconf -e 'relayhost ='");
     }
     if ($mail_config['realtime_blackhole_list'] != $old_ini_data['mail']['realtime_blackhole_list']) {
         $rbl_hosts = trim(preg_replace('/\\s+/', '', $mail_config['realtime_blackhole_list']));
         if ($rbl_hosts != '') {
             $rbl_hosts = explode(",", $rbl_hosts);
         }
         $options = explode(", ", exec("postconf -h smtpd_recipient_restrictions"));
         foreach ($options as $key => $value) {
             if (!preg_match('/reject_rbl_client/', $value)) {
                 $new_options[] = $value;
             }
         }
         if (is_array($rbl_hosts) && !empty($rbl_hosts)) {
             foreach ($rbl_hosts as $key => $value) {
                 $value = trim($value);
                 if ($value != '') {
                     $new_options[] = "reject_rbl_client " . $value;
                 }
             }
         }
         exec("postconf -e 'smtpd_recipient_restrictions = " . implode(", ", $new_options) . "'");
     }
     exec("postconf -e 'mailbox_size_limit = " . intval($mail_config['mailbox_size_limit'] * 1024 * 1024) . "'");
     exec("postconf -e 'message_size_limit = " . intval($mail_config['message_size_limit'] * 1024 * 1024) . "'");
 }
Example #28
0
 public function configure_dovecot()
 {
     global $conf;
     $config_dir = $conf['dovecot']['config_dir'];
     //* Configure master.cf and add a line for deliver
     if (is_file($config_dir . '/master.cf')) {
         copy($config_dir . '/master.cf', $config_dir . '/master.cf~2');
     }
     if (is_file($config_dir . '/master.cf~')) {
         chmod($config_dir . '/master.cf~2', 0400);
     }
     $content = rf($conf["postfix"]["config_dir"] . '/master.cf');
     // Only add the content if we had not addded it before
     if (!stristr($content, "dovecot/deliver")) {
         $deliver_content = 'dovecot   unix  -       n       n       -       -       pipe' . "\n" . '  flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}';
         af($conf["postfix"]["config_dir"] . '/master.cf', $deliver_content);
     }
     unset($content);
     unset($deliver_content);
     //* Reconfigure postfix to use dovecot authentication
     // Adding the amavisd commands to the postfix configuration
     $postconf_commands = array('dovecot_destination_recipient_limit = 1', 'virtual_transport = dovecot', 'smtpd_sasl_type = dovecot', 'smtpd_sasl_path = private/auth');
     // Make a backup copy of the main.cf file
     copy($conf["postfix"]["config_dir"] . '/main.cf', $conf["postfix"]["config_dir"] . '/main.cf~3');
     // Executing the postconf commands
     foreach ($postconf_commands as $cmd) {
         $command = "postconf -e '{$cmd}'";
         caselog($command . " &> /dev/null", __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     //* copy dovecot.conf
     $configfile = 'dovecot.conf';
     if (is_file($config_dir . '/' . $configfile)) {
         copy($config_dir . '/' . $configfile, $config_dir . '/' . $configfile . '~');
     }
     copy('tpl/debian6_dovecot.conf.master', $config_dir . '/' . $configfile);
     //* dovecot-sql.conf
     $configfile = 'dovecot-sql.conf';
     if (is_file($config_dir . '/' . $configfile)) {
         copy($config_dir . '/' . $configfile, $config_dir . '/' . $configfile . '~');
     }
     chmod($config_dir . '/' . $configfile . '~', 0400);
     $content = rf('tpl/debian6_dovecot-sql.conf.master');
     $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
     $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
     $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
     $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
     wf($config_dir . '/' . $configfile, $content);
     chmod($config_dir . '/' . $configfile, 0600);
     chown($config_dir . '/' . $configfile, 'root');
     chgrp($config_dir . '/' . $configfile, 'root');
 }
 public function chown($file, $owner, $recursive = false)
 {
     if (!$this->exists($file)) {
         return false;
     }
     if (!$recursive || !$this->is_dir($file)) {
         return @chown($file, $owner);
     }
     $filelist = $this->getdir($file);
     foreach ($filelist as $filename) {
         $this->chown($file . '/' . $filename, $owner, $recursive);
     }
     return true;
 }
	function chown($file,$owner,$recursive=false){
		if( ! $this->exists($file) )
			return false;
		if( ! $recursive )
			return @chown($file,$owner);
		if( ! $this->is_dir($file) )
			return @chown($file,$owner);
		//Is a directory, and we want recursive
		$filelist = $this->dirlist($file);
		foreach($filelist as $filename){
			$this->chown($file.'/'.$filename,$owner,$recursive);
		}
		return true;
	}