function SetSqlStore($sql) { $this->SQL_Store[] = $sql; if (true === DEBUG) { jlog('mysql_query_log', jstripslashes($sql['SQL']), 0); } }
public function add($postData) { $member = $this->is_jsg($postData['fromusername']); if ($member) { $imageID = 0; if ($postData['msgtype'] == "image") { $p = array('pic_url' => $postData['picurl'], 'uid' => $member['jsg_id']); $rets = jlogic('image')->upload($p); if ($rets['code'] < 0 && $rets['error']) { jlog('wechat', $postData, 0); jlog('wechat', $rets, 0); } $imageID = $rets['id']; } $r = jlogic("topic")->Add($postData['content'], 0, $imageID, 0, "wechat", "first", $member['jsg_id']); if (is_array($r) && $r['tid'] > 0) { } else { jlog('wechat', $postData, 0); } if ($r) { if (is_array($r)) { return $this->wechatConfig['add_weibo_success']; } else { return $r; } } else { return $this->wechatConfig['add_weibo_false']; } } }
public function __construct($param) { if (!$param['db_host'] || !$param['db_user'] || !$param['db_pass'] || !$param['db_name']) { jlog('mssql', 'db name or host or user or password is empty'); } if ($param['db_port']) { $pd = defined('PHP_OS') && substr(PHP_OS, 0, 3) == 'WIN' ? ',' : ':'; $param['db_host'] .= $pd . $param['db_port']; } if (!function_exists('mssql_connect')) { jlog('mssql', 'function mssql_connect is invalid'); } @ini_set('mssql.charset', $param['db_charset']); @ini_set('mssql.textlimit', 2147483647); @ini_set('mssql.textsize', 2147483647); $this->link = mssql_connect($param['db_host'], $param['db_user'], $param['db_pass']); if (!$this->link) { jlog('mssql', 'connect is invalid<br />error message: ' . $this->error()); } if (!mssql_select_db($param['db_name'], $this->link)) { mssql_close($this->link); jlog('mssql', 'db name select is invalid'); } return true; }
/** * Copy a file * * @param string $path The original path * @param string $newpath The new path * @param string $fileName The name of the file * @return void * @author Jonas Björk */ function jb_copy_file($path, $fileName) { // TODO: Great error handling, with return values. $newpath = jb_get_new_path($path, $path . NEW_DIR_NAME, $fileName); $p = jb_split_path($newpath); jb_create_dir($p['dir']); if (!@copy($fileName, $p['absolute'])) { if (DEBUG) { jlog(sprintf("Could not copy file %s to %s", $name, $p['absolute']), LOG_ERR); } } else { // if ( DEBUG ) printf( "INFO: Copied %s to %s\n", $name, $p['absolute'] ); } }
$infos = $nest->getDeviceInfo(); jlog($infos); echo "----------\n\n"; echo "Device schedule:\n"; // Returns as array, one element for each day of the week for which there has at least one scheduled event. // Array keys are a textual representation of a day, three letters, as returned by `date('D')`. Array values are arrays of scheduled temperatures, including a time (in minutes after midnight), and a mode (one of the TARGET_TEMP_MODE_* defines). $schedule = $nest->getDeviceSchedule(); jlog($schedule); echo "----------\n\n"; echo "Device next scheduled event:\n"; $next_event = $nest->getNextScheduledEvent(); jlog($next_event); echo "----------\n\n"; echo "Last 10 days energy report:\n"; $energy_report = $nest->getEnergyLatest(); jlog($energy_report); echo "----------\n\n"; /* Helper functions */ function json_format($json) { $tab = " "; $new_json = ""; $indent_level = 0; $in_string = false; $json_obj = json_decode($json); if ($json_obj === false) { return false; } $json = json_encode($json_obj); $len = strlen($json); for ($c = 0; $c < $len; $c++) {
function setSessionId($sid = null) { if (!is_null($sid)) { $this->sid = $sid; jsg_setcookie('sid', $sid, 311040000); } else { $this->sid = get_param('sid') ? get_param('sid') : jsg_getcookie('sid'); } if (!empty($this->sid)) { if (false == preg_match('~^[\\w\\d]{2,18}$~i', $this->sid)) { jlog('sid', $this->sid, 0); exit('sid is invalid'); } } }
private function check_signature() { $signature = $this->Get["signature"]; $timestamp = $this->Get["timestamp"]; $nonce = trim($this->Get["nonce"], "Vary:"); $token = TOKEN; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr); $tmpStr = implode($tmpArr); $tmpStr = sha1($tmpStr); if ($tmpStr == $signature) { return true; } else { jlog('wechat', "{$tmpStr} {$signature}", 0); return false; } }
if ($xbt['mid'] < 1) { return; } $p['id'] = $xbt['mid']; if (in_array($topic['type'], array('both', 'forward'))) { $p['status'] = $content; $p['is_comment'] = 'both' == $topic['type'] ? 1 : 0; $rets = sina_weibo_api('2/statuses/repost', $p); } else { $p['comment'] = $content; $rets = sina_weibo_api('2/comments/create', $p); } } if ($rets['error'] && $rets['error_code']) { if (jget('debug')) { debug($rets); } jlog('to_xwb.inc', $rets); } $mid = $rets['idstr'] ? $rets['idstr'] : $rets['id']; if ($mid > 0) { DB::query("replace into " . DB::table('xwb_bind_topic') . " (`tid`, `mid`) values ('{$tid}', '{$mid}')"); } } else { $GLOBALS['jsg_tid'] = $data['tid']; $GLOBALS['jsg_totid'] = $data['totid']; $GLOBALS['jsg_message'] = $data['content']; $GLOBALS['jsg_imageid'] = $data['imageid']; require_once ROOT_PATH . 'include/ext/xwb/sina.php'; require_once XWB_plugin::hackFile('newtopic'); }
function _filter(&$p, $try_ids = 0) { $ps = $p; if (is_array($ps) && count($ps) && $this->field) { $k_is_num = true; $ps_o = $ps; foreach ($ps as $k => $v) { if (is_array($v) && isset($v['glue']) && !$this->field[$v['key']]) { echo 'table _filter is invalid'; jlog('table__filter', $ps); } if ($try_ids) { $k_is_num = $k_is_num && is_numeric($k); } if (!$this->field[$k]) { $at_pos = strpos($k, '@'); if (false !== $at_pos) { $kk = substr($k, $at_pos + 1); if ($this->field[$kk]) { $glue = substr($k, 0, $at_pos); if ($glue && in_array($glue, array('=', '-', '+', '|', '&', '^', '>', '<', '<>', '>=', '<=', 'like', 'in', 'notin'))) { $ps['glue_' . mt_rand() . '_' . $kk] = array('glue' => $glue, 'key' => $kk, 'val' => $v); } } } unset($ps[$k]); } } if ($try_ids && !$ps && $k_is_num && $this->pri) { $ps = array($this->pri => $ps_o); $p['result_count'] = count($ps_o); $p['result_list_order_by_self'] = 1; $p['return_list'] = 1; } unset($p['sql_include_subquery']); if ($this->_sub_table_by_field && $this->_table && !$p['sql_table'] && !$p['return_sql'] && $p[$this->_sub_table_by_field]) { $p = $this->_set_sub_table($this->_sub_table_by_field, $p); if ($p['sql_table']) { $ps = array(); } } } return $ps; }
function CheckQuery($sql) { static $status = null, $checkcmd = array('SELECT', 'UPDATE', 'INSERT', 'REPLACE', 'DELETE'), $static_query_safes = array(); if ($status === null) { $status = QUERY_SAFE; } if ($status) { $cmd = trim(strtoupper(substr($sql, 0, strpos($sql, ' ')))); if (in_array($cmd, $checkcmd)) { $cache_id = md5($sql); if (false == ($test = $static_query_safes[$cache_id])) { if (isset($GLOBALS['_J']['query_safes'][$cache_id]) && $GLOBALS['_J']['query_safes'][$cache_id] == md5($cache_id . $GLOBALS['_J']['config']['auth_key'])) { $test = 1; } else { $test = $this->_do_query_safe($sql); } $static_query_safes[$cache_id] = $test; } if ($test < 1) { jlog('mysql_query_check', "[{$test}] {$sql}", true !== DEBUG); exit; } } } return true; }
if (is_file($tpic) && ($ps = getimagesize($tpic) && ($p_data = file_get_contents($tpic)))) { $p_name = basename($topic_image['name'] ? $topic_image['name'] : $tpic); if (!$p_name) { $p_name = mt_rand(); } $p_name = array_iconv($GLOBALS['_J']['config']['charset'], 'UTF-8', $p_name); $pic = array($ps['mime'], $p_name, $p_data); $t_result = $QQAuth->tAddPic($content, $pic); } else { $t_result = $QQAuth->tAdd($content); } } else { $t_result = $QQAuth->tAdd($content); } } else { $reid = DB::result_first("select `qqwb_id` from " . TABLE_PREFIX . "qqwb_bind_topic where `tid`='{$totid}'"); if ($reid < 1) { return; } $t_result = $QQAuth->tReply($reid, $content); } if ($t_result['errcode']) { if (jget('debug')) { debug($t_result); } jlog('to_qqwb.inc', $t_result); } $qqwb_id = $t_result['data']['id'] && is_numeric($t_result['data']['id']) ? $t_result['data']['id'] : 0; if ($qqwb_id > 0) { $return = DB::query("replace into " . TABLE_PREFIX . "qqwb_bind_topic (`tid`,`qqwb_id`) values ('{$tid}','{$qqwb_id}')"); }
static function _check_field_key($k) { $k = (string) $k; $cks = array('`', ',', '=', '(', ')', '<', '>'); foreach ($cks as $ck) { if (false !== strpos($k, $ck)) { echo "DB field key is invalid"; jlog('db__check_field_key', $k); } } return $k; }
function register($nickname, $password, $email, $username = '', $ucuid = 0, $role_id = 0) { $rets = jsg_member_register_check_status(); if ($rets['error']) { return 0; } $ip = $GLOBALS['_J']['client_ip']; $ret = $this->register_check_ip($ip); if (!$ret) { return -7; } $nickname = trim(strip_tags($nickname)); $jsg_result = $this->checkname($nickname, 1, $ucuid); if ($jsg_result < 1) { return $jsg_result; } $username = trim(strip_tags($username)); if ($username) { $jsg_result = $this->checkname($username, 0, $ucuid); if ($jsg_result < 1) { return $jsg_result; } } $jsg_result = $this->checkemail($email, $ucuid); if ($jsg_result < 1) { return $jsg_result; } if (true === UCENTER && $ucuid < 1) { $uc_result = uc_user_register($nickname, $password, $email); if ($uc_result < 1) { return $uc_result; } $ucuid = $uc_result; } elseif (true === PWUCENTER && $ucuid < 1) { define('P_W', 'admincp'); include_once ROOT_PATH . 'api/pw_api/security.php'; include_once ROOT_PATH . 'api/pw_api/pw_common.php'; include_once ROOT_PATH . './api/pw_client/uc_client.php'; $uc_result = uc_user_register($nickname, md5($password), $email); if ($uc_result < 1) { return $uc_result; } $ucuid = $uc_result; } $timestamp = time(); $sql_datas = array(); $sql_datas['ucuid'] = $ucuid; $sql_datas['salt'] = jsg_member_salt(); $sql_datas['password'] = jsg_member_password($password, $sql_datas['salt']); $sql_datas['nickname'] = $nickname; $sql_datas['username'] = $username ? $username : ''; $sql_datas['email'] = $email; $sql_datas['role_type'] = 'normal'; $sql_datas['role_id'] = (int) ($GLOBALS['_J']['config']['reg_email_verify'] ? $GLOBALS['_J']['config']['no_verify_email_role_id'] : $GLOBALS['_J']['config']['normal_default_role_id']); $sql_datas['invitecode'] = substr(md5(random(32)), -16); $sql_datas['regdate'] = $sql_datas['lastactivity'] = $timestamp; $sql_datas['regip'] = $sql_datas['lastip'] = $ip; $sql_datas['reg_ip_port'] = $sql_datas['last_ip_port'] = $GLOBALS['_J']['client_ip_port']; if ($GLOBALS['_J']['config']['extcredits_enable']) { $credits = jconf::get('credits'); foreach ($credits['ext'] as $_k => $_v) { if ($_v['enable'] && $_v['default']) { $sql_datas[$_k] = (int) $_v['default']; } } } $uid = jtable('members')->insert($sql_datas, 1); if ($uid < 1) { jlog('passport_register', $sql_datas, 0); return 0; } if (!$username) { DB::query("UPDATE `" . TABLE_PREFIX . "members` SET `username`=`uid` WHERE `username`=''"); } DB::query("insert into `" . TABLE_PREFIX . "memberfields` (`uid`) values ('{$uid}')"); #if NEDU if (defined('NEDU_MOYO')) { ndata('sync')->member()->register($uid); } #endif if ($GLOBALS['_J']['config']['reg_email_verify']) { jfunc('my'); my_member_validate($uid, $sql_datas['email'], (int) $GLOBALS['_J']['config']['normal_default_role_id'], 0, 0); } $ruids = jconf::get('default_regfollow'); if ($ruids) { $ruids = (array) $ruids; foreach ($ruids as $v) { $v = (int) $v; if ($v > 0) { buddy_add($v, $uid); } } } $followgroup_ary = jconf::get('follow'); if (empty($followgroup_ary) && !$GLOBALS['_J']['config']['acceleration_mode']) { $followgroup_ary = get_def_follow_group(); } if (!empty($followgroup_ary)) { foreach ($followgroup_ary as $value) { jtable('buddy_follow_group')->add($value, $uid); } } $pmLogic = jlogic('pm'); if (($sendmsgname = $GLOBALS['_J']['config']['notice_to_new_user']) && $GLOBALS['_J']['config']['notice_to_new_user_news']) { $pm_post = array('message' => $GLOBALS['_J']['config']['notice_to_new_user_news'], 'to_user' => $nickname); $admin_info = DB::fetch_first("select `uid`,`username`,`nickname` from `" . TABLE_PREFIX . "members` where `nickname` = '{$sendmsgname}'"); if ($admin_info) { $pmLogic->pmSend($pm_post, $admin_info['uid'], $admin_info['username'], $admin_info['nickname']); } } if (trim($sql_datas['role_id']) == 5) { $first_admin = DB::fetch_first("select `uid`,`username`,`nickname` from `" . TABLE_PREFIX . "members` where `uid` = 1"); $pm_post_touser = array('message' => $GLOBALS['_J']['config']['notice_to_waitvalidate_user'] ? $GLOBALS['_J']['config']['notice_to_waitvalidate_user'] : "******", 'to_user' => $sql_datas['nickname']); $return = $pmLogic->pmSend($pm_post_touser, $first_admin['uid'], $first_admin['username'], $first_admin['nickname']); if ($sendmsgname = $GLOBALS['_J']['config']['notice_to_admin']) { $pm_post_toadmin = array('message' => "有新注册用户进入待验证会员组,<a href='admin.php?mod=member&code=waitvalidate' target='_blank'>点击进入审核</a>。", 'to_user' => str_replace('|', ',', $sendmsgname)); $pmLogic->pmSend($pm_post_toadmin, $first_admin['uid'], $first_admin['username'], $first_admin['nickname']); } } if ($GLOBALS['_J']['plugins']['func']['reg']) { hookscript('reg', 'funcs', array('param' => array($uid), 'step' => 'reg'), 'reg'); } return $uid; }
function _send_mail_by_smtp($email_to, $email_subject, $email_message, $smtp_config = array(), $html = true) { $sys_config = jconf::get(); if (empty($smtp_config)) { $smtp_conf = jconf::get('smtp'); $k = array_rand($smtp_conf['smtp']); $smtp_config = $smtp_conf['smtp'][$k]; } if (empty($smtp_config)) { jlog('SMTP', '$smtp_config is empty', 0); } $mail['from'] = $smtp_config['mail']; $mail['server'] = ($smtp_config['ssl'] ? 'ssl:/' . '/' : '') . $smtp_config['host']; $mail['port'] = $smtp_config['port']; $mail['auth'] = (bool) ($smtp_config['username'] && $smtp_config['password']); $mail['auth_username'] = $smtp_config['username']; $mail['auth_password'] = $smtp_config['password']; $log = 'jlog'; $charset = $sys_config['charset']; $bbname = $sys_config['site_name']; $adminemail = $sys_config['site_admin_email']; $maildelimiter = NEW_LINE; $mailusername = 1; $email_subject = '=?' . $charset . '?B?' . base64_encode(str_replace("\r", '', str_replace("\n", '', $email_subject))) . '?='; $email_message = chunk_split(base64_encode(str_replace("\r\n.", " \r\n..", str_replace("\n", "\r\n", str_replace("\r", "\n", str_replace("\r\n", "\n", str_replace("\n\r", "\r", $email_message))))))); $email_from = $smtp_config['email_from'] ? $smtp_config['email_from'] : $smtp_config['mail']; $email_from = $email_from == '' ? '=?' . $charset . '?B?' . base64_encode($bbname) . "?= <{$adminemail}>" : (preg_match('/^(.+?) \\<(.+?)\\>$/', $email_from, $from) ? '=?' . $charset . '?B?' . base64_encode($from[1]) . "?= <{$from['2']}>" : $email_from); foreach (explode(',', $email_to) as $touser) { $tousers[] = preg_match('/^(.+?) \\<(.+?)\\>$/', $touser, $to) ? $mailusername ? '=?' . $charset . '?B?' . base64_encode($to[1]) . "?= <{$to['2']}>" : $to[2] : $touser; } $email_to = implode(',', $tousers); $headers = "From: {$email_from}{$maildelimiter}X-Priority: 3{$maildelimiter}X-Mailer: JishiGou " . SYS_VERSION . "{$maildelimiter}MIME-Version: 1.0{$maildelimiter}Content-type: text/" . ($html ? 'html' : 'plain') . "; charset={$charset}{$maildelimiter}Content-Transfer-Encoding: base64{$maildelimiter}"; $mail['port'] = $mail['port'] ? $mail['port'] : 25; if (!($fp = jfsockopen($mail['server'], $mail['port'], $errno, $errstr, 3))) { $log('SMTP', "({$mail['server']}:{$mail['port']}) CONNECT - Unable to connect to the SMTP server", 0); return false; } stream_set_blocking($fp, true); $lastmessage = fgets($fp, 512); if (substr($lastmessage, 0, 3) != '220') { $log('SMTP', "{$mail['server']}:{$mail['port']} CONNECT - {$lastmessage}", 0); return false; } fputs($fp, ($mail['auth'] ? 'EHLO' : 'HELO') . " JishiGou\r\n"); $lastmessage = fgets($fp, 512); if (substr($lastmessage, 0, 3) != 220 && substr($lastmessage, 0, 3) != 250) { $log('SMTP', "({$mail['server']}:{$mail['port']}) HELO/EHLO - {$lastmessage}", 0); return false; } while (1) { if (substr($lastmessage, 3, 1) != '-' || empty($lastmessage)) { break; } $lastmessage = fgets($fp, 512); } if ($mail['auth']) { fputs($fp, "AUTH LOGIN\r\n"); $lastmessage = fgets($fp, 512); if (substr($lastmessage, 0, 3) != 334) { $log('SMTP', "({$mail['server']}:{$mail['port']}) AUTH LOGIN - {$lastmessage}", 0); return false; } fputs($fp, base64_encode($mail['auth_username']) . "\r\n"); $lastmessage = fgets($fp, 512); if (substr($lastmessage, 0, 3) != 334) { $log('SMTP', "({$mail['server']}:{$mail['port']}) USERNAME - {$lastmessage}", 0); return false; } fputs($fp, base64_encode($mail['auth_password']) . "\r\n"); $lastmessage = fgets($fp, 512); if (substr($lastmessage, 0, 3) != 235) { $log('SMTP', "({$mail['server']}:{$mail['port']}) PASSWORD - {$lastmessage}", 0); return false; } $email_from = $mail['from']; } fputs($fp, "MAIL FROM: <" . preg_replace("/.*\\<(.+?)\\>.*/", "\\1", $email_from) . ">\r\n"); $lastmessage = fgets($fp, 512); if (substr($lastmessage, 0, 3) != 250) { fputs($fp, "MAIL FROM: <" . preg_replace("/.*\\<(.+?)\\>.*/", "\\1", $email_from) . ">\r\n"); $lastmessage = fgets($fp, 512); if (substr($lastmessage, 0, 3) != 250) { $log('SMTP', "({$mail['server']}:{$mail['port']}) MAIL FROM - {$lastmessage}", 0); return false; } } $email_tos = array(); foreach (explode(',', $email_to) as $touser) { $touser = trim($touser); if ($touser) { fputs($fp, "RCPT TO: <" . preg_replace("/.*\\<(.+?)\\>.*/", "\\1", $touser) . ">\r\n"); $lastmessage = fgets($fp, 512); if (substr($lastmessage, 0, 3) != 250) { fputs($fp, "RCPT TO: <" . preg_replace("/.*\\<(.+?)\\>.*/", "\\1", $touser) . ">\r\n"); $lastmessage = fgets($fp, 512); $log('SMTP', "({$mail['server']}:{$mail['port']}) RCPT TO - {$lastmessage}", 0); return false; } } } fputs($fp, "DATA\r\n"); $lastmessage = fgets($fp, 512); if (substr($lastmessage, 0, 3) != 354) { $log('SMTP', "({$mail['server']}:{$mail['port']}) DATA - {$lastmessage}", 0); return false; } $headers .= 'Message-ID: <' . gmdate('YmdHs') . '.' . substr(md5($email_message . microtime()), 0, 6) . rand(100000, 999999) . '@' . $_SERVER['HTTP_HOST'] . ">{$maildelimiter}"; fputs($fp, "Date: " . date('r') . "\r\n"); fputs($fp, "To: " . $email_to . "\r\n"); fputs($fp, "Subject: " . $email_subject . "\r\n"); fputs($fp, $headers . "\r\n"); fputs($fp, "\r\n\r\n"); fputs($fp, "{$email_message}\r\n.\r\n"); $lastmessage = fgets($fp, 512); if (substr($lastmessage, 0, 3) != 250) { $log('SMTP', "({$mail['server']}:{$mail['port']}) END - {$lastmessage}", 0); return false; } fputs($fp, "QUIT\r\n"); return true; }