public function __construct()
 {
     $this->fs = new Filesystem();
     // FIXME externalize
     $this->descriptions = array('httpd_type' => 'Type of webserver [none,apache,apache24,nginx]', 'log_dir' => 'Directory which stores log files', 'apache_dir' => 'Directory which stores Apache config files', 'apache_tpl' => 'Apache configuration template', 'apache24_tpl' => 'Apache 2.4 or greater configuration template', 'nginx_dir' => 'Directory which stores nginx config files', 'nginx_tpl' => 'Nginx configuration template', 'mysql_type' => 'How to connect to MySQL admin [dsn,mycnf,ram_disk,osx_ram_disk]', 'mysql_dsn' => 'Administrative credentials for MySQL', 'perm_type' => "How to set permissions on data directories [none,custom,linuxAcl,osxAcl,worldWritable]. See https://github.com/totten/amp/blob/master/doc/perm.md", 'perm_user' => 'Name of the web user [for linuxAcl,osxAcl]', 'perm_custom_command' => 'Command to set a directory as web-writeable [for custom]', 'ram_disk_dir' => 'Directory to create as a RAM disk', 'ram_disk_size' => 'Amount of space to allocate for ramdisk (MB)', 'ram_disk_type' => 'Type of RAM disk [auto,linux,osx]');
     // FIXME externalize
     // Each callback returns a scalar or array of examples
     $this->exampleCallbacks = array('mysql_dsn' => function () {
         $checker = new \Amp\Util\PortChecker();
         // Some folks report problems using "localhost"
         $dsns = $checker->filterUrls(array('mysql://*****:*****@127.0.0.1:3306', 'mysql://*****:*****@127.0.0.1:3307', 'mysql://*****:*****@127.0.0.1:8889', 'mysql://*****:*****@localhost:3306', 'mysql://*****:*****@localhost:3307', 'mysql://*****:*****@localhost:8889'));
         if (empty($dsns)) {
             return 'mysql://*****:*****@hostname:3306';
         } else {
             return $dsns;
         }
     }, 'perm_user' => function () {
         $webUsers = \Amp\Util\User::filterValidUsers(array('www-data', 'www', '_www', 'apache', 'apache2', 'nginx', 'httpd'));
         if (empty($webUsers)) {
             return 'www-data';
         } else {
             return implode(', ', $webUsers);
         }
     }, 'perm_custom_command' => function () {
         $examples = array();
         $examples[] = 'chmod 1777 {DIR}';
         if (preg_match('/Linux/', php_uname()) && FALSE !== \Amp\Util\Process::findExecutable('setfacl')) {
             $examples[] = 'setfacl -m u:www-data:rwx -m d:u:www-data:rwx {DIR}';
         }
         if (preg_match('/Darwin/', php_uname())) {
             $examples[] = '/bin/chmod +a "www allow delete,write,append,file_inherit,directory_inherit" {DIR}';
         }
         return count($examples) > 1 ? $examples : $examples[0];
     });
 }
Example #2
0
 protected function askPermUser()
 {
     return $this->createPrompt('perm_user')->setAsk(function ($default, InputInterface $input, OutputInterface $output, DialogHelper $dialog) {
         $value = $dialog->askAndValidate($output, "Enter perm_user> ", function ($user) {
             return \Amp\Util\User::validateUser($user);
         }, FALSE, $default);
         return empty($value) ? FALSE : $value;
     });
 }
