function process($user, $msg) { $msg = unwrap($msg); // remove chr(0) and chr(255) say("< " . $msg); $parts = explode("|", $msg); // CHAT|NICK|MESSAGE $action = strtoupper($parts[0]); switch ($action) { case "HELO": welcome($user, $parts[1], $parts[2]); break; // HELO|NICK|AVATAR // HELO|NICK|AVATAR case "CHAT": chat($user, $parts[2]); break; // CHAT|NICK|MESSAGE // CHAT|NICK|MESSAGE case "PRIV": break; // TODO: private chat // TODO: private chat case "EXIT": goodbye($user); break; // EXIT|NICK // EXIT|NICK default: console($action . " not understood"); break; } }
<?php function hello() { echo '<h1>hello</h1>'; } function goodbye() { echo '<h1>goodbye Vietnam</h1>'; } hello(); goodbye();
output("Checking for PHP imagick"); $is_ok_imagick = isInstalled("[ -f /opt/local/lib/php55/extensions/no-debug-non-zts-20121212/imagick.so ] && echo 'exists' || echo 'Not found'", array("exists"), false); output($is_ok_imagick ? "PHP imagick is OK" : "PHP imagick not found - installing now"); if (!$is_ok_imagick) { command("sudo port install php55-imagick"); } // check for imagick output("Checking for PHP memcached"); $is_ok_memcached = isInstalled("[ -f /opt/local/lib/php55/extensions/no-debug-non-zts-20121212/memcached.so ] && echo 'exists' || echo 'Not found'", array("exists"), false); output($is_ok_memcached ? "PHP memcached is OK" : "PHP memcached not found - installing now"); if (!$is_ok_memcached) { command("sudo port install php55-memcached"); } // is software available if (!$is_ok_xcode || !$is_ok_macports || !$is_ok_ffmpeg || !$is_ok_php || !$is_ok_imagick || !$is_ok_memcached) { goodbye("Update your software as specified above"); } // ensure sudo power before continuing enableSuperCow(); output("\nChecking paths"); // check if configuration files are available checkFile("_conf/httpd.conf", "Required file is missing from your configuration source"); checkFile("_conf/my.cnf", "Required file is missing from your configuration source"); checkFile("_conf/httpd-vhosts.conf", "Required file is missing from your configuration source"); checkFile("_conf/php.ini", "Required file is missing from your configuration source"); checkFile("_conf/apache.conf", "Required file is missing from your configuration source"); checkFile("~/.bash_profile", "Required file is missing from home directory"); output("\nCopying configuration"); // copy base configuration copyFile("_conf/httpd.conf", "/opt/local/apache2/conf/httpd.conf", "sudo"); copyFile("_conf/httpd-vhosts.conf", "/opt/local/apache2/conf/extra/httpd-vhosts.conf", "sudo");
#!/usr/bin/php <?php include "functions.php"; // start by requesting sudo power enableSuperCow(); $host = "localhost"; $user = "******"; $pass = ask("Database root password", false, true); $dumpname = isset($argv[1]) && $argv[1] ? $argv[1] : date("Ymd_His_") . "allusertables"; // connect to DB $mysqli = @new mysqli("p:" . $host, $user, $pass); if ($mysqli->connect_errno) { goodbye("Failed to connect to MySQL: " . $mysqli->connect_error); } $mysqli->set_charset("utf8"); // get all databases $select_query = "SHOW databases"; $result = $mysqli->query($select_query); $result_count = is_object($result) ? $result->num_rows : ($result ? $result : 0); // print $select_query."<br>"; // print "Count: " . $result_count."<br>"; if ($result_count) { $user_databases = array(); $results = $result->fetch_all(MYSQLI_ASSOC); foreach ($results as $database) { // only use "non-system" databases if (!preg_match("/^(information_schema|mysql|performance_schema|test)\$/", $database["Database"])) { array_push($user_databases, $database["Database"]); } } // print_r($user_databases);
} if (!$attachid) { exit_missing_param(); } if ($pending == "yes") { $sql = "SELECT * FROM forum_pending_attachment where attachmentid='{$attachid}'"; } else { $sql = "SELECT * FROM forum_attachment where attachmentid='{$attachid}'"; } $res = db_query($sql); if (!$res) { exit_error("Attachment Download error", "DB Error"); } $extension = substr(strrchr(strtolower(db_result($res, 0, 'filename')), '.'), 1); if (!$extension) { goodbye(_('The Attachment does not exist')); } $last = gmdate('D, d M Y H:i:s', db_result($res, 0, 'dateline')); header('X-Powered-By:'); header('Last-Modified: ' . $last . ' GMT'); header('ETag: "' . db_result($res, 0, 'attachmentid') . '"'); header('Content-disposition: attachment; filename="' . db_result($res, 0, 'filename') . '"'); header('Content-Length: ' . db_result($res, 0, 'filesize')); $mimetype = db_result($res, 0, 'mimetype'); if ($mimetype) { header('Content-type: ' . $mimetype); } else { header('Content-type: application/octet-stream'); } $filedata = base64_decode(db_result($res, 0, 'filedata')); for ($i = 0; $i < strlen($filedata); $i = $i + 100) {
/** * Check if file exists * * @param String $path File to check existance of */ function checkFile($path, $message) { // $path = preg_replace("/\~/", $_SERVER['HOME'], $path); $path = getAbsolutePath($path); if (file_exists($path)) { // output("$path - file exists"); } else { goodbye("{$path} is missing - " . $message); } }
// start by requesting sudo power enableSuperCow(); $full = ask("Make full backup? (y/n)", array("y", "n"), false); if ($full == "y") { goodbye("Not implemented yet"); // should copy to external drive } else { output("Creating quick backup"); $backup_time = date("Ymd_His"); if (file_exists(getAbsolutePath("~/Dropbox/backup"))) { $backup_path = getAbsolutePath("~/Dropbox/backup/") . $backup_time; } else { if (file_exists(getAbsolutePath("~/Google\\ Drive/backup"))) { $backup_path = getAbsolutePath("~/Google\\ Drive/backup/") . $backup_time; } else { goodbye("Could not find Dropbox or Google Drive for backup. You should create a folder named 'backup' to enable backup."); } } if (!file_exists($backup_path)) { mkdir($backup_path); } output("Backup location:" . $backup_path . "\n"); // Applications list $root_applications = scandir("/Applications"); array_unshift($root_applications, "Root apps:"); $home_applications = scandir(getAbsolutePath("~/Applications")); array_unshift($home_applications, "Home apps:"); file_put_contents($backup_path . "/Applications.txt", implode("\n", array_merge($root_applications, $home_applications))); output("Created applications list\n"); // Macports list $port_output = shell_exec("sudo port installed requested" . " 2>&1");