<?php
if(!defined('IN_CRONLITE'))exit();

$act=isset($_GET['act'])?$_GET['act']:null;

if($islogin==1)
{
if($conf['active']!=0)phone_check();
switch($act) {

case 'add':
	$qq=isset($_GET['qq'])?daddslashes($_GET['qq']):daddslashes($_POST['qq']);
	$qpwd=isset($_GET['qpwd'])?daddslashes($_GET['qpwd']):daddslashes($_POST['qpwd']);
	$qsid=isset($_GET['qsid'])?daddslashes($_GET['qsid']):daddslashes($_POST['qsid']);
	$skey=isset($_GET['skey'])?daddslashes($_GET['skey']):daddslashes($_POST['skey']);
	$pskey=isset($_GET['pskey'])?daddslashes($_GET['pskey']):daddslashes($_POST['pskey']);
	$superkey=isset($_GET['superkey'])?daddslashes($_GET['superkey']):daddslashes($_POST['superkey']);
	$qpwd=!empty($qpwd)?authcode($qpwd,'ENCODE',SYS_KEY):null;
	if($qq==""||$skey==""||$pskey==""){
		exit('{"code":-1,"msg":"参数不能为空！"}');
	}
	$rowm1=$DB->get_row("SELECT * FROM ".DBQZ."_qq WHERE qq='{$qq}' limit 1");
	if($rowm1['qq']==''){}else{
		qqtx($qq,$skey);
		if($rowm1['uid']!=$uid && $isadmin!=1) {
			$sqls=",uid='$uid'";
			$DB->query("UPDATE ".DBQZ."_qqjob SET uid='$uid' WHERE qq='$qq'");
		}
		if($rowm1['qqlevel'] && $_POST['qpwd']){
			get_curl($dgapi.'api/submit.php?act=update&id='.$rowm1['qqlevel'].'&qq='.$qq.'&pwd='.urlencode(authcode($_POST['qpwd'],'ENCODE','CLOUDKEY')));
		}
		if(!$_POST['qpwd'])$qpwd=$rowm1['pw'];
		$sql="update `".DBQZ."_qq` set `pw` ='$qpwd',`sid` ='$qsid',`skey` ='$skey',`pskey` ='$pskey',`superkey` ='$superkey',`status` ='1',`status2` ='1',`time`='$date'{$sqls} where `qq`='$qq'";
		$sds=$DB->query($sql);
		$DB->query("UPDATE ".DBQZ."_qqjob SET fail='0' WHERE qq='$qq'");
		if($sds)exit('{"code":1,"msg":"QQ状态更新成功！"}');
		else exit('{"code":0,"msg":"QQ状态更新失败！"}');
	}
	if(in_array($qq,explode("|",$conf['qqblock']))){
		exit('{"code":0,"msg":"您所添加的QQ不在系统允许范围内，请联系网站管理员！"}');
	}
	$gls=$DB->count("SELECT count(*) from ".DBQZ."_qq WHERE uid='{$uid}'");
	if($conf['peie_open']==1){
		if($gls>=$row['peie']) {
			exit('{"code":0,"msg":"您添加的QQ数量已超过你的配额，无法继续添加！请购买配额。"}');
		}
	}else{
		if($gls>=$conf['qqlimit'] && $isadmin!=1 && $isvip==0 && $conf['qqlimit']!=0){
			exit('{"code":0,"msg":"您添加的QQ数量已超过系统最大限制('.$conf['qqlimit'].'个)，无法继续添加！<br/>开通VIP后将解除这个限制。"}');
		}
		if($gls>=$conf['qqlimit2'] && $isadmin!=1 && $conf['qqlimit2']!=0){
			exit('{"code":0,"msg":"您添加的QQ数量已超过系统最大限制('.$conf['qqlimit'].'个)，无法继续添加！"}');
		}
	}
	if(!checksid($qq,$skey,$pskey)){
		exit('{"code":0,"msg":"添加失败。SKEY无效，请再试！"}');
	}
	if(!$conf['qqtx'])$conf['qqtx']='您的QQ已成功在 '.$conf['sitename'].' 添加，感谢您的使用！';
		qqtx($qq,$skey,$conf['qqtx']);
	if($conf['addbuluo']){
		include_once ROOT.'qq/qqsign.class.php';
		$qzone=new qqsign($qq,$sid,$skey);
		$qzone->addbuluo($superkey,$conf['addbuluo']);
	}
	if($conf['qzlike']){
		$qzlikes=explode('|',$conf['qzlike']);
		foreach($qzlikes as $qzlike){
			$gtk=getGTK($pskey);
			$cookie='pt2gguin=o0'.$qq.'; uin=o0'.$qq.'; skey='.$skey.'; p_skey='.$pskey.'; p_uin=o0'.$qq.';';
			$ua='Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36';
			$url='https://h5.qzone.qq.com/proxy/domain/w.qzone.qq.com/cgi-bin/likes/doLike?g_tk='.$gtk;
			$post='qzreferrer=https%3A%2F%2Fuser.qzone.qq.com%2F'.$qzlike.'&url=https%3A%2F%2Fuser.qzone.qq.com%2F'.$qzlike.'&cid='.$gtk.'&from=brand&format=json&scene=5&fupdate=1';
			get_curl($url,$post,'https://user.qzone.qq.com/'.$qzlike,$cookie,0,$ua);
		}
	}
	if($conf['addfriend']){
		include_once ROOT.'qq/qzone.class.php';
		$qzone=new qzone($qq,$sid,$skey,$pskey);
		$qzone->addfriend($conf['addfriend']);
	}
	$sql = "INSERT INTO `".DBQZ."_qq`(`uid`,`qq`,`pw`,`sid`,`skey`,`pskey`,`superkey`,`status`,`status2`,`time`) VALUES ('{$uid}','{$qq}','{$qpwd}','{$qsid}','{$skey}','{$pskey}','{$superkey}','1','1','{$date}')";
	$sds=$DB->query($sql);
	if($sds){
		$data='a:1:{s:6:"forbid";s:0:"";}';
		if($conf['addzan'])
			$DB->query("insert into `".DBQZ."_qqjob` (`uid`,`qq`,`type`,`sign`,`method`,`data`,`lasttime`,`nexttime`,`pl`,`start`,`stop`,`sysid`) values ('{$uid}','{$qq}','zan','0','3','{$data}','".time()."','".time()."','0','0','24','1')");
		exit('{"code":1,"msg":"QQ账号已成功添加！"}');
	}else exit('{"code":0,"msg":"QQ账号添加失败！'.$DB->error().'"}');
break;

case 'uppwd':
	$qq=daddslashes($_GET['qq']);
	$qpwd=trim(daddslashes($_GET['qpwd']));
	$row=$DB->get_row("SELECT * FROM ".DBQZ."_qq WHERE qq='{$qq}' limit 1");
	if($row['uid']!=$uid && $isadmin==0 && $isdeputy==0) {
		exit('{"code":0,"msg":"你只能操作自己的QQ哦！"}');
	}
	if($row['qqlevel'])
		get_curl($dgapi.'api/submit.php?act=update&id='.$row['qqlevel'].'&qq='.$qq.'&pwd='.urlencode(authcode($qpwd,'ENCODE','CLOUDKEY')));
	$qpwd=authcode($qpwd,'ENCODE',SYS_KEY);
	if($DB->query("update `".DBQZ."_qq` set `pw` ='{$qpwd}' where `qq`='$qq'"))
		exit('{"code":1,"msg":"QQ '.$qq.' 更新密码成功！"}');
	else
		exit('{"code":0,"msg":"QQ '.$qq.' 更新密码失败！'.$DB->error().'"}');
break;

case 'del':
	$qq=daddslashes($_GET['qq']);
	$row=$DB->get_row("SELECT * FROM ".DBQZ."_qq WHERE qq='{$qq}' limit 1");
	if($row['uid']!=$uid && $isadmin==0 && $isdeputy==0) {
		exit('{"code":0,"msg":"你只能操作自己的QQ哦！"}');
	}
	if($row['qqlevel'])
		get_curl($dgapi.'api/submit.php?act=close&id='.$row['qqlevel'].'&uin='.$qq.'&url='.$_SERVER['HTTP_HOST'].'&authcode='.$authcode);
	$sql="DELETE FROM ".DBQZ."_qq WHERE qq='$qq'";
	$sql2="DELETE FROM ".DBQZ."_qqjob WHERE qq='$qq'";
	if($DB->query($sql) && $DB->query($sql2))
		exit('{"code":1,"msg":"QQ '.$qq.' 已成功删除！"}');
	else
		exit('{"code":0,"msg":"QQ '.$qq.' 删除失败！"}');
break;

case 'update':
$qq=daddslashes($_GET['qq']);
$row=$DB->get_row("SELECT * FROM ".DBQZ."_qq WHERE qq='{$qq}' limit 1");
if($row['uid']!=$uid && $isadmin==0) {
	showmsg('你只能操作自己的QQ哦！');
}
$qpwd=authcode($row['pw'],'DECODE',SYS_KEY);

?>
<script>
var siteurl='<?php echo $qqlogin ?>';
</script>
<script src="qq/getsid/login.js?v=<?php echo VERSION ?>"></script>
<script src="qq/getsid/getsid.js?v=<?php echo VERSION ?>"></script>
<div class="col-md-6 col-sm-12 center-block">
<div class="widget">
	<div class="widget-content themed-background text-light-op">
		<span class="break"></span>&nbsp;<strong>更新QQ身份识别码</strong>
	</div>
	<div class="widget-content block full">
	<div class="block-title">
		<ul class="nav nav-tabs" data-toggle="tabs">
			<li class="active"><a href="#">帐号密码登录</a></li>
			<li><a href="#" onclick="addqq('qrlogin')">扫描二维码登录</a></li>
		</ul>
	</div>
<div id="load" class="alert alert-info">正在登录，请稍候...</div>
<div id="login" style="display:none;">
<div class="form-group">
<label>QQ帐号:</label><br/>
<input type="text" id="uin" value="<?php echo $qq ?>" class="form-control" disabled/>
</div>
<div class="form-group">
<label>QQ密码:</label><br/>
<input type="text" id="pwd" value="<?php echo $qpwd ?>" class="form-control" onkeydown="if(event.keyCode==13){submit.click()}"/>
</div>
</div>
<script>
checkvc();</script>
<div class="form-group code" style="display:none;">
<label>输入验证码:</label>
<div id="codeimg"></div>
<input type="text" id="code" class="form-control" onkeydown="if(event.keyCode==13){submit.click()}">
<br/>
</div>
<br/><button type="button" id="submit" class="btn btn-primary btn-block">确定</button>
<br/><a href="#" onclick="showlist('qqlist')">返回QQ挂机列表</a>
</div>
</div>
</div>
<?php

break;

case 'dama':
	$qq=daddslashes($_GET['qq']);
	$row=$DB->get_row("SELECT * FROM ".DBQZ."_qq WHERE qq='{$qq}' limit 1");
	if($row['status']!=4 && $row['status2']!=4) {
		showmsg('此QQ不在待打码列表！');
	}
?>
<!--
　
　
　
　
　　　　　　　　　　　　　　　　　　　　　　　　　　　　友情提醒
　
　　　　　　　　　　　　　　　　　　　　　　　　　 易Q网开发，版权所有
　
　　　　　　　　　　　　　　　　　　　　　　　　　盗代码，盗内容，Si全家
　　　　　　　　　　　　　　　　　　　　　　　　　
　　　　　　　　　　　　　　　　　　　　　　QQ:2222888891 站长吹水群:948388484
　　　　　　　　　　　　　　　　　　　　　　
　　　　　　　　　　　　　　　　　　　　　　   官网 https://www.isqq8.com
　
　
　

　
-->
<script src="qq/getsid/getsid2.js?v=<?php echo VERSION ?>"></script>
<div class="col-md-6 col-sm-12 center-block">
<div class="widget">
	<div class="widget-content themed-background text-light-op">
		<i class="fa fa-indent red"></i><span class="break"></span>&nbsp;<strong>协助更新QQ身份识别码</strong>
	</div>
	<div class="panel-body">
<div id="load" class="alert alert-info"></div>
<div id="login" style="display:none;">
<input type="text" id="uin" value="<?php echo $row['qq'] ?>"/>
</div>
<script>
checkvc();</script>
<div class="form-group code" style="display:none;">
<label>输入验证码:</label>
<div id="codeimg"></div>
<input type="text" id="code" class="form-control" onkeydown="if(event.keyCode==13){submit.click()}">
<br/>
</div>
<br/><button type="button" id="submit" class="btn btn-primary btn-block">确定</button>
<br/><a href="#" onclick="showlist('damalist')">返回待打码QQ列表</a>
</div>
</div>
</div>
<?php

break;

case 'login':
$qq=$_GET['qq']?$_GET['qq']:null;

?>
<script>
var siteurl='<?php echo $qqlogin ?>';
</script>
<script src="qq/getsid/login.js?v=<?php echo VERSION ?>"></script>
<script src="qq/getsid/getsid.js?v=<?php echo VERSION ?>"></script>
<div class="col-lg-8 col-md-12 col-lg-offset-2"> <div class="panel panel-default text-center"> <div class="list-group"> <div class="list-group-item bg-dark" style="background-color:#1c2b36;">
<div class="clear">使用提示</div>
</div>
<div class="list-group-item">1、首次使用可能会因为异地登陆而被TX临时冻结帐号，解除冻结后再添加一次即可。</div>
<div class="list-group-item">2、异地登录后可能提示被盗号的提醒，属于安全误报请勿担心，改密后既不会再提醒。</div>
<div class="list-group-item">3、使用前可绑定QQ安全中APP，将异地登陆确认为本人操作，可避免账号被再次冻结。</div> </div> </div>
<div id="bodys">
<div class="widget">
<div class="widget-content themed-background text-light-op">添加/更新QQ  <button class="btn btn-danger btn-xs pull-right" onclick="addqq('qrlogin') ;">切换到扫码添加</button> </div>
<div class="list-group-item text-bold text-danger">注：如遇到误报密码错误问题，可使用扫码添加</div>
<div id="login" class="list-group-item">
<div class="form-group">
<div class="input-group"><div class="input-group-addon">QQ帐号</div>
<input type="text" id="uin" value="<?php echo $qq ?>" class="form-control" onkeydown="if(event.keyCode==13){submit.click()}"/>
</div></div>
<div class="form-group">
<div class="input-group"><div class="input-group-addon">QQ密码</div>
<input type="text" id="pwd" value="" class="form-control" onkeydown="if(event.keyCode==13){submit.click()}"/>
</div></div>
<div id="load" class="alert alert-info" style="font-weight:bold;display:none;"></div>
<div class="form-group code" style="display:none;">
<div id="codeimg"></div>
<div class="input-group"><div class="input-group-addon">验证码</div>
<input type="text" id="code" class="form-control" onkeydown="if(event.keyCode==13){submit.click()}" placeholder="输入验证码">
</div>
</div>
<br/><button type="button" id="submit" class="btn btn-primary btn-block">确认添加</button>
<br/><a href="#" onclick="showlist('qqlist')">返回QQ挂机列表</a>
</div>
</div>
</div>
</div>
<?php

break;

case 'qrlogin':
$qq=$_GET['qq']?$_GET['qq']:null;

?>
<script>
var siteurl='<?php echo $qqlogin ?>';
</script>
<script src="qq/getsid/qrlogin.js?v=<?php echo VERSION ?>"></script>
<div class="col-lg-8 col-md-12 col-lg-offset-2"> <div class="panel panel-default text-center"> <div class="list-group"> <div class="list-group-item bg-dark" style="background-color:#1c2b36;">
<div class="clear">使用提示</div>
</div>
<div class="list-group-item">1、使用扫码添加QQ的无法自动更新SID和SKEY！</div>
<div class="list-group-item">2、因服务器所在地不是你的QQ常用登录地，首次使用可能会因为异地登录而冻结或风险提示！</div>
<div class="list-group-item">3、改密码即可解除，添加QQ前请设置好密保<?php echo $conf['serverlocal']?'。当前服务器所在地：'.$conf['serverlocal']:null;?></div>
<div class="list-group-item">4、如果QQ开启了网页登录保护，需要关闭才能添加。用QQ安全中心扫码添加不会被拉入保护模式</div> </div> </div>
<div id="bodys">
<div class="widget">
	<div class="widget-content themed-background text-light-op">
		<center><span class="break"></span>&nbsp;<strong>扫码添加QQ</strong>
	</div>
	<div class="widget-content block full" style="text-align: center;">
		<div class="list-group">
			<div class="list-group-item list-group-item-info" style="font-weight: bold;" id="login">
				<span id="loginmsg">使用QQ手机版扫描二维码</span><span id="loginload" style="padding-left: 10px;color: #790909;">.</span>
			</div>
			<div class="list-group-item" id="qrimg">
			</div>
			<div class="list-group-item" id="mobile" style="display:none;"><button type="button" id="mlogin" onclick="mloginurl()" class="btn btn-warning btn-block">跳转QQ快捷登录</button><br/><button type="button" onclick="loadScript()" class="btn btn-success btn-block">我已完成登录</button></div>
		</div>
</div>
</div>
</div>
<?php

break;

}
}else{
	showmsg('登录失败，可能是密码错误或者身份失效了，请<a href="index.php?mod=login">重新登录</a>！',3);
}