Example #3
0
 public function __construct()
 {
     $this->fs = new Filesystem();
     // FIXME externalize
     $this->descriptions = array('httpd_type' => 'Type of webserver [none,apache,apache24,nginx]', 'httpd_restart_command' => 'Command to restart httpd (ex: sudo apache2ctl graceful)', 'httpd_restart_wait' => 'Time to wait for HTTPD to restart (seconds)', 'httpd_shared_ports' => 'List of any http ports shared by multiple vhosts (comma-separated)', 'hosts_type' => 'Type of hostname management [none,file]', 'hosts_file' => 'Location of the hosts file (ex: /etc/hosts)', 'hosts_ip' => 'Default IP for new entries in hosts file (ex: 127.0.0.1)', 'log_dir' => 'Directory which stores log files', 'apache_dir' => 'Directory which stores Apache config files', 'apache_tpl' => 'Apache configuration template', 'apache24_tpl' => 'Apache 2.4 or greater configuration template', 'nginx_dir' => 'Directory which stores nginx config files', 'nginx_tpl' => 'Nginx configuration template', 'db_type' => 'How to connect to the database as admin [mysql_dsn,mysql_mycnf,mysql_ram_disk,mysql_osx_ram_disk,pg_dsn]', 'mysql_dsn' => 'Administrative credentials for MySQL', 'pg_dsn' => 'Administrative credentials for PostgreSQL', 'perm_type' => "How to set permissions on data directories [none,custom,linuxAcl,osxAcl,worldWritable]. See https://github.com/totten/amp/blob/master/doc/perm.md", 'perm_user' => 'Name of the web user [for linuxAcl,osxAcl]', 'perm_custom_command' => 'Command to set a directory as web-writeable [for custom]', 'ram_disk_dir' => 'Directory to create as a RAM disk', 'ram_disk_size' => 'Amount of space to allocate for ramdisk (MB)', 'ram_disk_type' => 'Type of RAM disk [auto,linux,osx,manual]');
     // FIXME externalize
     // Each callback returns a scalar or array of examples
     $this->exampleCallbacks = array('hosts_file' => function () {
         return array('/etc/hosts');
     }, 'hosts_ip' => function () {
         return array('127.0.0.1');
     }, 'mysql_dsn' => function () {
         $checker = new \Amp\Util\PortChecker();
         // Some folks report problems using "localhost"
         $dsns = $checker->filterUrls(array('mysql://*****:*****@127.0.0.1:3306', 'mysql://*****:*****@127.0.0.1:3307', 'mysql://*****:*****@127.0.0.1:8889', 'mysql://*****:*****@localhost:3306', 'mysql://*****:*****@localhost:3307', 'mysql://*****:*****@localhost:8889'));
         if (empty($dsns)) {
             return 'mysql://*****:*****@hostname:3306';
         } else {
             return $dsns;
         }
     }, 'pg_dsn' => function () {
         $checker = new \Amp\Util\PortChecker();
         // Some folks report problems using "localhost"
         $dsns = $checker->filterUrls(array('pgsql://*****:*****@127.0.0.1:5432/template1', 'pgsql://*****:*****@localhost:5432/template1'));
         if (empty($dsns)) {
             return 'pgsql://*****:*****@hostname:5432/template1';
         } else {
             return $dsns;
         }
     }, 'perm_user' => function () {
         $webUsers = \Amp\Util\User::filterValidUsers(array('www-data', 'www', '_www', 'apache', 'apache2', 'nginx', 'httpd'));
         if (empty($webUsers)) {
             return 'www-data';
         } else {
             return implode(', ', $webUsers);
         }
     }, 'perm_custom_command' => function () {
         $examples = array();
         $examples[] = 'chmod 1777 {DIR}';
         if (preg_match('/Linux/', php_uname()) && FALSE !== \Amp\Util\Process::findExecutable('setfacl')) {
             $examples[] = 'setfacl -m u:www-data:rwx -m d:u:www-data:rwx {DIR}';
         }
         if (preg_match('/Darwin/', php_uname())) {
             $examples[] = '/bin/chmod +a "www allow delete,write,append,file_inherit,directory_inherit" {DIR}';
         }
         return count($examples) > 1 ? $examples : $examples[0];
     }, 'httpd_restart_command' => function () {
         $APACHECTLS = array('apachectl', 'apache2ctl');
         $SYSDIRS = array('/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin');
         $examples = array();
         // Add-on kits. No need for sudo
         foreach (array('/Applications/MAMP/Library/bin') as $dir) {
             foreach ($APACHECTLS as $prog) {
                 if (file_exists("{$dir}/{$prog}")) {
                     $examples[] = "{$dir}/{$prog} graceful";
                 }
             }
         }
         // OS distributions. Require sudo.
         foreach ($APACHECTLS as $prog) {
             foreach ($SYSDIRS as $dir) {
                 if (file_exists("{$dir}/{$prog}")) {
                     $examples[] = "sudo {$dir}/{$prog} graceful";
                 }
             }
         }
         foreach ($SYSDIRS as $dir) {
             if (file_exists("{$dir}/service")) {
                 $examples[] = "sudo {$dir}/service apache2 restart";
                 $examples[] = "sudo {$dir}/service httpd restart";
             }
         }
         // Fallback example.
         if (empty($examples)) {
             $examples[] = "sudo apachectl graceful";
         }
         $examples[] = "NONE";
         return $examples;
     });
 }