/** * 生成缓存文件 * Enter description here ... */ private function get_server_config() { $alive_filename = $this->settings['alive_filename'] ? $this->settings['alive_filename'] : 'alive'; $filename = $alive_filename . '.php'; if (is_file(CACHE_DIR . $filename)) { include CACHE_DIR . $filename; } else { $this->db = hg_ConnectDB(); $sql = "SELECT id, host, output_dir, input_port, type FROM " . DB_PREFIX . "server_config "; $sql .= " WHERE status = 1 ORDER BY id DESC "; $q = $this->db->query($sql); $return = array(); while ($row = $this->db->fetch_array($q)) { $row['host'] = $row['host'] . ':' . $row['input_port']; $return[] = $row; } $content = '<?php if (!IS_READ) { exit(); } $return = ' . var_export($return, 1) . '; ?>'; hg_file_write(CACHE_DIR . $filename, $content); } return $return; }
public function __construct() { parent::__construct(); $this->extendField = new extendField(); $this->db1 = hg_ConnectDB(); }
/** * * 强制用户退出,非管理员角色使用需要赋予权限应用的“强制退出”权限 ... * @param user_id 强制退出用户ID * @param is_member 是否会员用户 * */ public function force_logout_user() { $this->verify_content_prms(array('_action' => 'force_logout_user')); $userId = (int) $this->input['user_id']; !($userId > 0) && $this->errorOutput(NO_USER_ID); $isMember = isset($this->input['is_member']) && $this->input['is_member'] ? 1 : 0; $databasename = ''; $servers = hg_load_login_serv(); if (!$servers || !$isMember) { $newdb = hg_ConnectDB(); } elseif ($servers && $isMember) { $server_index = $userId % count($servers); $server = $servers[$server_index]; if ($server) { class_exists('db', false) or (include ROOT_PATH . 'lib/db/db_mysql.class.php'); $server['pass'] = hg_encript_str($server['pass'], false); $newdb = new db(); $newdb->connect($server['host'], $server['user'], $server['pass'], $server['database'], $server['charset'], $server['pconnect']); $databasename = $server['database'] . '.'; } else { $newdb = hg_ConnectDB(); } } $sql = 'DELETE FROM ' . $databasename . DB_PREFIX . 'user_login WHERE user_id = "' . $userId . '" AND is_member = ' . $isMember; $redata = array('status' => 0, 'user_id' => $userId, 'is_member' => $isMember, 'copywriting' => 'UserID = ' . $userId . '的TOKEN清除失败'); $query = $newdb->query($sql); if ($query && $newdb->affected_rows()) { $redata['status'] = 1; $redata['copywriting'] = 'UserID = ' . $userId . '的TOKEN清除成功'; } elseif ($query) { $redata['copywriting'] = 'UserID = ' . $userId . '的用户未登录'; } $this->addItem($redata); $this->output(); }
public function settings() { $dbconfig = $this->dbconfig; unset($dbconfig['pass']); $this->addItem_withkey('db', $dbconfig); $settings = $this->settings; $const = $this->get_const(); if ($const) { foreach ($const as $k => $c) { $define[$k] = $c; } } $freespace = array(); if (function_exists('disk_free_space')) { $rdiskspace = @disk_free_space('/'); $cdiskspace = @disk_free_space(CUR_CONF_PATH); $freespace = array('rootfree' => array('size' => $rdiskspace, 'text' => hg_fetch_number_format($rdiskspace, true)), 'curfree' => array('size' => $cdiskspace, 'text' => hg_fetch_number_format($cdiskspace, true))); } if ($this->input['is_writes']) { $data_file_purview = 0; $cache_file_purview = 0; $config_file_purview = 0; if (is_writable(DATA_DIR)) { $data_file_purview = 1; } else { $data_file_purview = -1; } if (is_writable(CACHE_DIR)) { $cache_file_purview = 1; } else { $cache_file_purview = -1; } if (is_writable(CONF_FILE)) { $config_file_purview = 1; } else { $config_file_purview = -1; } $this->addItem_withkey('data_file_purview', $data_file_purview); $this->addItem_withkey('cache_file_purview', $cache_file_purview); $this->addItem_withkey('config_file_purview', $config_file_purview); } $this->addItem_withkey('freespace', $freespace); $this->addItem_withkey('api_dir', realpath(CUR_CONF_PATH)); $this->addItem_withkey('define', $define); $this->addItem_withkey('base', $settings); $this->addItem_withkey('debuged', DEBUG_MODE); $start_time = microtime(); $this->db = hg_ConnectDB(); //$this->db->mErrorExit = true; $totaltime = $this->cal_runtime($start_time); if ($this->db) { $connected = 1; } else { $connected = 0; } $this->addItem_withkey('dbconnected', $connected); $this->addItem_withkey('connect_time', $totaltime); $this->output(); }
if (is_array($_FILES)) { foreach ($_FILES as $key => $val) { $_FILES[$key]['tmp_name'] = str_replace('\\', '\\\\', $val['tmp_name']); } } foreach (array('_REQUEST', '_GET', '_POST', '_COOKIE', '_FILES') as $v) { stripslashes_vars(${$v}); } } define('SAFE_MODE', @ini_get('safe_mode') || @strtolower(ini_get('safe_mode')) == 'on' ? true : false); } else { define('MAGIC_QUOTES_GPC', false); define('SAFE_MODE', false); } if (!defined('WITHOUT_DB') || !WITHOUT_DB) { $gDB = hg_ConnectDB(); } /*/用户输入安全过滤 foreach (array('_REQUEST', '_GET', '_POST', '_COOKIE', '_FILES', '_SERVER') as $v) { $$v = hg_addslashes($$v); } */ $_INPUT = hg_init_input(); register_shutdown_function('hg_done'); function hg_done() { global $gDB; if ($gDB) { $gDB->close(); }
public function __construct() { parent::__construct(); $this->db1 = hg_ConnectDB(); }
public function dvr() { $stream = addslashes($this->input['stream']); $start_time = intval($this->input['starttime']); $duration = intval($this->input['duration']); $endtime = $start_time + $duration; if ($endtime > $this->mTimenow) { $endtime = $this->mTimenow; } $time_shift = $this->mChannelinfo['channel']['time_shift']; $shift_stime = $this->mTimenow - $time_shift * 3600000; if ($start_time < $shift_stime) { $start_time = $shift_stime; } $this->mChannelinfo['channel']['table_name'] = $this->mChannelinfo['channel']['table_name'] ? $this->mChannelinfo['channel']['table_name'] : 'dvr'; $channel_stream = $this->mChannelinfo['channel']['code'] . '_' . $stream; $this->db = hg_ConnectDB(); $sql = 'SELECT * FROM ' . DB_PREFIX . $this->mChannelinfo['channel']['table_name'] . " WHERE stream_name='{$channel_stream}' AND start_time >= {$start_time} AND start_time < {$endtime} ORDER BY start_time ASC "; $q = $this->db->query($sql); $ts = array(); while ($r = $this->db->fetch_array($q)) { $ts[$r['level']][] = $r; } $ts = $this->get_dvr_ts($ts); $sdate = date('Y-m-d', $start_time / 1000); $edate = date('Y-m-d', $endtime / 1000); $shield_time_zone = $this->get_shield($sdate); if ($sdate != $edate) { $shield_time_zone = array_merge($shield_time_zone, $this->get_shield($edate)); } $m3u8 = $this->build_m3u8($ts, '#EXT-X-ENDLIST', rtrim($this->mChannelinfo['channel']['config']['ts_host'], '/'), $shield_time_zone); $dir = DATA_DIR . $this->mChannelinfo['channel']['code'] . '/' . $stream . '/'; hg_mkdir($dir); $m3u8name = $start_time . ',' . $duration . '.m3u8'; $m3u8 = trim($m3u8); if (!$m3u8) { $this->header(404); } file_put_contents($dir . $m3u8name, $m3u8); $urls = $this->mChannelinfo['channel']['config']['out_host'] . $this->mChannelinfo['channel']['code'] . '/' . $stream . '/' . $m3u8name; $sm3u8 = $m3u8; if ($this->settings['ts_host']) { $m3u8 = str_replace($this->mChannelinfo['channel']['config']['ts_host'], $this->settings['ts_host'], $m3u8); file_put_contents($dir . 'm_' . $m3u8name, $m3u8); $urls .= "\n" . $this->mChannelinfo['channel']['config']['out_host'] . $this->mChannelinfo['channel']['code'] . '/' . $stream . '/m_' . $m3u8name; } if ($this->settings['open_push_cdn']) { include_once ROOT_PATH . 'lib/class/cdn.class.php'; $cdn = new cdn(); $cdn->push($urls, ''); } if ($this->settings['m3u8_host'] == 'http://' . $this->input['host']) { echo $m3u8; } else { echo $sm3u8; } }
function get_transcode_configs($config_id) { $gDB = hg_ConnectDB(); //获取不同码流的转码配置 $sql = "SELECT * FROM " . DB_PREFIX . "vod_config WHERE is_use = 1 AND type_id=" . $config_id . "\n\tAND is_default != 1 "; $q = $gDB->query($sql); $vod_config = array(); while ($r = $gDB->fetch_array($q)) { $r['codec_format'] = 'libx264'; $r['codec_profile'] = 'main'; if ($r['water_pic_position']) { $p_water = explode(',', trim($r['water_pic_position'])); $r['water_mark_x'] = $p_water[0]; $r['water_mark_y'] = $p_water[1]; } else { $r['water_mark_x'] = '0'; $r['water_mark_y'] = '0'; } $r['water_mark'] = $r['is_open_water'] ? basename($r['water_pos']) : ''; unset($r['water_pos'], $r['water_pic_position'], $r['config_order_id'], $r['name'], $r['is_use'], $r['id']); $vod_config[] = $r; } if (!$vod_config) { return false; } return $vod_config; }
public function change_pwd() { $db = hg_ConnectDB(); $username = trim($this->input['username']); $old_password = trim($this->input['old_password']); $password = trim($this->input['password']); $admin_id = intval($this->input['admin_id']); if (!$old_password || !$password || !$admin_id) { $this->addItem(array('error' => 1, 'msg' => '参数缺失')); $this->output(); } //验证旧密码 $sql = "SELECT password,salt FROM " . DB_PREFIX . "admin WHERE id = " . $admin_id . " AND user_name = '" . $username . "'"; $q = $db->query_first($sql); $salt = hg_generate_salt(); if ($this->input['md5once']) { $password = md5($password . $salt); $old_password = md5($old_password . $q['salt']); } else { $password = md5(md5($password) . $salt); $old_password = md5(md5($old_password) . $q['salt']); } if ($old_password != $q['password']) { $this->addItem(array('error' => 1, 'msg' => '原始密码有误')); $this->output(); } $data = array('password' => $password, 'salt' => $salt, 'update_time' => TIMENOW, 'forced_change_pwd' => 0); $re = $db->update_data($data, 'admin', 'id=' . $admin_id); if ($re) { $ret = array('error' => 0, 'msg' => 'success'); } else { $ret = array('error' => 1, 'msg' => '修改失败'); } $this->addItem($ret); $this->output(); }
private function get_shield_info($channel_id, $dates, $program_shield_dir = 'program_shield', $field = ' * ') { if (!$channel_id || !$program_shield_dir || !$dates) { return false; } $times = strtotime($dates); $dir = $dates; $dir = CACHE_DIR . $program_shield_dir . '/' . $dir; $filename = $channel_id . '.php'; $return = array(); if (is_file($dir . '/' . $filename)) { include $dir . '/' . $filename; $return = $program_shield; } else { $this->db = hg_ConnectDB(); $sql = "SELECT {$field} FROM " . DB_PREFIX . "program_shield "; $sql .= " WHERE channel_id = " . $channel_id; $sql .= " AND dates = '" . $dates . "'"; $q = $this->db->query($sql); $return = array(); while ($row = $this->db->fetch_array($q)) { $return[] = $row; } if (!is_dir($dir)) { hg_mkdir($dir); } $content = '<?php $program_shield = ' . var_export($return, 1) . '; ?>'; hg_file_write($dir . '/' . $filename, $content); } return $return; }