Example #1
0
 function preforward()
 {
     $form_file = $this->af->get('form_file');
     $form_file_p = $this->config->get('publish_dir') . $form_file . '.php';
     $form_file_m = $this->config->get('publish_dir') . $form_file . $this->config->get('mobile_suffix') . '.php';
     $published_p = is_file($form_file_p);
     $published_m = is_file($form_file_m);
     $type_options = array('p' => 'PC用テンプレートを作成', 'm' => '携帯用テンプレートを作成', 'r' => '既存テンプレートを再構築');
     $type = $this->af->get('type');
     if ($published_p || $published_m) {
         if ($type == null) {
             $type = 'r';
         }
     } else {
         $type = 'p';
         unset($type_options['r']);
     }
     $this->af->setApp('id', $this->af->get('id'));
     $this->af->setApp('index', $this->af->get('index'));
     $this->af->setApp('form_file', $form_file);
     $this->af->setApp('form_name', $this->af->get('form_name'));
     $this->af->setApp('type_options', $type_options);
     $this->af->setApp('type', $type);
     // filemtime
     clearStatCache();
     $list = array();
     if ($published_p) {
         $list[] = array('id' => 1, 'name' => 'PC用', 'file' => $form_file_p, 'time' => filemtime($form_file_p));
     }
     if ($published_m) {
         $list[] = array('id' => 2, 'name' => '携帯用', 'file' => $form_file_m, 'time' => filemtime($form_file_m));
     }
     $this->af->setApp('list', $list);
 }
Example #2
0
function _gs_ami_get_enabled()
{
    $conf_files_enabled = array();
    clearStatCache();
    $files = glob('/etc/gemeinschaft/asterisk/manager.conf.d-enabled/*.conf');
    foreach ($files as $filename) {
        $filename_basename = baseName($filename);
        $conf_files_enabled[] = $filename_basename;
    }
    unset($files);
    return $conf_files_enabled;
}
 /**
  * Return true, if an image file needs to be optimized. i.e. it is currenlty in an 'unoptimized' state.
  * @param $filename
  * @return bool
  */
 public function isUnoptimizedImage($filename)
 {
     $ret = true;
     $hash = $this->getHash($filename);
     $hashFilename = $this->getHashFilename($hash);
     if (is_readable($hashFilename)) {
         clearStatCache();
         $hashFile = file_get_contents($hashFilename);
         if ($hashFile === $this->getHashFile($filename)) {
             $ret = false;
         }
     }
     return $ret;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $history = new History();
     $imagesSearch = new ImagesSearch();
     $consolePadding = $this->getConsole()->padding($this->getLinePadding());
     $grandTotals = ['skipped' => 0, 'optimized' => 0, 'indexed' => 0, 'in' => 0, 'out' => 0, 'diff' => 0, 'diff_pct' => 0];
     $fileInfos = $imagesSearch->getFileInfos($this->getPath());
     $fileInfosCount = count($fileInfos);
     $fileInfosCounter = 0;
     $this->consoleBannerPrefix($fileInfosCount);
     foreach ($fileInfos as $fileInfo) {
         $fileInfosCounter++;
         $filename = $fileInfo->getPathname();
         if ($this->getIndexOnly()) {
             $consoleLabel = $this->labelHelper($fileInfosCount, $fileInfosCounter, $filename);
             $consolePadding->label($consoleLabel)->result('Indexed.');
             $history->setImageAsOptimized($filename);
             $grandTotals['indexed']++;
             continue;
         }
         if ($history->isUnoptimizedImage($filename)) {
             $subTotals = ['in' => filesize($filename), 'out' => 0, 'diff' => 0, 'diff_pct' => 0];
             $consoleLabel = $this->labelHelper($fileInfosCount, $fileInfosCounter, $filename);
             $consoleCurrentPadding = $consolePadding->label($consoleLabel);
             if ($this->optimizeImage($filename)) {
                 clearStatCache();
                 $subTotals['out'] = filesize($filename);
                 $subTotals['diff'] = $subTotals['in'] - $subTotals['out'];
                 if ($subTotals['out'] > 0 && $subTotals['in'] > 0) {
                     $subTotals['diff_pct'] = 100 - $subTotals['out'] / $subTotals['in'] * 100;
                 }
                 $consoleCurrentResult = sprintf('Saving: %01.4f %%.', $subTotals['diff_pct']);
                 $consoleCurrentPadding->result($consoleCurrentResult);
                 $grandTotals['in'] += $subTotals['in'];
                 $grandTotals['out'] += $subTotals['out'];
                 $history->setImageAsOptimized($filename);
                 $grandTotals['optimized']++;
             }
         } else {
             $consoleLabel = $this->labelHelper($fileInfosCount, $fileInfosCounter, $filename);
             $consolePadding->label($consoleLabel)->result('Skipped.');
             $grandTotals['skipped']++;
         }
     }
     $this->consoleGrandTotals($grandTotals, $fileInfosCount);
     $this->consoleBannerSuffix();
     return $this;
 }
