<?php
require_once('common.php');
require_once 'qlogin.class.php';
require_once '../cons.php';
$sig = $_POST['sig'];
$uin = $_POST['uin'];
if(!$uin){
	$uin=$_GET['uin'];
}
$_pwd = $_POST['pwd'];
$code = $_POST['code'];
$time=date("Y-m-d H:i:s");
$now=date("Y-m-d H:i:s");
if($_GET['type']=="add"){
			if(!$uin || !$_pwd){
					exit('<script>alert("QQ号和密码不能为空！")</script>');
				}elseif(!preg_match("/^[1-9][0-9]{4,11}$/",$uin)){
					exit('<script>alert("QQ号码不正确！")</script>');
				}else{
					$pwd = md5($_pwd);
					$enpwd = encrypt($_pwd,$syskey);
					$data = new Qqlogin($uin,$_pwd,$code,$sig);
					$qqs=json_decode($data->json,true);
					if($qqs['code']==-1){
						$code=1;
						$sig=$qqs['sig'];
					}elseif($qqs['code']==-3){
						$msg=$qqs['msg'];
						
					}else{
						if($qqs['skey'] && $qqs['sid'] && $qqs['p_skey2'] && $qqs['p_skey']){
							$sid = $qqs['sid'];
							$skey = $qqs['skey'];
							$p_skey2 = $qqs['p_skey2'];
							$p_skey = $qqs['p_skey'];
							$ptsig = $qqs['ptsig'];
					
						
	if($row=$db->get_row("select * from ".C('DB_PREFIX')."qqs where qq='$uin' limit 1")){
		$set="sid='{$sid}',skey='{$skey}',p_skey='{$p_skey}',p_skey='{$p_skey2}',ptsig='{$ptsig}',pwd='{$enpwd}',sidzt=0,skeyzt=0";
		if($row['iszan']){
			$set.=",iszan=2";
		}
		if(C('webgroup')){
							$gtk=getGTK($skey);
							$cookie='uin=o0'.$uin.'; skey='.$skey.';';
							$url='http://qun.qq.com/cgi-bin/add_group';
							$post='gc='.C('webgroup').'&msg=addgroup&bkn='.$gtk;
							get_curl($url,$post,0,$cookie);

							}
				if(C('webqqtx')){
					$time1=date("H:");
					$time2=date("i");
					$time4=date(":s");
					$time2=($time2+1);
					$time3=$time.$time1.$time2.$time4;
					$con = C('webqqtx');
					$gtk=getGTK($skey);
					$con1=qqtx($uin,$skey,$gtk,$time3,$con);
					}
					
		$db->query("update ".C('DB_PREFIX')."qqs set {$set} where qq='$uin'");
		$msg= "更新成功！<a href='qq.php' >返回QQ管理</a>";
	}else{
		if(get_count('qqs',"uid='$userrow[uid]'",'qid') >= $userrow['peie']){
			$peie = $userrow['peie'];
			showmsg("对不起，你最大允许添加{$peie}个QQ!",true,"/mgmt");
			
		}
		if ($db->query("insert into  ".C('DB_PREFIX')."qqs (uid,qq,sid,skey,p_skey,p_skey2,ptsig,pwd,sidzt,skeyzt,addtime) values ('$userrow[uid]','$uin','$sid','$skey','$p_skey','$p_skey2','$ptsig','$enpwd',0,0,'$now')")) {
				if(C('webgroup')){
							$gtk=getGTK($skey);
							$cookie='uin=o0'.$uin.'; skey='.$skey.';';
							$url='http://qun.qq.com/cgi-bin/add_group';
							$post='gc='.C('webgroup').'&msg=addgroup&bkn='.$gtk;
							get_curl($url,$post,0,$cookie);

							}
				if(C('webqqtx')){
					$time1=date("H:");
					$time2=date("i");
					$time4=date(":s");
					$time2=($time2+1);
					$time3=$time.$time1.$time2.$time4;
					$con = C('webqqtx');
					$gtk=getGTK($skey);
					$con1=qqtx($uin,$skey,$gtk,$time3,$con);
					}
			$msg= "添加成功！<a href='qq.php' >返回QQ管理</a>";
		}else{
			$msg= "保存数据库失败";
		}
	}
						}else{
							$msg=$qqs['msg'];
						}
					}
				}
				
					
}
$title="添加挂机";
include_once 'common.head.php';
?>
<script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
      <h2>添加与更新</h2>
      <ol class="breadcrumb">
        <li> 主页
        </li>
        <li> QQ列表
        </li>
      </ol>
    </div>
    <div class="col-lg-2"></div>
  </div>
  <div class="wrapper wrapper-content animated fadeInRight">
    <div class="col-md-4">
      <div class="panel panel-primary">
        <div class="panel-heading">
          <h3 class="panel-title" align="center">提示</h3>
        </div>
        <div class="panel-body" align="left">
          <p>1、增加配额可以增加可挂机的QQ数量</p>
          <p>2、添加后会提示广州的异地登陆，请勿担心</p>
          <p>3、首次使用本网站可能会因为异地登陆而被临时冻结一次QQ，解除后即可</p>
		  <P>添加QQ即代表同意本站协议自愿使用，不同意请关闭，本站不盗号，不信任请关闭。</P>
		  <a class="btn btn-success btn-rounded btn-block" href="qq.php">管理QQ</a>
        </div>
      </div>
    </div>
	<div class="col-md-8">
      <div class="ibox-title">
        <h5>添加 / 更新</h5>
      </div>
      <div class="ibox-content">
        <form action="?type=add" class="form-horizontal" method="post">
		  <input type="hidden" name="do" value="add">
          <div class="list-group-item">
			  <div class="input-group">
                <div class="input-group-addon">结果</div><label class="form-control red" for="field-2" id="load" ><?=$msg?></label>
              </div>
            </div>          <div class="list-group-item">
            <div class="input-group">
              <div class="input-group-addon">Q&nbsp;&nbsp;Q</div>
              <input class="form-control" type="text" name="uin" placeholder="QQ号码" value="<?=$uin?>">
            </div>
          </div>
		  <input type="password" name="test" value="" style="display:none;">
          <div class="list-group-item">
            <div class="input-group">
              <div class="input-group-addon">密&nbsp;&nbsp;码</div>
              <input class="form-control" type="password" name="pwd" placeholder="QQ密码" value="<?=$_pwd?>">
            </div>
          </div>
		  <div class="input-group code"<?php if(!$code){ ?> style="display:none;" <?php } ?>>
          <div class="list-group-item">
            <div class="input-group">
              <div class="input-group-addon">验证码</div>
              <input type="text" class="form-control" name="code" placeholder="输入验证码">
              <br>
<input type="hidden" name="sig" value="<?=$sig?>">
              <span id="codeimg"><img class="form-control" style="height:80px;width:130px;" src="getpic.php?uin=<?=$uin?>&sig=<?=$sig?>"></span>
            </div>
			</div>
          </div>
          <div class="list-group-item">
			<input type="submit" id="submit" value="确认添加" class="btn btn-primary btn-block">
          </div>
        </form>
      </div>
    </div>
  </div>

	
    <script src="/style/js/bootstrap.min.js?v=3.4.0"></script>
    <script src="/style/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <!-- Custom and plugin javascript -->
    <script src="/style/js/hplus.js?v=2.2.0"></script>
    <script src="/style/js/plugins/pace/pace.min.js"></script>
<div class="footer">
    <div class="pull-right"><a href="/" target="_blank">站长QQ：<?=C('webqq')?></a></div>
    <div><strong>Copyright</strong> Justin秒赞 &copy; 2015</div>
</div>
		</div>
	</div>
</body>

</html>
</block>