📄 install.inc
字号:
if(0 && (urlencode($passwd) != $passwd) or (strpos($passwd, "_") !== false)){ $this->msgbox("Illegal password. The password may contain only:\n\n" ."a) The alphanumeric characters 'a' through 'z',\n 'A' through 'Z' and '0' through '9'\n" ."b) The special characters '.' and '-'\n\n" ."Please try again.\n"); return false; } return true; } // PASSWORD_GET function password_get($msg="", $num_chars=4, $accept_cancel=false) { while(true) { $passwd = $this->passwdbox("$msg\n\nPassword: ", $accept_cancel); if($passwd != -1 && !$this->password_check($passwd, $num_chars)) { continue; } break; } return $passwd; } // PASSWORD_CHOOSE function password_choose($msg="", $num_chars=4, $accept_cancel=false) { while(true){ $passwd = $this->password_get($msg, $num_chars, $accept_cancel); if($passwd == -1) { return $passwd; } $checkpasswd = $this->passwdbox("Verify the password: "); if(strcmp($passwd, $checkpasswd) == 0){ printf ("\n"); break; } $this->msgbox("Passwords did not match, please try again."); } return $passwd; } // MENUBOX function menubox($msg, $menu_arr_orig, $allow_blank=false, $abort_msg="", $default=null) { $this->progress_bar_stop(); $this->logger->log ("MENU: $msg\n:" . var_export ($menu_arr_orig, true)); $temp_hash = array(); $menu_arr = array(); $index = 1; foreach($menu_arr_orig as $key=>$val){ if($default !== null && $default == $key) { $default_index = $index; } $temp_hash[$index] = $key; $menu_arr[$index] = $val; $index ++; } $default = isset($default_index)?$default_index:null; if(!empty($this->conf['dialog'])) { $menu_params = array ('0'); $item_len = 0; foreach ($menu_arr as $tag => $menu_item){ $menu_params[] = $tag; $menu_params[] = $menu_item; if(strlen($menu_item) > $item_len){ $item_len = strlen($menu_item); } } if($item_len > strlen($msg)-6){ /* message must be longer than items */ $len_add = $item_len - strlen($msg); $len_add = (strlen($msg)+10 > $this->conf['wrap_size'])? $this->conf['wrap_size'] - strlen($msg) : $len_add + 10; $msg .= str_repeat(" ", $len_add); } $msg = wordwrap($msg, $this->conf['wrap_size']); while(true) { $choice = $this->rundialog("menu", "\n{$msg}", $menu_params); if(!$choice) { if($allow_blank) { $choice = ""; } else { $this->on_abort($abort_msg); continue; } } else { $choice = $temp_hash[$choice]; } break; } } else { $msg = $this->add_dashes($msg); $count_lines = 0; $str = "\n$msg\n\n"; foreach ($menu_arr as $tag => $menu_item){ $str .= "[$tag] $menu_item\n"; $count_lines ++; } do { if($count_lines > 20){ $tmp_file = $this->make_path($this->conf['tmp_dir'], "tmp.scroll"); $this->str2file($str, $tmp_file); $this->show_file($tmp_file, false); } else{ print($str); } while(true){ $quest = "\nPlease select "; if ($default !== null) { $quest .= "[$default]"; } else if ($allow_blank) { if($count_lines > 20){ $quest .= "[S - show again, ENTER - leave empty]"; } else { $quest .= "[Press ENTER to leave empty]"; } } else if ($count_lines > 20) { $quest .= "[S - show again]"; } $quest .= ": "; $output = $this->my_readline($quest); if($output == "S" || $output == "s") { break; } if(empty($output) && $default !== null) { $output = $default; } if(empty($output) && $allow_blank){ /* if ENTER was pressed */ $choice = ""; break; } if(isset($menu_arr[$output])){ /* if this value exists */ $choice = $temp_hash[$output]; break; } else { if(!empty($output)) { $this->infobox("Illegal input: $output"); } } } } while(!isset($choice)); print("\n"); } $this->logger->log ("User's choice: $choice"); return $choice; } // CHECKLIST /* * @param string Text to display in the checklist box * @param array choices (key => choice) * @param array fired choices (choice => 1) * @return array fired choices (choice => 1) */ function checklist ($text, $choices, $default_choices=null) { if ($default_choices === null || !is_array($default_choices)) { $default_choices = array(); } $retval = array(); // Use integer counter for defining keys: $new_key = 1; $new_default_choices = array(); foreach ($choices as $orig_key => $choice) { $new_choices[$new_key] = $choice; $keys_f[$new_key] = $orig_key; if (isset($default_choices [$orig_key])) { $new_default_choices [$new_key] = 1; } $new_key ++; } $default_choices = $new_default_choices; $choices = $new_choices; if (empty($this->conf["dialog"])) { // Display text: print "\n{$text}\n\n"; // Until a legal option will be choosen do { // Display choices: $line = ""; foreach ($choices as $key => $choice) { if (isset($default_choices [$key])) { $line .= sprintf ("[X] %d. %s\n", $key, $choice); } else $line .= sprintf ("[ ] %d. %s\n", $key, $choice); } print "{$line}\n"; // Read the answer: $res = $this->my_readline ("[Change setting or press ENTER to continue]: "); // On empty answer - finish setting values if ($res === "") { foreach ($default_choices as $key => $value) { $retval [$keys_f[$key]] = $value; } break; } if (isset($keys_f[$res])) { if(isset($default_choices[$res])) { unset ($default_choices[$res]); } else $default_choices[$res] = 1; continue; } print "Illegal input: $res\n"; } while (true); } else { $checklist_params = array('0'); $item_len = 0; foreach ($choices as $key => $choice) { $checklist_params[] = $key; $checklist_params[] = $choice; $checklist_params[] = isset($default_choices [$key]) ? "On" : "Off"; if(strlen($choice) > $item_len){ $item_len = strlen($choice); } } if($item_len > strlen($text)-8){ /* message must be longer than the longer of items */ $len_add = $item_len - strlen($text); $len_add = (strlen($text)+10 > $this->conf['wrap_size'])? $this->conf['wrap_size'] - strlen($text) : $len_add + 10; $text .= str_repeat(" ", $len_add); } $text = wordwrap($text, $this->conf['wrap_size']); while(true) { $res = $this->rundialog("checklist", "\n{$text}", $checklist_params); if(!$res) { return array(); } else { $res = trim ($res, "\" \t
"); foreach (array_flip (explode ("\" \"", $res)) as $key => $val) { $key = trim ($key, "\" \t
"); $retval[$keys_f[$key]] = 1; } } break; } } return $retval; } // SHOW_FILE function show_file($file, $clean=true) { $this->progress_bar_stop(); if(!$this->conf['interactive']) { return; } $file = $this->file_word_wrap($file); if(!empty($this->conf['dialog'])){ $this->rundialog("textbox", $file); } else{ $this->clrscr(); popen("cat $file | more", "w"); if($clean){ $this->clrscr(); } } } // PROGRESS_BAR_START /* start external process with dialog progress bar */ function progress_bar_start($seconds, $message, $message_tty=null) { $message = "\n\n".$message; if(!$message_tty){ $message_tty = $message; } $pb_proc_env = array(); $pb_proc_env["TIME"] = $seconds; /* set progress bar timeout */ $pb_proc_env["MESSAGE"] = $message; $pb_proc_env["MESSAGE_TTY"] = $message_tty; $pb_proc_env["TITLE"] = $this->conf['title']; if(!empty($this->conf['dialog'])){ $pb_proc_env["DIALOG"] = $this->conf['dialog']; /* set path to dialog */ } $this->conf['progress_pid_file'] = $this->conf['tmp_dir'].$this->conf['slash']."progress_bar.pid"; $this->conf['progress_fatal_file'] = $this->conf['tmp_dir'].$this->conf['slash']."kill_progress_bar"; if (@file_exists ($this->conf['progress_fatal_file'])) { @unlink ($this->conf['progress_fatal_file']); } $pb_proc_env["PID_FILE"] = $this->conf['progress_pid_file']; $pb_proc_env["FATAL_FILE"] = $this->conf['progress_fatal_file']; $dspec = array( 0 => array("pipe", "r"), 2 => array("pipe", "w") ); $proc_env = ""; foreach ($pb_proc_env as $key => $val) { $val = strlen($val) ? $val : " "; $proc_env .= "{$key}=".escapeshellarg($val)." "; } if (isset($this->conf['php_run_cmd'])) { $php_cmd = $this->conf['php_run_cmd']; } else { $php_cmd = "./php -c ./php-install.ini"; } touch ($this->conf['progress_pid_file']); $this->conf['progress_fp'] = proc_open ("{$proc_env} {$php_cmd} -q ".dirname(__FILE__)."/progress_bar.php", $dspec, $pipes); $this->conf['progress_bar_started'] = true; } // PROGRESS_BAR_STOP function progress_bar_stop() /* stop the progress bar by killing it */ { if (!$this->conf['progress_bar_started']) { return; } while(!file_exists($this->conf['progress_pid_file'])); // Wait for process to create a file sleep(1); @touch($this->conf['progress_fatal_file']); @proc_close($this->conf['progress_fp']); if(empty($this->conf['dialog'])){ print("\n"); } $this->conf['progress_bar_started'] = false; sleep(1); } // DIALOG_CALC_MAX_SIZE function dialog_calc_max_size() { if(empty($this->conf['dialog'])){ return -1; } $this->dialog_execute($this->conf['dialog']." --print-maxsize"); $out = $this->dialog_get_output(); if(preg_match("/.*:\s(.*),\s(.*)$/m", $out, $match)){ $this->conf['max_y'] = $match[1]; $this->conf['max_x'] = $match[2]; } } // DIALOG_EXECUTE function dialog_execute($dialog_cmd) { if(empty($this->conf['dialog'])){ $this->logger->log ('Tried to run a dialog utility, while it doesn\'t exist!'); return -1; } $this->logger->log ($dialog_cmd); $fd = $this->my_popen("$dialog_cmd 2>". $this->conf['dialog_tmp'], "w", false); if(empty($fd)){ $this->on_error($this->conf['dialog_error']); } $status = $this->safe_pclose($fd); return $status; } // DIALOG_GET_OUTPUT function dialog_get_output() { if(!empty($this->conf['dialog'])){ return $this->file2str($this->conf['dialog_tmp']); } return false; } // ----------------------------- // WEBSERVER FUNCTIONS // ============================= // WEBSERVER_SUPPORTED_CHECK function webserver_supported_check($name) { if(empty($this->conf['supported_webservers'])){ return true; } else{ return array_search($name, $this->conf['supported_webservers']); } } // WEBSERVER_CHOOSE function webserver_choose($errmsg="") { if($this->conf['webserver'] != "Web server") { return true; } if(empty($this->conf['supported_webservers'])){ return false; } if(count($this->conf['supported_webservers']) == 1){ if($this->yesnobox("Are you using ".$this->conf['supported_webservers'][1]." Web server?")){ $this->conf['webserver'] = $this->conf['supported_webservers'][1]; } else{ if(empty($errmsg)){ $errmsg = "For now ".$this->conf['product']." supports only ". $this->conf['supported_webservers'][1]. " on ". $this->conf['uname']['sysname']; } $this->on_abort($errmsg, true); } } else{ $rc = $this->menubox("Choose one of supported Web servers:", $this->conf['supported_webservers'], false, $errmsg); $this->conf['webserver'] = $this->conf['supported_webservers'][$rc]; } } // WEBSERVER_ROOT_GUESS function webserver_root_guess() { if(empty($this->conf['webserver_root_dir'])){ $webserver_root = ""; if($this->conf['webserver'] == "Apache"){ $webserver_root = $this->apache_root_guess(); } else if($this->conf['webserver'] == "Zeus" && $this->my_dir_exists("/usr/local/zeus")) { $webserver_root = "/usr/local/zeus"; } else if($this->conf['webserver'] == "SunONE" && $this->my_dir_exists("/opt/SUNWwbsvr")) { $webserver_root = "/opt/SUNWwbsvr"; } $word = empty($webserver_root) ? "enter" : "confirm"; $this->conf['webserver_root_dir'] = $this->select_dir("Please $word your ".$this->conf['webserver']. " root directory", $webserver_root); if($this->conf['webserver'] == "Zeus"){ $this->conf['zeus_root'] = $this->conf['webserver_root_dir']; } else if($this->conf['webserver'] == "SunONE") { $this->conf['sunone_root'] = $this->conf['webserver_root_dir']; } } return $this->conf['webserver_root_dir']; } // WEBSERVER_DOCROOT_GUESS function webserver_docroot_guess() { if(isset($this->conf['webserver_doc_root']) && $this->my_dir_exists($this->conf['webserver_doc_root'])){ return $this->conf['webserver_doc_root']; } $this->logger->log ('Trying to guess ' . $t
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -