Esempio n. 1
0
function getRevisionAuthor($rev)
{
    $xmlLines = OS::executeAndReturnOutput("svn log -c {$rev} --xml");
    $xmlString = implode('', $xmlLines);
    $xml = simplexml_load_string($xmlString);
    return (string) $xml->logentry->author;
}
Esempio n. 2
0
 public function update()
 {
     if (isset($this->config['build'])) {
         OS::run('cd ' . OS::bashize($this->directory) . ';git pull');
         $this->readConfig();
     }
 }
Esempio n. 3
0
function db_executeSqlFile($filename)
{
    $dsn = Config::get('global.database');
    $parts = db_splitDsn($dsn);
    $command = sprintf("cat {$filename} | mysql -u %s %s %s", $parts['user'], $parts['database'], $parts['password'] ? "-p" . $parts['password'] : '');
    OS::executeAndAssert($command);
}
Esempio n. 4
0
function parseArguments()
{
    global $argv;
    $verbose = false;
    $fileName = FILE_NAME;
    for ($i = 1; $i < count($argv); $i++) {
        $arg = $argv[$i];
        if ($arg == "-v") {
            $verbose = true;
        } else {
            if ($arg == '-f') {
                $i++;
                $fileName = $argv[$i];
            } else {
                if ($arg == '-t') {
                    runTestSuite();
                    exit;
                } else {
                    OS::errorAndExit("Unknown flag: {$arg}");
                }
            }
        }
    }
    return array($verbose, $fileName);
}
Esempio n. 5
0
 public function run(array $arguments)
 {
     foreach ($arguments as $dep) {
         echo "* Removing {$dep}...\n";
         $dir = $this->deps->getPackageDirectory($dep);
         OS::run("rm -rf {$dir}");
     }
     return true;
 }
function closeCurrentFile()
{
    global $g_numFiles;
    global $g_curFileName;
    global $g_curFile;
    fprintf($g_curFile, "</urlset>\n");
    fclose($g_curFile);
    OS::executeAndAssert("gzip - < {$g_curFileName} > wwwbase/sitemap{$g_numFiles}.xml.gz");
    util_deleteFile($g_curFileName);
}
Esempio n. 7
0
 public static function bold($message)
 {
     if (!OS::isWindows()) {
         echo "";
     }
     echo $message;
     if (!OS::isWindows()) {
         echo "";
     }
 }
function GetWotdFromSubject($subject)
{
    $parts = preg_split("/\\s+/", trim($subject));
    if (count($parts) != 2) {
        OS::errorAndExit("Ignoring message '{$subject}' due to invalid subject", 0);
    }
    if ($parts[0] != Config::get('WotD.password')) {
        OS::errorAndExit("Ignoring message '{$subject}' due to invalid password in the subject", 0);
    }
    return $parts[1];
}
Esempio n. 9
0
 /** @return lat_lng_bound */
 public function get_grid_cell()
 {
     /** @var lat_lng_bound $cell */
     foreach (OS::cells() as $cell) {
         if ($cell->contains($this)) {
             return $cell;
         }
     }
     $bound = new \stdClass();
     $bound->code = 'N/A';
     return $bound;
 }
Esempio n. 10
0
 public function ensureThumbnail()
 {
     if (!$this->image) {
         return;
     }
     $fullImage = self::$IMAGE_DIR . "/{$this->image}";
     $fullThumb = self::$THUMB_DIR . "/{$this->image}";
     if (!file_exists($fullThumb) && file_exists($fullImage)) {
         $oldumask = umask(0);
         @mkdir(dirname($fullThumb), 0777, true);
         umask($oldumask);
         OS::executeAndAssert(sprintf("convert -strip -geometry %dx%d -sharpen 1x1 '%s' '%s'", self::$THUMB_SIZE, self::$THUMB_SIZE, $fullImage, $fullThumb));
     }
 }
