function sqs_client_enqueue($data, $config) { $result = array(); $err = ''; $region = empty($config['sqs_region']) ? empty($config['s3_region']) ? 'us-east-1' : $config['s3_region'] : $config['sqs_region']; // fallback to same region as s3 bucket $message_id = ''; $options_array = ['version' => 'latest', 'region' => $region]; if ($config['aws_secret_access_key'] && $config['aws_access_key_id']) { $options_array['credentials'] = []; $options_array['credentials']['key'] = $config['aws_access_key_id']; $options_array['credentials']['secret'] = $config['aws_secret_access_key']; } try { $sqs = new Aws\Sqs\SqsClient($options_array); $response = $sqs->sendMessage(['MessageBody' => json_encode($data), 'QueueUrl' => $config['sqs_queue_url']]); if ($config['log_api_response']) { log_file("sqs response:\n" . print_r($response, 1), $config); } if (empty($response['MessageId'])) { $err = 'Got no MessageId in sqs response'; } else { $result['id'] = $response['MessageId']; } } catch (Exception $e) { $err = $e->getMessage(); } if ($err) { $result['error'] = $err; } return $result; }
function sqs_client_enqueue($data, $config) { $result = array(); $err = ''; $variables = array(); $variables['Action'] = 'SendMessage'; $variables['MessageBody'] = json_encode($data); $variables['Version'] = '2012-11-05'; $parsed_url = parse_url($config['sqs_queue_url']); $headers = array(); $headers['Host'] = strtolower($parsed_url['host']); $headers['X-Amz-Date'] = gmdate(DATE_FORMAT_ISO8601_BASIC); $signature = __sqs_client_version_four($config['aws_secret_access_key'], $config['sqs_queue_url'], $variables, $headers, $config['s3_region'], 'post'); $region = empty($config['sqs_region']) ? empty($config['s3_region']) ? 'us-east-1' : $config['s3_region'] : $config['sqs_region']; // fallback to same region as s3 bucket $date_str = substr($headers['X-Amz-Date'], 0, 8); $headers['Authorization'] = "AWS4-HMAC-SHA256 Credential={$config['aws_access_key_id']}/{$date_str}/{$region}/sqs/aws4_request, SignedHeaders=host;x-amz-date, Signature={$signature}"; $post_result = http_send($config['sqs_queue_url'], $variables, $headers); $data = $post_result['result']; if ($data && $config['log_api_response']) { log_file("sqs response:\n" . print_r($data, 1), $config); } if ($post_result['error']) { $err = 'Could not make sqs request ' . $config['sqs_queue_url'] . ' ' . $post_result['error']; } else { if (!$data) { $err = 'Got no response from sqs request'; } else { $xml = @simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOENT); if (!is_object($xml)) { $err = 'Could not parse sqs response'; } else { if (sizeof($xml->Error)) { if (!$config['log_api_response']) { log_file("sqs response:\n" . $data, $config); } $err = 'Got error in sqs response'; } else { if (!(is_object($xml->SendMessageResult) && is_object($xml->SendMessageResult->MessageId))) { $err = 'Got no MessageId in sqs response'; } else { $result['id'] = (string) $xml->SendMessageResult->MessageId; } } } } } if ($err) { $result['error'] = $err; } return $result; }
/** * 处理扫描场景值关注 * 1.若未关注公众号,则会触发subscrible事件,EventKey中带有场景值(如:qrscene_Qggg) * 2.若已关注公众号,则会触发scan事件,EventKey中带有场景值(如:Qggg) * 3.注意两者区别 * @param $postObj */ function handleScan($postObj) { $uid = 0; $params = array(array("" . $postObj->FromUserName, SQLSRV_PARAM_IN), array("" . $postObj->ToUserName, SQLSRV_PARAM_IN), array($uid, SQLSRV_PARAM_OUT)); sp_execute("{call app_subscrible(?,?,?)}", $params); //用户扫描带场景值二维码 $scenestr = explode("-", $postObj->EventKey); $uid_from = str2num(CFG_ID_USER, $scenestr[0]); $cid = str2num(CFG_ID_CAR, $scenestr[1]); log_file("scan, uid_from:{$uid_from}, cid:{$cid}, uid:{$uid}"); //共享车辆 $params = array(array($cid, SQLSRV_PARAM_IN), array($uid_from, SQLSRV_PARAM_IN), array($uid, SQLSRV_PARAM_IN)); sp_execute("{call app_share_car(?,?,?)}", $params); //查询分享发起人信息 $params = array(array($uid_from, SQLSRV_PARAM_IN), array("", SQLSRV_PARAM_IN)); $rs = sp_execute("{call app_get_userinfo(?,?)}", $params); //准备图文消息 $newsContent = array("title" => "好友" . $rs[0]["nickname"] . "的车辆信息", "description" => "点击查看详情", "picUrl" => CFG_HTTP . CFG_CAR_DEFAULT, "url" => CFG_HTTP . "mobile/car_list.php"); response_news($postObj, $newsContent); }
function handleEvent($postObj) { if ($postObj->Event == "subscribe") { handleSubscribe($postObj); } else { if ($postObj->Event == "unsubscribe") { handleUnsubscribe($postObj); } else { if ($postObj->Event == "SCAN") { handleScan($postObj); } else { if ($postObj->Event == "CLICK") { handleClick($postObj); } else { if ($postObj->Event == "VIEW") { log_file("view test"); } else { if ($postObj->Event == "TEMPLATESENDJOBFINISH") { log_file("template msg send finished"); } else { if ($postObj->Event == "LOCATION") { handleLocation($postObj); } } } } } } } }
$offset = 0; } } //设置偏移值有效期时间10分钟 $time = time() + 600; setcookie($offset_tag, $offset, $time, "/"); if (isset($_REQUEST["s"])) { $s = $_REQUEST["s"]; $mode = $s == "d" ? "1" : ($s == "w" ? "2" : ($s == "m" ? "3" : "")); } // if (isset($_SESSION["offset"])) { $offset = $_SESSION["offset"]; unset($_SESSION["offset"]); } log_file("cid=" . $_SESSION["cid"] . ", mode={$mode}, offset={$offset}"); $params = array(array(intval($_SESSION["cid"]), SQLSRV_PARAM_IN), array($mode, SQLSRV_PARAM_IN), array($offset, SQLSRV_PARAM_IN), array($sdt, SQLSRV_PARAM_OUT), array($edt, SQLSRV_PARAM_OUT)); $rs = sp_execute("{call app_get_car_travel_list(?,?,?,?,?)}", $params); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no"> <meta name="format-detection" content="telephone=no"> <title><?php echo $_SESSION["carnum"]; ?> </title> <link rel="icon" href="../images/favicon.ico" type="image/x-icon"> <link href="css/style.css?v=16" rel="stylesheet">
} //HERE WE CARRY ONE WITH ACTIVE ITEM. WE GIVE A NEW ITEM THE WEIGHT OF THE MOST ACTIVE WEIGHT $item_ca_ac = $active_item_token; // here was in sql inserting item_ca but now we change inser statemet to item_ca_ac if ($item_ca_ac != 0) { if ($omit != 1 or !empty($item_ca_ac)) { $INSERT_LOG .= $barcode . $item . $brand . $serial . $item_ca; $insert2 = "INSERT INTO `item`(`pn` ,`brand` ,`name`,Item_has_Cat_id_item_cat) VALUES ('{$serial}','{$brand}','{$item}','{$item_ca_ac}')"; $BUF_MESSG = $ro; mysql_query($insert2) or die(mysql_error()); $last_id = mysql_insert_id(); $insert3 = "INSERT INTO `barcode` (`Item_id_item` ,`Barcode` ,`serial` ,`date`,stock_in,user_2,Site_site_id) VALUES ('{$last_id}','{$barcode}','0',NOW(),'1','{$user}','{$sesja}')"; mysql_query($insert3) or die("INSERT Barcode Wrong"); $INSERT_LOG .= $last_id . $sesja . $user; $INSERT_LOG .= date(); log_file($INSERT_LOG); $MESSG = 1; } } else { $MESSG = 12; } } else { //if not an bacode item yet in stock and type is not yet //// this modul/part happens only while wher item name was not in database. This creates a fresh weight //item weight echo "kolo inersta innasdddddddddddddddddduuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuwe"; if ($WEIGHT_PASS == 1) { if ($IS_SET_WEIGHT == 2) { } else { $IS_SET_WEIGHT = 1; $url = "add_stock.php?barcode=" . swap_hash($barcode) . "&item=" . $item . "&brand=" . $brand . "&serial=" . $serial . '&IS_SET_WEIGHT=1';
function log_warning($msg) { $msg = " [WARN] " . $msg; $filename = "../logs/warning_" . date('Y-m-d') . ".log"; log_file($msg, $filename); }
sp_execute("{call app_car_bind_dev(?,?,?)}", $params); } $status = "ok"; $info = "成功"; log_file("user_save_car:5"); } else { if ($oper == "edit") { log_file("user_save_car:6"); //修改 $params = array(array($_SESSION["cid"], SQLSRV_PARAM_IN), array("" . $_REQUEST["carnum"], SQLSRV_PARAM_IN), array("" . $picurl, SQLSRV_PARAM_IN)); sp_execute("{call app_set_car(?,?,?)}", $params); $status = "ok"; } } } else { log_file("user_save_car:7"); $status = "error"; $info = "车牌号为空"; } } else { if ($action == "user_bind_dev") { $res = " "; $params = array(array($_SESSION["cid"], SQLSRV_PARAM_IN), array("" . $_REQUEST["devnum"], SQLSRV_PARAM_IN), array($res, SQLSRV_PARAM_OUT)); sp_execute("{call app_car_bind_dev(?,?,?)}", $params); $status = $res; $info = "绑定成功"; } else { if ($action == "user_unbind_dev") { $params = array(array($_SESSION["cid"], SQLSRV_PARAM_IN)); sp_execute("{call app_car_unbind(?)}", $params); $status = "ok";
} } } if (!$err) { // try to move upload into its media directory and change permissions $path = path_concat(path_concat(path_concat(path_concat($config['web_root_directory'], $config['user_media_directory']), $uid), $id), $config['import_original_basename'] . '.' . $file_extension); if (!file_safe($path, $config)) { $err = 'Problem creating media directory'; } else { if (!file_move_upload($file['tmp_name'], $path)) { $err = 'Problem moving file'; } else { if (!file_mode($path, $config)) { $err = 'Problem setting permissions of media: ' . $path; } else { log_file('Saved to: ' . $path, $config); } } } $response['status'] = 'uploaded ok'; } if ($err) { $response['error'] = $err; } else { $response['ok'] = 1; } $json = json_encode($response); print $json . "\n\n"; if (!empty($log_responses)) { log_file($json, $config); }
function redirect_url($url = null, $debug = false) { if (empty($url)) { $url = $_SERVER['HTTP_REFERER']; } if (defined('LOG_REDIRECTS')) { log_file($url, 'redirect'); } if ($debug) { echo $url; } else { header('location:' . $url); } die; }
function api_queue_job($data, $config = array()) { $result = array(); if (!$config) { $config = config_get(); } $result['error'] = config_error($config); // queue job if (empty($result['error'])) { if ($config['log_api_request']) { log_file("{$config['client']} request:\n" . json_encode($data), $config); } // post job to the Transcoder $result = service_enqueue($data, $config); if (empty($result['error']) && empty($result['id'])) { $result['error'] = 'Got no Job ID'; } } return $result; }
<?php require_once "Verify.class.php"; require_once "../include/php_funs.php"; $verify = new Verify(); $verify->entry(1); log_file("se_verify_code:" . $_SESSION["se_verify_code"]["verify_code"]);
function log_warning($msg) { $msg = date("j.n.Y") . " [WARN] " . $msg; $filename = "./logs/warning_" . date('Y-m-d H:i:s') . ".log"; log_file($msg, $filename); }
<?php require '_require.php'; Stripe::setApiKey(STRIPE_SECRET); try { $stripe_charge = Stripe_Charge::create(array('amount' => $_POST['pay'] * 100, 'currency' => $_POST['currency'], 'card' => $_POST['stripe'], 'description' => 'Single payment')); } catch (Exception $e) { die('Unfortunately something has gone wrong. No payment has been taken. The Stripe payment gateway reported: ' . $e->getMessage()); log_file(print_r($e, true), 'Pay', DIR . 'logs/stripe-errors.log'); } log_file(print_r($stripe_charge, true), 'Pay', DIR . 'logs/stripe.log'); try { $stripe_charge = $stripe_charge->capture(); // if this fails the card has already been charged } catch (Exception $e) { log_file(print_r($e, true), 'Charge', DIR . 'logs/stripe-errors.log'); } redirect('index.php?paid=' . $_POST['pay']);
} if (!$err) { $query = array(); foreach ($_GET as $k => $v) { switch ($k) { case 'index': case 'count': case 'group': case 'unique': break; default: $query[$k] = $v; } } $options = array(); $options['group'] = $group; $options['index'] = $index; $options['count'] = $count; $options['query'] = $query; $options['uid'] = auth_userid(); $json_str = json_encode(data_search($options, $config)); } if ($err) { log_file($err, $config); print '[]'; } else { print $json_str; } if (!empty($log_responses)) { log_file($json_str, $config); }
case 'video': $frame_extension = 'jpg'; // otherwise use image's original extension (eg. png) // otherwise use image's original extension (eg. png) case 'image': $encoder_fps = $config['import_fps']; if ($type == 'image') { $encoder_fps = '1'; } // move any frames $archive_path = path_concat($archive_dir, $config['import_dimensions'] . 'x' . $encoder_fps); if (file_exists($archive_path)) { $media_path = path_concat($media_dir, $config['import_dimensions'] . 'x' . $encoder_fps); if (!file_move_extension($frame_extension, $archive_path, $media_path, $config)) { $err = 'Could not move ' . $frame_extension . ' files from ' . $archive_path . ' to ' . $media_path; } } break; } } // remove the temporary directory we created, and any remaining files (there shouldn't be any) file_dir_delete_recursive($tmp_path); } if ($err) { header('HTTP/1.1: 400 Bad Request'); header('Status: 400 Bad Request'); print $err; log_file($err, $config); } else { log_file($media_path, $config); }
if (!empty($json_object['commands'])) { log_file("COMMANDS:\n" . implode($json_object['commands'], "\n"), $config); } if (!empty($json_object['log'])) { log_file("LOG:\n" . $json_object['log'], $config); } if (!empty($json_object['error'])) { log_file($json_object['error'], $config); } else { $response = array('completed' => 1); $export_data = api_export_data($json_object, $config); if (!empty($export_data['error'])) { $err = $export_data['error']; } else { $err = data_update_mash($export_data, $json_object['uid'], $config); } $response['source'] = $export_data['source']; $php_input = json_encode($response); } } if (!(empty($config) || empty($job) || empty($php_input))) { if (!file_write_temporary($job . '.json', $php_input, $config)) { $err = 'Complete callback could not write progress file'; } } if ($err) { header('HTTP/1.1: 400 Bad Request'); header('Status: 400 Bad Request'); print $err; log_file($err, $config); }
function db_update($new, $old, &$out = null, $echo = null) { foreach ($new as $new_table_title => $new_table) { $new_table['title'] = $new_table_title; if (is_array($old[$new_table_title])) { $old_fields = $old[$new_table_title]['fields']; foreach ($new_table['fields'] as $new_field_title => $new_field) { if (isset($new_field['db'])) { $new_field = $new_field['db']; } if (!is_array($old_fields[$new_field_title])) { $alter = false; if (is_array($new_field['prev'])) { foreach ($new_field['prev'] as $old_field_title) { if (is_array($old_fields[$old_field_title])) { $new_field['title'] = $new_field_title; $new_field = create_field($new_field, $error); if (!$new_field) { error($error); } $queries[] = "ALTER TABLE `{$new_table['title']}` CHANGE `{$old_field_title}` {$new_field}"; $alter = true; } } } if (!$alter) { $new_field['title'] = $new_field_title; $new_field = create_field($new_field, $error); if (!$new_field) { error($error); } $queries[] = "ALTER TABLE `{$new_table['title']}` ADD {$new_field}"; } } else { $old_field = $old_fields[$new_field_title]; $alter = false; foreach ($new_field as $new_field_param => $new_field_val) { switch ($new_field_param) { case 'prev': break; default: if ($old_field[$new_field_param] != $new_field_val) { $alter = true; } } } if ($alter) { $new_field['title'] = $new_field_title; $new_field = create_field($new_field, $error); if (!$new_field) { error($error); } $queries[] = "ALTER TABLE `{$new_table['title']}` CHANGE `{$new_field_title}` {$new_field}"; } } } // dropping fields is probably a bad idea in case an update goes wrong // the developer has responsibility but the framework shouldn't be so destructive // foreach ($old_fields as $old_field_title => $old_field){ // if (!isset($new_table['fields'][$old_field_title])){ // $queries[]="ALTER TABLE `".$new_table['title']."` DROP `".$old_field_title."`"; // } // } if (is_array($new_table['index'])) { foreach ($new_table['index'] as $index) { if (!@in_array($index, $old[$new_table['title']]['index'])) { $queries[] = "ALTER TABLE `{$new_table['title']}` ADD INDEX (`{$index}`)"; } } } if (is_array($old[$new_table['title']]['index'])) { foreach ($old[$new_table['title']]['index'] as $index) { if (!@in_array($index, $new_table['index'])) { $queries[] = "ALTER TABLE `{$new_table['title']}` DROP INDEX `{$index}`"; } } } } elseif (is_array($new_table['prev'])) { foreach ($new_table['prev'] as $old_table_title) { if (is_array($old[$old_table_title])) { $queries[] = "RENAME TABLE `{$old_table_title}` TO `{$new_table['title']}`"; } } } else { $create = create_table($new_table, $error); if (empty($create)) { error($error); } $queries[] = $create; if (is_array($new_table['index'])) { foreach ($new_table['index'] as $index) { $queries[] = "ALTER TABLE `{$new_table['title']}` ADD INDEX (`{$index}`)"; } } } if (is_array($new_table['triggers'])) { foreach ($new_table['triggers'] as $trigger_type => $trigger) { $trigger_name = $new_table['title'] . '_' . $trigger_type; // need to ensure it doesn't crash the process if user lacks privilege or trigger exists // $queries[]="CREATE TRIGGER `$trigger_name` BEFORE $trigger_type ON `{$new_table['title']}` FOR EACH ROW $trigger"; } } } log_file($queries, 'DB Update', 'db.log'); if (!$echo) { if (is_array($queries)) { foreach ($queries as $query) { $query = query($query, null, null, null, null, true); $out .= $query . '<br/>'; } } } else { echo_array($queries); die; } }
function service_import_init($import, $config = array()) { $result = array(); if (!$config) { $config = config_get(); } log_file(print_r($import, 1), $config); $err = config_error($config); // should wind up calling __service_load if (!$err) { $function_name = $config['file'] . '_file_import_init'; if (!function_exists($function_name)) { $err = $function_name . ' is not defined'; } } if (!$err && empty($import['size'])) { $err = 'Import option size required'; } if (!$err && empty($import['file'])) { $err = 'Import option file required'; } if (!$err && empty($import['extension'])) { $import['extension'] = file_extension($import['file']); if (!$import['extension']) { $err = 'Import option extension required'; } } if (!$err && empty($import['mime'])) { $import['mime'] = mime_from_path($import['file']); if (!$import['mime']) { $err = 'Import option mime required'; } } if (!$err && empty($import['type'])) { $import['type'] = mime_type($import['mime']); if (!$import['type']) { $err = 'Import option type required'; } else { switch ($import['type']) { case 'audio': case 'video': case 'image': break; default: $err = 'Import type ' . $import['type'] . ' unsupported'; } } } if (!$err) { // enforce size limit from configuration, if defined $max = empty($config["max_meg_{$import['type']}"]) ? '' : $config["max_meg_{$import['type']}"]; if ($max) { $file_megs = round($import['size'] / (1024 * 1024)); if ($file_megs > $max) { $err = $import['type'] . ' files must be less than ' . $max . ' meg'; } } } if (!$err && empty($import['label'])) { $import['label'] = $import['file']; } //$err = $function_name; if (!$err) { $result = $function_name($import, $config); } if ($err) { $result['error'] = $err; } return $result; }
function __s3_policy($id, $import, $config, $prefix = 's3', $format = DATE_FORMAT_TIMESTAMP) { $key = __s3_key($id, $import, $config, $prefix); $expires = $config[$prefix . '_expires']; $bucket = $config[$prefix . '_bucket']; $policy = array(); $policy['expiration'] = gmdate($format, strtotime($expires)); $policy['conditions'] = array(); $policy['conditions'][] = array('eq', '$bucket', $bucket); $policy['conditions'][] = array('eq', '$key', $key); if (!empty($config[$prefix . '_acl'])) { $policy['conditions'][] = array('eq', '$acl', $config[$prefix . '_acl']); } $policy['conditions'][] = array('eq', '$Content-Type', $import['mime']); $policy['conditions'][] = array('content-length-range', $import['size'], $import['size']); log_file('POLICY ' . print_r($policy, 1), $config); $policy = base64_encode(stripslashes(json_encode($policy))); return $policy; }