function test_mail_sender($to = "*****@*****.**")
{
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    if (function_exists('posix_getuid')) {
        $uid = posix_getuid();
    } else {
        $uid = '??';
    }
    if (function_exists('posix_geteuid')) {
        $euid = posix_geteuid();
    } else {
        $euid = '??';
    }
    if (function_exists('posix_getpwuid')) {
        $real_user = posix_getpwuid($uid);
        $effective_user = posix_getpwuid($euid);
    } else {
        $real_user = $uid;
        $effective_user = $euid;
    }
    if (function_exists('posix_getcwd')) {
        $cwd = posix_getcwd();
    } else {
        $cwd = getcwd();
    }
    $subject = sprintf("[Default mail sender] First mail from %s", $_SERVER['SERVER_NAME']);
    $message = sprintf("SAPI: %s\nreal user: %s\neffective user: %s\ncurrent dir: %s\nPHP version: %s", var_export(php_sapi_name(), true), var_export($real_user, true), var_export($effective_user, true), var_export($cwd, true), var_export(phpversion(), true));
    $headers = sprintf("X-Mailer: PHP/%s", phpversion());
    $mail = mail($to, $subject, $message, $headers);
    printf("mail() returned: %s", var_export($mail, true));
}
Example #2
0
 private function doExecute(Manager $args) : Generator
 {
     if (posix_geteuid() !== 0) {
         throw new AcmeException("Please run this script as root!");
     }
     $server = $args->get("server");
     $protocol = substr($server, 0, strpos("://", $server));
     if (!$protocol || $protocol === $server) {
         $server = "https://" . $server;
     } elseif ($protocol !== "https") {
         throw new \InvalidArgumentException("Invalid server protocol, only HTTPS supported");
     }
     $keyPair = $this->checkRegistration($args);
     $acme = new AcmeService(new AcmeClient($server, $keyPair), $keyPair);
     $this->logger->info("Revoking certificate ...");
     $pem = (yield get($args->get("cert")));
     $cert = new Certificate($pem);
     if ($cert->getValidTo() < time()) {
         $this->logger->warning("Certificate did already expire, no need to revoke it.");
         return;
     }
     $this->logger->info("Certificate was valid for: " . implode(", ", $cert->getNames()));
     (yield $acme->revokeCertificate($pem));
     $this->logger->info("Certificate has been revoked.");
 }
Example #3
0
 function get($s = '')
 {
     $this->sessionState(0);
     $bits = explode('/', $s);
     if (empty($bits[0]) || empty($bits[1]) || !isset($this->types[$bits[0]])) {
         $this->jerr("invalid url");
     }
     $s = str_replace('/', '-', $bits[1]);
     $ui = posix_getpwuid(posix_geteuid());
     $ff = HTML_FlexyFramework::get();
     $compile = session_save_path() . '/' . $ui['name'] . '-' . $ff->project . '-' . $ff->version . '-' . $bits[0] . 'compile';
     $fn = $compile . '/' . $s . '.' . $bits[0];
     if (!file_exists($fn)) {
         header('Content-Type: ' . $this->types[$bits[0]]);
         echo "// compiled file not found = {$fn}";
         exit;
     }
     $last_modified_time = filemtime($fn);
     if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time || isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == md5($fn)) {
         header("HTTP/1.1 304 Not Modified");
         exit;
     }
     header('Content-Type: ' . $this->types[$bits[0]]);
     header("Pragma: public");
     header('Content-Length: ' . filesize($fn));
     header('Cache-Control: max-age=2592000, public');
     header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 2592000));
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', $last_modified_time));
     header('Etag: ' . md5($fn));
     $fh = fopen($fn, 'r');
     fpassthru($fh);
     fclose($fh);
     exit;
 }
Example #4
0
 public static function getLog()
 {
     if (!self::$log) {
         $path = PhabricatorEnv::getEnvConfig('log.ssh.path');
         $format = PhabricatorEnv::getEnvConfig('log.ssh.format');
         $format = nonempty($format, "[%D]\t%p\t%h\t%r\t%s\t%S\t%u\t%C\t%U\t%c\t%T\t%i\t%o");
         // NOTE: Path may be null. We still create the log, it just won't write
         // anywhere.
         $data = array('D' => date('r'), 'h' => php_uname('n'), 'p' => getmypid(), 'e' => time());
         $sudo_user = PhabricatorEnv::getEnvConfig('phd.user');
         if (strlen($sudo_user)) {
             $data['S'] = $sudo_user;
         }
         if (function_exists('posix_geteuid')) {
             $system_uid = posix_geteuid();
             $system_info = posix_getpwuid($system_uid);
             $data['s'] = idx($system_info, 'name');
         }
         $client = getenv('SSH_CLIENT');
         if (strlen($client)) {
             $remote_address = head(explode(' ', $client));
             $data['r'] = $remote_address;
         }
         $log = id(new PhutilDeferredLog($path, $format))->setFailQuietly(true)->setData($data);
         self::$log = $log;
     }
     return self::$log;
 }
 /**
  * Get the system user.
  *
  * @return string
  */
 protected function getSystemUser()
 {
     if (str_contains(strtolower(php_uname()), 'windows')) {
         return getenv('USERNAME');
     }
     return posix_getpwuid(posix_geteuid())['name'];
 }
Example #6
0
 /**
  * Initializes the identifier prefix when setting the cache.
  *
  * @param \TYPO3\FLOW3\Cache\Frontend\FrontendInterface $cache
  * @return void
  */
 public function setCache(\TYPO3\FLOW3\Cache\Frontend\FrontendInterface $cache)
 {
     parent::setCache($cache);
     $processUser = extension_loaded('posix') ? posix_getpwuid(posix_geteuid()) : array('name' => 'default');
     $pathHash = substr(md5(FLOW3_PATH_WEB . PHP_SAPI . $processUser['name'] . $this->context), 0, 12);
     $this->identifierPrefix = 'FLOW3_' . $pathHash;
 }
 public function obtain()
 {
     if (function_exists('posix_geteuid') && function_exists('posix_getegid')) {
         $this->myuid = posix_geteuid();
         $this->mygid = posix_getegid();
     } else {
         $randName = '/tmp/rutorrent-' . rand() . '.tmp';
         @file_put_contents($randName, '');
         $ss = @stat($randName);
         if ($ss) {
             $this->mygid = $ss['gid'];
             $this->myuid = $ss['uid'];
             @unlink($randName);
         }
     }
     $req = new rXMLRPCRequest(new rXMLRPCCommand("to_kb", floatval(1024)));
     if ($req->run()) {
         $this->linkExist = true;
         if (!$req->fault) {
             $this->badXMLRPCVersion = false;
         }
         $req = new rXMLRPCRequest(array(new rXMLRPCCommand("get_directory"), new rXMLRPCCommand("get_session"), new rXMLRPCCommand("system.client_version"), new rXMLRPCCommand("system.library_version"), new rXMLRPCCommand("set_xmlrpc_size_limit", 67108863)));
         if ($req->run() && !$req->fault) {
             $this->directory = $req->val[0];
             $this->session = $req->val[1];
             $this->version = $req->val[2];
             $this->libVersion = $req->val[3];
             $parts = explode('.', $this->version);
             $this->iVersion = 0;
             for ($i = 0; $i < count($parts); $i++) {
                 $this->iVersion = ($this->iVersion << 8) + $parts[$i];
             }
             if (is_dir($this->session) && isLocalMode()) {
                 $ss = @stat($this->session . 'rtorrent.lock');
                 if (!$ss) {
                     $ss = @stat($this->session . 'rtorrent.dht_cache');
                 }
                 if (!$ss) {
                     $ss = @stat($this->session);
                 }
                 if ($ss) {
                     $this->gid = $ss['gid'];
                     $this->uid = $ss['uid'];
                     if (!empty($this->directory) && $this->directory[0] == '~') {
                         if (function_exists('posix_getpwuid')) {
                             $ui = posix_getpwuid($this->uid);
                             $this->directory = $ui["dir"] . substr($this->directory, 1);
                         } else {
                             $req = new rXMLRPCRequest(new rXMLRPCCommand("execute_capture", array("echo", "~")));
                             if ($req->run() && !$req->fault) {
                                 $this->directory = trim($req->val[0]) . substr($this->directory, 1);
                             }
                         }
                     }
                 }
             }
             $this->store();
         }
     }
 }
