Пример #1
0
 /**
  * @param string $menu
  */
 protected static function resolveChoice($menu, $choices = 'yn', $default = 'y')
 {
     $choice = false;
     while ($choice === false) {
         $choice = \cli\choose($menu, $choices, $default);
     }
     \cli\line();
     return $choice;
 }
Пример #2
0
<?php

/*
 * Copyright 2015 Jack Sleight <http://jacksleight.com/>
 * This source file is subject to the MIT license that is bundled with this package in the file LICENCE.md. 
 */
if (cli\choose("Are you sure", 'yn', 'n') == 'n') {
    exit;
}
require_once $cmds['cache-clear']->name();
$schema = new \Doctrine\ORM\Tools\SchemaTool($app->em->value());
cli\line('Deleting existing files..');
if ($app->config->dataDir->exists()) {
    $app->config->dataDir->remove(true);
}
if ($app->config->publicDataDir->exists()) {
    $app->config->publicDataDir->remove(true);
}
cli\line('Dropping existing database..');
$schema->dropDatabase();
$app->em->beginTransaction();
try {
    cli\line('Creating schema..');
    $schema->createSchema($app->em->getMetadataFactory()->getAllMetadata());
    cli\line('Creating default user..');
    $user = new \Chalk\Core\User();
    $user->fromArray(['name' => 'Root', 'emailAddress' => '*****@*****.**', 'passwordPlain' => 'password', 'role' => \Chalk\Core\User::ROLE_DEVELOPER]);
    $app->em->persist($user);
    $app->em->flush();
    cli\line('Creating default page..');
    $page = new \Chalk\Core\Page();
Пример #3
0
 * Copyright 2015 Jack Sleight <http://jacksleight.com/>
 * This source file is subject to the MIT license that is bundled with this package in the file LICENCE.md. 
 */
if (cli\choose("Are you sure", 'yn', 'n') == 'n') {
    exit;
}
require_once $cmds['cache-clear']->name();
$schema = new \Doctrine\ORM\Tools\SchemaTool($app->em->value());
cli\line('Calculating changes..');
$stmts = $schema->getUpdateSchemaSql($app->em->getMetadataFactory()->getAllMetadata(), false);
if (!count($stmts)) {
    cli\line("Nothing to update");
    exit;
}
cli\line("The following statements will be executed:\n  " . implode("\n  ", $stmts));
if (cli\choose("Execute these statements", 'yn', 'n') == 'n') {
    exit;
}
$app->em->beginTransaction();
try {
    $bar = new cli\progress\Bar("Executing statements..", count($stmts), 1);
    $conn = $app->em->getConnection();
    foreach ($stmts as $stmt) {
        $conn->exec($stmt);
        $bar->tick();
    }
    $bar->finish();
    $app->em->commit();
} catch (Exception $e) {
    $app->em->rollback();
    cli\err('Error: ' . $e->getMessage());
 public static function inspect($folders2check = array(), $halt_on_error = true)
 {
     if (defined('WP_CLI') && WP_CLI) {
         if (!self::switch_to_httpd_user()) {
             return false;
         }
     }
     if (!is_array($folders2check) || empty($folders2check)) {
         $folders2check = array('/*');
     }
     foreach ($folders2check as $folder) {
         $recursive = substr($folder, -2) == "/*" ? true : false;
         $folder_base = trim(str_replace('/*', '', str_replace('//', '/', str_replace(self::$_real_abspath, '', $folder))), '/');
         if (!file_exists(self::$_real_abspath . '/' . $folder_base) && file_exists('/' . $folder_base)) {
             $folder_base = '/' . $folder_base;
             if (is_link($folder_base)) {
                 $resolved_folder_path = realpath(readlink($folder_base));
             } else {
                 $resolved_folder_path = $folder_base;
             }
         } else {
             if (is_link(self::$_real_abspath . '/' . $folder_base)) {
                 $resolved_folder_path = realpath(readlink(self::$_real_abspath . '/' . $folder_base));
             } else {
                 $resolved_folder_path = self::$_real_abspath . '/' . $folder_base;
             }
         }
         if (!self::$_force_default_allowed_dirs && !file_exists($resolved_folder_path)) {
             continue;
         }
         $file_path = $resolved_folder_path . '/.ac_inspector_testfile';
         $allowed_dir = false;
         if ($recursive) {
             if (in_array($folder, self::$_options['allowed_dirs'])) {
                 $allowed_dir = true;
             } else {
                 if (!empty($folder_base)) {
                     foreach (self::$_options['allowed_dirs'] as $dir) {
                         if (preg_match("|" . str_replace('/*', '/.*', $dir) . "|", $file_path)) {
                             $allowed_dir = true;
                             break;
                         }
                     }
                 }
             }
         } else {
             if (in_array($folder, self::$_options['allowed_dirs'])) {
                 $allowed_dir = true;
             }
         }
         $bad_folder_perm = false;
         $bad_file_perm = false;
         try {
             $file_handle = @fopen($file_path, 'w');
             if (!$file_handle) {
                 if ($allowed_dir) {
                     throw new Exception('Was not able to create a file in allowed folder `' . $resolved_folder_path . '`. Check your file permissions.');
                 }
             } else {
                 // Test was successful, let's cleanup before returning true...
                 fclose($file_handle);
                 unlink($file_path);
                 if (!$allowed_dir) {
                     throw new Exception('Was able to create a file in disallowed folder `' . $resolved_folder_path . '`. Check your file permissions.');
                 }
             }
         } catch (Exception $e) {
             AC_Inspector::log($e->getMessage(), __CLASS__);
             $bad_folder_perm = true;
             if (defined('WP_CLI') && WP_CLI && $halt_on_error) {
                 $response = cli\choose("Bad permissions detected, continue inspecting file permissions", $choices = 'yn', $default = 'n');
                 if ($response == 'y') {
                     $halt_on_error = false;
                 } else {
                     if (defined('WP_CLI') && WP_CLI) {
                         self::restore_wp_cli_user();
                     }
                     return false;
                 }
             }
         }
         $files = array_filter(glob($resolved_folder_path . "/*"), 'is_file');
         foreach ($files as $file) {
             $file = str_replace('//', '/', $file);
             if (!$allowed_dir && self::file_user_may('w', $file)) {
                 $bad_file_perm = true;
                 AC_Inspector::log("Writable file `{$file}` is in a file directory that should not be writeable. Check your file permissions.", __CLASS__);
             } else {
                 if ($allowed_dir && !self::file_user_may('w', $file)) {
                     $bad_file_perm = true;
                     AC_Inspector::log("Unwritable file `{$file}` is in a file directory that should be writeable. Check your file permissions.", __CLASS__);
                 }
             }
             if (defined('WP_CLI') && WP_CLI && $bad_file_perm && $halt_on_error) {
                 $response = cli\choose("Bad permissions detected, continue inspecting file permissions", $choices = 'yn', $default = 'n');
                 if ($response == 'y') {
                     $halt_on_error = false;
                 } else {
                     if (defined('WP_CLI') && WP_CLI) {
                         self::restore_wp_cli_user();
                     }
                     return false;
                 }
             }
         }
         if (substr($folder, -2) == "/*" && (!$halt_on_error || !$bad_folder_perm && !$bad_file_perm)) {
             $subfolders = glob($resolved_folder_path . "/*", GLOB_ONLYDIR);
             if (is_array($subfolders) && !empty($subfolders)) {
                 foreach (array_keys($subfolders) as $sf_key) {
                     $subfolders[$sf_key] = trim($subfolders[$sf_key], '/') . '/*';
                     if ($f2c_key = array_search($subfolders[$sf_key], $folders2check)) {
                         unset($subfolders[$f2c_key]);
                     }
                 }
                 if (is_array($subfolders) && count($subfolders) > 0 && !empty($subfolders[0])) {
                     if (false === self::inspect($subfolders, $halt_on_error)) {
                         if (defined('WP_CLI') && WP_CLI) {
                             self::restore_wp_cli_user();
                         }
                         return false;
                     }
                 }
             }
         }
     }
     if (defined('WP_CLI') && WP_CLI) {
         if (!self::restore_wp_cli_user()) {
             return false;
         }
     }
     return true;
 }