Esempio n. 11
0
function recursiveScan($path, $logFile)
{
    global $IGNORED_DIRS, $EXTENSIONS, $beforeBytes, $afterBytes;
    $files = scandir($path);
    foreach ($files as $file) {
        if (in_array($file, $IGNORED_DIRS)) {
            continue;
        }
        $full = "{$path}/{$file}";
        if (is_dir($full)) {
            recursiveScan($full, $logFile);
        } else {
            $extension = pathinfo(strtolower($full), PATHINFO_EXTENSION);
            $fullNoExt = substr($full, 0, strlen($full) - strlen($extension) - 1);
            // Strip the dot as well
            if (in_array($extension, $EXTENSIONS)) {
                OS::executeAndAssert("convert -strip '{$full}' '" . Config::get('global.tempDir') . "/fileNoExif.{$extension}'");
                OS::executeAndAssert("convert '" . Config::get('global.tempDir') . "/fileNoExif.{$extension}' '/fileNoExifPng.png'");
                OS::executeAndAssert("optipng '" . Config::get('global.tempDir') . "/fileNoExifPng.png'");
                $fs1 = filesize($full);
                $fs2 = filesize(Config::get('global.tempDir') . "/fileNoExif.{$extension}");
                $fs3 = filesize(Config::get('global.tempDir') . '/fileNoExifPng.png');
                $beforeBytes += $fs1;
                if ($fs3 < $fs1 && $fs3 < $fs2) {
                    $compression = 100.0 * (1 - $fs3 / $fs1);
                    $afterBytes += $fs3;
                    fprintf($logFile, "%s -- Strip EXIF, convert to PNG and optimize: %d/%d bytes, %.2f%% saved\n", $full, $fs3, $fs1, $compression);
                    unlink($full);
                    unlink(Config::get('global.tempDir') . "/fileNoExif.{$extension}");
                    rename(Config::get('global.tempDir') . '/fileNoExifPng.png', "{$fullNoExt}.png");
                } else {
                    if ($fs2 < $fs1) {
                        $compression = 100.0 * (1 - $fs2 / $fs1);
                        $afterBytes += $fs2;
                        fprintf($logFile, "%s -- Strip EXIF: %d/%d bytes, %.2f%% saved\n", $full, $fs2, $fs1, $compression);
                        unlink($full);
                        rename(Config::get('global.tempDir') . "/fileNoExif.{$extension}", $full);
                        unlink(Config::get('global.tempDir') . '/fileNoExifPng.png');
                    } else {
                        $afterBytes += $fs1;
                        fprintf($logFile, "{$full} -- leave unchanged\n");
                        unlink(Config::get('global.tempDir') . "/fileNoExif.{$extension}");
                        unlink(Config::get('global.tempDir') . '/fileNoExifPng.png');
                    }
                }
            }
        }
    }
}
Esempio n. 12
0
 function createThumb()
 {
     $url = Config::get('static.url') . self::STATIC_DIR . $this->path;
     $ext = pathinfo($url, PATHINFO_EXTENSION);
     $localFile = "/tmp/a.{$ext}";
     $localThumbFile = "/tmp/thumb.{$ext}";
     $contents = file_get_contents($url);
     file_put_contents($localFile, $contents);
     $command = sprintf("convert -strip -geometry %sx%s -sharpen 1x1 '%s' '%s'", self::THUMB_SIZE, self::THUMB_SIZE, $localFile, $localThumbFile);
     OS::executeAndAssert($command);
     $f = new FtpUtil();
     $f->staticServerPut($localThumbFile, self::STATIC_THUMB_DIR . $this->path);
     unlink($localFile);
     unlink($localThumbFile);
 }
Esempio n. 13
0
 /**
  * build the global Error object and create the WMI connection
  */
 public function __construct()
 {
     parent::__construct();
     // don't set this params for local connection, it will not work
     $strHostname = '';
     $strUser = '';
     $strPassword = '';
     // initialize the wmi object
     $objLocator = new COM('WbemScripting.SWbemLocator');
     if ($strHostname == "") {
         $this->_wmi = $objLocator->ConnectServer();
     } else {
         $this->_wmi = $objLocator->ConnectServer($strHostname, 'rootcimv2', $strHostname . '\\' . $strUser, $strPassword);
     }
     $this->_getCodeSet();
 }
