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); } } } }
/** * 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; }
/** * 尝试建立目录 * @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; }
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'); } }
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'; }
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()); } }
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 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__); }
/** * Create Icinga Web 2's configuration directory * * USAGE: * * icingacli setup config directory [options] * * OPTIONS: * * --config=<directory> Path to Icinga Web 2's configuration files [/etc/icingaweb2] * * --mode=<mode> The access mode to use [2770] * * --group=<group> Owner group for the configuration directory [icingaweb2] * * EXAMPLES: * * icingacli setup config directory * * icingacli setup config directory --mode=2775 --config=/opt/icingaweb2/etc */ public function directoryAction() { $configDir = trim($this->params->get('config', $this->app->getConfigDir())); if (strlen($configDir) === 0) { $this->fail($this->translate('The argument --config expects a path to Icinga Web 2\'s configuration files')); } $group = trim($this->params->get('group', 'icingaweb2')); if (strlen($group) === 0) { $this->fail($this->translate('The argument --group expects a owner group for the configuration directory')); } $mode = trim($this->params->get('mode', '2770')); if (strlen($mode) === 0) { $this->fail($this->translate('The argument --mode expects an access mode for the configuration directory')); } if (!file_exists($configDir) && !@mkdir($configDir)) { $e = error_get_last(); $this->fail(sprintf($this->translate('Can\'t create configuration directory %s: %s'), $configDir, $e['message'])); } if (!@chmod($configDir, octdec($mode))) { $e = error_get_last(); $this->fail(sprintf($this->translate('Can\'t change the mode of the configuration directory to %s: %s'), $mode, $e['message'])); } if (!@chgrp($configDir, $group)) { $e = error_get_last(); $this->fail(sprintf($this->translate('Can\'t change the group of %s to %s: %s'), $configDir, $group, $e['message'])); } printf($this->translate('Successfully created configuration directory %s') . PHP_EOL, $configDir); }
/** * Append recorded video to live entry * * @action appendRecording * @param string $entryId Live entry id * @param string $assetId Live asset id * @param KalturaMediaServerIndex $mediaServerIndex * @param KalturaDataCenterContentResource $resource * @param float $duration in seconds * @param bool $isLastChunk Is this the last recorded chunk in the current session (i.e. following a stream stop event) * @return KalturaLiveEntry The updated live entry * * @throws KalturaErrors::ENTRY_ID_NOT_FOUND */ function appendRecordingAction($entryId, $assetId, $mediaServerIndex, KalturaDataCenterContentResource $resource, $duration, $isLastChunk = false) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || !$dbEntry instanceof LiveEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $dbAsset = assetPeer::retrieveById($assetId); if (!$dbAsset || !$dbAsset instanceof liveAsset) { throw new KalturaAPIException(KalturaErrors::ASSET_ID_NOT_FOUND, $assetId); } $lastDuration = $dbEntry->getLengthInMsecs(); if (!$lastDuration) { $lastDuration = 0; } $liveSegmentDurationInMsec = (int) ($duration * 1000); $currentDuration = $lastDuration + $liveSegmentDurationInMsec; $maxRecordingDuration = (kConf::get('max_live_recording_duration_hours') + 1) * 60 * 60 * 1000; if ($currentDuration > $maxRecordingDuration) { KalturaLog::err("Entry [{$entryId}] duration [" . $dbEntry->getLengthInMsecs() . "] and current duration [{$currentDuration}] is more than max allwoed duration [{$maxRecordingDuration}]"); throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_EXCEEDED_MAX_RECORDED_DURATION, $entryId); } $kResource = $resource->toObject(); $filename = $kResource->getLocalFilePath(); if (!$resource instanceof KalturaServerFileResource) { $filename = kConf::get('uploaded_segment_destination') . basename($kResource->getLocalFilePath()); kFile::moveFile($kResource->getLocalFilePath(), $filename); chgrp($filename, kConf::get('content_group')); chmod($filename, 0640); } if ($dbAsset->hasTag(assetParams::TAG_RECORDING_ANCHOR) && $mediaServerIndex == KalturaMediaServerIndex::PRIMARY) { KalturaLog::debug("Appending assetId {$assetId} to entryId {$entryId}"); $dbEntry->setLengthInMsecs($currentDuration); // Extract the exact video segment duration from the recorded file $mediaInfoParser = new KMediaInfoMediaParser($filename, kConf::get('bin_path_mediainfo')); $recordedSegmentDurationInMsec = $mediaInfoParser->getMediaInfo()->videoDuration; $currentSegmentVodToLiveDeltaTime = $liveSegmentDurationInMsec - $recordedSegmentDurationInMsec; $recordedSegmentsInfo = $dbEntry->getRecordedSegmentsInfo(); $recordedSegmentsInfo->addSegment($lastDuration, $recordedSegmentDurationInMsec, $currentSegmentVodToLiveDeltaTime); $dbEntry->setRecordedSegmentsInfo($recordedSegmentsInfo); if ($isLastChunk) { // Save last elapsed recording time $dbEntry->setLastElapsedRecordingTime($currentDuration); } $dbEntry->save(); } kJobsManager::addConvertLiveSegmentJob(null, $dbAsset, $mediaServerIndex, $filename, $currentDuration); if ($mediaServerIndex == KalturaMediaServerIndex::PRIMARY) { if (!$dbEntry->getRecordedEntryId()) { $this->createRecordedEntry($dbEntry, $mediaServerIndex); } $recordedEntry = entryPeer::retrieveByPK($dbEntry->getRecordedEntryId()); if ($recordedEntry) { $this->ingestAsset($recordedEntry, $dbAsset, $filename); } } $entry = KalturaEntryFactory::getInstanceByType($dbEntry->getType()); $entry->fromObject($dbEntry, $this->getResponseProfile()); return $entry; }
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); }
private function checkInProjectFolder(DirectoryIterator $frs_project_dirs) { foreach ($frs_project_dirs as $frs_project_dir) { if ($this->folderNeedsToBeUpdated($frs_project_dir)) { echo $frs_project_dir->getPathname() . ' needs to be updated' . PHP_EOL; chgrp($frs_project_dir->getPathname(), $this->needed_group_name); } } }
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); } } }
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')); } } }
/** * Set the group for a given directory or file * * @param $path * @param $group * @param boolean $recursive */ public function setGroup($path, $group, $recursive) { chgrp($path, $group); if (!$recursive || !is_dir($path)) { return; } foreach ($this->getIterator($path) as $file) { chgrp($file, $group); } }
/** * 递归建目录函数 * * @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; }
/** * @param string $path * @param string|null $group * @return string */ public static function createFile($path, $group = null) { if (!file_exists($path)) { touch($path); chmod($path, 0775); if (!is_null($group)) { chgrp($path, $group); } } return realpath($path); }
/** * 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; }
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 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) . "'"); }
function _chgrp_r($path, $group) { chgrp($path, $group); if (!is_dir($path)) { return; } $dir = new DirectoryIterator($path); foreach ($dir as $fileinfo) { if (!$fileinfo->isDot()) { _chgrp_r($path . '/' . $fileinfo->getFilename(), $group); } } }
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'); }
function build() { $kav = new Kav4Proxy(); $conf = $kav->build_config(); echo "Starting......: " . date("H:i:s") . " Kav4proxy building configuration done\n"; @file_put_contents("/etc/opt/kaspersky/kav4proxy.conf", $conf); shell_exec("/bin/chown -R kluser /etc/opt/kaspersky"); shell_exec("/bin/chown -R kluser /var/log/kaspersky/kav4proxy"); @mkdir("/tmp/Kav4proxy", 0777); @chmod("/tmp/Kav4proxy", 0777); @chown("/tmp/Kav4Proxy", "kluser"); @chgrp("/tmp/Kav4Proxy", "kluser"); templates(); }
function chgrp($file,$group,$recursive=false){ if( ! $this->exists($file) ) return false; if( ! $recursive ) return @chgrp($file,$group); if( ! $this->is_dir($file) ) return @chgrp($file,$group); //Is a directory, and we want recursive $filelist = $this->dirlist($file); foreach($filelist as $filename){ $this->chgrp($file.'/'.$filename,$group,$recursive); } return true; }
function init() { $unix = new unix(); $rm = $unix->find_program("rm"); shell_exec("{$rm} -rf /var/lib/squid/session/ssl >/dev/null 2>&1"); @mkdir("/var/lib/squid/session/ssl", 0755, true); @chown("/var/lib/squid/session/ssl", "squid"); @chgrp("/var/lib/squid/session/ssl", "squid"); $sslcrtd_program = $unix->squid_locate_generic_bin("ssl_crtd"); $chown = $unix->find_program("chown"); exec("{$sslcrtd_program} -c -s /var/lib/squid/session/ssl/ssl_db 2>&1", $results); shell_exec("{$chown} -R squid:squid /var/lib/squid/session"); squid_admin_mysql(1, "SSL database initialized", @implode("\n", $results), __FILE__, __LINE__); }
/** * Export virtual hosts * @param DatabaseSqlite3 &$db Database object * @return boolean */ public function exportVirtualHosts(&$db) { // Smarty template if ($this->smarty === null) { $this->smarty = TemplateFactory::create(); if ($this->smarty === false) { return false; } } // Get all virtual hosts and generate virtual configuration $this->vhosts = array(); $db->query('SELECT * FROM `virtualHost`'); while ($db->next_row()) { // Store in array $this->vhosts[] = $db->row; // Make sure the forwarders file exists $forwarderFile = $db->row[6] . '/' . $db->row[3] . '/etc/' . $db->row[2] . '/forwarders'; if (!is_file($forwarderFile)) { // Create empty file $rc = touch($forwarderFile); if ($rc === false) { Log::error('Error while creating forwarder file: ' . $forwarderFile); return false; } // Set proper user ownership $rc = chown($forwarderFile, $db->row[3]); if ($rc === false) { Log::error('Error while setting user ownerhsip of forwarder file: ' . $forwarderFile); return false; } // Set proper group ownership $rc = chgrp($forwarderFile, 'dovecot'); if ($rc === false) { Log::error('Error while setting group ownerhsip of forwarder file: ' . $forwarderFile); return false; } } } // Assign variables $this->smarty->assignByRef('VHOSTS', $this->vhosts); // Generate virtual_mailbox_domains file $rc = $this->saveConfigFile(Config::read('postfix|virtualDomainsFile'), 'virtualdomainsfile', 'postfix.tpl', $this->smarty); if ($rc === false) { return false; } // Compile with postmap exec('/usr/sbin/postmap ' . Config::read('postfix|virtualDomainsFile')); return true; }
public function manage($id = null) { if (!$this->Application->exists($id)) { throw new NotFoundException(__('Invalid data')); } $app = $this->Application->find('first', array('conditions' => array('Application.id' => $id))); if ($this->request->is('post')) { //esto es que estoy subiendo el fichero $name = $this->request->data['name']; $type = $this->request->data['type']; $objFile = $_FILES["uploaded"]; $fileName = basename($objFile["name"]); $strPath = $_SERVER['CONTEXT_DOCUMENT_ROOT'] . DS . 'pool' . DS; if (!is_dir($strPath)) { mkdir($strPath); chgrp($strPath, "www-data"); chmod($strPath, 0777); } $strPath .= $app['Application']['name'] . DS; if (!is_dir($strPath)) { mkdir($strPath); chgrp($strPath, "www-data"); chmod($strPath, 0777); } $strPath .= $app['Application']['version'] . DS; if (!is_dir($strPath)) { mkdir($strPath); chgrp($strPath, "www-data"); chmod($strPath, 0777); } // Se crea los datos a almacenar y se guardan $data = array('Data' => array('application_id' => $id, 'name' => $name, 'filename' => $fileName, 'type' => $type, 'verificate' => 0)); $this->Data->create(); if ($this->Data->save($data)) { //si se salvo en la BD entonces procedo a mover el fichero a su destino final $strPath .= $this->Data->id . '.zip'; if (!copy($objFile["tmp_name"], $strPath)) { $this->Session->setFlash('No se pudo colocar el fichero elimine el dato insertado manualmente.'); //Aqui puedo eliminar el dato yo mismo //$this->Data-delete(); } else { $app = $this->Application->find('first', array('conditions' => array('Application.id' => $id))); } } } else { // esto es que estoy mostrando el formulario } $this->set('app', $app); }
public function chgrp($file, $group, $recursive = false) { if (!$this->exists($file)) { return false; } if (!$recursive || !$this->is_dir($file)) { return @chgrp($file, $group); } $file = rtrim($file, '/') . '/'; $filelist = $this->getdir($file); foreach ($filelist as $filename) { $this->chgrp($file . $filename, $group, $recursive); } return true; }