Skip to content

Commit

Permalink
2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
zorlan committed Sep 25, 2019
1 parent 4214dc2 commit 19e77d0
Show file tree
Hide file tree
Showing 146 changed files with 7,791 additions and 1,313 deletions.
22 changes: 11 additions & 11 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^app/(\w+)/(.*)$ app/$1/index.php [QSA,PT,L,E=PATH_INFO:$2]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,PT,L,E=PATH_INFO:$1]
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^app/(\w+)/(.*)$ app/$1/index.php [QSA,PT,L,E=PATH_INFO:$2]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,PT,L,E=PATH_INFO:$1]
</IfModule>
54 changes: 24 additions & 30 deletions SkycaijiApp/admin/behavior/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public function run(){
}

if($s_userid>0){
$GLOBALS['user']=$muser->getByUid($s_userid);
if(!empty($GLOBALS['user'])){
$GLOBALS['user']=$GLOBALS['user']->toArray();
$GLOBALS['user']['group']=model('Usergroup')->getById($GLOBALS['user']['groupid']);
if(!empty($GLOBALS['user']['group'])){
$GLOBALS['user']['group']=$GLOBALS['user']['group']->toArray();
if(model('Usergroup')->is_admin($GLOBALS['user']['group'])){
$GLOBALS['_sc']['user']=$muser->getByUid($s_userid);
if(!empty($GLOBALS['_sc']['user'])){
$GLOBALS['_sc']['user']=$GLOBALS['_sc']['user']->toArray();
$GLOBALS['_sc']['user']['group']=model('Usergroup')->getById($GLOBALS['_sc']['user']['groupid']);
if(!empty($GLOBALS['_sc']['user']['group'])){
$GLOBALS['_sc']['user']['group']=$GLOBALS['_sc']['user']['group']->toArray();
if(model('Usergroup')->is_admin($GLOBALS['_sc']['user']['group'])){
session('is_admin',true);
}else{
session('is_admin',null);
Expand All @@ -81,7 +81,7 @@ public function run(){
}
}

if(!empty($GLOBALS['user'])&&session('is_admin')){
if(!empty($GLOBALS['_sc']['user'])&&session('is_admin')){
/*是管理员,进行下列操作*/
if('index'==$curController&&'index'==strtolower(request()->action())){

Expand All @@ -108,38 +108,32 @@ public function run(){
}
/*通用操作,全局变量*/
$mconfig=model('Config');
$latestDate=$mconfig->max('dateline');
$keyConfig='cache_config_all';
$cacheConfig=cache($keyConfig);
$configList=array();
if(empty($cacheConfig)||$cacheConfig['update_time']!=$latestDate){

$configDbList=$mconfig->column('*');
$configDbList=empty($configDbList)?array():$configDbList;
foreach ($configDbList as $configItem){
$configItem=$mconfig->convertData($configItem);
$configList[$configItem['cname']]=$configItem['data'];
}
cache($keyConfig,array('update_time'=>$latestDate,'list'=>$configList));
}else{
$configList=$cacheConfig['list'];
$configList=$mconfig->getConfigList();
if(empty($configList)){
$mconfig->cacheConfigList();
$configList=$mconfig->getConfigList();
}
$GLOBALS['config']=$configList;
$GLOBALS['_sc']['c']=$configList;

if(!empty($GLOBALS['config']['site']['closelog'])){
if(!empty($GLOBALS['_sc']['c']['site']['closelog'])){

\think\Log::init(array('type'=>'test','level'=>array()));
}
if(!empty($GLOBALS['config']['site']['dblong'])){
if(!empty($GLOBALS['_sc']['c']['site']['dblong'])){

$dbParams=config('database.params');
$dbParams[\PDO::ATTR_PERSISTENT]=true;
config('database.params',$dbParams);
}

$GLOBALS['clientinfo']=clientinfo();
if(!empty($GLOBALS['clientinfo'])){
$GLOBALS['clientinfo']=base64_encode(json_encode($GLOBALS['clientinfo']));

if(empty($GLOBALS['_sc']['c']['download_img'])){
$GLOBALS['_sc']['c']['download_img']=$mconfig->get_img_config_from_caiji($GLOBALS['_sc']['c']['caiji']);
}

$GLOBALS['_sc']['clientinfo']=clientinfo();
if(!empty($GLOBALS['_sc']['clientinfo'])){
$GLOBALS['_sc']['clientinfo']=base64_encode(json_encode($GLOBALS['_sc']['clientinfo']));
}


Expand All @@ -150,7 +144,7 @@ public function run(){
$usertoken=md5($usertoken);
session('usertoken',$usertoken);
}
$GLOBALS['usertoken']=$usertoken;
$GLOBALS['_sc']['usertoken']=$usertoken;
}
}

Expand Down
104 changes: 82 additions & 22 deletions SkycaijiApp/admin/command/Collect.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,37 @@ protected function execute(Input $input, Output $output){
if(is_array($cacheConfig)){
\think\Config::set($cacheConfig);
}
if ($input->hasOption('cli_user')){

$cliUser=$input->getOption('cli_user');
$cliUser=base64_decode($cliUser);
$cliUser=explode('_', $cliUser);
$muser=new \skycaiji\admin\model\User();
$user=$muser->where('username',$cliUser[0])->find();
if(!empty($user)){
$user['username']=strtolower($user['username']);
$op=$input->getArgument('op');

static $loginOps=array('task','batch');

if(in_array($op, $loginOps)){

if ($input->hasOption('cli_user')){

if($user['username']==$cliUser[0]&&$cliUser[1]==md5($user['username'].$user['password'])){
session('user_id',$user['uid']);
$cliUser=$input->getOption('cli_user');
$cliUser=base64_decode($cliUser);
$cliUser=explode('_', $cliUser);
if(!empty($cliUser[0])){

$muser=new \skycaiji\admin\model\User();
$user=$muser->where('username',$cliUser[0])->find();
if(!empty($user)){
$user['username']=strtolower($user['username']);

if($user['username']==$cliUser[0]&&$cliUser[1]==md5($user['username'].$user['password'])){
session('user_id',$user['uid']);
}
}
}
}

if(!session('?user_id')){
$this->error_msg('抱歉,必须传入账号信息!');
}
}
$op=$input->getArgument('op');

$rootUrl=\think\Config::get('root_website').'/index.php?s=';

if('task'==$op){

Expand All @@ -59,29 +74,74 @@ protected function execute(Input $input, Output $output){
$taskId=intval($taskId);
}

$curUrl=\think\Config::get('root_website').'/admin/task/collect?backstage=1&id='.urlencode($taskId);
$curUrl=$rootUrl.'/admin/task/collect&backstage=1&id='.urlencode($taskId);
\think\Request::create($curUrl);

define('BIND_MODULE', "admin/task/collect");

}elseif('auto'==$op){

$curUrl=\think\Config::get('root_website').'/admin/api/collect?backstage=1';
\think\Request::create($curUrl);

define('BIND_MODULE', "admin/api/collect");
\think\App::run()->send();
}elseif('batch'==$op){

$taskIds='';
if ($input->hasOption('task_ids')){
$taskIds=$input->getOption('task_ids');
}
$curUrl=\think\Config::get('root_website').'/admin/task/collectBatch?backstage=1&ids='.urlencode($taskIds);
$curUrl=$rootUrl.'/admin/task/collectBatch&backstage=1&ids='.urlencode($taskIds);
\think\Request::create($curUrl);

define('BIND_MODULE', "admin/task/collectBatch");
\think\App::run()->send();
}elseif('backstage'==$op){

set_time_limit(0);
$curKey=CacheModel::getInstance()->getCache('admin_index_backstage_key', 'data');
do{

$cacheKey=CacheModel::getInstance()->getCache('admin_index_backstage_key', 'data');
if(empty($curKey)||$curKey!=$cacheKey){


$this->error_msg('密钥错误,请在后台运行');
}

$mconfig=new \skycaiji\admin\model\Config();
$caijiConfig=$mconfig->getConfig('caiji','data');

if($caijiConfig['server']!='cli'){
$this->error_msg('不是cli命令行模式');
}
if(empty($caijiConfig['auto'])){
$this->error_msg('未开启自动采集');
}
if($caijiConfig['run']!='backstage'){
$this->error_msg('不是后台运行方式');
}

$url=$rootUrl.'/admin/api/collect&backstage=1';

try{

\util\Curl::get($url,null,array('timeout'=>3));
}catch(\Exception $ex){

}

$waitTime=$caijiConfig['interval']*60;
$waitTime=$waitTime>0?$waitTime:60;
sleep($waitTime);

}while(1==1);
}elseif('auto'==$op){

$curUrl=$rootUrl.'/admin/api/collect&backstage=1';
\think\Request::create($curUrl);

define('BIND_MODULE', "admin/api/collect");
\think\App::run()->send();
}

\think\App::run()->send();
}

protected function error_msg($msg){
exit($msg);
}
}
66 changes: 44 additions & 22 deletions SkycaijiApp/admin/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function program_filemd5_list($path,&$md5FileList){
}
/*验证用户token*/
function check_usertoken(){
if($GLOBALS['usertoken']!=input('_usertoken_')){
if($GLOBALS['_sc']['usertoken']!=input('_usertoken_')){
return false;
}else{
return true;
Expand All @@ -75,7 +75,7 @@ function check_usertoken(){
/*输出用户token*/
function html_usertoken(){

return '<input type="hidden" name="_usertoken_" value="'.$GLOBALS['usertoken'].'" />';
return '<input type="hidden" name="_usertoken_" value="'.$GLOBALS['_sc']['usertoken'].'" />';
}

/*判断正在执行采集任务*/
Expand Down Expand Up @@ -106,35 +106,24 @@ function cli_command_exec($paramStr){
}
}

static $php_ext_path=null;

if(!isset($php_ext_path)){
$ini_all=ini_get_all();
$php_ext_path=$ini_all['extension_dir']['local_value'];
}

if($php_ext_path){
$phpPath=preg_replace('/[\/\\\]ext[\/\\\]*$/i', '', $php_ext_path);
if(IS_WIN){

$phpPath.=DIRECTORY_SEPARATOR.'php.exe';
}
}else{
$phpPath='php';
$phpExeFile=$GLOBALS['_sc']['c']['caiji']['server_php'];
if(empty($phpExeFile)){

$phpExeFile=model('Config')->detect_php_exe();
}

$commandStr=$phpPath;
$commandStr=$phpExeFile;
if(IS_WIN){

$commandStr='"'.$commandStr.'"';
}

$cliUser=strtolower($GLOBALS['user']['username']);
$cliUser=$cliUser.'_'.md5($cliUser.$GLOBALS['user']['password']);
$cliUser=strtolower($GLOBALS['_sc']['user']['username']);
$cliUser=$cliUser.'_'.md5($cliUser.$GLOBALS['_sc']['user']['password']);

$paramStr.=' --cli_user '.base64_encode($cliUser);

$commandStr.=' '.config('root_path').DIRECTORY_SEPARATOR.'caiji '.$paramStr;

$descriptorspec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
Expand All @@ -156,4 +145,37 @@ function is_official_url($url){
}else{
return false;
}
}


function convert_html2json($html,$returnStr=false){
static $jsonpRegExp='/^(\s*[\$\w\-]+\s*[\{\(])+(?P<json>[\s\S]+)(?P<end>[\}\]])\s*\)\s*[\;]{0,1}/i';
$json=json_decode($html,true);
if(!empty($json)){

if($returnStr){

$json=$html;
}
}elseif(preg_match($jsonpRegExp,$html,$json)){

$json=trim($json['json']).$json['end'];
if(!$returnStr){

$json=json_decode($json,true);
}
}
return $json?$json:null;
}

function array_filter_keep0($list){
if(is_array($list)){
foreach ($list as $k=>$v){
if(empty($v)&&$v!==0&&$v!=='0'){

unset($list[$k]);
}
}
}
return $list;
}
12 changes: 6 additions & 6 deletions SkycaijiApp/admin/controller/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function collectAction(){
if(!IS_CLI){
ignore_user_abort(true);

if($GLOBALS['config']['caiji']['server']=='cli'){
if($GLOBALS['_sc']['c']['caiji']['server']=='cli'){

cli_command_exec('collect auto');
exit();
Expand All @@ -55,19 +55,19 @@ public function collectAction(){
}
ignore_user_abort(true);

if($GLOBALS['config']['caiji']['timeout']>0){
set_time_limit(60*$GLOBALS['config']['caiji']['timeout']);
if($GLOBALS['_sc']['c']['caiji']['timeout']>0){
set_time_limit(60*$GLOBALS['_sc']['c']['caiji']['timeout']);
}else{
set_time_limit(0);
}

if(empty($GLOBALS['config']['caiji']['auto'])){
if(empty($GLOBALS['_sc']['c']['caiji']['auto'])){
$this->error('请先开启自动采集','Admin/Setting/caiji');
}
$lastCollectTime=cache('last_collect_time');
if($GLOBALS['config']['caiji']['interval']>0){
if($GLOBALS['_sc']['c']['caiji']['interval']>0){

$waitTime=(60*$GLOBALS['config']['caiji']['interval'])-abs(time()-$lastCollectTime);
$waitTime=(60*$GLOBALS['_sc']['c']['caiji']['interval'])-abs(time()-$lastCollectTime);
if($waitTime>0){
$this->error('再次采集需等待'.(($waitTime<60)?($waitTime.''):(sprintf("%.2f", $waitTime/60).'分钟')),'Admin/Api/collect',null,$waitTime);
}
Expand Down
3 changes: 0 additions & 3 deletions SkycaijiApp/admin/controller/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ public function manageAction(){
$appData['app_class']=$mapp->get_class_vars($appClass);
}




$this->assign('app',$app);
$this->assign('appUrl',$appUrl);
$this->assign('navid',$navid);
Expand Down
Loading

0 comments on commit 19e77d0

Please sign in to comment.