function connectIfNeeded() { if (@$GLOBALS['DBH']) { return; } connectToMySQL(); }
/** * Returns the data in the following format: * ["movies": $movies, "commonCast" : $commonCast, "commonGenres" : $commonGenres, "commonDirectors" : $commonDirectors] */ function get_data() { $con = connectToMySQL(); // try loading movies and commmonCast from 1) sesion, 2) local data json files, 3) mysql $rootDir = $_SERVER['DOCUMENT_ROOT']; $movies_file_name = $rootDir . '/data/movies.json'; $commonCast_file_name = $rootDir . '/data/commonCast.json'; $commonGenres_file_name = $rootDir . '/data/commonGenres.json'; $commonDirectors_file_name = $rootDir . '/data/commonDirectors.json'; $movies = false; $commonCast = false; $commonGenres = false; $commonDirectors = false; $successfullyLoaded = false; //// try loading from session //if ($_SESSION['movies'] and $_SESSION['commonCast'] and $_SESSION['commonGenres']){ // $movies = $_SESSION['movies']; // $commonCast = $_SESSION['commonCast']; // $commonGenres = $_SESSION['commonGenres']; // $successfullyLoaded = true; //} //else { if (file_exists($movies_file_name) && file_exists($commonCast_file_name) && file_exists($commonGenres_file_name) && file_exists($commonDirectors_file_name)) { $movies = json_decode(file_get_contents($movies_file_name), true); $commonCast = json_decode(file_get_contents($commonCast_file_name), true); $commonGenres = json_decode(file_get_contents($commonGenres_file_name), true); $commonDirectors = json_decode(file_get_contents($commonDirectors_file_name), true); if ($movies != false && $commonCast != false && $commonGenres != false && $commonDirectors != false) { $successfullyLoaded = true; } } //} if (!$successfullyLoaded) { // something went wrong => reload data loadDataFromDB($con, $movies_file_name, $commonCast_file_name, $commonGenres_file_name, $commonDirectors_file_name); //$_SESSION['movies'] = $movies; //$_SESSION['commonCast'] = $commonCast; //$_SESSION['commonGenres'] = $commonGenres; } $return_value = array("movies" => $movies, "commonCast" => $commonCast, "commonGenres" => $commonGenres, "commonDirectors" => $commonDirectors); mysql_close($con); return $return_value; }
<?php include '../lib/mysql.php'; $mysqli = connectToMySQL(); $email = str_replace('%2B', '+', $_POST['email']); $query = "INSERT INTO results (email, data, survey_id) VALUES (?, ?, ?)"; $stmt = $mysqli->prepare($query); $null = NULL; $stmt->bind_param('sbi', $email, $null, $_POST['survey_id']); $stmt->send_long_data(1, $_POST['data']); if ($stmt->execute()) { echo 'true'; } else { die('Error : (' . $mysqli->errno . ') ' . $mysqli->error); } $stmt->close(); $mysqli->close();
<?php /** * The main template file * */ include "header.php"; if (isset($_SESSION['admin'])) { ?> <h1 id="pageTitle">Logs</h1> <?php require_once "functions.php"; $conn = connectToMySQL(); //grabbing all logs from the database in order by date time $query = "SELECT * FROM tbl_logs ORDER BY dateTime DESC"; $result = mysqli_query($conn, $query) or die(mysqli_error($conn)); while ($row = mysqli_fetch_assoc($result)) { echo "<article class='logs'>\r\n\t\t\t\t\t {$row['dateTime']}, {$row['requestUri']}, {$row['logComment']}\r\n\t\t\t\t </article>"; } include "sidebar.php"; include "footer.php"; } else { header("Location:404.php"); }
function getNotRoleFunctions($ID) { try { $db = connectToMySQL(); $query = "SELECT FunctionID, Name\n\t\t FROM functions WHERE FunctionID NOT IN\n\t\t (SELECT functions.FunctionID\n\t\t FROM functions, rolefunctions\n\t\t WHERE rolefunctions.RoleID = :ID AND functions.FunctionID = rolefunctions.FunctionID)\n ORDER BY functions.Name"; $statement = $db->prepare($query); $statement->bindValue(':ID', $ID); $statement->execute(); $results = $statement->fetchAll(); $statement->closeCursor(); return $results; } catch (PDOException $e) { displayDBError($e->getMessage()); } }
<tr><td align="right">Password:</td> <td align="left"><input type="password" name ="passwd"> </td> </tr> <tr><td align="right">php.ini path:</td> <td align="left"><input type="text" name ="phpini"> </td> </tr> <tr><td align="right">httpd.conf Path:</td> <td align="left"><input type="text" name ="httpdconf"> </td> </tr> <tr><td align="right"><input type="submit" name="connect" value="Connect"></td></tr> </table> </form> <br /> <?php if (isset($_POST['connect'])) { $host = $_POST['host']; $user = $_POST['user']; $passwd = $_POST['passwd']; $phpini = $_POST['phpini']; $httpdconf = $_POST['httpdconf']; $connected = connectToMySQL($host, $user, $passwd, $phpini, $httpdconf); $db_created = CreateDB(); $tables_created = createTables(); $directives_populated = populateValues(); if ($connected && $db_created && $tables_created && $directives_populated) { echo "Database setup successfully completed. Please "; } ?> <a href="index.php"> Continue... </a> <?php } ?> <br /> <!-- END Slider --> </div>
$APP = array('version' => '2.65', 'build' => '1122', 'id' => '19', 'key' => '35809', 'alerts' => @$GLOBALS['APP']['alerts']); define('PREFIX_URL', $SETTINGS['webPrefixUrl']); // v2.53 define('CMS_ASSETS_URL', parse_url(dirname($SETTINGS['adminUrl']), PHP_URL_PATH)); // for more complicated path references: parse_url( realUrl('../cms-assets', $SETTINGS['adminUrl']), PHP_URL_PATH)); $GLOBALS['CMS_ASSETS_URL'] = CMS_ASSETS_URL; // set timezone _init_setTimezone(); // check for internet connectivity if (!isInstalled()) { _init_showInternetConnectivityErrors(); } // only run if software not installed yet // connect to mysql if (isInstalled()) { connectToMySQL(); } // load plugins loadPlugins(); // Check for accidentally added whitespace or other output (by end users) - extra linebreaks at the end of library or plugin files // ... can cause ajax calls to fail (whitespace is interpreted as error message and returned in 'blank' popups) or gzip output to // ... become corrupted. Note that server behaviour will vary based on output_buffering another other settings (search "output" in phpinfo) if (defined('IS_CMS_ADMIN')) { // only run this in CMS admin, we don't want errors on viewer pages $unexpectedOutputErrors = ''; if (headers_sent($outputSentFile, $outputSentLine)) { // headers_sent() gets triggered when php's 'output_buffer' bytes are exceeded $unexpectedOutputErrors .= sprintf('Unexpected output was sent by the following file: %1$s (on line %2$s)', htmlencode(@$outputSentFile), htmlencode(@$outputSentLine)) . "\n"; $unexpectedOutputErrors .= "Developers: Check plugins and library files for accidentally added whitespace or other characters.\n"; die(nl2br($unexpectedOutputErrors)); // start_session will fail if headers_sent so we need to die here to show error.
function installIfNeeded() { global $SETTINGS, $APP, $TABLE_PREFIX; if (isInstalled()) { return; } // skip if already installed // rename default files renameOrRemoveDefaultFiles(); // error checking if ($SETTINGS['uploadDir'] && !is_dir($SETTINGS['uploadDir'])) { print "Upload directory doesn't exist, please update 'uploadDir' in /data/" . SETTINGS_FILENAME . "<br/>\n"; print "Current uploadDir value: " . htmlencode($SETTINGS['uploadDir']) . "<br/>\n"; print "Suggested uploadDir value: uploads/ or ../uploads/<br/>\n"; exit; } // error checking checkFilePermissions(); // display license if (@$_REQUEST['menu'] == 'license') { showInterface('license.php'); } // save if (@$_REQUEST['save']) { // error checking if (!$_REQUEST['licenseCompanyName']) { alert("Please enter your 'Company Name'<br/>\n"); } if (!$_REQUEST['licenseDomainName']) { alert("Please enter your 'Domain Name'<br/>\n"); } if (!$_REQUEST['licenseProductId']) { alert("Please enter your 'Product Id'<br/>\n"); } else { if (!isValidProductId($_REQUEST['licenseProductId'])) { alert("Invalid Product Id!<br/>\n"); } } if (!$_REQUEST['agreeToOneInstall']) { alert("Please check 'I agree not to use this 'Product Id' for multiple installs'<br/>\n"); } if (!$_REQUEST['understandTermination']) { alert("Please check 'I understand doing so may cause be to lose my right to use this software'<br/>\n"); } if (!$_REQUEST['agreeToLicense']) { alert("Please check 'I accept the terms of the License Agreement'<br/>\n"); } if (!$_REQUEST['mysqlHostname']) { alert("Please enter your 'MySQL Hostname'<br/>\n"); } if (!$_REQUEST['mysqlDatabase']) { alert("Please enter your 'MySQL Database'<br/>\n"); } if (!$_REQUEST['mysqlUsername']) { alert("Please enter your 'MySQL Username'<br/>\n"); } if (!$_REQUEST['mysqlTablePrefix']) { alert("Please enter your 'MySQL Table Prefix'<br/>\n"); } elseif (preg_match("/[A-Z]/", $_REQUEST['mysqlTablePrefix'])) { alert("Value for 'MySQL Table Prefix' must be lowercase.<br/>\n"); } elseif (!preg_match("/^[a-z]/i", $_REQUEST['mysqlTablePrefix'])) { alert("Value for 'MySQL Table Prefix' must start with a letter.<br/>\n"); } elseif (!preg_match("/_\$/", $_REQUEST['mysqlTablePrefix'])) { alert("Value for 'MySQL Table Prefix' must end in underscore.<br/>\n"); } // New Installation if (!@$_REQUEST['restoreFromBackup']) { if (!$_REQUEST['adminFullname']) { alert("Please enter 'Admin Full Name'<br/>\n"); } if (!$_REQUEST['adminEmail']) { alert("Please enter 'Admin Email'<br/>\n"); } elseif (!isValidEmail($_REQUEST['adminEmail'])) { alert("Please enter a valid email for 'Admin Email' (Example: user@example.com)<br/>\n"); } if (!$_REQUEST['adminUsername']) { alert("Please enter 'Admin Username'<br/>\n"); } $passwordErrors = getNewPasswordErrors($_REQUEST['adminPassword1'], $_REQUEST['adminPassword2'], $_REQUEST['adminUsername']); // v2.52 if ($passwordErrors) { alert(nl2br(htmlencode($passwordErrors))); } } // Restore from Backup if (@$_REQUEST['restoreFromBackup']) { if (!$_REQUEST['restore']) { alert("Please select a backup file to restore<br/>\n"); } } // Advanced - v2.53 if (!@$_REQUEST['useCustomSettingsFile']) { if (is_file(SETTINGS_DEV_FILEPATH)) { alert(t("You must select 'Use Custom Settings File' since a custom settings file for this domain already exists!") . "<br/>\n"); } elseif (isDevServer()) { alert("This is a development server, you must select 'Use Custom Settings File'." . "<br/>\n"); } } if (@$_REQUEST['webPrefixUrl'] != '') { if (!preg_match("|^(\\w+:/)?/|", $_REQUEST['webPrefixUrl'])) { alert(t("Website Prefix URL must start with /") . "<br/>\n"); } if (preg_match("|/\$|", $_REQUEST['webPrefixUrl'])) { alert(t("Website Prefix URL cannot end with /") . "<br/>\n"); } } // update settings (not saved unless there are no errors) $SETTINGS['cookiePrefix'] = substr(md5(mt_rand()), 0, 5) . '_'; //v2.51 shortened prefix so it's easy to see full cookie names in browser cookie list $SETTINGS['adminEmail'] = @$SETTINGS['adminEmail'] ? $SETTINGS['adminEmail'] : $_REQUEST['adminEmail']; $SETTINGS['licenseCompanyName'] = $_REQUEST['licenseCompanyName']; $SETTINGS['licenseDomainName'] = $_REQUEST['licenseDomainName']; $SETTINGS['licenseProductId'] = $_REQUEST['licenseProductId']; $SETTINGS['webRootDir'] = @$SETTINGS['webRootDir'] ? $SETTINGS['webRootDir'] : @$_SERVER['DOCUMENT_ROOT']; $SETTINGS['mysql']['hostname'] = $_REQUEST['mysqlHostname']; $SETTINGS['mysql']['database'] = $_REQUEST['mysqlDatabase']; $SETTINGS['mysql']['username'] = $_REQUEST['mysqlUsername']; $SETTINGS['mysql']['password'] = $_REQUEST['mysqlPassword']; $SETTINGS['mysql']['tablePrefix'] = $_REQUEST['mysqlTablePrefix']; $TABLE_PREFIX = $_REQUEST['mysqlTablePrefix']; // update TABLE_PREFIX global as well. $SETTINGS['webPrefixUrl'] = $_REQUEST['webPrefixUrl']; // display errors if (alert()) { require "lib/menus/install.php"; exit; } // connect to mysql $errors = connectToMySQL('returnErrors'); if ($errors) { alert($errors); require "lib/menus/install.php"; exit; } else { connectToMySQL(); } // create schema tables createMissingSchemaTablesAndFields(); clearAlertsAndNotices(); // don't show "created table/field" alerts // New Installation: check if admin user already exists if (!@$_REQUEST['restoreFromBackup']) { $passwordHash = getPasswordDigest($_REQUEST['adminPassword1']); $identicalUserExists = mysql_count('accounts', array('username' => $_REQUEST['adminUsername'], 'password' => $passwordHash, 'isAdmin' => '1')); if (!$identicalUserExists) { // if the don't exist, check if a user with the same username exists and show an error if they do $count = mysql_count('accounts', array('username' => $_REQUEST['adminUsername'])); if (!$identicalUserExists && $count > 0) { alert("Admin username already exists, please choose another.<br/>\n"); } } // create admin user if (!$identicalUserExists && !alert()) { mysqlStrictMode(false); // disable Mysql strict errors for when a field isn't defined below (can be caused when fields are added later) mysql_query("INSERT INTO `{$TABLE_PREFIX}accounts` SET\n createdDate = NOW(),\n createdByUserNum = '0',\n updatedDate = NOW(),\n updatedByUserNum = '0',\n fullname = '" . mysql_escape($_REQUEST['adminFullname']) . "', email = '" . mysql_escape($_REQUEST['adminEmail']) . "',\n username = '******'adminUsername']) . "', password = '******',\n disabled = '0',\n isAdmin = '1',\n expiresDate = '0000-00-00 00:00:00',\n neverExpires = '1'") or alert("MySQL Error Creating Admin User:<br/>\n" . htmlencode(mysql_error()) . "\n"); // create accesslist entry mysql_query("INSERT INTO `{$TABLE_PREFIX}_accesslist` (userNum, tableName, accessLevel, maxRecords, randomSaveId)\n VALUES (LAST_INSERT_ID(), 'all', '9', NULL, '1234567890')") or alert("MySQL Error Creating Admin Access List:<br/>\n" . htmlencode(mysql_error()) . "\n"); } } // Restore from Backup: Restore backup file if (@$_REQUEST['restoreFromBackup']) { $userCount = mysql_count('accounts'); if ($userCount) { $userTable = $TABLE_PREFIX . 'accounts'; $errorMessage = sprintf("Can't restore from backup because it would overwrite the %s existing user accounts in the specified database location.<br/>\n", $userCount); $errorMessage .= sprintf("Try changing the MySQL Database or Table Prefix to restore to a different location, or remove existing users from '%s'.<br/>\n", $userTable); alert($errorMessage); } else { // restore database $filename = @$_REQUEST['restore']; mysqlStrictMode(false); // disable Mysql strict errors restoreDatabase(DATA_DIR . '/backups/' . $filename); notice("Restored backup file /data/backups/{$filename}"); makeAllUploadRecordsRelative(); } } // save settings if (!alert()) { saveSettings(@$_REQUEST['useCustomSettingsFile']); isInstalled(true); // save installed status redirectBrowserToURL('?menu=home', true); // refresh page exitl; } } // set defaults if (!array_key_exists('licenseDomainName', $_REQUEST)) { $_REQUEST['licenseDomainName'] = $_SERVER['HTTP_HOST']; } if (!array_key_exists('mysqlHostname', $_REQUEST)) { $_REQUEST['mysqlHostname'] = $SETTINGS['mysql']['hostname']; } if (!array_key_exists('mysqlDatabase', $_REQUEST)) { $_REQUEST['mysqlDatabase'] = $SETTINGS['mysql']['database']; } if (!array_key_exists('mysqlUsername', $_REQUEST)) { $_REQUEST['mysqlUsername'] = $SETTINGS['mysql']['username']; } if (!array_key_exists('mysqlTablePrefix', $_REQUEST)) { $_REQUEST['mysqlTablePrefix'] = $SETTINGS['mysql']['tablePrefix']; } // show form require "lib/menus/install.php"; exit; }
/** * Runs the appropriate FFmpeg shell command * @param $scheduleItems The list of Schedule Items for the Schedule */ function runFFmpeg($scheduleItems, $minsSinceMidnight, $channelID) { $scheduleItemID = ""; $scheduleItemOffset = 0; $scheduleItemComplete = null; $scheduleItemTakenDown = null; //Get Schedule Item based on elapsed minutes. //If the number of minutes since midnight is greater than the offset of the current schedule item, check the next foreach ($scheduleItems as $row) { //Any schedule item after first item, else the first item if ($row[0] > $minsSinceMidnight && $row != 0) { $scheduleItemOffset = $row[0] - 1; //time offset $scheduleItemID = $row[1] - 1; //scheduleItemID $scheduleItemTakenDown = $row[2] - 1; //taken_down $scheduleItemComplete = $row[3] - 1; //complete break; } else { if ($row[0] < $minsSinceMidnight && $row[0] + 1 > $minsSinceMidnight && $row == 0) { $scheduleItemOffset = $row[0]; $scheduleItemID = $row[1]; $scheduleItemTakenDown = $row[2]; $scheduleItemComplete = $row[3]; break; } } } $getFileLocation = "SELECT location FROM File INNER JOIN (`Schedule Item`,`Video`) ON (`Schedule Item`.scheduleItemID='" + $scheduleItemID + "' AND `Schedule Item`.videoID = Video.videoID AND Video.fileID=File.fileID)"; $fileLocationResult = connectToMySQL($getFileLocation); $rowTest = mysqli_fetch_array($fileLocationResult); $rowTest2 = $rowTest["location"]; shell_exec("ffmpeg -re -i " + $rowTest2 + " -preset ultrafast http://localhost:8090/Channel" . $channelID . ".ffm &"); //No Schedule Item OR Current Schedule Item Taken Down if ($scheduleItemID == "" || $scheduleItemTakenDown == true) { //Channel Off Air Placeholder //shell_exec("ffmpeg -re -i /var/www/videos/programmes/P00000000-1080-30.mp4 -preset ultrafast http://localhost:8090/Channel".$channelID.".ffm &"); } else { if ($scheduleItemComplete == true) { //Next Schedule Item $getFileLocation = "SELECT File.fileID, location FROM File INNER JOIN (`Schedule Item`,`Video`) ON (`Schedule Item`.scheduleItemID='2016-04-12-0001' AND `Schedule Item`.videoID = Video.videoID AND Video.fileID=File.fileID)"; $fileLocationResult = connectToMySQL($getFileLocation); $fileLocationResult2 = $fileLocationResult["location"]; echo shell_exec("ffmpeg -re -i " + $fileLocationResult2 + " -preset ultrafast http://localhost:8090/Channel1.ffm &"); } else { if ($minsSinceMidnight - $scheduleItemOffset <= 1) { echo "mark schedule item complete"; $markCompleteQuery = "UPDATE `Schedule Item` SET complete=1 WHERE scheduleItemID=" . $scheduleItemID; connectToMySQL($markCompleteQuery); } } } }
function queryAndStreamXML($conditions, $randomize = false, $limit = null) { $beginTime = microtime(true); $mysql = connectToMySQL(); $conditions[] = '`isactive` = 1'; $query = 'SELECT `edittype`, `editid`, `comment`, `user`, `user_edit_count`, `user_distinct_pages`, `user_warns`, `prev_user`, UNIX_TIMESTAMP( `user_reg_time` ) AS `user_reg_time_unix`, UNIX_TIMESTAMP( `common_page_made_time` ) AS `common_page_made_time_unix`, `common_title`, `common_namespace`, `common_creator`, `common_num_recent_edits`, `common_num_recent_reversions`, `current_minor`, UNIX_TIMESTAMP( `current_timestamp` ) AS `current_timestamp_unix`, `current_text`, UNIX_TIMESTAMP( `previous_timestamp` ) AS `previous_timestamp_unix`, `previous_text`, `isvandalism`, `isactive`, `source`, UNIX_TIMESTAMP( `updated` ) AS `updated_unix`, `reviewers`, `reviewers_agreeing` FROM `editset` WHERE '; $query .= implode(' AND ', $conditions); if ($randomize) { $query .= ' ORDER BY RAND()'; } else { if ($randomize === false and ($limit !== null and strpos(',', $limit) === false or $limit === null)) { $row = mysql_fetch_assoc(mysql_query('SELECT COUNT(*) as `count` FROM `editset` WHERE ' . implode(' AND ', $conditions))); $start = rand(0, $row['count'] - ($limit === null ? 0 : $limit)); if ($limit !== null and strpos(',', $limit) === false) { $limit = $start . ',' . $limit; } else { $limit = $start . ',18446744073709551615'; } } } if ($limit !== null) { $query .= ' LIMIT ' . $limit; } $xml = new XMLWriter(); $xml->openURI('php://output'); $xml->setIndent(true); $xml->startDocument('1.0', 'UTF-8'); $xml->startElement('WPEditSet'); $xml->startComment(); $xml->startElement('EditDB'); $xml->writeElement('query', $query); $xml->writeElement('time', time()); if (function_exists('posix_uname')) { $uname = posix_uname(); $xml->startElement('uname'); foreach ($uname as $key => $value) { $xml->writeElement($key, $value); } $xml->endElement(); } if (function_exists('posix_getlogin')) { $xml->writeElement('username', posix_getlogin()); } $xml->endElement(); $xml->endComment(); $result = mysql_unbuffered_query($query); if (!$result) { error('MySQL Query Error: ' . mysql_error() . "\n" . 'Query: ' . $query); } $count = 0; while ($row = mysql_fetch_assoc($result)) { $xml->startElement('WPEdit'); $xml->startElement('EditDB'); $xml->writeElement('isActive', $row['isactive'] ? 'true' : 'false'); $xml->writeElement('source', $row['source']); $xml->writeElement('lastUpdated', $row['updated_unix']); $xml->endElement(); $xml->writeElement('EditType', $row['edittype']); $xml->writeElement('EditID', $row['editid']); $xml->writeElement('comment', $row['comment']); $xml->writeElement('user', $row['user']); $xml->writeElement('user_edit_count', $row['user_edit_count']); $xml->writeElement('user_distinct_pages', $row['user_distinct_pages']); $xml->writeElement('user_warns', $row['user_warns']); $xml->writeElement('prev_user', $row['prev_user']); $xml->writeElement('user_reg_time', $row['user_reg_time_unix']); $xml->startElement('common'); $xml->writeElement('page_made_time', $row['common_page_made_time_unix']); $xml->writeElement('title', $row['common_title']); $xml->writeElement('namespace', $row['common_namespace']); $xml->writeElement('creator', $row['common_creator']); $xml->writeElement('num_recent_edits', $row['common_num_recent_edits']); $xml->writeElement('num_recent_reversions', $row['common_num_recent_reversions']); $xml->endElement(); $xml->startElement('current'); $xml->writeElement('minor', $row['current_minor'] ? 'true' : 'false'); $xml->writeElement('timestamp', $row['current_timestamp_unix']); $xml->writeElement('text', $row['current_text']); $xml->endElement(); $xml->startElement('previous'); $xml->writeElement('timestamp', $row['previous_timestamp_unix']); $xml->writeElement('text', $row['previous_text']); $xml->endElement(); $xml->writeElement('isVandalism', $row['isvandalism'] ? 'true' : 'false'); $xml->startElement('ReviewInterface'); $xml->writeElement('reviewers', $row['reviewers']); $xml->writeElement('reviewers_agreeing', $row['reviewers_agreeing']); $xml->endElement(); $xml->endElement(); $count++; } $xml->writeComment('Generated in ' . (microtime(true) - $beginTime) . ' seconds. ' . $count . ' entries returned.'); $xml->endElement(); $xml->endDocument(); $xml->flush(); }