Example #8
0
function check_file($f)
{
    echo "\nFile {$f}\n";
    echo '1.' . (file_exists($f) ? ' exists' : ' does NOT exist') . " \n";
    if (!file_exists($f)) {
        echo 'Remaining checks skipped' . " \n";
        return;
    }
    echo '2. is' . (is_file($f) ? '' : ' NOT') . " a file\n";
    echo '3. is' . (is_readable($f) ? '' : ' NOT') . " readable\n";
    echo '4. is' . (is_writable($f) ? '' : ' NOT') . " writable\n";
    echo '5. has permissions ' . substr(sprintf('%o', fileperms($f)), -4) . "\n";
    echo '6. owner id ' . fileowner($f) . " (0 on Windows, blank if not permitted)\n";
    if (function_exists('posix_geteuid')) {
        $details = posix_getpwuid(posix_geteuid());
        echo '6. owner name ' . $details['name'] . " \n";
        echo '6. owner gid ' . $details['gid'] . " \n";
        $details = posix_getgrgid($details['gid']);
        echo '6. group name ' . $details['name'] . " \n";
    }
    echo '7. group id ' . filegroup($f) . " (0 on Windows, blank if not permitted)\n";
    if (function_exists('posix_getegid')) {
        $details = posix_getgrgid(posix_getegid());
        echo '7. group name ' . $details['name'] . " \n";
    }
}
 public static function GetExpectedPerms_file($file)
 {
     if (!self::HasFunctions()) {
         return '666';
     }
     //if user id's match
     $puid = posix_geteuid();
     $suid = self::file_uid($file);
     if ($suid !== false && $puid == $suid) {
         return '644';
     }
     //if group id's match
     $pgid = posix_getegid();
     $sgid = self::file_group($file);
     if ($sgid !== false && $pgid == $sgid) {
         return '664';
     }
     //if user is a member of group
     $snam = self::file_owner($file);
     $pmem = self::process_members();
     if (in_array($suid, $pmem) || in_array($snam, $pmem)) {
         return '664';
     }
     return '666';
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (0 != posix_geteuid()) {
         echo "You have to be root to run this command\n";
         return 1;
     }
     $container = $this->getContainer();
     $doctrine = $container->get('doctrine');
     $em = $doctrine->getManager();
     $user = $doctrine->getRepository('BinovoElkarBackupBundle:User')->find(User::SUPERUSER_ID);
     if (!$user) {
         $user = new User();
     } else {
         if ($input->getOption('reset')) {
             echo "Admin user exists. Trying to reset to initial values.\n";
         } else {
             echo "Admin user exists and reset was not requested. Nothing to do.\n";
             return 0;
         }
     }
     $factory = $container->get('security.encoder_factory');
     $encoder = $factory->getEncoder($user);
     $user->setUsername('root');
     $user->setEmail('root@localhost');
     $user->setRoles(array('ROLE_ADMIN'));
     $user->setSalt(md5(uniqid(null, true)));
     $password = $encoder->encodePassword('root', $user->getSalt());
     $user->setPassword($password);
     $em->persist($user);
     $em->flush();
     return 0;
 }
Example #11
0
 /**
  * Initializes the identifier prefix when setting the cache.
  *
  * @param \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache
  * @return void
  */
 public function setCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache)
 {
     parent::setCache($cache);
     $processUser = extension_loaded('posix') ? posix_getpwuid(posix_geteuid()) : array('name' => 'default');
     $pathHash = \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5(PATH_site . $processUser['name'] . $this->context, 12);
     $this->identifierPrefix = 'TYPO3_' . $pathHash;
 }
 private function handleLaunchEvent(PhutilEvent $event)
 {
     $id = $event->getValue('id');
     $current_user = posix_getpwuid(posix_geteuid());
     $daemon = id(new PhabricatorDaemonLog())->setDaemonID($id)->setDaemon($event->getValue('daemonClass'))->setHost(php_uname('n'))->setPID(getmypid())->setRunningAsUser($current_user['name'])->setStatus(PhabricatorDaemonLog::STATUS_RUNNING)->setArgv($event->getValue('argv'))->setExplicitArgv($event->getValue('explicitArgv'))->save();
     $this->daemons[$id] = $daemon;
 }
Example #13
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         if (!$input->getOption('allow-root')) {
             $aProcessUser = posix_getpwuid(posix_geteuid());
             if ($aProcessUser['name'] == 'root') {
                 throw new \InvalidArgumentException('You can however run a command with ' . 'sudo using --allow-root option');
             }
         }
         DaemonUtils::configCheck();
         //Check daemons
         $daemons = DaemonUtils::getDaemonsFromConfig();
         foreach ($daemons as $daemon) {
             if (!$daemon instanceof DaemonizerInterface) {
                 throw new \Exception('Invalid [cli-daemonizer.php] file: file contain not-implementer ' . 'DaemonizerInterface class');
             }
             DaemonUtils::checkScheduleItem($daemon->getSchedule(), get_class($daemon));
         }
         $id = mt_rand(1, 100000);
         shell_exec(DAEMON_FILE . " internal:master --id={$id} > /dev/null 2>&1 &");
         $output->writeln("<info>Daemon started</info>");
     } catch (\Exception $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
     }
 }
 public function checkPermissions()
 {
     // Check we have permissions to create project and run system events
     if (posix_geteuid() != 0) {
         throw new Project_Creation_Exception("You need to be root to create a project for import");
     }
 }
 /**
  * Вход в управление сервисом Pinger.
  * 
  * @param array $argv Копия массива <code>$argv</code> с аргументами вызова скрипта.
  * @access public
  * @static
  */
 public static function main($argv)
 {
     if ('cli' !== PHP_SAPI) {
         echo "CLI only!\n";
         exit(1);
     }
     if (0 !== posix_geteuid()) {
         echo "Error: Pinger Service must be launched as root!\n";
         exit(1);
     }
     $argv += array_fill(0, 4, null);
     switch ($argv[1]) {
         case 'start':
             static::cmdStart();
             break;
         case 'stop':
             static::cmdStop();
             break;
         case 'restart':
             static::cmdRestart();
             break;
         case 'reload':
             static::cmdReload();
             break;
         case 'status':
             static::cmdStatus();
             break;
         case 'help':
         default:
             static::cmdHelp($argv[1], $argv[2]);
             break;
     }
     exit(0);
 }
 public function testChangeGroup()
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         $this->markTestSkipped("chown tests don't work on Windows");
     }
     $userinfo = posix_getpwuid(posix_geteuid());
     $username = $userinfo['name'];
     //we may change the group only if we belong to it
     //so find a group that we are in
     $group = null;
     foreach (array('users', 'www-data', 'cdrom') as $groupname) {
         $grpinfo = posix_getgrnam($groupname);
         if ($grpinfo['gid'] == $userinfo['gid']) {
             //current group id, the file has that group anyway
             continue;
         }
         if (in_array($username, $grpinfo['members'])) {
             $group = $grpinfo;
             break;
         }
     }
     if ($group === null) {
         $this->markTestSkipped('found no group we can change ownership to');
     }
     $this->project->setUserProperty('targetuser', $username . '.' . $group['name']);
     $this->executeTarget(__FUNCTION__);
     $a = stat(PHING_TEST_BASE . '/etc/tasks/system/tmp/chowntestA');
     $b = stat(PHING_TEST_BASE . '/etc/tasks/system/tmp/chowntestB');
     $this->assertNotEquals($group['gid'], $a['gid'], 'chowntestA group should not have changed');
     $this->assertEquals($group['gid'], $b['gid'], 'chowntestB group should have changed');
 }