Esempio n. 14
0
 public function run(array $arguments)
 {
     $json = $this->deps->nearestJson();
     $linkDir = dirname($json);
     $package = new Package(dirname($json));
     $name = $package->getName();
     if (!$name) {
         echo "Error: no name for package\n";
     } else {
         echo "* Linking package {$name} to {$linkDir}...\n";
         $dir = $this->deps->getPackageDirectory($package->getName());
         if (is_dir($dir)) {
             OS::run("rm -rf {$dir}");
         }
         OS::run("ln -s {$linkDir} {$dir}");
     }
 }
 /**
  * build the global Error object and create the WMI connection
  */
 public function __construct()
 {
     parent::__construct();
     // don't set this params for local connection, it will not work
     $strHostname = '';
     $strUser = '';
     $strPassword = '';
     try {
         // initialize the wmi object
         $objLocator = new COM('WbemScripting.SWbemLocator');
         if ($strHostname == "") {
             $this->_wmi = $objLocator->ConnectServer();
         } else {
             $this->_wmi = $objLocator->ConnectServer($strHostname, 'rootcimv2', $strHostname . '\\' . $strUser, $strPassword);
         }
     } catch (Exception $e) {
         $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
     }
     $this->_getCodeSet();
 }
Esempio n. 16
0
 public function run(array $arguments)
 {
     $json = $this->deps->nearestJson();
     $linkDir = dirname($json);
     $package = new Package(dirname($json));
     $name = $package->getName();
     if (!$name) {
         echo "Error: no name for package\n";
     } else {
         echo "Do you want to create symlink from {$name} to {$linkDir}? (yes/no)\n";
         $l = readline();
         if (trim($l) == 'yes') {
             echo "* Linking package {$name} to {$linkDir}...\n";
             $dir = $this->deps->getPackageDirectory($package->getName());
             if (is_dir($dir)) {
                 OS::run("rm -rf {$dir}");
             }
             OS::run("ln -s {$linkDir} {$dir}");
         } else {
             echo "Aborting.\n";
         }
     }
 }
Esempio n. 17
0
 /**
  * deleteContents of a folder recursively, but not the folder itself.
  *
  * On Windows systems this will try to remove the read-only attribute if needed.
  *
  * @param string $path Path of folder whose contents will be deleted
  *
  * @throws \RuntimeException Thrown when something could not be deleted.
  */
 public static function deleteContents($path)
 {
     if (!is_dir($path)) {
         return;
     }
     /** @var \SplFileInfo[] $files */
     $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($files as $fileInfo) {
         if ($fileInfo->isDir()) {
             if (@rmdir($fileInfo->getRealPath()) === false) {
                 throw new \RuntimeException(sprintf("Unable to delete child folder '%s' in '%s': %s", $fileInfo->getFilename(), $fileInfo->getPathname(), error_get_last()['message']));
             }
         } elseif (@unlink($fileInfo->getRealPath()) === false) {
             if (OS::isWindows()) {
                 Exec::create('attrib', '-R', $fileInfo->getRealPath())->run();
                 if (@unlink($fileInfo->getPathname())) {
                     continue;
                 }
             }
             throw new \RuntimeException(sprintf("Unable to delete file '%s' in folder '%s': %s", $fileInfo->getFilename(), $fileInfo->getPathname(), error_get_last()['message']));
         }
     }
 }
Esempio n. 18
0
 public function run(array $arguments)
 {
     Terminal::info("* Updating deps from git...\n");
     $dir = $this->deps->getDirectory();
     OS::run("cd {$dir}; git pull");
 }
Esempio n. 19
0
foreach ($schemaOnly as $table) {
    $command .= " {$table}";
}
$command .= " >> {$SQL_FILE}";
OS::executeAndAssert($command);
if (!$doFullDump) {
    // Anonymize the User table. Handle the case for id = 0 separately, since
    // "insert into _User_Copy set id = 0" doesn't work (it inserts an id of 1).
    log_scriptLog('Anonymizing the User table');
    db_execute("create table _User_Copy like User");
    db_execute("insert into _User_Copy select * from User where id = 0");
    db_execute("update _User_Copy set id = 0 where id = 1");
    db_execute("insert into _User_Copy select * from User where id > 0");
    db_execute("update _User_Copy set password = md5('1234'), email = concat(id, '@anonymous.com'), identity = null");
    OS::executeAndAssert("{$COMMON_COMMAND} _User_Copy | sed 's/_User_Copy/User/g' >> {$SQL_FILE}");
    db_execute("drop table _User_Copy");
    log_scriptLog('Anonymizing the Source table');
    db_execute("create table _Source_Copy like Source");
    db_execute("insert into _Source_Copy select * from Source");
    db_execute("update _Source_Copy set link = null");
    OS::executeAndAssert("{$COMMON_COMMAND} _Source_Copy | sed 's/_Source_Copy/Source/g' >> {$SQL_FILE}");
    db_execute("drop table _Source_Copy");
    // Dump only the Definitions for which we have redistribution rights
    log_scriptLog('Filtering the Definition table');
    OS::executeAndAssert("{$COMMON_COMMAND} Definition --lock-all-tables --where='Definition.sourceId in (select id from Source where canDistribute)' " . ">> {$SQL_FILE}");
}
OS::executeAndAssert("gzip -f {$SQL_FILE}");
$f = new FtpUtil();
$f->staticServerPut($GZ_FILE, $remoteFile);
unlink($GZ_FILE);
log_scriptLog('dumpDatabase.php completed successfully (against all odds)');
Esempio n. 20
0
 /**
  * call parent constructor
  */
 public function __construct()
 {
     parent::__construct();
     $this->error->addError("WARN", "The Minix version of phpSysInfo is work in progress, some things currently don't work");
 }
Esempio n. 21
0
 /**
  * call parent constructor
  */
 public function __construct()
 {
     parent::__construct();
 }
Esempio n. 22
0
function wgetAndGunzip($url)
{
    $tmpFile = tempnam(Config::get('global.tempDir'), 'xmldump_');
    OS::executeAndAssert("wget -q -O {$tmpFile}.gz {$url}");
    OS::executeAndAssert("gunzip -f {$tmpFile}.gz");
    return $tmpFile;
}
Esempio n. 23
0
File: Exec.php Progetto: nochso/omni
 /**
  * @param string $argument
  *
  * @return string
  */
 private function escapeArgument($argument)
 {
     // Always escape an empty argument so it doesn't get lost.
     if ($argument === '') {
         return escapeshellarg($argument);
     }
     if (!OS::isWindows()) {
         return $this->escapeLinuxArgument($argument);
     }
     return $this->escapeWindowsArgument($argument);
 }
Esempio n. 24
0
require_once "../phplib/util.php";
ini_set('max_execution_time', '3600');
define('DB_QUERY', 'select * from Lexem where isLoc order by formNoAccent');
$locVersion = util_getRequestParameter('locVersion');
$newLocVersion = util_getRequestParameter('newLocVersion');
if ($newLocVersion) {
    if ($locVersion == $newLocVersion) {
        FlashMessage::add('Ați selectat aceeași versiune LOC de două ori');
        util_redirect('scrabble-loc');
    }
    $file1 = tempnam('/tmp', 'loc_diff_');
    $file2 = tempnam('/tmp', 'loc_diff_');
    writeLexems($locVersion, $file1);
    writeLexems($newLocVersion, $file2);
    $diff = OS::executeAndReturnOutput("diff {$file1} {$file2} || true");
    print "<pre>\n";
    foreach ($diff as $line) {
        if (StringUtil::startsWith($line, '< ')) {
            print sprintf("<span style=\"color: red\">%s: %s</span>\n", $locVersion, substr($line, 2));
        } else {
            if (StringUtil::startsWith($line, '> ')) {
                print sprintf("<span style=\"color: green\">%s: %s</span>\n", $newLocVersion, substr($line, 2));
            }
        }
    }
    print "</pre>\n";
    util_deleteFile($file1);
    util_deleteFile($file2);
    exit;
}
Esempio n. 25
0
File: Deps.php Progetto: Rhoban/deps
 public function install($dep, $rebuildDeps = true)
 {
     if (isset($this->installed[$dep])) {
         return;
     }
     $this->installed[$dep] = true;
     if (!$this->hasPackage($dep)) {
         Terminal::info("* Installing {$dep}...\n");
         $target = $this->getPackageDirectory($dep);
         if (is_dir($target)) {
             OS::run("rm -rf {$target}");
         }
         $btarget = OS::bashize($target);
         $remotes = $this->remotes->getRemotes();
         $addr = $remotes[$this->remotes->getCurrent()];
         $addr = sprintf($addr, $dep);
         $return = OS::run("git clone --depth=1 {$addr} {$btarget}");
         if ($return != 0) {
             OS::run("rm -rf {$target}");
             throw new \Exception("Unable to install package {$dep}");
         }
         $package = new Package($target);
         if (!$package->hasConfig()) {
             OS::run("rm -rf {$btarget}");
             throw new \Exception("{$dep} doesn't look like a deps package (no deps.json)");
         }
         $package->updateRemotes($this->remotes, true);
         $this->packages[$package->getName()] = $package;
     } else {
         $this->update($dep);
         $package = $this->getPackage($dep);
     }
     $package->readConfig();
     foreach ($package->getDependencies() as $sdep) {
         if ($rebuildDeps) {
             $this->install($sdep);
         } else {
             if (!$this->hasPackage($sdep)) {
                 $this->install($sdep);
             }
         }
     }
     $this->build($dep);
 }