Example #5
0
function gs_hylafax_authfile_sync($authfile = '')
{
    # It will be assumed that the server is accessible, that the file
    # exists and that the admin account exists otherwise the
    # connection will fail.
    # There is a fallback mechanism which copies the file instead of
    # FTP put'ting it if the fax server is running on the local machine.
    if (!$authfile) {
        $authfile = '/tmp/gs-hylafax-hosts.hfaxd-' . rand(100000, 999999);
    }
    # create authfile locally
    #
    $result = gs_hylafax_authfile_create($authfile);
    if ($result !== true) {
        clearStatCache();
        if (file_exists($authfile)) {
            @exec('sudo rm -f ' . qsa($authfile) . ' 2>>/dev/null');
        }
        return $result;
    }
    # put authfile to the fax server
    #
    $ret = gs_hylafax_authfile_put($authfile);
    if ($ret !== true) {
        # if ftp put fails, try to copy it locally.
        //FIXME: Will fail if the fax host is not "127.0.0.1" or "localhost"
        #
        if (gs_get_conf('GS_FAX_HYLAFAX_HOST') === '127.0.0.1' || gs_get_conf('GS_FAX_HYLAFAX_HOST') === 'localhost') {
            $authfile_dst = gs_get_conf('GS_FAX_HYLAFAX_PATH', '/var/spool/hylafax/') . 'etc/hosts.hfaxd';
            $err = 0;
            $out = array();
            @exec('sudo mv ' . qsa($authfile) . ' ' . qsa($authfile_dst) . ' 2>>/dev/null', $out, $err);
            if ($err !== 0) {
                @exec('sudo rm -f ' . qsa($authfile) . ' 2>>/dev/null');
                return new GsError('Error updating fax authentication on localhost.');
            }
            $err = 0;
            $out = array();
            @exec('sudo chown ' . qsa(gs_get_conf('GS_FAX_HYLAFAX_USER', 'uucp')) . ' ' . qsa($authfile_dst) . ' 2>>/dev/null', $out, $err);
            if ($err != 0) {
                @exec('sudo rm -f ' . qsa($authfile) . ' 2>>/dev/null');
                return new GsError('Error updating fax authentication on localhost.');
            }
            $err = 0;
            $out = array();
            @exec('sudo chmod ' . '0600' . ' ' . qsa($authfile_dst) . ' 2>>/dev/null', $out, $err);
            if ($err !== 0) {
                @exec('sudo rm -f ' . qsa($authfile) . ' 2>>/dev/null');
                return new GsError('Error updating fax authentication on localhost.');
            }
            $ret = true;
            @exec('sudo rm -f ' . qsa($authfile) . ' 2>>/dev/null');
            if (@is_dir('/etc/hylafax')) {
                # Debian
                @exec('sudo cp ' . qsa($authfile_dst) . ' ' . qsa('/etc/hylafax/hosts.hfaxd') . ' 2>>/dev/null');
            }
        }
    }
    clearStatCache();
    if (file_exists($authfile)) {
        @exec('sudo rm -f ' . qsa($authfile) . ' 2>>/dev/null');
    }
    return $ret;
}
Example #6
0
    if (!file_exists($download_script)) {
        echo 'Error.';
        return;
    }
    //$download_script = '/opt/gpbx-svn/trunk/deb-factory/custom/gemeinschaft/usr-local-bin-gpbx-upgrade-download';
    $err = 0;
    $out = array();
    @exec('sudo sh -c ' . qsa($download_script . ' ' . qsa($gpbx_upgrade_script) . ' ' . qsa($gpbx_upgrade_file) . ' ' . qsa(($content_length_mb + 4) * 1000000) . ' ' . qsa('GPBX') . ' 1>>/dev/null 2>>/dev/null &') . ' 0<&- 1>&- 2>&- &', $out, $err);
    //echo $err;
    //echo "<pre>", implode("\n",$out) ,"</pre>";
    if ($err !== 0) {
        echo 'Fehler.';
        return;
    }
    sleep(4);
    clearStatCache();
}
# download in progress?
#
if (file_exists('/tmp/gpbx-downloading-upgrade.pid') || (int) @shell_exec('sudo ps ax 2>>/dev/null | grep gpbx-upgrade-download | grep -v grep | wc -l') > 0) {
    echo '<br /><p>', 'Momentan wird ein Upgrade heruntergeladen.', '</p>', "\n";
    $upgrade_info = @gs_file_get_contents($gpbx_userdata . 'upgrades/upgrade-info');
    //$upgrade_info = ' gpbx_upgrade_size = 250420000 ';
    if (preg_match('/^\\s*gpbx_upgrade_size\\s*=\\s*([^\\s]*)/m', $upgrade_info, $m)) {
        $upgrade_size = (int) _upgrade_info_decode_val($m[1]);
        if ($upgrade_size > 50) {
            if (file_exists($gpbx_userdata . 'upgrades/dl/download')) {
                $download_size = @fileSize($gpbx_userdata . 'upgrades/dl/download');
                //$download_size = 210420000;
                if ($download_size !== false) {
                    echo '<p>', 'Fortschritt', ': &nbsp; <b>', number_format($download_size / $upgrade_size * 100, 1, ',', ''), ' %</b>';
Example #7
0
File: log.php Project: rkania/GS3
function gs_log($level, $msg, $logfile = null, $fifo = false)
{
    global $gs_is_in_gs_log;
    static $log_to = null;
    static $logfiles = array();
    static $levels = array(GS_LOG_DEBUG => array('v' => 'debug', 'sll' => LOG_DEBUG), GS_LOG_NOTICE => array('v' => 'note', 'sll' => LOG_INFO), GS_LOG_WARNING => array('v' => 'WARN', 'sll' => LOG_WARNING), GS_LOG_FATAL => array('v' => 'ERROR', 'sll' => LOG_ERR));
    static $syslog_opened = false;
    static $syslog_facility = null;
    if (@$gs_is_in_gs_log) {
        return false;
    }
    # prevent recursive calls to gs_log()
    if ($level > GS_LOG_LEVEL) {
        return true;
    }
    $gs_is_in_gs_log = true;
    if ($log_to === null) {
        $log_to = gs_get_conf('GS_LOG_TO');
    }
    $level_info = array_key_exists($level, $levels) ? $levels[$level] : array('v' => '???? ', 'sll' => LOG_WARNING);
    //$msg = str_replace(GS_DIR, '<GS_DIR>', $msg);
    $msg = str_replace(GS_DIR, '', $msg);
    $backtrace = debug_backtrace();
    if (is_array($backtrace) && isset($backtrace[0])) {
        $file = @$backtrace[0]['file'];
        if (subStr($file, 0, strLen(GS_DIR)) === GS_DIR) {
            $file = str_replace(GS_DIR, '', $file);
        }
        $line = @$backtrace[0]['line'];
    } else {
        $file = '';
        $line = 0;
    }
    if ($fifo) {
        $log_to = 'file';
    }
    if ($log_to === 'file') {
        $dateFn = GS_LOG_GMT ? 'gmDate' : 'date';
        if (strLen($line) < 4) {
            $line = str_pad($line, 4, ' ', STR_PAD_LEFT);
        }
        $msg = $dateFn('Y-m-d H:i:s') . ' [' . str_pad($level_info['v'], 5) . '] ' . $file . ':' . $line . ': ' . $msg . "\n";
        if (!$logfile) {
            $logfile = GS_LOG_FILE;
        }
        if (@subStr($logfile, 0, 1) != '/') {
            $logfile = '/var/log/gemeinschaft/' . $logfile;
        }
        if (!@array_key_exists($logfile, $logfiles)) {
            $sudo = posix_getEUid() == 0 ? '' : 'sudo ';
            # if the logfile should be a fifo but isn't then remove it so
            # it will be created as a fifo
            if ($fifo && file_exists($logfile) && !@is_fifo($logfile)) {
                $err = 0;
                $out = array();
                @exec($sudo . 'rm -f ' . qsa($logfile) . ' 1>>/dev/null 2>>/dev/null', $out, $err);
                if ($err != 0) {
                    # probably permission denied
                    $gs_is_in_gs_log = false;
                    return false;
                }
                clearStatCache();
            }
            if (!@file_exists($logfile)) {
                $err = 0;
                $out = array();
                @exec($sudo . 'mkdir -p ' . qsa(dirName($logfile)) . ' 1>>/dev/null 2>>/dev/null', $out, $err);
                if ($err != 0) {
                    # probably permission denied
                    $gs_is_in_gs_log = false;
                    return false;
                }
                if ($fifo) {
                    $err = 0;
                    $out = array();
                    @exec($sudo . 'mkfifo ' . qsa($logfile) . ' 1>>/dev/null 2>>/dev/null', $out, $err);
                    if ($err != 0) {
                        # probably permission denied
                        $gs_is_in_gs_log = false;
                        return false;
                    }
                }
            }
            //@chmod($logfile, 0666);  # in octal mode!
            @exec($sudo . 'chmod 0666 ' . qsa($logfile) . ' 1>>/dev/null 2>>/dev/null');
            if (!$fifo) {
                $logfiles[$logfile] = @fOpen($logfile, 'ab');
                # might fail if permission denied
            } else {
                $logfiles[$logfile] = fOpen($logfile, 'ab+');
                # The trick is to open the FIFO for reading *and writing*.
                # "a" : open(..., O_WRONLY|O_CREAT|O_APPEND|O_LARGEFILE, ...)
                # "a+": open(..., O_RDWR  |O_CREAT|O_APPEND|O_LARGEFILE, ...)
                # O_WRONLY blocks for FIFOs. O_RDWR does not.
            }
            if (!$logfiles[$logfile]) {
                $gs_is_in_gs_log = false;
                return false;
            }
        }
        if ($fifo) {
            @stream_set_blocking($fd, false);
            # not even really needed
            # Just to be sure check that the stream will not block.
            # However by using the above trick it will not block anyways.
            $select = array($logfiles[$logfile]);
            # needs to be passed by reference
            $null = null;
            # needs to be passed by reference
            if (stream_select($null, $select, $null, 0, 0) < 1) {
                $gs_is_in_gs_log = false;
                return false;
            }
        }
        $ok = @fWrite($logfiles[$logfile], $msg, strLen($msg)) !== false;
    } elseif ($log_to === 'syslog') {
        if ($syslog_facility === null) {
            $fac_name = strToUpper(gs_get_conf('GS_LOG_SYSLOG_FACILITY'));
            if (in_array($fac_name, array('LOCAL0', 'LOCAL1', 'LOCAL2', 'LOCAL3', 'LOCAL4', 'LOCAL5', 'LOCAL6', 'LOCAL7', 'USER', 'MAIL', 'DAEMON', 'AUTH', 'AUTHPRIV', 'SYSLOG', 'LPR', 'NEWS', 'UUCP', 'CRON'), true) && defined('LOG_' . $fac_name)) {
                $syslog_facility = constant('LOG_' . $fac_name);
            } else {
                $syslog_facility = LOG_USER;
            }
        }
        if (subStr($file, -4) === '.php') {
            $file = subStr($file, 0, -4);
        }
        if (strLen($file) <= 32) {
            $tag = $file;
        } else {
            $tag = baseName($file);
        }
        $msg = $tag . '#' . $line . ': (' . $level_info['v'] . ') ' . $msg;
        if (!$syslog_opened) {
            if (!$syslog_facility) {
                $syslog_facility = LOG_LOCAL5;
            }
            $syslog_opened = @openLog('gemeinschaft', LOG_ODELAY, $syslog_facility);
        }
        $sll = @$level_info['sll'];
        if ($sll === null) {
            $sll = LOG_WARNING;
        }
        $ok = @sysLog($sll, addCSlashes($msg, "\\\r\n\t....ÿ"));
    } else {
        $ok = false;
    }
    $gs_is_in_gs_log = false;
    return $ok;
}