function login() { global $set, $apx, $db; //Weiterleiten auf Startseite, wenn angemeldet if ($apx->user->info['userid']) { header('Location: index.php'); } if ($_POST['send']) { if ($_POST['login_user'] && $_POST['login_pwd']) { $res = $db->first("SELECT userid,password,salt,active,gtype FROM " . PRE . "_user AS a LEFT JOIN " . PRE . "_user_groups AS b USING(groupid) WHERE LOWER(username_login)='" . addslashes(strtolower($_POST['login_user'])) . "' LIMIT 1"); list($count) = $db->first("SELECT count(time) FROM " . PRE . "_loginfailed WHERE ( userid='" . $res['userid'] . "' AND time>='" . (time() - 15 * 60) . "' )"); if (!checkToken()) { infoInvalidToken(); } elseif ($count >= 5) { printInfo($apx->lang->get('INFO_BLOCK')); } elseif (!$res['userid'] || $res['password'] != md5(md5($_POST['login_pwd']) . $res['salt'])) { if ($res['userid']) { $db->query("INSERT INTO " . PRE . "_loginfailed VALUES ('" . $res['userid'] . "','" . time() . "')"); } if ($count == 4) { printInfo($apx->lang->get('INFO_BLOCK')); } else { printInfo($apx->lang->get('INFO_FAIL')); } } elseif ($res['gtype'] != 'admin' && $res['gtype'] != 'indiv') { printInfo($apx->lang->get('INFO_NOGROUP')); } elseif (!$res['active']) { printInfo($apx->lang->get('INFO_BANNED')); } else { $apx->session->set('apxses_userid', $res['userid']); $apx->session->set('apxses_password', $res['password']); $timeout = (int) $_POST['cookie_time']; if ($timeout <= 0) { $timeout = 100; } //Cookie setzen für Dauerlogin if ($_POST['savecookie']) { setcookie($set['main']['cookie_pre'] . '_admin_userid', $res['userid'], time() + $timeout * 24 * 3600, '/'); setcookie($set['main']['cookie_pre'] . '_admin_password', $res['password'], time() + $timeout * 24 * 3600, '/'); } //Public-Login if ($_POST['publogin']) { setcookie($set['main']['cookie_pre'] . '_userid', $res['userid'], time() + $timeout * 24 * 3600, '/'); setcookie($set['main']['cookie_pre'] . '_password', $res['password'], time() + $timeout * 24 * 3600, '/'); } //Loginfailed löschen $db->query("DELETE FROM " . PRE . "_loginfailed WHERE userid='" . $res['userid'] . "'"); $apx->user->info['userid'] = $res['userid']; //Für Log logit('USER_LOGIN'); printJSRedirect('index.php'); } } else { printInfo($apx->lang->get('CORE_BACK')); } return; } else { $apx->tmpl->loaddesign('blank'); $apx->tmpl->parse('login'); } }
* Version: 1.0 */ //作为一个守护进程? 可以查看启动哪些server define('STARTBASEPATH', dirname(dirname(__FILE__))); define('SuperProcessName', 'Swoole-Controller'); define('uniSockPath', "/tmp/" . SuperProcessName . ".sock"); $cmds = array('start', 'stop', 'reload', 'restart', 'shutdown', 'status'); //php swoole.php testserver start $name = $argv[1]; $cmd = $argv[2]; //cmd name $cmd = empty($cmd) ? $name : $cmd; $RunningServer = array(); //需要cmd 和 name name 支持 all 和 具体的serverName if (!$cmd || !$name && ($cmd != 'status' && $cmd != 'shutdown') || !in_array($cmd, $cmds)) { printInfo(); } //todo 支持 list if ($cmd != 'status' && $cmd != 'shutdown') { //获取所有的server名称 $configDir = STARTBASEPATH . "/conf/*.ini"; $configArr = glob($configDir); // 配置名必须是servername $servArr = array(); foreach ($configArr as $k => $v) { $servArr[] = basename($v, '.ini'); //获取所有的neame } //合法性校验 支持自杀 单独一个命令字 if (!in_array($name, $servArr)) { echo "your server name {$name} not exist" . PHP_EOL;
<p> Sie haben hier die Möglichkeit eine Lieferantenbestellung (für das Lager) zu erfassen<br> <b>Sie müssen über die nötigen Berechtigungen verfügen um alles zu sehen!</b> </p> </div> <?php //if($_SESSION['userrole'] != 3) die(printError("Sie haben keine berechtigungen für diese Seite!")); ?> </div> </div> <div class="row"> <div class="large-12 columns"> <h3>Einfache Lieferantenbestellung erfassen</h3> <?php printInfo('Es werden nur Artikel angezeigt, welche auch einem Lieferanten zugeordnet sind und im Lager geführt werden!'); ?> <div class="row"> <div class="large-8 small-8 columns"> <form enctype="multipart/form-data" action="" method="POST"> <div class="row collapse"> <div class="small-6 large-6 columns"> <select name="artikel"> <?php $sql = "SELECT\n id,\n bezeichnung,\n nummer\n FROM\n artikel\n where \n lager = 1\n AND \n id in (SELECT distinct artikelId FROM lieferantArtikel);"; $stmt = $db->query($sql); if (!$stmt) { printError("Fehler bei den Tabellenangaben!"); } else { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo '<option value="' . $row["id"] . '">' . $row["bezeichnung"] . ' (' . $row['nummer'] . ')</option>';
//验证用户名密码 if ($username !== $row['username'] || $password !== md5($row['password'])) { echo "verify password fail!<br>"; return; } echo "verify password success!<br>"; //session存在 if (isset($_SESSION['LAST_REMOTE_ADDR'])) { //与上次同一个device if ($sessionkey == $row['sessionkey'] && $_SESSION['LAST_REMOTE_ADDR'] == $_SERVER['REMOTE_ADDR'] && $_SESSION['HTTP_USER_AGENT'] == $_SERVER['HTTP_USER_AGENT']) { echo "you come from same IP!<br>"; printInfo($sessionkey, $row['sessionkey']); } else { //更新数据 $_SESSION['LAST_REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR']; $_SESSION['HTTP_USER_AGENT'] = $_SERVER['HTTP_USER_AGENT']; @mysql_query("update users set sessionkey='{$sessionkey}' where username = '******'") or die("process query update fail!"); echo "you come from diffent IP, session destroyed!<br>"; printInfo($sessionkey, $row['sessionkey']); session_destroy(); } } else { //更新数据 $_SESSION['LAST_REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR']; $_SESSION['HTTP_USER_AGENT'] = $_SERVER['HTTP_USER_AGENT']; @mysql_query("update users set sessionkey='{$sessionkey}' where username = '******'") or die("process query update fail!"); echo "you come for the first time!<br>"; } } else { echo "verify user fail!<br>"; }
function info($text) { printInfo($text); }
/** * * * @param int $argc * @param array $argv * * @return void * * @throws \InvalidArgumentException * @throws \RuntimeException if this function is called in a script that is not run at the command line. */ function createController($argc, array $argv) { ////////////////////////////////////////// // START: Environment and Args Validation ////////////////////////////////////////// if (!isPhpRunningInCliMode()) { $err_msg = '`' . __FUNCTION__ . '($argc, array $argv)` should only be called from within' . ' php scripts that should be run via the command line!!!' . PHP_EOL; throw new \RuntimeException($err_msg); } if (is_string($argc) && is_numeric($argc)) { $argc = (int) $argc; } if (!is_int($argc)) { $err_msg = 'The expected value for the first argument to ' . '`' . __FUNCTION__ . '($argc, array $argv)` should be an int.' . ' `' . ucfirst(gettype($argc)) . '` with the value below was supplied:' . PHP_EOL . var_export($argc, true) . PHP_EOL . PHP_EOL . 'Good bye!!!'; throw new \InvalidArgumentException($err_msg); } if (count($argv) < 1) { $err_msg = 'The expected value for the second argument to ' . '`' . __FUNCTION__ . '($argc, array $argv)` should be an array with at least one element. Empty Array was supplied.' . 'This second argument is expected to be the $argv array passed by PHP to the script calling this function.'; throw new \InvalidArgumentException($err_msg); } ////////////////////////////////////////// // END: Environment and Args Validation ////////////////////////////////////////// ////////////////////////////////// ///START: COMMAND PROCESSING ////////////////////////////////// $ds = DIRECTORY_SEPARATOR; if ($argc < 5 || in_array('--help', $argv) || in_array('-help', $argv) || in_array('-h', $argv) || in_array('-?', $argv)) { displayHelp(basename($argv[0])); } else { if ($argc === 5 && (in_array('--controller-name', $argv) || in_array('-c', $argv)) && (in_array('--path-to-src-folder', $argv) || in_array('-p', $argv)) || $argc >= 7 && (in_array('--controller-name', $argv) || in_array('-c', $argv)) && (in_array('--path-to-src-folder', $argv) || in_array('-p', $argv)) && (in_array('--extends-controller', $argv) || in_array('-e', $argv))) { $templates_dir = dirname(__DIR__) . $ds . 'templates' . $ds; $controller_name = getOptVal('--controller-name', $argv); if ($controller_name === false) { $controller_name = getOptVal('-c', $argv); } $studly_controller_name = \Slim3MvcTools\Functions\Str\dashesToStudly(\Slim3MvcTools\Functions\Str\underToStudly($controller_name)); $dashed_controller_name = \Slim3MvcTools\Functions\Str\toDashes($controller_name); if (!isValidClassName($studly_controller_name)) { printError("Invalid controller class name `{$controller_name}` supplied. Goodbye!!"); return; } $src_folder_path = getOptVal('--path-to-src-folder', $argv); if ($src_folder_path === false) { $src_folder_path = getOptVal('-p', $argv); } $src_folder_path = normalizeFolderPathForOs($src_folder_path); if (!file_exists($src_folder_path) || !is_dir($src_folder_path)) { printError("The src folder path `{$src_folder_path}` supplied is a non-existent directory. Goodbye!!"); return; } //////////////////////////////////////////////////////////////////////////// $default_controller_2_extend = '\\Slim3MvcTools\\Controllers\\BaseController'; $controller_2_extend = getOptVal('--extends-controller', $argv); if ($controller_2_extend === false) { $controller_2_extend = getOptVal('-e', $argv); if ($controller_2_extend !== false) { if (!isValidExtendsClassName($controller_2_extend)) { printError("Invalid controller class name `{$controller_2_extend}` for extension supplied. Goodbye!!"); return; } } else { //use default controller class to be extended $controller_2_extend = $default_controller_2_extend; } } else { if (!isValidExtendsClassName($controller_2_extend)) { printError("Invalid controller class name `{$controller_2_extend}` for extension supplied. Goodbye!!"); return; } } //////////////////////////////////////////////////////////////////////////// $namepace_declaration = ''; //omit namespace declaration by default $namepace_4_controller = getOptVal('--namespace-4-controller', $argv); if ($namepace_4_controller === false) { $namepace_4_controller = getOptVal('-n', $argv); if ($namepace_4_controller !== false) { if (!isValidNamespaceName($namepace_4_controller)) { printError("Invalid namespace `{$namepace_4_controller}` supplied. Goodbye!!"); return; } //validation passed $namepace_declaration = "namespace {$namepace_4_controller};"; } else { $namepace_4_controller = ''; } } else { if (!isValidNamespaceName($namepace_4_controller)) { printError("Invalid namespace `{$namepace_4_controller}` supplied. Goodbye!!"); return; } //validation passed $namepace_declaration = "namespace {$namepace_4_controller};"; } //read template controller and substitute __TEMPLTATE_CONTROLLER__ with given controller name \Slim3MvcTools\Functions\Str\underToStudly(dashesToStudly($controller_name_from_cli)) //substitute {{TEMPLTATE_CONTROLLER_VIEW_FOLDER}} with the view folder name \Slim3MvcTools\Functions\Str\toDashes($controller_name_from_cli) //write processed controller file to S3MVC_APP_ROOT_PATH.$ds.'src'.$ds.'controllers'.$ds //make the dir S3MVC_APP_ROOT_PATH.$ds.'src'.$ds.'views'.$ds.\Slim3MvcTools\Functions\Str\toDashes($controller_name_from_cli) //read template controller index view and substitute __TEMPLTATE_CONTROLLER__ with given controller name \Slim3MvcTools\Functions\Str\underToStudly(dashesToStudly($controller_name_from_cli)) //write processed controller file to S3MVC_APP_ROOT_PATH.$ds.'src'.$ds.'views'.$ds.\Slim3MvcTools\Functions\Str\toDashes($controller_name_from_cli) $template_controller_file = $templates_dir . 'controller-class-template.php.tpl'; $dest_controller_class_file_folder = $src_folder_path . 'controllers' . $ds; $dest_controller_class_file = $dest_controller_class_file_folder . "{$studly_controller_name}.php"; if (!file_exists($dest_controller_class_file_folder) && !mkdir($dest_controller_class_file_folder, 0775, true)) { printError("Failed to create `{$dest_controller_class_file_folder}`; the folder supposed to contain the controller named `{$studly_controller_name}`. Goodbye!!"); return; } $template_view_file = $templates_dir . 'index-view-template.php'; $dest_view_file_folder = $src_folder_path . 'views' . $ds . "{$dashed_controller_name}{$ds}"; $dest_view_file = "{$dest_view_file_folder}index.php"; if (!file_exists($dest_view_file_folder) && !mkdir($dest_view_file_folder, 0775, true)) { printError("Failed to create `{$dest_view_file_folder}`; the folder supposed to contain views for the controller named `{$studly_controller_name}`. Goodbye!!"); return; } if (file_exists($dest_controller_class_file)) { printError("Controller class `{$studly_controller_name}` already exists in `{$dest_controller_class_file}`. Goodbye!!"); return; } if (file_exists($dest_view_file)) { printError("View file `{$dest_view_file}` already exists for Controller class `{$studly_controller_name}`. Goodbye!!"); return; } printInfo("Creating Controller Class `{$studly_controller_name}` in `{$dest_controller_class_file}` ...."); //////////////////////////////////////////////////////////////////////////// $replaces = ['__CONTROLLER_2_EXTEND__' => $controller_2_extend, '__TEMPLTATE_CONTROLLER__' => $studly_controller_name, 'namespace __NAMESPACE_2_REPLACE__;' => $namepace_declaration, '{{TEMPLTATE_CONTROLLER_VIEW_FOLDER}}' => $dashed_controller_name, "'__login_success_redirect_controller__'" => "'{$dashed_controller_name}'"]; if (processTemplateFile($template_controller_file, $dest_controller_class_file, $replaces) === false) { printError("Failed transforming template controller `{$template_controller_file}` to `{$dest_controller_class_file}`. Goodbye!!"); } else { printInfo("Successfully created `{$dest_controller_class_file}` ...." . PHP_EOL); } printInfo("Creating index view for `{$studly_controller_name}::actionIndex()` in `{$dest_view_file}` ...."); $replaces['__TEMPLTATE_CONTROLLER__'] = rtrim($namepace_4_controller, '\\') . '\\' . $studly_controller_name; if (processTemplateFile($template_view_file, $dest_view_file, $replaces) === false) { printError("Failed creating index view for `{$studly_controller_name}::actionIndex()` in `{$dest_view_file}`."); printInfo("Deleting `{$dest_controller_class_file}` ...."); if (!unlink($dest_controller_class_file)) { printInfo("Failed to delete `{$dest_controller_class_file}`. Please delete it manually. Goodbye!!"); } else { printInfo("Goodbye!!"); } return; } else { printInfo("Successfully created `{$dest_view_file}` ...." . PHP_EOL); } printInfo("All done!!"); if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { //test if composer is avaliable only if server OS on which this script is being run //is not windows if (isCommandAvailableOnOs('composer')) { passthru('composer dumpautoload'); } else { printInfo("Remember to run `composer dumpautoload` so that composer can pick up the newly created controller class `{$studly_controller_name}` in `{$dest_controller_class_file}`."); } } else { printInfo("Remember to run `composer dumpautoload` so that composer can pick up the newly created controller class `{$studly_controller_name}` in `{$dest_controller_class_file}`."); } //we are done } else { displayHelp(basename($argv[0])); } } ////////////////////////////////// ///END: COMMAND PROCESSING ////////////////////////////////// }
printError("Could not delete `{$raw_root_folder}slim3-psr7.pub` ! " . PHP_EOL); } sleep(1); //////////////////////////////////////////////////////////// printInfo("Deleting `{$raw_root_folder}phpunit.xml.dist` ...." . PHP_EOL); if (@unlink("{$root_folder}phpunit.xml.dist")) { printInfo("Successfully Deleted! " . PHP_EOL); } else { printError("Could not delete `{$raw_root_folder}phpunit.xml.dist` ! " . PHP_EOL); } sleep(1); //////////////////////////////////////////////////////////////////////////////// $logs_folder = __DIR__ . "{$ds}..{$ds}logs"; printInfo("Making `{$logs_folder}` writable ...." . PHP_EOL); if (chmod($logs_folder, 0777)) { printInfo("Successfully made `{$logs_folder}` writable! " . PHP_EOL); } else { printError("Could not make `{$logs_folder}` writable!! " . PHP_EOL); } function printError($str, $append_new_line = true) { echo \Slim3MvcTools\Functions\Str\color_4_console("ERROR: {$str}", "red", "black"); if ($append_new_line) { echo PHP_EOL; } } function printInfo($str, $append_new_line = true) { echo \Slim3MvcTools\Functions\Str\color_4_console($str, "green", "black"); if ($append_new_line) { echo PHP_EOL;
public function testThatPrintInfoWorksAsExpected() { $output1 = $this->execFuncAndReturnBufferedOutput('printInfo', ['test string', false]); $output2 = $this->execFuncAndReturnBufferedOutput('printInfo', ['test string', true]); $this->assertStringStartsWith("[0;32m[40m", $output1); $this->assertStringStartsWith("[0;32m[40m", $output2); $this->assertStringEndsWith("[0m", $output1); $this->assertStringEndsWith(PHP_EOL, $output2); /////////////////////////////////////////// //Test \InvalidArgumentException messages /////////////////////////////////////////// $args = array('Integer' => 111, 'Double' => 111.1234, 'Boolean' => true, 'Array' => [], 'Object' => new stdclass(), 'NULL' => null, 'Resource' => tmpfile()); $function_sig_in_err_msg = 'printInfo($str, $append_new_line = true)'; foreach ($args as $arg_type => $arg) { try { printInfo($arg); $msg = '\\InvalidArgumentException should have been thrown in `' . __FILE__ . '`' . ' on line ' . (__LINE__ - 1); static::fail($msg); } catch (\InvalidArgumentException $e) { $msg_substr = "The expected value for the first argument to `{$function_sig_in_err_msg}`" . " should be a String value. `{$arg_type}` with the value below was supplied:"; $this->assertContains($msg_substr, $e->getMessage()); } } // test the callable type try { printInfo(function () { echo 'blah'; }); $msg = '\\InvalidArgumentException should have been thrown in `' . __FILE__ . '`' . ' on line ' . (__LINE__ - 1); static::fail($msg); } catch (\InvalidArgumentException $e) { $msg_substr = "The expected value for the first argument to `{$function_sig_in_err_msg}`" . " should be a String value. `Object` with the value below was supplied:"; $this->assertContains($msg_substr, $e->getMessage()); } }
<?php //作为一个守护进程? 可以查看启动哪些server use Swoole\ArgParser; define('START_BASE_PATH', dirname(dirname(__DIR__))); define('SuperProcessName', 'Swoole-Controller'); define('uniSockPath', "/tmp/" . SuperProcessName . ".sock"); require START_BASE_PATH . '/library/Swoole/ArgParser.php'; $cmds = ['start', 'stop', 'reload', 'restart', 'shutdown', 'status', 'list', 'startall']; //php swoole.php testserver start $parser = new ArgParser(); $parser->add('name', ['help' => 'The name of config filename']); $parser->add('cmd', ['help' => 'The cmd of start|stop|restart', 'default' => '']); $usage = $parser->usage(printInfo()); // Try to parse the arguments if (!($args = $parser->parse())) { print $parser->help(); exit; } $name = $args['name']; $cmd = $args['cmd']; //cmd name $cmd = empty($cmd) ? $name : $cmd; $RunningServer = []; //需要cmd 和 name name 支持 all 和 具体的serverName if (!$cmd || !$name && ($cmd != 'status' && $cmd != 'shutdown' && $cmd != 'list' && $cmd != 'startall') || !in_array($cmd, $cmds)) { echo $usage; exit(1); } //servername 合法性校验 if ($cmd != 'status' && $cmd != 'shutdown' && $cmd != 'startall' && $cmd != 'list') {
<li><a href="index.html">Home</a></li> <li class="selected"><a href="Assignment0.php">Assignment0</a></li> <li><a href="Assignment1.php">Assignment1</a></li> <li><a href="Assignment2.php">Assignment2</a></li> <li><a href="FinalP.php">Final Project</a></li> <li><a href="comments.php">Comments</a></li> </ul> </div> </div> <div id="site_content"> <div id="content"> <!-- insert the page content here --> <?php echo "<h1><b>Projects</b></h1>"; include 'ParseLog.php'; parseXML(); printInfo("teapot"); //Print files info echo "<h1><b>Files</b></h1>"; include 'ParseList.php'; parseListXML(); printFileInfo("teapot"); ?> </div> </div> <div id="footer"> </div> </div> </body> </html>
echo $siteinfo['state']; ?> , <?php echo $siteinfo['country']; ?> <br/>"; <?php printInfo($siteinfo, 'mat', 'Mean Annual Temp'); printInfo($siteinfo, 'map', 'Mean Annual Precip'); printInfo($siteinfo, 'greenhouse', 'Greenhouse Study'); printInfo($siteinfo, 'time_zone', 'Local Time'); printInfo($siteinfo, 'sand_pct', 'Sand Pct'); printInfo($siteinfo, 'clay_pct', 'Clay Pct'); printInfo($siteinfo, 'soil', 'Soil'); printInfo($siteinfo, 'notes', 'Notes'); printInfo($siteinfo, 'soilnotes', 'Soil Notes'); ?> var infowindow = new google.maps.InfoWindow({content: info}); infowindow.open(map, marker); validate(); } <?php } ?> </script> </head> <body> <div id="wrap"> <div id="stylized"> <h1>Selected Site</h1> <p>Set parameters for the run.</p>
<li><a href="Assignment0.php">Assignment0</a></li> <li class="selected"><a href="Assignment1.php">Assignment1</a></li> <li><a href="Assignment2.php">Assignment2</a></li> <li><a href="FinalP.php">Final Project</a></li> </ul> </div> </div> <div id="site_content"> <div id="content"> <!-- insert the page content here --> <?php echo "<h1><b>Projects</b></h1>"; include 'ParseLog.php'; parseXML(); printInfo("Chess"); printInfo("assignment1"); //Print files info echo "<h1><b>Files</b></h1>"; include 'ParseList.php'; parseListXML(); printFileInfo("Chess"); printFileInfo("assignment1.1"); printFileInfo("assignment1.2"); ?> </div> </div> <div id="footer"> </div> </div> </body>
<li><a href="Assignment0.php">Assignment0</a></li> <li><a href="Assignment1.php">Assignment1</a></li> <li class="selected"><a href="Assignment2.php">Assignment2</a></li> <li><a href="FinalP.php">Final Project</a></li> </ul> </div> </div> <div id="site_content"> <div id="content"> <!-- insert the page content here --> <?php //Print projects info echo "<h1><b>Projects</b></h1>"; include 'ParseLog.php'; parseXML(); printInfo("assignment2"); //Print files info echo "<h1><b>Files</b></h1>"; include 'ParseList.php'; parseListXML(); printFileInfo("assignment2.0"); printFileInfo("assignment2.1"); printFileInfo("assignment2.2"); ?> </div> </div> <div id="footer"> </div> </div> </body>
<?php //Write a PHP script PersonalInfo.php. Declare a few variables. The first variable should hold your first name, the second should hold your last name, the third - your age, and the last one should hold your full name (use concatenation). The result should be printed. function printInfo($firstName, $lastName, $age) { echo "My name is {$firstName} {$lastName} and I am {$age} years old.\n"; } printInfo('Mister', 'Dakman', 21); printInfo('Pesho', 'Peshev', 55);