Example #17
0
/**
 * @version $Id: footer.php 107 2008-07-22 17:27:12Z soeren $
 * @package eXtplorer
 * @copyright soeren 2007
 * @author The eXtplorer project (http://sourceforge.net/projects/extplorer)
 * @author The  The QuiX project (http://quixplorer.sourceforge.net)
 * 
 * @license
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * Alternatively, the contents of this file may be used under the terms
 * of the GNU General Public License Version 2 or later (the "GPL"), in
 * which case the provisions of the GPL are applicable instead of
 * those above. If you wish to allow use of your version of this file only
 * under the terms of the GPL and not to allow others to use
 * your version of this file under the MPL, indicate your decision by
 * deleting  the provisions above and replace  them with the notice and
 * other provisions required by the GPL.  If you do not delete
 * the provisions above, a recipient may use your version of this file
 * under either the MPL or the GPL."
 * 
 * Shows the About Box!
 */
function show_about()
{
    // footer for html-page
    echo "\n<div id=\"ext_footer\" style=\"text-align:center;\">\r\n\t<img src=\"" . _EXT_URL . "/images/MangosWeb_small.png\" align=\"middle\" alt=\"Mangosweb Enhanced Logo\" />\r\n\t<br />\r\n\t" . ext_Lang::msg('your_version') . ": <a href=\"" . $GLOBALS['ext_home'] . "\" target=\"_blank\">eXtplorer {$GLOBALS['ext_version']}</a>\r\n\t<br />\r\n (<a href=\"http://virtuemart.net/index2.php?option=com_versions&amp;catid=5&amp;myVersion=" . $GLOBALS['ext_version'] . "\" onclick=\"javascript:void window.open('http://virtuemart.net/index2.php?option=com_versions&catid=5&myVersion=" . $GLOBALS['ext_version'] . "', 'win2', 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=580,directories=no,location=no'); return false;\" title=\"" . $GLOBALS["messages"]["check_version"] . "\">" . $GLOBALS["messages"]["check_version"] . "</a>)\r\n\t\r\n\t";
    if (function_exists("disk_free_space")) {
        $size = disk_free_space($GLOBALS['home_dir'] . $GLOBALS['separator']);
        $free = parse_file_size($size);
    } elseif (function_exists("diskfreespace")) {
        $size = diskfreespace($GLOBALS['home_dir'] . $GLOBALS['separator']);
        $free = parse_file_size($size);
    } else {
        $free = "?";
    }
    echo '<br />' . $GLOBALS["messages"]["miscfree"] . ": " . $free . " \n";
    if (extension_loaded("posix")) {
        $owner_info = '<br /><br />' . ext_Lang::msg('current_user') . ' ';
        if (ext_isFTPMode()) {
            $my_user_info = posix_getpwnam($_SESSION['ftp_login']);
            $my_group_info = posix_getgrgid($my_user_info['gid']);
        } else {
            $my_user_info = posix_getpwuid(posix_geteuid());
            $my_group_info = posix_getgrgid(posix_getegid());
        }
        $owner_info .= $my_user_info['name'] . ' (' . $my_user_info['uid'] . '), ' . $my_group_info['name'] . ' (' . $my_group_info['gid'] . ')';
        echo $owner_info;
    }
    echo "\r\n\t</div>";
}
 /**
  * Initializes the identifier prefix when setting the cache.
  *
  * @param t3lib_cache_frontend_Frontend $cache The frontend for this backend
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 public function setCache(t3lib_cache_frontend_Frontend $cache)
 {
     parent::setCache($cache);
     $processUser = extension_loaded('posix') ? posix_getpwuid(posix_geteuid()) : array('name' => 'default');
     $pathHash = t3lib_div::shortMD5(PATH_site . $processUser['name'], 12);
     $this->identifierPrefix = 'TYPO3_' . $pathHash;
 }
Example #19
0
File: Sys.php Project: jbzoo/utils
 /**
  * Check is current user ROOT
  *
  * @return bool
  */
 public static function isRoot()
 {
     if (self::isFunc('posix_geteuid')) {
         return posix_geteuid() === 0;
     }
     return false;
     // @codeCoverageIgnore
 }
 /**
  * Ensures that the user is running this PHP script with root
  * permissions. If not running with root permissions, causes the
  * script to exit.
  */
 public static function ExitIfNotRoot()
 {
     // Need to check that we are superuser before running this.
     if (posix_geteuid() != 0) {
         echo "Must be root user.\n";
         exit(1);
     }
 }
 /**
  * Get Current User
  *
  * @return string
  */
 public static function getCurrentUser()
 {
     $processUser = posix_getpwuid(posix_geteuid());
     if (true === isset($processUser['name'])) {
         return $processUser['name'];
     }
     return get_current_user();
 }
 public function preUp()
 {
     $processUser = posix_getpwuid(posix_geteuid());
     $username = $processUser['name'];
     if ($username != 'root') {
         throw new Exception('Must be root to run this upgrade');
     }
 }