function isImage($fileName)
{
    // Check that the image exists
    $output = OS::executeAndReturnOutput("file \"{$fileName}\"");
    assert(count($output) == 1);
    if (strpos($output[0], 'JPEG image data') === false) {
        return IMG_NOT_JPEG;
    }
    $output = OS::executeAndReturnOutput("identify -verbose \"{$fileName}\" 2>&1 1>/dev/null");
    if (count($output)) {
        return IMG_CORRUPT;
        // because there are warnings
    }
    return IMG_NORMAL;
}
Esempio n. 27
0
 function postProcess($fileName)
 {
     $tmpFile = tempnam($this->tmpDir, 'loc_');
     log_scriptLog('* removing diacritics');
     $s = file_get_contents($fileName);
     $s = StringUtil::unicodeToLatin($s);
     file_put_contents($tmpFile, $s);
     log_scriptLog('* removing duplicates and sorting');
     OS::executeAndAssert("sort -u {$tmpFile} -o {$fileName}");
     unlink($tmpFile);
 }
Esempio n. 28
0
 /**
  * Get the total parent count of a class
  *
  * @param string $class Full classname or instance
  *
  * @return integer
  */
 protected function _getAncestorCount($class)
 {
     return count(OS::_getAncestors($class));
 }
<?php

require_once "../phplib/util.php";
$PS_COMMAND = 'ps -eo user,pid,etime,args --no-headers --sort etime';
$APACHE_USER = '******';
$PHP_EXECUTABLE = '/usr/lib/cgi-bin/php5';
$TIME_LIMIT = 3600;
/*seconds */
log_scriptLog('Running killOrphanPhpProcesses.php.');
$output = OS::executeAndReturnOutput($PS_COMMAND);
foreach ($output as $line) {
    $parts = preg_split('/ +/', $line, 4);
    $runningTime = getRunningTime($parts[2]);
    if ($parts[0] == $APACHE_USER && $runningTime > $TIME_LIMIT && $parts[3] == $PHP_EXECUTABLE) {
        log_scriptLog("killing process {$parts[1]}");
        OS::executeAndAssert("kill -9 {$parts[1]}");
    }
}
log_scriptLog('killOrphanPhpProcesses.php done.');
/****************************************************************************/
// ps gives us the running time in [[DD-]hh:]mm:ss format.
function getRunningTime($string)
{
    $matches = array();
    preg_match("/^(?:(?:(\\d+)-)?(\\d+):)?(\\d+):(\\d+)\$/", $string, $matches);
    return $matches[1] * 86400 + $matches[2] * 3600 + $matches[3] * 60 + $matches[4];
}
Esempio n. 30
0
require_once '../commons/base.inc.php';
try {
    // Send the dmi information.
    if ($_REQUEST['action'] == 'dmi') {
        print $FOGCore->getSetting('FOG_PLUGIN_CAPONE_DMI');
    } else {
        if ($_REQUEST['action'] == 'imagelookup' && $_REQUEST['key'] != null) {
            $key = trim(base64_decode(trim($_REQUEST['key'])));
            // Find the key association
            $Capones = $FOGCore->getClass('CaponeManager')->find();
            if ($FOGCore->getClass('CaponeManager')->count() > 0) {
                foreach ($Capones as $Capone) {
                    if (stristr($key, $Capone->get('key'))) {
                        $Image = new Image($Capone->get('imageID'));
                        $OS = new OS($Capone->get('osID'));
                        $StorageGroup = new StorageGroup($Image->get('storageGroupID'));
                        $StorageNode = $StorageGroup->getMasterStorageNode();
                        switch ($Image->get('imageTypeID')) {
                            case 1:
                                $imgType = 'n';
                                break;
                            case 2:
                                $imgType = 'mps';
                                break;
                            case 3:
                                $imgType = 'mpa';
                                break;
                            case 4:
                                $imgType = 'dd';
                                break;