function JBCacheFiles() { parent::JBCacheDriver(); if (function_exists('JB_get_cache_dir')) { $this->cache_dir = JB_get_cache_dir(); } else { $dir = dirname(__FILE__); $dir = explode(DIRECTORY_SEPARATOR, $dir); $blank = array_pop($dir); $blank = array_pop($dir); $blank = array_pop($dir); $dir = implode('/', $dir); $this->cache_dir = $dir . '/' . 'cache' . '/'; } $this->file_prefix = 'jb_cache_'; }
function JB_discover_new_file_owner($verbose = false) { $owner = ''; $temp = JB_get_cache_dir() . 'owner_test.tmp'; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { if ($verbose) { echo "Does not work on windows"; } return false; } if (file_exists($temp)) { if (!unlink($temp)) { if ($verbose) { echo "There was an error with deleting {$temp} - please remove this file via FTP<br>"; } } } if (touch($temp)) { $disabled = explode(', ', ini_get('disable_functions')); if (in_array('exec', $disabled)) { return 'exec no permitted on this server'; } JB_exec('ls -o ' . $temp, $output); $parts = preg_split('/[\\s]+/', $output[0]); array_shift($parts); // these are the file permssions // the next one should be owner foreach ($parts as $part) { if (strlen($part) > 2 && preg_match('/[a-z0-9]{3}/i', $part)) { $owner = $part; break; } } unlink($temp); if (!$owner) { echo $owner = 'nobody'; } return $owner; } else { if ($verbose) { echo 'cannot create file: ' . $temp . ' Please give the following directory permissions for writing: <br>'; } } }
<hr> <?php if ($_REQUEST['save_feed'] != '') { if ($error = JBXM_validate_xml_feed_input()) { $JBMarkup->error_msg("Cannot save the feed due to the following errors:"); echo $error; JBXM_display_xml_feed_form(); } else { JBXM_save_xml_feed_input(); $JBMarkup->ok_msg('Changes Saved.'); } } if ($_REQUEST['clear'] != '') { $cache_dir = JB_get_cache_dir(); $filename = $cache_dir . 'feed_' . md5($_REQUEST['clear'] . $_REQUEST['feed_key']) . ".xml"; @unlink($filename); $JBMarkup->ok_msg('Cache Cleared.'); } if ($_REQUEST['delfeed'] != '') { $sql = "DELETE FROM xml_export_feeds WHERE feed_id='" . jb_escape_sql($_REQUEST['feed_id']) . "' "; JB_mysql_query($sql) or die(mysql_error()); $JBMarkup->ok_msg('Feed Deleted.'); } if ($_REQUEST['new'] == 'yes') { if ($_REQUEST['schema_id'] == '') { echo '<p>'; echo 'Please select what type of feed you would like to create (Schema):<br>'; ?> <form method='post' action="<?php
function get_cache_dir() { if (function_exists('JB_get_cache_dir')) { return JB_get_cache_dir(); } else { static $dir; if (isset($dir)) { return $dir; } $dir = dirname(__FILE__); $dir = preg_split('%[/\\\\]%', $dir); $blank = array_pop($dir); $blank = array_pop($dir); $blank = array_pop($dir); $dir = implode('/', $dir) . '/cache/'; JBPLUG_do_callback('get_cache_dir', $dir); return $dir; } }
function log_entry($line) { $line = $date = date("D, j M Y H:i:s O") . ' - ' . $line . "\n"; $s = md5(JB_SITE_NAME); if (function_exists('JB_get_cache_dir')) { $cache_dir = JB_get_cache_dir(); } else { $cache_dir = JB_basedirpath() . 'cache/'; } $file_name = $cache_dir . 'import_log_' . $s . '.txt'; if (file_exists($file_name)) { if (time() - filemtime($file_name) > time() + 60 * 60) { // older than 24 hrs? $open_mode = 'wb'; // overwrite the file $line .= date("D, j M Y H:i:s O") . ' - ' . "Cleared the log\n" . $line; } else { $open_mode = 'ab'; } } else { $open_mode = 'wb'; } $fp = fopen($file_name, $open_mode); fputs($fp, $line); fclose($fp); if ($this->verbose) { echo htmlentities($line); flush(); ob_flush(); } }
function jb_custom_error_handler($errno, $errmsg, $filename, $linenum, $vars) { if ($errno <= 4 || $errno == 'sql') { // Log the fatals & warnings $str .= date('r', time()); $str .= ' | '; $str .= $errno . ' | '; $str .= $errmsg . ' | '; $str .= 'file: ' . $filename . ' | '; $str .= 'line: ' . $linenum . ' | '; $str .= "<br>\n"; if (!function_exists('JB_get_cache_dir')) { $dir = 'cache/'; } else { $dir = JB_get_cache_dir(); } $filename = $dir . 'error_log_' . md5(md5(JB_ADMIN_PASSWORD)); $fp = fopen($filename, 'a'); fwrite($fp, $str, strlen($str)); fclose($fp); return true; } }
function JBXML_generate_xml_feed($feed_id) { if (!is_numeric($feed_id)) { return; } $offset = 0; if (isset($_REQUEST['offset'])) { $offset = (int) $_REQUEST['offset']; } $sql = "SELECT * from xml_export_feeds WHERE feed_id='" . jb_escape_sql($feed_id) . "' "; $result = JB_mysql_query($sql); $feed_row = mysql_fetch_array($result, MYSQL_ASSOC); if ($feed_row['publish_mode'] == 'PRI') { // private mode if ($feed_row['feed_key'] != $_REQUEST['k']) { die('Invalid Key. Please contact ' . JB_SITE_CONTACT_EMAIL); } } $hosts = array(); $hosts = explode(',', $feed_row['hosts_allow']); $allowed = false; if (sizeof($hosts) > 0) { foreach ($hosts as $host) { if (strtoupper($host) == 'ALL') { // all hosts $allowed = true; } if (strtolower($host) == 'localhost' && $_SERVER['REMOTE_ADDR'] == '127.0.0.1') { $allowed = true; } if ($host == $_SERVER['REMOTE_ADDR']) { $allowed = true; } } if (!$allowed) { die('Access is restricted form your IP. Please contact ' . JB_SITE_CONTACT_EMAIL); } } $feed_row['field_settings'] = unserialize($feed_row['field_settings']); $feed_row['search_settings'] = unserialize($feed_row['search_settings']); // build the search query up... if (is_array($feed_row['search_settings'])) { foreach ($feed_row['search_settings'] as $key => $val) { $_SEARCH_INPUT[$key] = $val; } $_SEARCH_INPUT['action'] = 'search'; global $post_tag_to_search; global $tag_to_search; $where_sql = JB_generate_search_sql($feed_row['form_id'], $_SEARCH_INPUT); } if ($feed_row['max_records'] > 0) { $limit = "LIMIT {$offset}, " . jb_escape_sql($feed_row['max_records']); } switch ($feed_row['form_id']) { case 1: if ($feed_row['include_imported'] == 'Y') { if ($where_sql) { $where_sql = ' AND ' . $where_sql; } $sql = "SELECT * FROM posts_table WHERE `expired`='N' AND `approved`='Y' {$where_sql} ORDER BY `post_date` DESC {$limit} "; } else { $sql = "SELECT * FROM posts_table WHERE `expired`='N' AND `approved`='Y' AND `guid`='' {$where_sql} ORDER BY `post_date` DESC {$limit} "; } break; case 2: break; case 3: break; case 4: break; case 5: break; } $records = JB_mysql_query($sql); // Gzip compress the output, if supported by PHP & the browser //if (function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) { //ob_start("ob_gzhandler"); //} else { //ob_start(); //} header('Content-type: application/xml; charset=UTF-8'); if ($_REQUEST['d'] != '') { // download? header('Content-Disposition: attachment; filename="feed-' . htmlentities($feed_id) . '.xml"'); } // check to see if we have this feed in the cache if (function_exists('JB_get_cache_dir')) { $cache_dir = JB_get_cache_dir(); } else { $cache_dir = JB_basedirpath() . 'cache/'; } if (is_dir($cache_dir)) { if ($dh = opendir($cache_dir)) { while (($file = readdir($dh)) !== false) { if (filetype($cache_dir . $file) == 'file' && strpos($file, '.xml') !== false) { $stats = stat($cache_dir . $file); if ($stats['mtime'] + 3600 < time()) { // has 1 hour elapsed? (3600 sec) unlink($cache_dir . $file); } } } closedir($dh); } } $do_update = false; $filename = $cache_dir . 'feed_' . md5($feed_row['feed_id'] . $feed_row['feed_key'] . $offset) . ".xml"; if (!file_exists($filename)) { $do_update = true; } $do_update = true; if ($do_update) { // Generate the XML feed & cache the result. echo '<?xml version="1.0" encoding="UTF-8" ?>'; $fh = fopen($filename, "wb"); if (flock($fh, LOCK_EX)) { // do an exclusive lock ftruncate($fh, 0); // truncate file JBXM_xml_feed_gen_engine($feed_row, '', $records, $data, false, $fh); flock($fh, LOCK_UN); // release the lock } else { echo "<error>Couldn't get the lock!</error>"; } fclose($fh); } else { // Return the cached xml feed $fh = fopen($filename, 'rb'); $contents = fread($fh, filesize($filename)); fclose($fh); echo $contents; } ob_end_flush(); }
# You can obtain one at http://mozilla.org/MPL/2.0/. ########################################################################### require "../config.php"; require dirname(__FILE__) . "/admin_common.php"; JB_admin_header('Admin -> XML Import Log'); ?> <b>[XML Import]</b> <span style="background-color:#F2F2F2; border-style:outset; padding:5px; "><a href="xmlimport.php">Import Setup</a></span> <span style="background-color:#FFFFCC; border-style:outset; padding:5px; "><a href="xmlimport_log.php">Import Log</a></span> <span style="background-color:#F2F2F2; border-style:outset; padding: 5px;"><a href="xmlimporthelp.php">Import Help</a></span> <hr> <h3>Import Log</h3> <?php $s = md5(JB_SITE_NAME); $filename = JB_get_cache_dir() . 'import_log_' . $s . '.txt'; if ($_REQUEST['clear_log'] == true) { if (file_exists($filename)) { unlink($filename); } } // READ THE LOG if (file_exists($filename)) { $size = filesize($filename); $bytes_read = 0; if ($size > 0) { $fp = fopen($filename, 'r'); echo '<textarea rows="25" cols="100" style="width:99%">'; while (!feof($fp)) { $log = fread($fp, 1024); $bytes_read += 1024;
function process_payment_return() { global $label; if (PAYPAL_USE_CURL == 'YES') { // cannot use cURL for PTD, use for IPN only //return false; } //////////// // Paypal ########################### // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-synch'; $tx_token = $_GET['tx']; $auth_token = PAYPAL_AUTH_TOKEN; $req .= "&tx={$tx_token}&at={$auth_token}"; $result = ''; if (PAYPAL_USE_CURL == 'YES') { // Use curl to post back to PayPAl // and put the result in a file. // open the file using $fp pp_log_entry('PDD - Using cURL to POST to PayPal'); $URL = "https://" . PAYPAL_SERVER . "/cgi-bin/webscr"; $ch = curl_init(); if (PAYPAL_CURL_PROXY != '') { curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE); curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); curl_setopt($ch, CURLOPT_PROXY, PAYPAL_CURL_PROXY); } //$req = "username=test&password=test"; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_URL, $URL); curl_setopt($ch, CURLOPT_TIMEOUT, 20); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $req); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); pp_log_entry('PDT posting to PayPal and using cURL: ' . $result); $result = curl_exec($ch); pp_log_entry(curl_error($ch)); curl_close($ch); pp_log_entry('PDD -Got this from result from cURL: ' . $result); $filename = JB_get_cache_dir() . md5(time() . PAYPAL_AUTH_TOKEN) . 'PDT.paypal'; $fp = fopen($filename, 'w'); fwrite($fp, $result, strlen($result)); $fp = fclose($fp); // open for reading $fp = fopen($filename, 'r'); } else { // post back to PayPal system to validate $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen(PAYPAL_SERVER, 80, $errno, $errstr, 30); // If possible, securely post back to paypal using HTTPS // Your PHP server will need to be SSL enabled // $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); } if (!$fp) { // HTTP ERROR //echo "fp error"; pp_log_entry('PDD -Could not open socket / file'); } else { if (PAYPAL_USE_CURL != 'YES') { fputs($fp, $header . $req); // post to paypal } // read the body data $res = ''; $headerdone = false; while (!feof($fp)) { $line = fgets($fp, 1024); if (strcmp($line, "\r\n") == 0) { // read the header $headerdone = true; } else { if ($headerdone) { // header has been read. now read the contents $res .= $line; } } } } fclose($fp); if (PAYPAL_USE_CURL == 'YES') { unlink($filename); } // parse the data $lines = explode("\n", $res); $keyarray = array(); if (strcmp($lines[0], "SUCCESS") == 0 || strpos($result, 'SUCCESS') !== false) { pp_log_entry('PDD - Notification verfified'); for ($i = 1; $i < count($lines); $i++) { list($key, $val) = explode("=", $lines[$i]); $keyarray[urldecode($key)] = urldecode($val); } //print_r($_REQUEST); // check the payment_status is Completed // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment $firstname = $keyarray['first_name']; $lastname = $keyarray['last_name']; $itemname = $keyarray['item_name']; $amount = $keyarray['payment_gross']; $txn_id = $keyarray['txn_id']; $mc_gross = $keyarray['mc_gross']; $mc_currency = $keyarray['mc_currency']; $payer_email = $keyarray['payer_email']; $payment_status = $keyarray['payment_status']; $invoice_id = jb_strip_order_id($keyarray['invoice']); $product_type = substr($invoice_id, 0, 1); // 'P' or 'S' $invoice_id = substr($invoice_id, 1); JBPLUG_do_callback('pay_trn_verification_passed', $invoice_id, $product_type); if ($payment_status == 'Completed') { if ($product_type == 'P') { ?> <center> <img src="<?php echo JB_SITE_LOGO_URL; ?> "> <?php $label['payment_posts_completed2'] = str_replace("%URL%", JB_BASE_HTTP_PATH . JB_EMPLOYER_FOLDER . 'manager.php', $label['payment_posts_completed2']); ?> <p><?php echo $label['payment_posts_completed2']; ?> </p> </center> <?php } elseif ($product_type == 'S') { ?> <center> <img src="<?php echo JB_SITE_LOGO_URL; ?> "> <?php $label['payment_subscription_completed2'] = str_replace("%URL%", JB_BASE_HTTP_PATH . JB_EMPLOYER_FOLDER . 'search.php', $label['payment_subscription_completed2']); ?> <p><?php echo $label['payment_subscription_completed2']; ?> </p> </center> <?php } elseif ($product_type == 'M') { // membership completed ?> <center> <img src="<?php echo JB_SITE_LOGO_URL; ?> "> <?php //$label['payment_membership_completed'] = str_replace("%URL%", JB_BASE_HTTP_PATH.JB_EMPLOYER_FOLDER, $label['payment_membership_completed']); ?> <p><?php echo $label['payment_membership_completed']; ?> </p> </center> <?php } $sql = "SELECT * FROM jb_txn WHERE txn_id='" . jb_escape_sql($txn_id) . "' and origin='PayPal' "; $result = JB_mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { // already in the database, possibly entered in by the IPN System } else { if ($product_type == 'P') { JB_complete_package_invoice($invoice_id, 'PayPal'); } elseif ($product_type == 'S') { if (PAYPAL_MANUAL_APPROVE == 'Y') { pp_subscr_manual_approve($invoice_id); } else { JB_complete_subscription_invoice($invoice_id, 'PayPal'); } } elseif ($product_type == 'M') { JB_complete_membership_invoice($invoice_id, 'PayPal'); } JB_debit_transaction($invoice_id, $mc_gross, $mc_currency, $txn_id, $reason_code, 'PayPal', $product_type, $_REQUEST['subscr_id']); } JBPLUG_do_callback('pay_trn_completed', $invoice_id, $product_type); } elseif ($payment_status == 'Pending') { if ($product_type == 'P') { JB_pend_package_invoice($invoice_id, 'PayPal', $reason_code); } elseif ($product_type == 'S') { JB_pend_subscription_invoice($invoice_id, 'PayPal', $reason_code); } elseif ($product_type == 'M') { JB_pend_membership_invoice($invoice_id, 'PayPal', $reason_code); } JBPLUG_do_callback('pay_trn_pending', $invoice_id, $product_type); $label['payment_return_pending'] = str_replace("%PAYMENT_GW%", $this->name, $label['payment_return_pending']); ?> <center> <img src="<?php echo JB_SITE_LOGO_URL; ?> "> <p><?php echo $label['payment_return_pending']; ?> </p> </center> <?php } else { echo "Payment status: {$payment_status}"; } } else { if (strcmp($lines[0], "FAIL") == 0) { // log for manual investigation pp_log_entry('PDD - verification failed'); JBPLUG_do_callback('pay_trn_verification_failed', $invoice_id, $product_type); echo $label['paypal_ipn_fail']; ?> <?php } } ?> <p> </p> <p> </p> <p> </p> <p> </p> <?php }
if (JB_SET_CUSTOM_ERROR != 'YES') { echo "<p>Note: Custom error logging is disabled. Please go to Main Config and enable it from there if you want to have all errors logged here</p>"; } ?> <input type="button" value="Refresh" onclick="window.document.location='<?php echo htmlentities($_SERVER['PHP_SELF']); ?> '"> | <input type="button" value="Clear" onclick="window.document.location='<?php echo $_SERVER['PHP_SELF']; ?> ?clear=1'"><br> <?php $dir = jb_get_cache_dir(); if ($_REQUEST['clear'] == 1) { $filename = JB_get_cache_dir() . "error_log_" . md5(md5(JB_ADMIN_PASSWORD)); if (file_exists($filename)) { $handle = fopen($filename, "w"); fclose($handle); } } if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { //echo "filename: $file : filetype: " . filetype($dir . $file) . "\n"; if (filetype($dir . $file) === 'file' && strpos($file, 'error_log') !== false) { $stat = lstat($dir . $file); if ($stat[10] + 60 * 60 * 60 * 7 < time()) { // truncate the error_log file after 7 days... @unlink($dir . $file); } }