function GetMailAccount($strNickname, $service = 'imap')
{
    // make CSV file full path
    $info = posix_getpwuid(posix_geteuid());
    // get user HOME dir
    $strDataFileName = $info['dir'] . '/auth/data/mailaccount.csv';
    // return data (mail account data)
    $aryAccount = array('protocol' => '', 'server' => '', 'port' => '', 'user' => '', 'password' => '');
    $hFile = fopen($strDataFileName, 'r');
    if ($hFile == FALSE) {
        // open error, return blank array
        return $aryAccount;
    }
    while (!feof($hFile)) {
        $strTmp = rtrim(fgets($hFile));
        if (strlen($strTmp) < 1) {
            continue;
        }
        if (!strcmp(substr($strTmp[0], 0, 1), '#')) {
            // comment line (begin with '#')
            continue;
        }
        $aryData = explode(',', $strTmp);
        if (count($aryData) != 8) {
            // vaild data line is 8 column
            continue;
        }
        // find first nickname matched line
        if (!strcmp($aryData[0], $strNickname) && stripos($aryData[4], $service) !== false) {
            $aryAccount['server'] = $aryData[1];
            $aryAccount['user'] = $aryData[2];
            $aryAccount['password'] = $aryData[3];
            $aryAccount['protocol'] = strtolower($service);
            switch ($service) {
                case 'imap':
                    $aryAccount['port'] = $aryData[5];
                    break;
                case 'pop3':
                    $aryAccount['port'] = $aryData[6];
                    break;
                case 'smtp':
                    $aryAccount['port'] = $aryData[7];
                    break;
                default:
                    $aryAccount['port'] = '';
                    break;
            }
            break;
        }
    }
    fclose($hFile);
    // if port_no is blank, reset all value of array
    if (strlen($aryAccount['port']) <= 0) {
        $aryAccount = array('protocol' => '', 'server' => '', 'port' => '', 'user' => '', 'password' => '');
    }
    return $aryAccount;
}
function gs_asterisks_reload($host_ids, $dialplan_only)
{
    $dialplan_only = !!$dialplan_only;
    if (!$host_ids || !is_array($host_ids)) {
        $host_ids = false;
    }
    # connect to db
    #
    $db = gs_db_master_connect();
    if (!$db) {
        return new GsError('Could not connect to database.');
    }
    # get hosts
    #
    $hosts = @gs_hosts_get();
    if (isGsError($hosts)) {
        return new GsError($hosts->getMsg());
    }
    if (!is_array($hosts)) {
        return new GsError('Failed to get hosts.');
    }
    $GS_INSTALLATION_TYPE_SINGLE = gs_get_conf('GS_INSTALLATION_TYPE_SINGLE');
    if (!$GS_INSTALLATION_TYPE_SINGLE) {
        # get our host IDs
        #
        $our_host_ids = @gs_get_listen_to_ids();
        if (isGsError($our_host_ids)) {
            return new GsError($our_host_ids->getMsg());
        }
        if (!is_array($our_host_ids)) {
            return new GsError('Failed to get our host IDs.');
        }
    }
    # are we root? do we have to sudo?
    #
    $uid = @posix_geteuid();
    $uinfo = @posix_getPwUid($uid);
    $uname = @$uinfo['name'];
    $sudo = $uname == 'root' ? '' : 'sudo ';
    $ok = true;
    foreach ($hosts as $host) {
        if (!$host_ids || in_array($host['id'], $host_ids)) {
            $cmd = '/opt/gemeinschaft/sbin/start-asterisk' . ($dialplan_only ? ' --dialplan' : '');
            if (!$GS_INSTALLATION_TYPE_SINGLE && !in_array($host['id'], $our_host_ids)) {
                # this is not the local node
                $cmd = $sudo . 'ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root ' . qsa($host['host']) . ' ' . qsa($cmd);
            }
            @exec($sudo . $cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err);
            $ok = $ok && $err == 0;
        }
    }
    if (!$ok) {
        return new GsError('Failed to reload Asterisks.');
    }
    return true;
}
 public function __construct($opts = FALSE, $args = FALSE)
 {
     parent::__construct($opts, $args);
     $this->site_info = new \GR\SiteInfo();
     $this->type = \GR\Hash::fetch($opts, 'type', $this->site_info->environment);
     $this->set_database_credentials();
     $this->domain = \GR\Hash::fetch($opts, 'domain', 'giantrabbit.com');
     $process_user = posix_getpwuid(posix_geteuid());
     $this->alias = \GR\Hash::fetch($opts, 'alias', $process_user['name']);
 }
