Exemplo n.º 1
0
 public function getTempDir($suffix = '')
 {
     $dir = sprintf('%s/tmp%s', $this->bootLoader->getBaseDir(), $suffix ? "/{$suffix}" : '');
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     return $dir;
 }
Exemplo n.º 2
0
 public function index($jobs)
 {
     header('Content-type: text/plain');
     if ($cron_job = $jobs[0] ?? null) {
         if (!empty($cron_job->cron_job_id)) {
             $script = realpath(sprintf('%s/vendor/bin/script-runner', $this->bootLoader->getBaseDir()));
             $run_cmd = sprintf('%s --input="%d"', $script, $cron_job->cron_job_id);
             $output = $this->shell->capture($run_cmd);
             echo $output;
         }
     }
 }
Exemplo n.º 3
0
 public function write()
 {
     $pdo = $this->database->getConnection();
     $tables = $pdo->select(sprintf("SELECT TABLE_NAME as `table`, COLUMN_NAME as pk FROM information_schema.columns WHERE table_schema = '%s' AND COLUMN_KEY = 'PRI'", $pdo->getDatabaseName()));
     foreach ($tables as $table) {
         $name = $table->table;
         if (!$this->resolver->getModel($name)) {
             $path = sprintf('%s/app/Model/%s.php', $this->bootLoader->getBaseDir(), ucfirst(Str::camel(Str::singular("{$name}"))));
             if (!file_exists($path)) {
                 $this->writer->write($path, ['class' => $this->utils->filename($path), 'table' => $table->table, 'pk' => $table->pk], 'Created new model');
             }
         }
     }
 }
Exemplo n.º 4
0
 public function index($_jobs)
 {
     $lastRun = $this->config->get(self::cronKey . '/lastRun', 0);
     foreach ($_jobs as $job) {
         $schedules = json_decode($job->schedules_json);
         foreach ($schedules as $schedule) {
             $str = @join(' ', [$schedule->min, $schedule->hour, $schedule->daymonth, $schedule->month, $schedule->dayweek]);
             $cron = CronExpression::factory($str);
             $next = $cron->getNextRunDate()->format('Y-m-d H:i:s');
             if (empty($settings['schedules'][$job->cron_job_id]) || strtotime($settings['schedules'][$job->cron_job_id]) > strtotime($next)) {
                 $job->metadata = ['nextRun' => $next];
             }
         }
     }
     return (new View())->set('lastRun', time() - $lastRun)->set('baseDir', $this->bootLoader->getBaseDir());
 }
Exemplo n.º 5
0
 protected function getCacheDir()
 {
     $cacheDir = sprintf('%s/%s', $this->bootLoader->getBaseDir(), 'tmp/cache');
     if (!is_dir($cacheDir)) {
         mkdir($cacheDir, 0777, true);
     }
     return realpath($cacheDir);
 }
Exemplo n.º 6
0
 public function handle(RouterEvent $event)
 {
     if (php_sapi_name() === 'cli-server') {
         $method = $event->getMethod();
         if ($method === 'GET' && !$event->getRoute()) {
             $base = realpath($this->bootLoader->getBaseDir() . '/public');
             $filePath = realpath($base . '/' . ltrim($event->getPath(), '/'));
             $extension = pathinfo($filePath, PATHINFO_EXTENSION);
             if ($filePath && is_file($filePath) && preg_match('/^(css|js|jpg|jpeg|gif|png|mp3|mp4|map|woff|woff2|ttf)$/i', $extension)) {
                 if (strpos($filePath, $base) === 0 && $filePath != $base . DIRECTORY_SEPARATOR . 'index.php' && substr(basename($filePath), 0, 1) != '.') {
                     $mime = $this->mimeUtils->getMimeType($filePath);
                     header("Content-type: {$mime}");
                     readfile($filePath);
                     exit;
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 public function setup(HttpRequestEx $request)
 {
     $params = $request->getParameters();
     try {
         if (!empty($params['db']['database']) && !empty($params['db']['username']) && !empty($params['db']['password'])) {
             try {
                 $conn = $this->database->connect($params['db']);
                 if ($pdo = $conn->getPdo()) {
                     $conf = sprintf('%s/app/Config/db-config', $this->bootLoader->getBaseDir());
                     if (file_put_contents($conf, sprintf('mysql://%s:%s@%s/%s', $params['db']['username'], $params['db']['password'], $params['db']['host'], $params['db']['database']))) {
                         if ($this->installer->install(['minutephp/site'], 'require', true)) {
                             $sth = $pdo->prepare('REPLACE INTO users SET email = :email, password = :password, ip_addr = :ip, created_at = NOW(), updated_at = NOW(), first_name = "Admin", verified = "true"');
                             $sth->execute(['email' => sprintf('admin@%s', $params['site']['domain'] ?? 'localhost'), 'password' => password_hash(Str::random(), PASSWORD_DEFAULT), 'ip' => $this->sniffer->getUserIP()]);
                             if ($admin_id = $pdo->lastInsertId()) {
                                 $sth = $pdo->prepare('REPLACE INTO m_user_groups set user_id = :user_id, group_name = "admin", created_at = NOW(), updated_at = NOW(), 
                                                                        expires_at = "20200101", credits = 999, comments = "First run"');
                                 $sth->execute(['user_id' => $admin_id]);
                                 $types = ['public' => $params['site'] ?? [], 'private' => []];
                                 foreach ($types as $type => $data) {
                                     $sth = $pdo->prepare('REPLACE INTO m_configs set type = :type, data_json = :data');
                                     $sth->execute(['type' => $type, 'data' => json_encode($data)]);
                                 }
                                 $this->session->startSession($admin_id);
                                 return 'pass';
                             }
                         } else {
                             throw new FirstRunError($this->lang->getText("Unable to run composer"));
                         }
                     }
                 }
             } catch (\Throwable $e) {
                 throw new FirstRunError($this->lang->getText("Unable to connect to database.\n") . $e->getMessage());
             }
         }
         throw new FirstRunError($this->lang->getText('All connection parameters are required. Please check connection details'));
     } catch (\Throwable $e) {
         if (!empty($conf) && file_exists($conf)) {
             @unlink($conf);
         }
         throw new FirstRunError("Error: " . $e->getMessage());
     }
 }
Exemplo n.º 8
0
 /**
  * Return the DSN
  *
  * Priority
  * 1. CUSTOM_DSN environment variable
  * 2. RDS environment variables
  * 3. DSN string stored in /app/config/db-config
  *
  * @return array
  */
 public function getDsn() : array
 {
     if (!empty(getenv('PHP_CUSTOM_DSN'))) {
         $dsn = getenv('PHP_CUSTOM_DSN');
     } elseif ($this->hasRdsAccess()) {
         $dsn = sprintf("mysql://%s:%s@%s/%s", getenv('RDS_USERNAME'), getenv('RDS_PASSWORD'), getenv('RDS_HOSTNAME'), getenv('RDS_DB_NAME'));
     } elseif ($fn = realpath($this->bootLoader->getBaseDir() . '/app/Config/db-config')) {
         $dsn = trim(file_get_contents($fn));
     }
     return !empty($dsn) ? $this->parseDsn($dsn) : [];
 }
Exemplo n.º 9
0
 protected function compress($regex, $content, $type = 'js', $version, $excludes)
 {
     $files = [];
     $compressed = preg_replace_callback($regex, function ($matches) use(&$files, $type, $excludes) {
         if (!empty($excludes) && preg_match("~{$excludes}~", basename($matches[1] ?? ''))) {
             return $matches[0];
         }
         if ($type === 'css' && !preg_match('/rel="stylesheet"/i', $matches[0])) {
             return $matches[0];
         } else {
             $files[] = $matches[1];
         }
         return '';
     }, $content);
     if (!empty($files)) {
         MMinifiedDatum::unguard(true);
         $name = sprintf('%s.%s', md5(json_encode($files)), $type);
         $count = MMinifiedDatum::where('name', '=', $name)->where('version', '=', $version)->count();
         $baseDir = $this->bootLoader->getBaseDir();
         if (empty($count)) {
             set_time_limit(120);
             $asset = new AssetCollection(array_map(function ($f) use($type, $baseDir) {
                 $file = realpath(sprintf('%s/public/%s', $baseDir, $f));
                 $minified = preg_match('/\\.min\\./', $file);
                 if ($type === 'css') {
                     $url = preg_replace('#.*/static/#', '/static/', $this->utils->unixPath($file));
                     $filters = array_merge([new CssImportFilter(), new CssRewriteFilter()], !$minified ? [new CssMinFilter()] : []);
                 } elseif (!$minified) {
                     $filters = [new JSMinFilter()];
                 }
                 return new FileAsset($file, !empty($filters) ? $filters : [], $baseDir . '/public', !empty($url) ? $url : '');
             }, $files));
             $asset->setTargetPath(sprintf('/static/cache/%s/', $type));
             if (MMinifiedDatum::create(['name' => $name, 'version' => $version, 'content' => $asset->dump(), 'created_at' => Carbon::now()])) {
                 $count = 1;
             }
         }
     }
     if (!empty($count) && !empty($name)) {
         $tag = sprintf($type == 'js' ? '<scrip' . 't src="%s"></script>' : '<lin' . 'k href="%s" type="text/css" rel="stylesheet" media="all">', "/static/cache/{$version}/{$name}");
         $compressed = $type === 'css' ? preg_replace('#(<style|</head)#ms', "{$tag}\n\\1", $compressed, 1) : preg_replace('#(<script|</head)#ms', "{$tag}\n\\1", $compressed, 1);
         return $compressed;
     }
     return $content;
 }
Exemplo n.º 10
0
 public function getHttpdConf(ImportEvent $event)
 {
     $httpd = file_get_contents(__DIR__ . '/data/apache.conf.txt');
     $conf = $this->engine->render($httpd, array_merge($this->config->getPublicVars(), ['path' => realpath($this->bootLoader->getBaseDir() . '/public')]));
     $event->setContent(['conf' => $conf]);
 }
Exemplo n.º 11
0
<?php

#define('DEBUG_MODE', true);
use App\Config\BootLoader;
use Minute\App\App;
require_once '../vendor/autoload.php';
$bootLoader = new BootLoader();
$injector = $bootLoader->getInjector();
/** @var App $app */
$app = $injector->make('Minute\\App\\App');
$app->run();