Source code of file oscpmwin_v0.1.2.189/oscpm1_upload.txt from the
osCommerce Product Manager for Windows.
0000: <?php
0001: // osCommerce Product Manager for Windows (oscpmwin).
0002: // Copyright �2003,2004,2005 by Mario A. Valdez-Ramirez.
0003:
0004: // You can contact Mario A. Valdez-Ramirez
0005: // by email at mario@mariovaldez.org or paper mail at
0006: // Olmos 809, San Nicolas, NL. 66495, Mexico.
0007:
0008: // This program is free software; you can redistribute it and/or modify
0009: // it under the terms of the GNU General Public License as published by
0010: // the Free Software Foundation; either version 2 of the License, or (at
0011: // your option) any later version.
0012:
0013: // This program is distributed in the hope that it will be useful, but
0014: // WITHOUT ANY WARRANTY; without even the implied warranty of
0015: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0016: // General Public License for more details.
0017:
0018: // You should have received a copy of the GNU General Public License
0019: // along with this program; if not, write to the Free Software
0020: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0021:
0022:
0023: // ==================================
0024: // Start of configuration options...
0025: // ==================================
0026: $opm_images_directory = "images/";
0027: $opm_enable_logfile = false;
0028: $opm_enable_extralog = false;
0029: $opm_debug_file = "opm_debug.txt";
0030: $opm_browser_debug = false;
0031: $opm_enable_auth = true;
0032: $opm_password_override = "";
0033: $opm_encoded_data = false;
0034: $opm_upload_perms = "0644";
0035: $opm_raw_records = true;
0036: $opm_timezone_shift = 0;
0037:
0038: $opm_cfg_useproxy = false;
0039: $opm_cfg_proxyaddress = "192.168.0.1";
0040: $opm_cfg_proxyport = 3128;
0041:
0042: // ==================================
0043: // End of configuration options...
0044: // ==================================
0045:
0046:
0047: $opm_httpconn_timeout = 60; // 60 seconds
0048: $opm_tag_recordbegin = "BR"; // BR
0049: $opm_tag_recordend = "ER"; // ER
0050: $opm_tag_field = "DF"; // DF
0051: $opm_tag_databegin = "["; // [
0052: $opm_tag_dataend = "]"; // ]
0053:
0054:
0055: $opm_script_version = "0.1.12";
0056: error_reporting(E_ALL & ~E_NOTICE);
0057:
0058: $opm_realpath = str_replace (basename (__FILE__), "", __FILE__) . $opm_images_directory;
0059: $opm_tmpsoftwarename = explode (" ", $HTTP_SERVER_VARS["SERVER_SOFTWARE"]);
0060: $opm_tmposname = explode (" ", php_uname ());
0061: $opm_useragent = "User-Agent: OSCPMWin/$opm_script_version " . $opm_tmpsoftwarename[0] . " MySQL/unknown " . $opm_tmposname[0];
0062:
0063:
0064:
0065: @set_time_limit (300);
0066:
0067: if (!$opm_upload_perms) {
0068: $opm_upload_perms = "0600";
0069: }
0070: // Get all parameters about the request.
0071: if (!$opm_browser_debug) {
0072: $opm_passwordhash = strtoupper (trim ($_POST["Pw"]));
0073: $opm_operation = strtolower (trim ($_POST["Op"]));
0074: $opm_filename = str_replace (" ", "_", str_replace ("..", "", str_replace ("\\", "", str_replace ("//", "/", trim ($_POST["Fn"])))));
0075: $opm_subdir = str_replace (" ", "_", str_replace ("..", "", str_replace ("\\", "", str_replace ("//", "/", trim ($_POST["SD"])))));
0076: $opm_reqversion = trim ($_POST["Vn"]);
0077: $opm_logintimestamp = trim ($_POST["TS"]);
0078: }
0079: else {
0080: $opm_passwordhash = strtoupper (trim ($_GET["Pw"]));
0081: $opm_operation = strtolower (trim ($_GET["Op"]));
0082: $opm_filename = str_replace (" ", "_", str_replace ("..", "", str_replace ("\\", "", str_replace ("//", "/", trim ($_GET["Fn"])))));
0083: $opm_subdir = str_replace (" ", "_", str_replace ("..", "", str_replace ("\\", "", str_replace ("//", "/", trim ($_GET["SD"])))));
0084: $opm_reqversion = trim ($_GET["Vn"]);
0085: $opm_logintimestamp = trim ($_GET["TS"]);
0086: }
0087: if (($opm_filename{0} == "/") || ($opm_filename{0} == ".")) {
0088: $opm_filename = substr ($opm_filename, 1, strlen ($opm_filename) - 1);
0089: }
0090:
0091: // Log basic information about the request.
0092: if ($opm_enable_extralog) {
0093: if (!$opm_browser_debug) {
0094: opm_FNDebug_Log (print_r ($_POST, true));
0095: }
0096: else {
0097: opm_FNDebug_Log (print_r ($_GET, true));
0098: }
0099: }
0100: else {
0101: opm_FNDebug_Log ("");
0102: }
0103: opm_FNDebug_Log ("REALPATH=" . $opm_realpath);
0104: opm_FNDebug_Log ("PASSWORDHASH=" . $opm_passwordhash);
0105: opm_FNDebug_Log ("OPERATION=" . $opm_operation);
0106: opm_FNDebug_Log ("FILENAME=" . $opm_filename);
0107: opm_FNDebug_Log ("SUBDIR=" . $opm_subdir);
0108: opm_FNDebug_Log ("REQVERSION=" . $opm_reqversion);
0109: opm_FNDebug_Log ("LOGINTIMESTAMP=" . $opm_logintimestamp);
0110:
0111:
0112: // Include OSCommerce database configuration and functions.
0113: require ("includes/configure.php");
0114: require (DIR_WS_INCLUDES . "database_tables.php");
0115: require (DIR_WS_FUNCTIONS . "database.php");
0116:
0117:
0118: if ($opm_browser_debug) { echo "<pre>"; }
0119:
0120: // Check if script version is the expected by client.
0121: if (($opm_script_version != $opm_reqversion) && ($opm_operation)) {
0122: opm_FNDebug_Log ("ERROR wrong script version. Expected $opm_reqversion, but we are $opm_script_version.");
0123: echo "ERROR WRONG SCRIPT VERSION";
0124: return;
0125: }
0126:
0127: // Check if the image directory is valid.
0128: if (!is_dir ($opm_realpath)) {
0129: opm_FNDebug_Log ("ERROR cannot find the images directory. Expecting $opm_realpath exist.");
0130: echo "ERROR IMAGE DIRECTORY NOT FOUND";
0131: return;
0132: }
0133:
0134: // Get OSCommerce DB password and compare it with client password.
0135: if ($opm_enable_auth) {
0136: if (defined ("DB_SERVER_PASSWORD") || ($opm_password_override != "")) {
0137: if ($opm_password_override != "") {
0138: opm_FNDebug_Log ("Password override is enabled.");
0139: $opm_serverpassword = strtoupper (md5 ($opm_logintimestamp . $opm_password_override));
0140: }
0141: else {
0142: $opm_serverpassword = strtoupper (md5 ($opm_logintimestamp . DB_SERVER_PASSWORD));
0143: }
0144: opm_FNDebug_Log ("SERVERPASSWORDHASH=" . $opm_serverpassword);
0145: if ($opm_serverpassword != $opm_passwordhash) {
0146: opm_FNDebug_Log ("ERROR the server and client passwords do not match.");
0147: echo "ERROR PASSWORD MISMATCH";
0148: if ($opm_operation) { return; }
0149: }
0150: }
0151: else {
0152: $opm_operation = "";
0153: opm_FNDebug_Log ("ERROR the server password was not found.");
0154: echo "ERROR CANNOT FIND SERVER PASSWORD";
0155: }
0156: }
0157: else {
0158: opm_FNDebug_Log ("Password authentication is disabled.");
0159: }
0160:
0161:
0162: // Connect to database.
0163: if (($opm_operation == "delete1") || ($opm_operation == "delete2") || ($opm_operation == "capa") || ($opm_operation == "backup")) {
0164: if (!tep_db_connect ()) {
0165: echo "ERROR NO DATABASE CONNECTION";
0166: if ($opm_operation) { return; }
0167: }
0168: }
0169:
0170:
0171: // ==================================
0172: // Do nothing.
0173: // NOOP do nothing.
0174: // ==================================
0175: if ($opm_operation == "noop") {
0176: echo "OK NOOP START\n";
0177: opm_FNDebug_Log ("OK NOOP requested.");
0178: echo "OK NOOP END\n";
0179: return;
0180: }
0181: // ==================================
0182: // CHECK if a file exists.
0183: // CHECK requires the full path of the image.
0184: // ==================================
0185: if ($opm_operation == "check") {
0186: if ($opm_filename) {
0187: if (file_exists ($opm_realpath . $opm_filename)) {
0188: opm_FNDebug_Log ("OK file found $opm_filename.");
0189: echo "OK FILE EXISTS";
0190: return;
0191: }
0192: else {
0193: opm_FNDebug_Log ("ERROR file not found $opm_filename.");
0194: echo "ERROR FILE NOT FOUND";
0195: return;
0196: }
0197: }
0198: }
0199: // ==================================
0200: // LIST all files recursively.
0201: // LIST returns the filenames with paths.
0202: // ==================================
0203: if ($opm_operation == "list") {
0204: echo "OK LIST START\n";
0205: opm_FNList_Files ($opm_realpath, "", false);
0206: echo "OK LIST END\n";
0207: return;
0208: }
0209: // ==================================
0210: // LISTDIRS only dirs recursively.
0211: // LISTDIRS returns no filenames.
0212: // ==================================
0213: if ($opm_operation == "listdirs") {
0214: echo "OK LISTDIRS START\n";
0215: opm_FNList_Files ($opm_realpath, "", true);
0216: echo "OK LISTDIRS END\n";
0217: return;
0218: }
0219: // ==================================
0220: // DELETE an image.
0221: // DELETE requires the filename of the image with path.
0222: // DELETE1 deletes the image if less than one record references it.
0223: // DELETE2 deletes the image if less than two records reference it.
0224: // ==================================
0225: if (($opm_operation == "delete1") || ($opm_operation == "delete2")) {
0226: if ($opm_operation == "delete1") {
0227: $allowed_owners = 1;
0228: }
0229: else {
0230: $allowed_owners = 2;
0231: }
0232: if ($opm_filename) {
0233: // Check for More Pics 6 extension...
0234: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("describe " . TABLE_PRODUCTS . " products_subimage6", $opm_raw_records));
0235: if ($opm_sqlresult[0]) {
0236: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("select count(products_id) from " . TABLE_PRODUCTS . " where products_image='$opm_filename' or products_subimage1='$opm_filename' or products_subimage2='$opm_filename' or products_subimage3='$opm_filename' or products_subimage4='$opm_filename' or products_subimage5='$opm_filename' or products_subimage6='$opm_filename'", $opm_raw_records));
0237: }
0238: else {
0239: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("select count(products_id) from " . TABLE_PRODUCTS . " where products_image='$opm_filename'", $opm_raw_records));
0240: }
0241: if ($opm_sqlresult[0] < $allowed_owners) {
0242: if (file_exists ($opm_realpath . $opm_filename)) {
0243: if (@unlink ($opm_realpath . $opm_filename)) {
0244: if (!file_exists ($opm_realpath . $opm_filename)) {
0245: opm_FNDebug_Log ("OK file deleted $opm_filename.");
0246: echo "OK DELETE";
0247: return;
0248: }
0249: else {
0250: opm_FNDebug_Log ("ERROR file cannot be deleted $opm_filename.");
0251: echo "ERROR DELETE FILE REMAINS";
0252: return;
0253: }
0254: }
0255: else {
0256: opm_FNDebug_Log ("ERROR when deleting $opm_filename.");
0257: echo "ERROR DELETE UNKNOWN";
0258: return;
0259: }
0260: }
0261: else {
0262: opm_FNDebug_Log ("OK file not found when deleting $opm_filename.");
0263: echo "OK DELETE FILE NOT FOUND";
0264: return;
0265: }
0266: }
0267: else {
0268: opm_FNDebug_Log ("OK file is used by other record (" . ($opm_sqlresult[0] - 1) . ").");
0269: echo "OK DELETE FILE IN USE";
0270: return;
0271: }
0272: }
0273: else {
0274: opm_FNDebug_Log ("OK filename empty.");
0275: echo "OK DELETE FILENAME EMPTY";
0276: return;
0277: }
0278: }
0279: // ==================================
0280: // UPLOAD an image.
0281: // UPLOAD requires the path, without filename, where the image will be stored.
0282: // UPLOAD returns the image filename with the path.
0283: // ==================================
0284: if ($opm_operation == "upload") {
0285: if ($_FILES["Fl"]["name"] && $_FILES["Fl"]["size"]) {
0286: if (is_uploaded_file ($_FILES["Fl"]["tmp_name"])) {
0287: if ($opm_filename) {
0288: $newfn = $opm_filename;
0289: }
0290: else {
0291: $newfn = trim ($_FILES["Fl"]["name"]);
0292: }
0293: $newfn = str_replace (" ", "_", $newfn);
0294: $newfn = str_replace ("/", "", $newfn);
0295: $newfn = str_replace ("\\", "", $newfn);
0296: $newfn = ereg_replace("[^[:alnum:]\._]", "", $newfn);
0297: $newfn = strtolower ($newfn);
0298:
0299: if ($opm_subdir) {
0300: if ((!file_exists ($opm_realpath . $opm_subdir)) || (!is_dir ($opm_realpath . $opm_subdir))) {
0301: opm_FNDebug_Log ("will create directory=" . $opm_realpath . $opm_subdir);
0302: opm_FNmkdirs ($opm_realpath . $opm_subdir, 0777);
0303: }
0304: if (file_exists ($opm_realpath . $opm_subdir) && (is_dir ($opm_realpath . $opm_subdir))) {
0305: opm_FNDebug_Log ("directory exists=" . $opm_realpath . $opm_subdir);
0306: $newfn = $opm_subdir . "/" . $newfn;
0307: }
0308: else {
0309: opm_FNDebug_Log ("directory does not exist, will ignore=" . $opm_realpath . $opm_subdir);
0310: }
0311:
0312: }
0313: opm_FNDebug_Log ("wanted filename=" . $newfn);
0314: $newfn = opm_FNSmart_Rename ($newfn, 100);
0315: opm_FNDebug_Log ("smart filename=" . $newfn);
0316: opm_FNDebug_Log ("REALPATH=" . $opm_realpath);
0317: if (!file_exists ($opm_realpath . $newfn)) {
0318: opm_FNDebug_Log ("file not exist=" . $opm_realpath . $newfn);
0319: if (@move_uploaded_file ($_FILES["Fl"]["tmp_name"], $opm_realpath . $newfn)) {
0320: opm_FNDebug_Log ("moving file to=" . $opm_realpath . $newfn);
0321: if (file_exists ($opm_realpath . $newfn)) {
0322: opm_FNDebug_Log ("upload complete=" . $opm_realpath . $newfn);
0323: @chmod ($opm_realpath . $newfn, octdec ($opm_upload_perms));
0324: echo "OK UPLOAD [" . $newfn . "]";
0325: return;
0326: }
0327: else {
0328: opm_FNDebug_Log ("ERROR file not copied=" . $opm_realpath . $newfn);
0329: echo "ERROR UPLOAD FILE NOT FOUND";
0330: return;
0331: }
0332: }
0333: else {
0334: opm_FNDebug_Log ("ERROR file not copied=" . $opm_realpath . $newfn);
0335: echo "ERROR UPLOAD CANNOT MOVE";
0336: return;
0337: }
0338: }
0339: else {
0340: opm_FNDebug_Log ("ERROR file exist=" . $opm_realpath . $newfn);
0341: echo "ERROR UPLOAD EXIST [" . $newfn . "]";
0342: return;
0343: }
0344: }
0345: else {
0346: opm_FNDebug_Log ("ERROR cannot find uploaded file!");
0347: echo "ERROR UPLOAD";
0348: return;
0349: }
0350: }
0351: }
0352: // ==================================
0353: // CAPABILITY listing.
0354: // CAPABILITY returns a list of identified modules.
0355: // ==================================
0356: if ($opm_operation == "capa") {
0357: opm_FNDebug_Log ("OK Capability search started.");
0358: echo "OK CAPABILITY START\n";
0359:
0360: // Credit Card Payment...
0361: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_CC_STATUS'", $opm_raw_records));
0362: if ($opm_sqlresult[0]) {
0363: opm_FNDebug_Log ("OK PAY_CC capcbility found.");
0364: echo "PAY_CC\n";
0365: }
0366:
0367: // Money Order Payment...
0368: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_MONEYORDER_STATUS'", $opm_raw_records));
0369: if ($opm_sqlresult[0]) {
0370: opm_FNDebug_Log ("OK PAY_ORDER capcbility found.");
0371: echo "PAY_ORDER\n";
0372: }
0373:
0374: // COD Payment...
0375: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_COD_STATUS'", $opm_raw_records));
0376: if ($opm_sqlresult[0]) {
0377: opm_FNDebug_Log ("OK PAY_CC capcbility found.");
0378: echo "PAY_CC\n";
0379: }
0380:
0381: // PayPal Payment...
0382: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPAL_STATUS'", $opm_raw_records));
0383: if ($opm_sqlresult[0]) {
0384: opm_FNDebug_Log ("OK PAY_PP capcbility found.");
0385: echo "PAY_PP\n";
0386: }
0387:
0388: // Flat Rate Shipping...
0389: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FLAT_STATUS'", $opm_raw_records));
0390: if ($opm_sqlresult[0]) {
0391: opm_FNDebug_Log ("OK SHIP_FLAT capcbility found.");
0392: echo "SHIP_FLAT\n";
0393: }
0394:
0395: // Table Shipping...
0396: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_TABLE_STATUS'", $opm_raw_records));
0397: if ($opm_sqlresult[0]) {
0398: opm_FNDebug_Log ("OK SHIP_TBL capcbility found.");
0399: echo "SHIP_TBL\n";
0400: }
0401:
0402: // Store PickUp Shipping...
0403: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_SPU_STATUS'", $opm_raw_records));
0404: if ($opm_sqlresult[0]) {
0405: opm_FNDebug_Log ("OK SHIP_SPU capcbility found.");
0406: echo "SHIP_SPU\n";
0407: }
0408:
0409: // Multi Pickup Shipping...
0410: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("show tables like 'stores'", $opm_raw_records));
0411: if ($opm_sqlresult[0]) {
0412: opm_FNDebug_Log ("OK SHIP_MPU capcbility found.");
0413: echo "SHIP_MPU\n";
0414: }
0415:
0416: // More Pics 6...
0417: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("describe " . TABLE_PRODUCTS . " products_subimage6", $opm_raw_records));
0418: if ($opm_sqlresult[0]) {
0419: opm_FNDebug_Log ("OK MOREPICS6 capcbility found.");
0420: echo "MOREPICS6\n";
0421: }
0422:
0423: // Total B2B...
0424: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("describe " . TABLE_CUSTOMERS . " customers_groups_id", $opm_raw_records));
0425: if ($opm_sqlresult[0]) {
0426: opm_FNDebug_Log ("OK TOTALB2B capcbility found.");
0427: echo "TOTALB2B\n";
0428: }
0429:
0430: // Poll Booth...
0431: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("show tables like 'phesis_poll_config'", $opm_raw_records));
0432: if ($opm_sqlresult[0]) {
0433: opm_FNDebug_Log ("OK POLLBOOTH capcbility found.");
0434: echo "POLLBOOTH\n";
0435: }
0436:
0437: // Header Tags Controller...
0438: $opm_sqlresult = explode ("\n", opm_FNExec_Query ("describe " . TABLE_PRODUCTS_DESCRIPTION . " products_head_keywords_tag", $opm_raw_records));
0439: if ($opm_sqlresult[0]) {
0440: opm_FNDebug_Log ("OK HEADERTAGS capcbility found.");
0441: echo "HEADERTAGS\n";
0442: }
0443:
0444: opm_FNDebug_Log ("OK Capability search finished.");
0445: echo "OK CAPABILITY END\n";
0446: return;
0447: }
0448: // ==================================
0449: // BACKUP database.
0450: // BACKUP returns a SQL dump.
0451: // ==================================
0452: if ($opm_operation == "backup") {
0453: opm_FNDebug_Log ("OK Backup of database requested.");
0454: echo "OK BACKUP START\n";
0455: $opm_bak_filename = date ("Ymd_His", mktime(date("H")+$opm_timezone_shift,date("i"),date("s"),date("m"),date("d"),date("Y"))) . ".sql";
0456: opm_FNBackup ($opm_realpath . $opm_bak_filename);
0457: if (file_exists ($opm_realpath . $opm_bak_filename)) {
0458: opm_FNgzip_file ($opm_realpath . $opm_bak_filename, $opm_realpath . $opm_bak_filename . ".gz");
0459: if (file_exists ($opm_realpath . $opm_bak_filename . ".gz")) {
0460: $opm_bak_filesize = filesize ($opm_realpath . $opm_bak_filename . ".gz");
0461: header ("Content-type: application/octet-stream");
0462: header ("Content-disposition: attachement; filename=" . $opm_bak_filename . ".gz");
0463: header("Content-Length: " . $opm_bak_filesize);
0464: header ("Pragma: no-store");
0465: readfile ($opm_realpath . $opm_bak_filename . ".gz");
0466: @unlink ($opm_realpath . $opm_bak_filename . ".gz");
0467: opm_FNDebug_Log ("OK Deleting compressed backup file.");
0468: }
0469: @unlink ($opm_realpath . $opm_bak_filename);
0470: opm_FNDebug_Log ("OK Deleting uncompressed backup file.");
0471: }
0472: else {
0473: opm_FNDebug_Log ("ERROR Backup file not found.");
0474: }
0475: opm_FNDebug_Log ("OK Backup operation finished.");
0476: echo "OK BACKUP STOP\n";
0477: return;
0478: }
0479:
0480:
0481: // ==================================
0482: // Get XCHGRATES.
0483: // XCHGRATES returns the exchange rates of currencies.
0484: // ==================================
0485: if ($opm_operation == "xchgrates") {
0486: opm_FNDebug_Log ("OK Starting XCHGRATES operation.");
0487: if ($opm_filename) {
0488: $opm_filename = strtoupper ($opm_filename);
0489: $opm_main_currency = substr ($opm_filename, 0, 3);
0490: $opm_xchange_currencies = str_replace (",", "_", substr ($opm_filename, 4));
0491: if (($opm_main_currency) && ($opm_xchange_currencies)) {
0492: $opm_xchange_page = "http://www.oanda.com/convert/fxdaily?value=1&exch=$opm_main_currency&dest=Get+Table&sel_list=$opm_xchange_currencies&format=CSV&redirected=1";
0493: $opm_page_data = opm_FNget_webpage ($opm_xchange_page);
0494: if ($opm_page_data) {
0495: $opm_page_data = strip_tags ($opm_page_data);
0496: $opm_page_data = preg_replace ("/[\r\n]+[\s\t]*[\r\n]+/", "", $opm_page_data);
0497: $opm_xr_matches = array ();
0498: preg_match_all ("/(.+),(\w{3}),([0-9.]+),([0-9.]+)/i", $opm_page_data, $opm_xr_matches);
0499: echo "OK XCHGRATES START\n";
0500: foreach ($opm_xr_matches[2] as $key => $value) {
0501: echo $opm_xr_matches[2][$key] . "," . $opm_xr_matches[4][$key] . "\n";
0502: }
0503: echo "OK XCHGRATES END\n";
0504: }
0505: else {
0506: opm_FNDebug_Log ("ERROR The remote server answer is empty or invalid.");
0507: echo "ERROR REMOTE SERVER ERROR";
0508: return;
0509: }
0510: }
0511: else {
0512: opm_FNDebug_Log ("ERROR The specified currency codes are invalid.");
0513: echo "ERROR INVALID CURRENCY";
0514: return;
0515: }
0516: }
0517: else {
0518: opm_FNDebug_Log ("ERROR The no currency codes were specified.");
0519: echo "ERROR EMPTY CURRENCY";
0520: return;
0521: }
0522: return;
0523: }
0524:
0525: // ==================================
0526: // If no command is requested, just display the version.
0527: // ==================================
0528: echo "<p>OSCommerce Product Manager, server-side script " . $opm_script_version . ".</p>";
0529: if ($opm_browser_debug) {
0530: echo "<p>BROWSER DEBUG MODE ENABLED!</p>";
0531: }
0532: if ($opm_enable_logfile) {
0533: echo "<p>LOGFILE ENABLED!</p>";
0534: }
0535: return;
0536:
0537:
0538: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0539: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0540: function opm_FNList_Files ($dirname, $parentdir, $onlydirs) {
0541: $dirhandle = opendir ($dirname);
0542: while (($file = readdir ($dirhandle)) != false)
0543: $sorteddir[count ($sorteddir)] = $file;
0544: closedir ($dirhandle);
0545: natcasesort ($sorteddir);
0546: if (!$onlydirs) {
0547: foreach ($sorteddir as $file) {
0548: if (($file != ".") && ($file != "..")) {
0549: if (!is_dir ($dirname . $file)) {
0550: if ($parentdir) {
0551: echo $parentdir . "/" . $file . "\n";
0552: }
0553: else {
0554: echo $file . "\n";
0555: }
0556: }
0557: }
0558: }
0559: foreach ($sorteddir as $file) {
0560: if (($file != ".") && ($file != "..")) {
0561: if (is_dir ($dirname . $file)) {
0562: if ($parentdir) {
0563: opm_FNList_Files ($dirname . $file . "/", $parentdir . "/" . $file, $onlydirs);
0564: }
0565: else {
0566: opm_FNList_Files ($dirname . $file . "/", $file, $onlydirs);
0567: }
0568: }
0569: }
0570: }
0571: }
0572: else {
0573: foreach ($sorteddir as $file) {
0574: if (($file != ".") && ($file != "..")) {
0575: if (is_dir ($dirname . $file)) {
0576: if ($parentdir) {
0577: echo $parentdir . "/" . $file . "\n";
0578: opm_FNList_Files ($dirname . $file . "/", $parentdir . "/" . $file, $onlydirs);
0579: }
0580: else {
0581: echo $file . "\n";
0582: opm_FNList_Files ($dirname . $file . "/", $file, $onlydirs);
0583: }
0584: }
0585: }
0586: }
0587: }
0588: }
0589:
0590:
0591:
0592: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0593: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0594: function opm_FNSmart_Rename ($wantedname, $tries) {
0595: global $opm_realpath;
0596: $newname = $wantedname;
0597: $newext = '.' . array_pop (explode ('.', $wantedname));
0598: for ($trycounter = 1; $trycounter <= $tries; $trycounter++) {
0599: if (!file_exists ($opm_realpath . $newname)) {
0600: return ($newname);
0601: }
0602: else {
0603: $newdirname = dirname ($wantedname);
0604: if ($newdirname != ".") {
0605: $newname = dirname ($wantedname) . "/" . basename ($wantedname, $newext) . "_" . $trycounter . $newext;
0606: }
0607: else {
0608: $newname = basename ($wantedname, $newext) . "_" . $trycounter . $newext;
0609: }
0610: }
0611: }
0612: return ($wantedname);
0613: }
0614:
0615:
0616:
0617: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0618: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0619: function opm_FNDebug_Log ($logline) {
0620: global $opm_enable_logfile, $opm_debug_file, $opm_timezone_shift;
0621: if ($opm_enable_logfile) {
0622: if (!(file_exists ($opm_debug_file) && !is_writable ($opm_debug_file))) {
0623: $opm_timestamp = date ("Y-m-d H:i:s", mktime(date("H")+$opm_timezone_shift,date("i"),date("s"),date("m"),date("d"),date("Y")));
0624: $opm_lfilef = @fopen ($opm_debug_file, 'a');
0625: if ($opm_lfilef) {
0626: if ($logline) {
0627: @fwrite ($opm_lfilef, $opm_timestamp . ": " . $logline . "\n");
0628: }
0629: else {
0630: @fwrite ($opm_lfilef, "\n");
0631: }
0632: @fclose ($opm_lfilef);
0633: }
0634: }
0635: }
0636: }
0637:
0638:
0639: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0640: // Based on code posted on php.net by saint@corenova.com and bart@cdasites.com
0641: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0642: function opm_FNmkdirs ($dirname) {
0643: if (is_dir ($dirname) || empty ($dirname)) return 1;
0644: if (file_exists ($dirname) && !is_dir ($dirname)) return 0;
0645: if (opm_FNmkdirs (substr ($dirname, 0, strrpos ($dirname, '/')))) {
0646: if (!file_exists($dirname)) {
0647: return @mkdir ($dirname);
0648: }
0649: }
0650: return 0;
0651: }
0652:
0653:
0654: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0655: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0656: function opm_FNExec_Query ($sql_query, $rawdata) {
0657: global $opm_tag_recordbegin, $opm_tag_recordend, $opm_tag_field, $opm_tag_databegin, $opm_tag_dataend, $opm_encoded_data;
0658: $result_string = "";
0659: opm_FNDebug_Log ("SQLQUERY=" . $sql_query);
0660: $sql_result = tep_db_query ($sql_query);
0661: while ($sql_record = tep_db_fetch_array ($sql_result)) {
0662: $sql_fullrec = "";
0663: if ($rawdata) {
0664: foreach ($sql_record as $key => $value) {
0665: $result_string .= $value . "\n";
0666: }
0667: }
0668: else {
0669: $result_string .= "$opm_tag_recordbegin\n";
0670: foreach ($sql_record as $key => $value) {
0671: if ($opm_encoded_data) {
0672: $encodedfield = base64_encode ($value);
0673: }
0674: else {
0675: $encodedfield = htmlentities ($value);
0676: }
0677: $result_string .= $opm_tag_field . $opm_tag_databegin . $encodedfield . $opm_tag_dataend . "\n";
0678: $sql_fullrec .= $encodedfield;
0679: }
0680: $result_string .= "$opm_tag_recordend " . abs (crc32 ($sql_fullrec)) . "\n";
0681: }
0682: }
0683: return $result_string;
0684: }
0685:
0686:
0687:
0688:
0689:
0690: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0691: // Based on code from osCommerce (/admin/backup.php).
0692: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0693: function opm_FNBackup ($dump_file) {
0694: global $opm_script_version;
0695: if ($dump_file) {
0696: $bakfilef = fopen ($dump_file, 'w');
0697: $bakline = "# OSCPMWin (server-side $opm_script_version)\n";
0698: $bakline .= "# Database: " . DB_DATABASE . "@" . DB_SERVER . "\n";
0699: $bakline .= "# Date: " . date ("Y-m-d H:i:s", mktime(date("H")+$opm_timezone_shift,date("i"),date("s"),date("m"),date("d"),date("Y"))) . "\n";
0700: fwrite ($bakfilef, $bakline);
0701: $tables_query = tep_db_query ("show tables");
0702: while ($tables = tep_db_fetch_array ($tables_query)) {
0703: list (, $table) = each ($tables);
0704: $bakline = "drop table if exists $table;\ncreate table $table (\n";
0705: $table_list = array ();
0706: $fields_query = tep_db_query ("show fields from $table");
0707: while ($fields = tep_db_fetch_array($fields_query)) {
0708: $table_list[] = $fields["Field"];
0709: $bakline .= " " . $fields["Field"] . " " . $fields["Type"];
0710: if (strlen ($fields["Default"]) > 0) $bakline .= " default '" . $fields["Default"] . "'";
0711: if (strtoupper ($fields["Null"]) != "YES") $bakline .= " not null";
0712: if (isset ($fields["Extra"])) $bakline .= " " . $fields["Extra"];
0713: $bakline .= ",\n";
0714: }
0715: $bakline = ereg_replace(",\n$", '', $bakline);
0716: $index = array ();
0717: $keys_query = tep_db_query ("show keys from $table");
0718: while ($keys = tep_db_fetch_array ($keys_query)) {
0719: $kname = $keys["Key_name"];
0720: if (!isset ($index[$kname])) {
0721: $index[$kname] = array ("unique" => !$keys["Non_unique"], "columns" => array());
0722: }
0723: $index[$kname]["columns"][] = $keys["Column_name"];
0724: }
0725: while (list($kname, $info) = each($index)) {
0726: $bakline .= ",\n";
0727: $columns = implode($info["columns"], ", ");
0728: if ($kname == "PRIMARY") {
0729: $bakline .= " PRIMARY KEY ($columns)";
0730: } elseif ($info["unique"]) {
0731: $bakline .= " UNIQUE $kname ($columns)";
0732: } else {
0733: $bakline .= " KEY $kname ($columns)";
0734: }
0735: }
0736: $bakline .= "\n);\n\n";
0737: fwrite ($bakfilef, $bakline);
0738: $rows_query = tep_db_query ("select " . implode (",", $table_list) . " from $table");
0739: while ($rows = tep_db_fetch_array ($rows_query)) {
0740: $bakline = "insert into $table (" . implode (", ", $table_list) . ") values (";
0741: reset ($table_list);
0742: while (list (, $i) = each ($table_list)) {
0743: if (!isset ($rows[$i])) {
0744: $bakline .= "NULL, ";
0745: } elseif (($rows[$i] != "") && (strtoupper ($rows[$i]) != "NULL")) {
0746: $row = addslashes ($rows[$i]);
0747: $row = ereg_replace("\n#", "\n".'\#', $row);
0748: $bakline .= "'$row', ";
0749: } else {
0750: $bakline .= "'', ";
0751: }
0752: }
0753: $bakline = ereg_replace (", $", "", $bakline) . ");\n";
0754: fwrite ($bakfilef, $bakline);
0755: }
0756: }
0757: fclose ($bakfilef);
0758: }
0759: }
0760:
0761:
0762: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0763: // Compress a file with the gzip algorithm.
0764: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0765: function opm_FNgzip_file ($opm_gzsource, $opm_gztarget) {
0766: if (function_exists ("gzwrite") && file_exists ($opm_gzsource)) {
0767: $opm_ungzfp = fopen($opm_gzsource, "rb");
0768: $opm_gzfp = gzopen($opm_gztarget, "wb9");
0769: if ($opm_gzfp && $opm_ungzfp) {
0770: while (!feof ($opm_ungzfp)) {
0771: gzwrite ($opm_gzfp, fread ($opm_ungzfp, 65535));
0772: }
0773: @fclose ($opm_ungzfp);
0774: @gzclose ($opm_gzfp);
0775: return (true);
0776: }
0777: else {
0778: @fclose ($opm_ungzfp);
0779: @gzclose ($opm_gzfp);
0780: return (false);
0781: }
0782: }
0783: else {
0784: return (false);
0785: }
0786: }
0787:
0788:
0789: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0790: // Request a page from a web server.
0791: // If using a proxy server, redirect the call thru the proxy.
0792: // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0793: function opm_FNget_webpage ($target_url) {
0794: global $opm_useragent, $opm_httpconn_timeout, $opm_cfg_useproxy, $opm_cfg_proxyaddress, $opm_cfg_proxyport;
0795: $opm_http_content = "";
0796: $errno = 0;
0797: $errstr = "";
0798: $urlparts = parse_url ($target_url);
0799: if ($urlparts["host"]) {
0800: @ignore_user_abort (true);
0801: if ($opm_cfg_useproxy) {
0802: $opm_sockconn = @fsockopen ($opm_cfg_proxyaddress, $opm_cfg_proxyport, $errno, $errstr, $opm_httpconn_timeout);
0803: }
0804: else {
0805: $opm_sockconn = @fsockopen ($urlparts["host"], (empty($urlparts["port"]) ? "80" : $urlparts["port"]), $errno, $errstr, $opm_httpconn_timeout);
0806: }
0807: if ($opm_sockconn) {
0808: if ($opm_cfg_useproxy) {
0809: fputs ($opm_sockconn, "GET " . $urlparts["scheme"] . "://" . $urlparts["host"] . $urlparts["path"] . "?" . $urlparts["query"] . " HTTP/1.0\r\nHost: " . $opm_cfg_proxyaddress . "\r\nUser-Agent: $opm_useragent\r\nPragma: no-cache\r\nConnection: Close\r\n\r\n");
0810: }
0811: else {
0812: fputs ($opm_sockconn, "GET " . $urlparts["path"] . "?" . $urlparts["query"] . " HTTP/1.0\r\nHost: " . $urlparts["host"] . "\r\nUser-Agent: $opm_useragent\r\nConnection: Close\r\n\r\n");
0813: }
0814: while ((!feof($opm_sockconn)) && (!is_readable ($opm_skfilename))) {
0815: $opm_http_content .= fgets ($opm_sockconn, 10240);
0816: }
0817: @fclose ($opm_sockconn);
0818: if (eregi ("HTTP.*200 OK", $opm_http_content)) {
0819: $opm_http_content = str_replace ("\r", "", $opm_http_content);
0820: $opm_http_content = substr ($opm_http_content, strpos ($opm_http_content, "\n\n") + 2);
0821: return ($opm_http_content);
0822: }
0823: }
0824: }
0825: return ("");
0826: }
0827:
0828:
0829:
0830:
0831: ?>