Example #26
0
 protected function setUsersGid()
 {
     // figure out the GID for "users" for tests
     $this->usersGid = 1000;
     // default
     if (posix_geteuid() === 0 && function_exists('posix_getgrnam')) {
         $info = posix_getgrnam('users');
         $this->usersGid = $info['gid'];
     }
 }
function dp_derive_gen_vhost()
{
    $user_info = posix_getpwuid(posix_geteuid());
    if (strlen($user_info['name']) > 2 && substr($user_info['name'], 0, 2) == "w_") {
        $vhost = substr($user_info['name'], 2);
    } else {
        $vhost = $user_info['name'];
    }
    return $vhost;
}
 function runAs($userName)
 {
     if (posix_getuid() != 0 && posix_geteuid() != 0) {
         return;
     }
     $this->user = posix_getpwnam($userName);
     if (!$this->user) {
         throw new \InvalidArgumentException("Cannot find user '{$userName}'.");
     }
 }
 public function __construct($logDir, $kernelDir)
 {
     if (function_exists('posix_getpwuid')) {
         $this->wwwUser = posix_getpwuid(posix_geteuid());
     } else {
         $this->wwwUser = array('name' => get_current_user(), 'dir' => '-');
     }
     $this->logDir = $logDir;
     $this->symfonyCommand = 'php ' . $kernelDir . '/console';
 }
 public function getSetupCommands()
 {
     if ($this->setup_commands) {
         return $this->setup_commands;
     }
     $user = posix_getpwuid(posix_geteuid());
     $user_name = $user['name'];
     $this->setup_commands = ["mkdir -p {$this->dnsmasq_dir} {$this->resolver_dir}", "touch {$this->dnsmasq_config}", "chown {$user_name}:admin {$this->dnsmasq_config} " . "{$this->dnsmasq_dir} {$this->resolver_dir}", "brew services start dnsmasq"];
     return $this->setup_commands;
 }