| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Console\Commands\Install; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Console\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use App\Models\Eloquent\Group; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use App\Models\Eloquent\User; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Hash; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class Install extends Command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * The name and signature of the console command. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     protected $signature='install'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * The console command description. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     protected $description='Install NOJ'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public static $license=1630315446; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public static $logoGeneral=<<< LOGOG | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |           ___ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |           \\\\|| | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |          ,'_,-\ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |          ;'____\ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |          || =\=| | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |          ||  - |  Haec sententia nullam significationem habet, sed Latina pulchra est. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      ,---'._--''-,,---------.--.----_, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     / `-._- _--/,,|  ___,,--'--'._< | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |    /-._,  `-.__;,,|' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |   /   ;\      / , ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  /  ,' | _ - ',/, ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | (  (   |     /, ,,; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  \  \  |     ',,/,; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |   \  \ |    /, / ,; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  (| ,^.|   / ,, ,/; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |   `-'./ `-._,, ,/,; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |        ⧫-._ `-._,,; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |        |/,,`-._ `-. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |        |, ,;, ,`-._\ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | ╔═══════════════════════════════════════════════════════════════════════════════════════════════════════╗ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | ║ ███╗   ██╗ ██████╗      ██╗    ██╗███╗   ██╗███████╗████████╗ █████╗ ██╗     ██╗     ███████╗██████╗  ║ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | ║ ████╗  ██║██╔═══██╗     ██║    ██║████╗  ██║██╔════╝╚══██╔══╝██╔══██╗██║     ██║     ██╔════╝██╔══██╗ ║ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | ║ ██╔██╗ ██║██║   ██║     ██║    ██║██╔██╗ ██║███████╗   ██║   ███████║██║     ██║     █████╗  ██████╔╝ ║ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | ║ ██║╚██╗██║██║   ██║██   ██║    ██║██║╚██╗██║╚════██║   ██║   ██╔══██║██║     ██║     ██╔══╝  ██╔══██╗ ║ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | ║ ██║ ╚████║╚██████╔╝╚█████╔╝    ██║██║ ╚████║███████║   ██║   ██║  ██║███████╗███████╗███████╗██║  ██║ ║ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | ║ ╚═╝  ╚═══╝ ╚═════╝  ╚════╝     ╚═╝╚═╝  ╚═══╝╚══════╝   ╚═╝   ╚═╝  ╚═╝╚══════╝╚══════╝╚══════╝╚═╝  ╚═╝ ║ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | ╚═══════════════════════════════════════════════════════════════════════════════════════════════════════╝ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | LOGOG; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * Create a new command instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         parent::__construct(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * Execute the console command. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     public function handle() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $this->initWelcone(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $this->initSystemCheck(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         if ($this->confirm('Do you wish to continue?')) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             if(!$this->acceptLicense()){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                 return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             if($this->createFrontAdminUser()){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                 $this->createFrontAdminGroup(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             $this->installBabelExtensionNOJ(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             $this->importExampleProblem(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             $this->importBackAdminMenuPermissionsRoles(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             $this->createBackAdminUser(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     protected function initWelcone() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $this->line('<fg=cyan>'.static::$logoGeneral.'</>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $this->line(sprintf('NOJ <comment>version</comment> <info>%s</info>', version())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $this->comment(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         sleep(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     protected function initSystemCheck() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $this->info('All system check completed with 0 warning 0 error.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $this->comment(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         sleep(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     protected function acceptLicense() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $this->warn('NOJ open-source license has been updated, please accept it first:'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $this->comment(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         sleep(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         $this->line(file_get_contents(base_path('LICENSE'))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $this->warn('Notice that above license is actually a copy from https://github.com/ZsgsDesign/NOJ and remote license is the one that takes effect.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         $this->comment(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         sleep(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         return $this->confirm('Do you agree with the license?'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     protected function createFrontAdminUser() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         $this->line('Creating frontstage admin user...'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $this->comment(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $shallCreate = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         if (User::count()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             $shallCreate = $this->confirm('Detected existing frontstage user, do you really want to create frontstage admin?'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             $this->comment(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         if (!$shallCreate) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         while(true) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |                 $createdUser = $this->createFrontUser(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |             } catch(Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                 $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>Error occured while creating admin user.</>\n"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |     private function createFrontUser() { | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |         $username = $this->ask('Please choose a username:', 'admin'); | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |         $email = $this->ask('Please choose a email address:', '[email protected]'); | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |         $password = Hash::make(Str::random(8)); | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |         $createdUser=User::create([ | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |             'name' => $username, | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |             'email' => $email, | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |             'password' => $password, | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |             'avatar' => '/static/img/avatar/noj.png', | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |         ]); | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |         $createdUser->markEmailAsVerified(); | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |         return $createdUser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     protected function createFrontAdminGroup() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     protected function installBabelExtensionNOJ() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     protected function importExampleProblem() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     protected function importBackAdminMenuPermissionsRoles() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     protected function createBackAdminUser() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 175 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 176 |  |  |  | 
            
                        
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return,dieorexitstatements that have been added for debug purposes.In the above example, the last
return falsewill never be executed, because a return statement has already been met in every possible execution path.