Best Atoum code snippet using dateInterval
cron_reports.php
Source:cron_reports.php
1<?php2set_time_limit(0);3if($argc < 2){4 echo 'param error';5 exit;6}7$dateinterval = $argv[1];8$type = $argv[2];9$start = $argv[3];10$end = $argv[4];11$diy_id = $argv[5];12//var_dump($argv);13$host = "localhost";14$username = "freesvr";15$pwd = "freesvr";16$dbname = "audit_sec";17mysql_connect($host, $username, $pwd) or die(mysql_error());18mysql_select_db($dbname) or die(mysql_error());19mysql_query("set names utf8") or die(mysql_error());20switch($dateinterval){21 case 'month': 22 $start = (empty($argv[3]) ? date('Y-m-d') : $argv[3]);23 $ymd = explode('-', $start);24 $start = date('Y-m-d 00:00:00', mktime(0, 0, 0, $ymd[1]-1, 1, $ymd[0]));25 $end = date('Y-m-d 23:59:59', mktime(0, 0, 0, $ymd[1], 0, $ymd[0]));26 break;27 case 'day':28 $start = empty($start) ? date('Y-m-d', mktime(0,0,1, date('m'), date('d')-1, date('Y'))) : $start;29 $end = $start.' 23:59:59';30 $start = $start.' 00:00:00';31 break;32 case 'week':33 $start = (empty($argv[3]) ? date('Y-m-d') : $argv[3]);34 $ymd = explode('-', $start);35 $start = date('Y-m-d 00:00:00', mktime(0, 0, 0, $ymd[1], $ymd[2]-date('w')-7+1, $ymd[0]));36 $end = date('Y-m-d 23:59:59', mktime(0, 0, 0, $ymd[1], $ymd[2]-date('w'), $ymd[0]));37 break;38 case 'diy':39 $start = empty($start) ? date('Y-m-d') : $start;40 $start = $argv[3];41 $start = $start.' 00:00:00';42 $end = $end.' 23:59:59';43 $diyinfo = mysql_query("SELECT * FROM report_diy WHERE sid='".$diy_id."'");44 $diyinfo = mysql_fetch_array($diyinfo);45 //var_dump($diyinfo);46 $diy_ugroupid = $diyinfo['ugroupid'];47 $diy_sgroupid = $diyinfo['sgroupid'];48 $diy_username = $diyinfo['username'];49 $diy_server = $diyinfo['server'];50 if(empty($diy_ugroupid)){51 if($diy_ldapid2_u){52 $diy_ugroupid = $diy_ldapid2_u;53 }else if($diy_ldapid1_u){54 $diy_ugroupid = $diy_ldapid1_u;55 }56 }57 if(empty($diy_sgroupid)){58 if($ldapid2){59 $diy_sgroupid = $diy_ldapid2;60 }else if($diy_ldapid1){61 $diy_sgroupid = $diy_ldapid1;62 }63 }64 $diy_alltmpusername = array(-1);65 if(empty($diy_username)){66 $allusers = mysql_query("SELECT uid,username FROM member WHERE groupid=".$diy_ugroupid." or groupid IN(SELECT id FROM servergroup WHERE ldapid=".$diy_ugroupid.") or groupid IN(SELECT id FROM servergroup WHERE ldapid IN(SELECT id FROM servergroup WHERE ldapid=".$diy_ugroupid."))");67 while($row = mysql_fetch_array($allusers)){68 $diy_alltmpusername[]=$row['uid'];69 }70 }71 $diy_alltmpip = array(-1);72 if(empty($diy_server)){ 73 $allips = mysql_query("SELECT device_ip FROM servers WHERE groupid=".$diy_ugroupid." or groupid IN(SELECT id FROM servergroup WHERE ldapid=".$diy_ugroupid.") or groupid IN(SELECT id FROM servergroup WHERE ldapid IN(SELECT id FROM servergroup WHERE ldapid=".$diy_ugroupid."))");74 while($row = mysql_fetch_array($allips)){75 $diy_alltmpip[]=$row['device_ip'];76 }77 }78 break;79 default:80 break;81}82//ȨÏÞ±¨±í83echo ${'sql_admin_log_statistic_'.$dateinterval} = "INSERT INTO admin_log_".$dateinterval."(luser,action,resource,resource_user,optime,administrator,result,realname,groupname".($dateinterval=='diy' ? ',createid' : '').") SELECT a.luser,a.action,a.resource,a.resource_user,a.optime,a.administrator,a.result,b.realname,c.groupname".($dateinterval=='diy' ? ','.$diy_id : '')." FROM admin_log a LEFT JOIN member b ON a.luser=b.username LEFT JOIN servergroup c ON b.groupid=c.id WHERE 1=1 AND optime >='$start' AND optime <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND b.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND b.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND a.resource="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND a.resource IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." ORDER BY optime desc ";84echo ";\n\n";85echo ${'sql_accountrecord_statistic_'.$dateinterval} = "INSERT INTO account_record_".$dateinterval."(date,ip,user,uid,gid,home,shell,action".($dateinterval=='diy' ? ',createid' : '').") SELECT date,ip,user,uid,gid,home,shell,action".($dateinterval=='diy' ? ','.$diy_id : '')." FROM account_record WHERE 1=1 AND date >='$start' AND date <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND user="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND ip="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND ip IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." ORDER BY date desc ";86echo ";\n\n";87//µÇ¼±¨±í88echo ${'sql_login_statistic_'.$dateinterval} = "INSERT INTO logintimes_".$dateinterval."(username,realname,groupname,sct,tct,rct,act,vct,fct,sfct,webct,xct,ct,start,serverip".($dateinterval=='diy' ? ',createid' : '').") select IFNULL(m.username,'') username,IFNULL(m.realname,'') realname,ug.groupname,IFNULL(s.sct,0) sct,IFNULL(t.tct,0) tct, IFNULL(r.rct,0) rct,IFNULL(a.act,0) act, IFNULL(f.fct,0) fct, IFNULL(sf.sfct,0) sfct, IFNULL(web.webct,0) webct,IFNULL(v.vct,0) vct,IFNULL(x.xct,0) xct,(IFNULL(s.sct,0)+IFNULL(a.act,0)+IFNULL(t.tct,0)+IFNULL(r.rct,0)+IFNULL(f.fct,0)+IFNULL(sf.sfct,0)+IFNULL(web.webct,0)+IFNULL(v.vct,0)+IFNULL(x.xct,0)) as ct,'$start' start,m.device_ip".($dateinterval=='diy' ? ','.$diy_id : '')." from (select member.username,member.realname,member.groupid,servers.device_ip from member join servers WHERE 1 ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND member.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND member.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND servers.device_ip="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND servers.device_ip IN("'.implode('","', $diy_alltmpip).'")' : '')) : '').") m left join (select count(*) sct,luser,start,addr from sessions where start >= '$start' AND end <= '$end' AND type='ssh' AND 1 group by addr,luser) s on m.username=s.luser and m.device_ip=s.addr left join (select count(*) tct,luser,start,addr from sessions where start >= '$start' AND end <= '$end' AND type='telnet' AND 1 group by addr,luser) t on m.username=t.luser and m.device_ip=t.addr left join (select count(*) rct,luser,start,addr from rdpsessions where start >= '$start' AND end <= '$end' AND (LOGIN_TEMPLATE=8 ) AND 1 group by addr,luser) r on m.username=r.luser and m.device_ip=r.addr left join (select count(*) act,luser,start,addr from rdpsessions where start >= '$start' AND end <= '$end' AND (LOGIN_TEMPLATE=26) AND 1 group by addr,luser) a on m.username=a.luser and m.device_ip=a.addr left join (select count(*) vct,luser,start,addr from rdpsessions where start >= '$start' AND end <= '$end' AND (LOGIN_TEMPLATE=21) AND 1 group by addr,luser) v on m.username=v.luser and m.device_ip=v.addr left join (select count(*) xct,luser,start,addr from rdpsessions where start >= '$start' AND end <= '$end' AND (LOGIN_TEMPLATE=22) AND 1 group by addr,luser) x on m.username=x.luser and m.device_ip=x.addr left join (select count(*) fct,radius_user,start,svraddr from ftpsessions where start >= '$start' AND end <= '$end' AND 1 group by svraddr,radius_user) f on m.username=f.radius_user and m.device_ip=f.svraddr left join (select count(*) sfct,radius_user,start,svraddr from sftpsessions where start >= '$start' AND end <= '$end' AND 1 group by svraddr,radius_user) sf on m.username=sf.radius_user and m.device_ip=sf.svraddr left join (select count(*) webct,audituser,time,serverip from loginacct where time >= '$start' AND time <= '$end' and portocol='web' AND 1 group by serverip,audituser) web on m.username=web.audituser and m.device_ip=web.serverip LEFT JOIN servergroup ug ON m.groupid=ug.id WHERE 1 ORDER BY ct DESC ";89echo ";\n\n";90echo ${'sql_loginacct_statistic_'.$dateinterval} = "INSERT INTO loginacct_".$dateinterval."(pid,time,sourceip,auditip,serverip,portocol,audituser,systemuser,authenticationstatus,failreason,realname,groupname".($dateinterval=='diy' ? ',createid' : '').") SELECT a.pid,a.time,a.sourceip,a.auditip,a.serverip,a.portocol,a.audituser,a.systemuser,a.authenticationstatus,a.failreason,m.realname,ug.groupname".($dateinterval=='diy' ? ','.$diy_id : '')." FROM loginacct a LEFT JOIN member m ON a.audituser=m.username LEFT JOIN servergroup ug ON ug.id=m.groupid WHERE 1=1 AND `time` >='$start' AND `time` <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND a.serverip="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND a.serverip IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." ORDER BY time desc ";91echo ";\n\n";92echo ${'sql_loginfailed_statistic_'.$dateinterval} = "INSERT INTO loginfailed_".$dateinterval."(ct,serverip,sourceip,audituser,portocol,time".($dateinterval=='diy' ? ',createid' : '').") SELECT count(*) ct,serverip,a.sourceip,audituser,portocol,time".($dateinterval=='diy' ? ','.$diy_id : '')." FROM loginacct a left join member m on a.audituser=m.uid WHERE authenticationstatus=0 AND `time` >='$start' AND `time` <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND a.serverip="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND a.serverip IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." GROUP BY serverip,a.sourceip,audituser,portocol ORDER BY ct desc ";93echo ";\n\n";94echo ${'sql_devlogin_statistic_'.$dateinterval} = "INSERT INTO devlogin_".$dateinterval."(luser,realname,groupname,device_ip,hostname,type,user,mstart,mend,ct".($dateinterval=='diy' ? ',createid' : '').") SELECT luser,realname,ug.groupname,t.device_ip,hostname,type,user,mstart,mend,ct".($dateinterval=='diy' ? ','.$diy_id : '')." FROM (SELECT a.luser,m.realname,m.groupid,a.type,a.user,if(locate(':',addr)=0, addr,left(addr, locate(':',addr)-1)) device_ip, MIN(start) mstart, MAX(start) mend,IFNULL(COUNT(*),0) ct FROM sessions a LEFT JOIN (SELECT COUNT(*) ct,sid FROM commands GROUP BY sid) bb ON bb.sid=a.sid LEFT JOIN member m ON a.luser=m.username WHERE 1=1 AND start >='$start' AND start <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND if(locate(":",addr)=0, addr,left(addr, locate(":",addr)-1))="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND if(locate(":",addr)=0, addr,left(addr, locate(":",addr)-1)) IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." GROUP BY if(locate(':',addr)<0, addr,left(addr, locate(':',addr)-1)),user,luser,type UNION SELECT a1.luser,m.realname,m.groupid,a1.type,a1.user,if(locate(':',addr)=0, addr,left(addr, locate(':',addr)-1)) device_ip, MIN(start) mstart, MAX(start) mend,IFNULL(COUNT(*),0) ct FROM rdpsessions a1 LEFT JOIN (SELECT COUNT(*) ct,sid FROM rdpinput GROUP BY sid) bb1 ON bb1.sid=a1.sid LEFT JOIN member m ON a1.luser=m.username WHERE 1=1 AND start >='$start' AND start <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND if(locate(":",addr)=0, addr,left(addr, locate(":",addr)-1))="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND if(locate(":",addr)=0, addr,left(addr, locate(":",addr)-1)) IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." GROUP BY if(locate(':',addr)<0, addr,left(addr, locate(':',addr)-1)),user,luser,type UNION SELECT a2.radius_user luser,m.realname,m.groupid,'sftp' type,a2.sftp_user user,if(locate(':',svraddr)=0, svraddr,left(svraddr, locate(':',svraddr)-1)) device_ip, MIN(start) mstart, MAX(start) mend,IFNULL(COUNT(*),0) ct FROM sftpsessions a2 LEFT JOIN (SELECT COUNT(*) ct,sid FROM sftpcomm GROUP BY sid) bb2 ON bb2.sid=a2.sid LEFT JOIN member m ON a2.radius_user=m.username WHERE 1=1 AND start >='$start' AND start <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND if(locate(":",svraddr)=0, svraddr,left(svraddr, locate(":",svraddr)-1))="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND if(locate(":",svraddr)=0, svraddr,left(svraddr, locate(":",svraddr)-1)) IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." GROUP BY if(locate(':',svraddr)<0, svraddr,left(svraddr, locate(':',svraddr)-1)),sftp_user,radius_user UNION SELECT a3.radius_user luser,m.realname,m.groupid,'ftp' type,a3.ftp_user user,if(locate(':',svraddr)=0, svraddr,left(svraddr, locate(':',svraddr)-1)) device_ip, MIN(start) mstart, MAX(start) mend,IFNULL(COUNT(*),0) ct FROM ftpsessions a3 LEFT JOIN (SELECT COUNT(*) ct,sid FROM ftpcomm GROUP BY sid) bb3 ON bb3.sid=a3.sid LEFT JOIN member m ON a3.radius_user=m.username WHERE 1=1 AND start >='$start' AND start <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND if(locate(":",svraddr)=0, svraddr,left(svraddr, locate(":",svraddr)-1))="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND if(locate(":",svraddr)=0, svraddr,left(svraddr, locate(":",svraddr)-1)) IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." GROUP BY if(locate(':',svraddr)<0, svraddr,left(svraddr, locate(':',svraddr)-1)),ftp_user,radius_user ) t LEFT JOIN servers s ON t.device_ip=s.device_ip LEFT JOIN servergroup ug ON t.groupid=ug.id WHERE 1 ORDER BY ct desc ";95echo ";\n\n";96echo ${'sql_applogin_statistic_'.$dateinterval} = "INSERT INTO applogin_".$dateinterval."(user,realname,groupname,serverip,appname,apppath,url,mstart,mend,ct".($dateinterval=='diy' ? ',createid' : '').") SELECT b.username user,b.realname,ug.groupname,serverip,a.appname,a.apppath,c.url, MIN(start) mstart, MAX(start) mend,count(*)".($dateinterval=='diy' ? ','.$diy_id : '')." FROM appcomm a LEFT JOIN member b ON a.memberid=b.uid LEFT JOIN apppub c ON a.serverip=c.appserverip and a.appname=c.name LEFT JOIN servergroup ug ON b.groupid=ug.id WHERE 1=1 AND start >='$start' AND start <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND b.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND b.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND serverip="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND serverip IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." GROUP BY serverip,appname,memberid ORDER BY count(*) desc ";97echo ";\n\n";98echo ${'sql_loginapproved_statistic_'.$dateinterval} = "INSERT INTO loginapproved_".$dateinterval."(webuser,realname,groupname,ip,username,login_method,applytime,approvetime,approveuser,logintime".($dateinterval=='diy' ? ',createid' : '').") SELECT m.username,m.realname,ug.groupname,login4approve.ip,login4approve.username,login4approve.login_method,login4approve.applytime,login4approve.approvetime,login4approve.approveuser,login4approve.logintime".($dateinterval=='diy' ? ','.$diy_id : '')." FROM login4approve LEFT JOIN member m ON login4approve.webuser=m.username LEFT JOIN servergroup ug ON m.groupid=ug.id WHERE approved = 2 AND logintime >='$start' AND logintime <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND login4approve.ip="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND login4approve.ip IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." ORDER BY logintime DESC ";99echo ";\n\n";100//²Ù×÷±¨±í101echo ${'sql_command_statistic_'.$dateinterval} = "INSERT INTO commandstatistic_".$dateinterval."(addr,luser,realname,groupname,user,mstart,mend,ct".($dateinterval=='diy' ? ',createid' : '').") SELECT a.addr, a.luser, m.realname,ug.groupname, a.user, MIN(start), MAX(start),SUM(bb.ct)".($dateinterval=='diy' ? ','.$diy_id : '')." FROM sessions a LEFT JOIN (SELECT COUNT(*) ct,sid FROM commands WHERE 1 GROUP BY sid) bb ON bb.sid=a.sid LEFT JOIN member m ON a.luser=m.username LEFT JOIN servergroup ug ON m.groupid=ug.id WHERE 1=1 AND start >='$start' AND start <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND addr="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND addr IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." GROUP BY addr,user,luser ORDER BY ct desc ";102echo ";\n\n";103echo ${'sql_cmdcache_statistic_'.$dateinterval} = "INSERT INTO cmdcache_".$dateinterval."(luser,realname,groupname,user,addr,ocmd,ct,at".($dateinterval=='diy' ? ',createid' : '').") SELECT a.luser,d.realname,ug.groupname,a.user,a.addr,b.cmd ocmd,COUNT(*) ct,b.at".($dateinterval=='diy' ? ','.$diy_id : '')." FROM (SELECt * FROM sessions WHERE start >='$start' AND start <='$end' ) a LEFT JOIN (SELECT * FROM commands WHERE at >='$start' AND at <='$end') b ON a.sid=b.sid LEFT JOIN cmdcache c ON lower(left(b.cmd, length(c.cmd)+1))=concat(lower(c.cmd), ' ') LEFT JOIN member d ON a.luser=d.username LEFT JOIN servergroup ug ON d.groupid=ug.id WHERE b.cid IS NOT NULL AND c.id IS NOT NULL ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND d.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND d.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND a.addr="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND a.addr IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." GROUP BY a.addr,a.luser,a.user, c.cmd ";104echo ";\n\n";105echo ${'sql_cmdlist_statistic_'.$dateinterval} = "INSERT INTO cmdlist_".$dateinterval."(luser,realname,groupname,addr,cmd,at,dangerlevel".($dateinterval=='diy' ? ',createid' : '').") SELECT b.luser,m.realname,ug.groupname,b.addr,a.cmd,a.at,dangerlevel".($dateinterval=='diy' ? ','.$diy_id : '')." FROM commands a LEFT JOIN sessions b ON a.sid=b.sid LEFT JOIN member m ON b.luser=m.username LEFT JOIN servergroup ug ON m.groupid=ug.id WHERE 1 AND at >='$start' AND at <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND b.addr="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND b.addr IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." ORDER BY at desc ";106echo ";\n\n";107echo ${'sql_app_statistic_'.$dateinterval} = "INSERT INTO appreport_".$dateinterval."(luser,realname,groupname,user,serverip,appname,mstart,mend,ct".($dateinterval=='diy' ? ',createid' : '').") SELECT b.username ,b.realname,ug.groupname,r.user ,a.serverip,a.appname, MIN(a.start), MAX(a.start),count(*)".($dateinterval=='diy' ? ','.$diy_id : '')." FROM appcomm a LEFT JOIN rdpsessions r ON a.sid=r.sid LEFT JOIN member b ON a.memberid=b.uid LEFT JOIN servergroup ug ON b.groupid=ug.id WHERE 1=1 AND a.start >='$start' AND a.start <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND b.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND b.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND r.addr="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND r.addr IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." GROUP BY a.serverip,appname,memberid ORDER BY count(*) desc ";108echo ";\n\n";109echo ${'sql_sftpcmd_statistic_'.$dateinterval} = "INSERT INTO sftpreport_".$dateinterval."(radius_user,realname,groupname,sftp_user,putct,getct,ct,mstart,mend,serverip".($dateinterval=='diy' ? ',createid' : '').") SELECT radius_user,m.realname,ug.groupname,sftp_user,SUM(putct),SUM(getct),SUM(ct),MIN(start) mstart, MAX(start) mend,t.device_ip".($dateinterval=='diy' ? ','.$diy_id : '')." FROM (SELECT a.svraddr device_ip,a.sftp_user,a.radius_user,a.start,a.end, IF(b.ct,b.ct,0) putct,IF(c.ct,c.ct,0) getct,IF(bb.ct,bb.ct,0) ct FROM sftpsessions a LEFT JOIN (SELECT COUNT(*) ct,sid FROM sftpcomm WHERE LEFT(comm,3)='put' GROUP BY sid) b ON b.sid=a.sid LEFT JOIN (SELECT COUNT(*) ct,sid FROM sftpcomm WHERE LEFT(comm,3)='get' GROUP BY sid) c ON c.sid=a.sid LEFT JOIN (SELECT COUNT(*) ct,sid FROM sftpcomm WHERE 1 GROUP BY sid) bb ON bb.sid=a.sid WHERE 1 GROUP BY a.sid, radius_user,sftp_user) t LEFT JOIN member m ON t.radius_user=m.username LEFT JOIN servergroup ug ON ug.id=m.groupid WHERE 1=1 AND start >='$start' AND start <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND t.device_ip="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND t.device_ip IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." GROUP BY radius_user,sftp_user ORDER BY ct desc";110echo ";\n\n";111echo ${'sql_ftpcmd_statistic_'.$dateinterval} = "INSERT INTO ftpreport_".$dateinterval."(radius_user,realname,groupname,ftp_user,putct,getct,ct,mstart,mend,serverip".($dateinterval=='diy' ? ',createid' : '').") SELECT radius_user,m.realname,ug.groupname,ftp_user,SUM(putct),SUM(getct),SUM(ct),MIN(start) mstart, MAX(start) mend,t.device_ip ".($dateinterval=='diy' ? ','.$diy_id : '')." FROM (SELECT a.svraddr device_ip,a.ftp_user,a.radius_user,a.start,a.end, IF(b.ct,b.ct,0) putct,IF(c.ct,c.ct,0) getct,IF(bb.ct,bb.ct,0) ct FROM ftpsessions a LEFT JOIN (SELECT COUNT(*) ct,sid FROM ftpcomm WHERE LEFT(comm,3)='put' GROUP BY sid) b ON b.sid=a.sid LEFT JOIN (SELECT COUNT(*) ct,sid FROM ftpcomm WHERE LEFT(comm,3)='get' GROUP BY sid) c ON c.sid=a.sid LEFT JOIN (SELECT COUNT(*) ct,sid FROM ftpcomm WHERE 1 GROUP BY sid) bb ON bb.sid=a.sid WHERE 1 GROUP BY a.sid, radius_user,ftp_user) t LEFT JOIN member m ON t.radius_user=m.username LEFT JOIN servergroup ug ON ug.id=m.groupid WHERE 1=1 AND start >='$start' AND start <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND t.device_ip="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND t.device_ip IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." GROUP BY radius_user,ftp_user ORDER BY ct desc ";112echo ";\n\n";113//Î¥¹æ±¨±í114echo ${'sql_dangercmd_statistic_'.$dateinterval} = "INSERT INTO dangercmdreport_".$dateinterval."(luser,realname,groupname,user,device_ip,cmd,ct,mstart,mend".($dateinterval=='diy' ? ',createid' : '').") SELECT a.luser,m.realname,ug.groupname,a.user,a.addr,bb.cmd,SUM(bb.ct), MIN(start), MAX(start)".($dateinterval=='diy' ? ','.$diy_id : '')." FROM sessions a LEFT JOIN (SELECT COUNT(*) ct,sid,cmd FROM commands WHERE dangerlevel > 0 GROUP BY sid,cmd) bb ON bb.sid=a.sid LEFT JOIN member m ON a.luser=m.username LEFT JOIN servergroup ug ON ug.id=m.groupid WHERE 1=1 AND a.start >='$start' AND a.start <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND a.addr="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND a.addr IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." AND ct > 0 GROUP BY addr,user,luser,cmd ORDER BY ct desc";115echo ";\n\n";116echo ${'sql_dangercmdlist_statistic_'.$dateinterval} = "INSERT INTO dangercmdlistreport_".$dateinterval."(luser,realname,groupname,user,device_ip,cmd,type,dangerlevel,at".($dateinterval=='diy' ? ',createid' : '').") SELECT bb.luser,m.realname,ug.groupname,bb.user,bb.addr,a.cmd,bb.type,dangerlevel,at".($dateinterval=='diy' ? ','.$diy_id : '')." FROM commands a LEFT JOIN sessions bb ON bb.sid=a.sid LEFT JOIN member m ON bb.luser=m.username LEFT JOIN servergroup ug ON ug.id=m.groupid WHERE 1=1 AND at >='$start' AND at <='$end' ".($dateinterval=='diy' ? (!empty($diy_username) ? ' AND m.username="'.$diy_username.'" ' : (!empty($diy_ugroupid) ? ' AND m.uid IN("'.implode('","', $diy_alltmpusername).'")' : '')) : '')." ".($dateinterval=='diy' ? (!empty($diy_server) ? ' AND bb.addr="'.$diy_server.'" ' : (!empty($diy_sgroupid) ? ' AND bb.addr IN("'.implode('","', $diy_alltmpip).'")' : '')) : '')." AND dangerlevel > 0 ORDER BY at desc";117echo ";\n\n";118switch($type){119 case 'all': 120 mysql_query(${'sql_admin_log_statistic_'.$dateinterval});121 echo "sql_admin_log_statistic_ updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";122 mysql_query(${'sql_accountrecord_statistic_'.$dateinterval});123 echo "sql_accountrecord_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";124 mysql_query(${'sql_login_statistic_'.$dateinterval});125 echo "sql_login_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";126 mysql_query(${'sql_loginacct_statistic_'.$dateinterval});127 echo "sql_loginacct_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";128 mysql_query(${'sql_loginfailed_statistic_'.$dateinterval});129 echo "sql_loginfailed_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";130 mysql_query(${'sql_devlogin_statistic_'.$dateinterval});131 echo "sql_devlogin_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";132 mysql_query(${'sql_applogin_statistic_'.$dateinterval});133 echo "sql_applogin_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";134 mysql_query(${'sql_loginapproved_statistic_'.$dateinterval});135 echo "sql_loginapproved_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";136 mysql_query(${'sql_command_statistic_'.$dateinterval});137 echo "sql_command_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";138 mysql_query(${'sql_cmdcache_statistic_'.$dateinterval});139 echo "sql_cmdcache_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";140 mysql_query(${'sql_cmdlist_statistic_'.$dateinterval});141 echo "sql_cmdlist_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";142 mysql_query(${'sql_app_statistic_'.$dateinterval});143 echo "sql_app_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";144 mysql_query(${'sql_sftpcmd_statistic_'.$dateinterval});145 echo "sql_sftpcmd_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";146 mysql_query(${'sql_ftpcmd_statistic_'.$dateinterval});147 echo "sql_ftpcmd_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";148 mysql_query(${'sql_dangercmd_statistic_'.$dateinterval});149 echo "sql_dangercmd_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";150 mysql_query(${'sql_dangercmdlist_statistic_'.$dateinterval});151 echo "sql_dangercmdlist_statistic_updated:".mysql_affected_rows().",errorno:".mysql_errno().",error:".mysql_error()."\n";152 if($diy_id) mysql_query("UPDATE report_diy SET status=1,createtime=NOW() WHERE sid='$diy_id'");153 break;154 default:155 echo ${'sql_'.$type.'_'.$dateinterval};156 echo "\n";157 mysql_query(${'sql_'.$type.'_'.$dateinterval});158 echo "updated:".mysql_affected_rows()."\n";159 if($diy_id) mysql_query("UPDATE report_diy SET status=1,createtime=NOW() WHERE sid='$diy_id'");160 break;161}162?>...
Reading.php
Source:Reading.php
1<?php2namespace Kusabi\Date\Tests\DateInterval;3use Exception;4use Kusabi\Date\DateInterval;5use PHPUnit\Framework\TestCase;6class Reading extends TestCase7{8 /**9 * Test fetching the number of days10 *11 * @throws Exception12 *13 * @return void14 *15 * @covers \Kusabi\Date\DateInterval::getDays16 */17 public function testGetDays()18 {19 $this->assertSame(0, DateInterval::instance()->getDays());20 $this->assertSame(0, DateInterval::instance()->invert()->getDays());21 $this->assertSame(0, DateInterval::second()->getDays());22 $this->assertSame(0, DateInterval::second()->invert()->getDays());23 $this->assertSame(0, DateInterval::seconds(30)->getDays());24 $this->assertSame(0, DateInterval::seconds(30)->invert()->getDays());25 $this->assertSame(0, DateInterval::minute()->getDays());26 $this->assertSame(0, DateInterval::minute()->invert()->getDays());27 $this->assertSame(0, DateInterval::hour()->getDays());28 $this->assertSame(0, DateInterval::hour()->invert()->getDays());29 $this->assertSame(1, DateInterval::day()->getDays());30 $this->assertSame(-1, DateInterval::day()->invert()->getDays());31 $this->assertSame(28, DateInterval::month()->getDays());32 $this->assertSame(-28, DateInterval::month()->invert()->getDays());33 $this->assertSame(336, DateInterval::year()->getDays());34 $this->assertSame(-336, DateInterval::year()->invert()->getDays());35 }36 /**37 * Test fetching the number of hours38 *39 * @throws Exception40 *41 * @return void42 *43 * @covers \Kusabi\Date\DateInterval::getHours44 */45 public function testGetHours()46 {47 $this->assertSame(0, DateInterval::instance()->getHours());48 $this->assertSame(0, DateInterval::instance()->invert()->getHours());49 $this->assertSame(0, DateInterval::second()->getHours());50 $this->assertSame(0, DateInterval::second()->invert()->getHours());51 $this->assertSame(0, DateInterval::seconds(30)->getHours());52 $this->assertSame(0, DateInterval::seconds(30)->invert()->getHours());53 $this->assertSame(0, DateInterval::minute()->getHours());54 $this->assertSame(0, DateInterval::minute()->invert()->getHours());55 $this->assertSame(1, DateInterval::hour()->getHours());56 $this->assertSame(-1, DateInterval::hour()->invert()->getHours());57 $this->assertSame(24, DateInterval::day()->getHours());58 $this->assertSame(-24, DateInterval::day()->invert()->getHours());59 $this->assertSame(672, DateInterval::month()->getHours());60 $this->assertSame(-672, DateInterval::month()->invert()->getHours());61 $this->assertSame(8064, DateInterval::year()->getHours());62 $this->assertSame(-8064, DateInterval::year()->invert()->getHours());63 }64 /**65 * Test fetching the number of minutes66 *67 * @throws Exception68 *69 * @return void70 *71 * @covers \Kusabi\Date\DateInterval::getMinutes72 */73 public function testGetMinutes()74 {75 $this->assertSame(0, DateInterval::instance()->getMinutes());76 $this->assertSame(0, DateInterval::instance()->invert()->getMinutes());77 $this->assertSame(0, DateInterval::second()->getMinutes());78 $this->assertSame(0, DateInterval::second()->invert()->getMinutes());79 $this->assertSame(0, DateInterval::seconds(30)->getMinutes());80 $this->assertSame(0, DateInterval::seconds(30)->invert()->getMinutes());81 $this->assertSame(1, DateInterval::minute()->getMinutes());82 $this->assertSame(-1, DateInterval::minute()->invert()->getMinutes());83 $this->assertSame(60, DateInterval::hour()->getMinutes());84 $this->assertSame(-60, DateInterval::hour()->invert()->getMinutes());85 $this->assertSame(1440, DateInterval::day()->getMinutes());86 $this->assertSame(-1440, DateInterval::day()->invert()->getMinutes());87 $this->assertSame(40320, DateInterval::month()->getMinutes());88 $this->assertSame(-40320, DateInterval::month()->invert()->getMinutes());89 $this->assertSame(483840, DateInterval::year()->getMinutes());90 $this->assertSame(-483840, DateInterval::year()->invert()->getMinutes());91 }92 /**93 * Test fetching the number of months94 *95 * @throws Exception96 *97 * @return void98 *99 * @covers \Kusabi\Date\DateInterval::getMonths100 */101 public function testGetMonths()102 {103 $this->assertSame(0, DateInterval::instance()->getMonths());104 $this->assertSame(0, DateInterval::instance()->invert()->getMonths());105 $this->assertSame(0, DateInterval::second()->getMonths());106 $this->assertSame(0, DateInterval::second()->invert()->getMonths());107 $this->assertSame(0, DateInterval::seconds(30)->getMonths());108 $this->assertSame(0, DateInterval::seconds(30)->invert()->getMonths());109 $this->assertSame(0, DateInterval::minute()->getMonths());110 $this->assertSame(0, DateInterval::minute()->invert()->getMonths());111 $this->assertSame(0, DateInterval::hour()->getMonths());112 $this->assertSame(0, DateInterval::hour()->invert()->getMonths());113 $this->assertSame(0, DateInterval::day()->getMonths());114 $this->assertSame(0, DateInterval::day()->invert()->getMonths());115 $this->assertSame(1, DateInterval::month()->getMonths());116 $this->assertSame(-1, DateInterval::month()->invert()->getMonths());117 $this->assertSame(12, DateInterval::year()->getMonths());118 $this->assertSame(-12, DateInterval::year()->invert()->getMonths());119 }120 /**121 * Test fetching the number of days as a float122 *123 * @throws Exception124 *125 * @return void126 *127 * @covers \Kusabi\Date\DateInterval::getRealDays128 */129 public function testGetRealDays()130 {131 $this->assertSame(0.0, DateInterval::instance()->getRealDays());132 $this->assertSame(0.0, DateInterval::instance()->invert()->getRealDays());133 $this->assertSame(0.000011574074074074073, DateInterval::second()->getRealDays());134 $this->assertSame(-0.000011574074074074073, DateInterval::second()->invert()->getRealDays());135 $this->assertSame(0.00034722222222222224, DateInterval::seconds(30)->getRealDays());136 $this->assertSame(-0.00034722222222222224, DateInterval::seconds(30)->invert()->getRealDays());137 $this->assertSame(0.00069444444444444447, DateInterval::minute()->getRealDays());138 $this->assertSame(-0.00069444444444444447, DateInterval::minute()->invert()->getRealDays());139 $this->assertSame(0.041666666666666664, DateInterval::hour()->getRealDays());140 $this->assertSame(-0.041666666666666664, DateInterval::hour()->invert()->getRealDays());141 $this->assertSame(1.0, DateInterval::day()->getRealDays());142 $this->assertSame(-1.0, DateInterval::day()->invert()->getRealDays());143 $this->assertSame(28.0, DateInterval::month()->getRealDays());144 $this->assertSame(-28.0, DateInterval::month()->invert()->getRealDays());145 $this->assertSame(336.0, DateInterval::year()->getRealDays());146 $this->assertSame(-336.0, DateInterval::year()->invert()->getRealDays());147 }148 /**149 * Test fetching the number of hours as a float150 *151 * @throws Exception152 *153 * @return void154 *155 * @covers \Kusabi\Date\DateInterval::getRealHours156 */157 public function testGetRealHours()158 {159 $this->assertSame(0.0, DateInterval::instance()->getRealHours());160 $this->assertSame(0.0, DateInterval::instance()->invert()->getRealHours());161 $this->assertSame(0.00027777777777777778, DateInterval::second()->getRealHours());162 $this->assertSame(-0.00027777777777777778, DateInterval::second()->invert()->getRealHours());163 $this->assertSame(0.0083333333333333332, DateInterval::seconds(30)->getRealHours());164 $this->assertSame(-0.0083333333333333332, DateInterval::seconds(30)->invert()->getRealHours());165 $this->assertSame(0.016666666666666666, DateInterval::minute()->getRealHours());166 $this->assertSame(-0.016666666666666666, DateInterval::minute()->invert()->getRealHours());167 $this->assertSame(1.0, DateInterval::hour()->getRealHours());168 $this->assertSame(-1.0, DateInterval::hour()->invert()->getRealHours());169 $this->assertSame(24.0, DateInterval::day()->getRealHours());170 $this->assertSame(-24.0, DateInterval::day()->invert()->getRealHours());171 $this->assertSame(672.0, DateInterval::month()->getRealHours());172 $this->assertSame(-672.0, DateInterval::month()->invert()->getRealHours());173 $this->assertSame(8064.0, DateInterval::year()->getRealHours());174 $this->assertSame(-8064.0, DateInterval::year()->invert()->getRealHours());175 }176 /**177 * Test fetching the number of minutes as a float178 *179 * @throws Exception180 *181 * @return void182 *183 * @covers \Kusabi\Date\DateInterval::getRealMinutes184 */185 public function testGetRealMinutes()186 {187 $this->assertSame(0.0, DateInterval::instance()->getRealMinutes());188 $this->assertSame(0.0, DateInterval::instance()->invert()->getRealMinutes());189 $this->assertSame(0.016666666666666666, DateInterval::second()->getRealMinutes());190 $this->assertSame(-0.016666666666666666, DateInterval::second()->invert()->getRealMinutes());191 $this->assertSame(0.5, DateInterval::seconds(30)->getRealMinutes());192 $this->assertSame(-0.5, DateInterval::seconds(30)->invert()->getRealMinutes());193 $this->assertSame(1.0, DateInterval::minute()->getRealMinutes());194 $this->assertSame(-1.0, DateInterval::minute()->invert()->getRealMinutes());195 $this->assertSame(60.0, DateInterval::hour()->getRealMinutes());196 $this->assertSame(-60.0, DateInterval::hour()->invert()->getRealMinutes());197 $this->assertSame(1440.0, DateInterval::day()->getRealMinutes());198 $this->assertSame(-1440.0, DateInterval::day()->invert()->getRealMinutes());199 $this->assertSame(40320.0, DateInterval::month()->getRealMinutes());200 $this->assertSame(-40320.0, DateInterval::month()->invert()->getRealMinutes());201 $this->assertSame(483840.0, DateInterval::year()->getRealMinutes());202 $this->assertSame(-483840.0, DateInterval::year()->invert()->getRealMinutes());203 }204 /**205 * Test fetching the number of months as a float206 *207 * @throws Exception208 *209 * @return void210 *211 * @covers \Kusabi\Date\DateInterval::getRealMonths212 */213 public function testGetRealMonths()214 {215 $this->assertSame(0.0, DateInterval::instance()->getRealMonths());216 $this->assertSame(0.0, DateInterval::instance()->invert()->getRealMonths());217 $this->assertSame(0.00000041335978835978832, DateInterval::second()->getRealMonths());218 $this->assertSame(-0.00000041335978835978832, DateInterval::second()->invert()->getRealMonths());219 $this->assertSame(0.000012400793650793651, DateInterval::seconds(30)->getRealMonths());220 $this->assertSame(-0.000012400793650793651, DateInterval::seconds(30)->invert()->getRealMonths());221 $this->assertSame(0.000024801587301587302, DateInterval::minute()->getRealMonths());222 $this->assertSame(-0.000024801587301587302, DateInterval::minute()->invert()->getRealMonths());223 $this->assertSame(0.001488095238095238, DateInterval::hour()->getRealMonths());224 $this->assertSame(-0.001488095238095238, DateInterval::hour()->invert()->getRealMonths());225 $this->assertSame(0.035714285714285712, DateInterval::day()->getRealMonths());226 $this->assertSame(-0.035714285714285712, DateInterval::day()->invert()->getRealMonths());227 $this->assertSame(1.0, DateInterval::month()->getRealMonths());228 $this->assertSame(-1.0, DateInterval::month()->invert()->getRealMonths());229 $this->assertSame(12.0, DateInterval::year()->getRealMonths());230 $this->assertSame(-12.0, DateInterval::year()->invert()->getRealMonths());231 }232 /**233 * Test fetching the number of years as a float234 *235 * @throws Exception236 *237 * @return void238 *239 * @covers \Kusabi\Date\DateInterval::getRealYears240 */241 public function testGetRealYears()242 {243 $this->assertSame(0.0, DateInterval::instance()->getRealYears());244 $this->assertSame(0.0, DateInterval::instance()->invert()->getRealYears());245 $this->assertSame(0.00000003444664902998236, DateInterval::second()->getRealYears());246 $this->assertSame(-0.00000003444664902998236, DateInterval::second()->invert()->getRealYears());247 $this->assertSame(0.000001033399470899471, DateInterval::seconds(30)->getRealYears());248 $this->assertSame(-0.000001033399470899471, DateInterval::seconds(30)->invert()->getRealYears());249 $this->assertSame(0.0000020667989417989419, DateInterval::minute()->getRealYears());250 $this->assertSame(-0.0000020667989417989419, DateInterval::minute()->invert()->getRealYears());251 $this->assertSame(0.0001240079365079365, DateInterval::hour()->getRealYears());252 $this->assertSame(-0.0001240079365079365, DateInterval::hour()->invert()->getRealYears());253 $this->assertSame(0.002976190476190476, DateInterval::day()->getRealYears());254 $this->assertSame(-0.002976190476190476, DateInterval::day()->invert()->getRealYears());255 $this->assertSame(0.083333333333333329, DateInterval::month()->getRealYears());256 $this->assertSame(-0.083333333333333329, DateInterval::month()->invert()->getRealYears());257 $this->assertSame(1.0, DateInterval::year()->getRealYears());258 $this->assertSame(-1.0, DateInterval::year()->invert()->getRealYears());259 }260 /**261 * Test fetching the number of seconds262 *263 * @throws Exception264 *265 * @return void266 *267 * @covers \Kusabi\Date\DateInterval::getSeconds268 */269 public function testGetSeconds()270 {271 $this->assertSame(0, DateInterval::instance()->getSeconds());272 $this->assertSame(0, DateInterval::instance()->invert()->getSeconds());273 $this->assertSame(1, DateInterval::second()->getSeconds());274 $this->assertSame(-1, DateInterval::second()->invert()->getSeconds());275 $this->assertSame(30, DateInterval::seconds(30)->getSeconds());276 $this->assertSame(-30, DateInterval::seconds(30)->invert()->getSeconds());277 $this->assertSame(60, DateInterval::minute()->getSeconds());278 $this->assertSame(-60, DateInterval::minute()->invert()->getSeconds());279 $this->assertSame(3600, DateInterval::hour()->getSeconds());280 $this->assertSame(-3600, DateInterval::hour()->invert()->getSeconds());281 $this->assertSame(86400, DateInterval::day()->getSeconds());282 $this->assertSame(-86400, DateInterval::day()->invert()->getSeconds());283 $this->assertSame(2419200, DateInterval::month()->getSeconds());284 $this->assertSame(-2419200, DateInterval::month()->invert()->getSeconds());285 $this->assertSame(29030400, DateInterval::year()->getSeconds());286 $this->assertSame(-29030400, DateInterval::year()->invert()->getSeconds());287 }288 /**289 * Test fetching the number of years290 *291 * @throws Exception292 *293 * @return void294 *295 * @covers \Kusabi\Date\DateInterval::getYears296 */297 public function testGetYears()298 {299 $this->assertSame(0, DateInterval::instance()->getYears());300 $this->assertSame(0, DateInterval::instance()->invert()->getYears());301 $this->assertSame(0, DateInterval::second()->getYears());302 $this->assertSame(0, DateInterval::second()->invert()->getYears());303 $this->assertSame(0, DateInterval::seconds(30)->getYears());304 $this->assertSame(0, DateInterval::seconds(30)->invert()->getYears());305 $this->assertSame(0, DateInterval::minute()->getYears());306 $this->assertSame(0, DateInterval::minute()->invert()->getYears());307 $this->assertSame(0, DateInterval::hour()->getYears());308 $this->assertSame(0, DateInterval::hour()->invert()->getYears());309 $this->assertSame(0, DateInterval::day()->getYears());310 $this->assertSame(0, DateInterval::day()->invert()->getYears());311 $this->assertSame(0, DateInterval::month()->getYears());312 $this->assertSame(0, DateInterval::month()->invert()->getYears());313 $this->assertSame(1, DateInterval::year()->getYears());314 $this->assertSame(-1, DateInterval::year()->invert()->getYears());315 }316 /**317 * Test that we can read the spec string318 *319 * @throws Exception320 *321 * @return void322 *323 * @covers \Kusabi\Date\DateInterval::getSpec324 */325 public function testGetSpec()326 {327 $interval = new DateInterval('P1Y2M3DT4H5M6S');328 $this->assertSame('P1Y2M3DT4H5M6S', $interval->getSpec());329 $interval->subYear()->subMonths(2)->subDays(3);330 $this->assertSame('PT4H5M6S', $interval->getSpec());331 }332}...
DateIntervalNormalizerTest.php
Source:DateIntervalNormalizerTest.php
1<?php2namespace Symfony\Component\Serializer\Tests\Normalizer;3use PHPUnit\Framework\TestCase;4use Symfony\Component\Serializer\Normalizer\DateIntervalNormalizer;5/**6 * @author Jérôme Parmentier <jerome@prmntr.me>7 */8class DateIntervalNormalizerTest extends TestCase9{10 /**11 * @var DateIntervalNormalizer12 */13 private $normalizer;14 protected function setUp()15 {16 $this->normalizer = new DateIntervalNormalizer();17 }18 public function dataProviderISO()19 {20 $data = array(21 array('P%YY%MM%DDT%HH%IM%SS', 'P00Y00M00DT00H00M00S', 'PT0S'),22 array('P%yY%mM%dDT%hH%iM%sS', 'P0Y0M0DT0H0M0S', 'PT0S'),23 array('P%yY%mM%dDT%hH%iM%sS', 'P10Y2M3DT16H5M6S', 'P10Y2M3DT16H5M6S'),24 array('P%yY%mM%dDT%hH%iM', 'P10Y2M3DT16H5M', 'P10Y2M3DT16H5M'),25 array('P%yY%mM%dDT%hH', 'P10Y2M3DT16H', 'P10Y2M3DT16H'),26 array('P%yY%mM%dD', 'P10Y2M3D', 'P10Y2M3DT0H'),27 );28 return $data;29 }30 public function testSupportsNormalization()31 {32 $this->assertTrue($this->normalizer->supportsNormalization(new \DateInterval('P00Y00M00DT00H00M00S')));33 $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));34 }35 public function testNormalize()36 {37 $this->assertEquals('P0Y0M0DT0H0M0S', $this->normalizer->normalize(new \DateInterval('PT0S')));38 }39 /**40 * @dataProvider dataProviderISO41 */42 public function testNormalizeUsingFormatPassedInContext($format, $output, $input)43 {44 $this->assertEquals($output, $this->normalizer->normalize(new \DateInterval($input), null, array(DateIntervalNormalizer::FORMAT_KEY => $format)));45 }46 /**47 * @dataProvider dataProviderISO48 */49 public function testNormalizeUsingFormatPassedInConstructor($format, $output, $input)50 {51 $this->assertEquals($output, (new DateIntervalNormalizer($format))->normalize(new \DateInterval($input)));52 }53 /**54 * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException55 * @expectedExceptionMessage The object must be an instance of "\DateInterval".56 */57 public function testNormalizeInvalidObjectThrowsException()58 {59 $this->normalizer->normalize(new \stdClass());60 }61 public function testSupportsDenormalization()62 {63 $this->assertTrue($this->normalizer->supportsDenormalization('P00Y00M00DT00H00M00S', \DateInterval::class));64 $this->assertFalse($this->normalizer->supportsDenormalization('foo', 'Bar'));65 }66 public function testDenormalize()67 {68 $this->assertDateIntervalEquals(new \DateInterval('P00Y00M00DT00H00M00S'), $this->normalizer->denormalize('P00Y00M00DT00H00M00S', \DateInterval::class));69 }70 /**71 * @dataProvider dataProviderISO72 */73 public function testDenormalizeUsingFormatPassedInContext($format, $input, $output)74 {75 $this->assertDateIntervalEquals(new \DateInterval($output), $this->normalizer->denormalize($input, \DateInterval::class, null, array(DateIntervalNormalizer::FORMAT_KEY => $format)));76 }77 /**78 * @dataProvider dataProviderISO79 */80 public function testDenormalizeUsingFormatPassedInConstructor($format, $input, $output)81 {82 $this->assertDateIntervalEquals(new \DateInterval($output), (new DateIntervalNormalizer($format))->denormalize($input, \DateInterval::class));83 }84 /**85 * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException86 */87 public function testDenormalizeExpectsString()88 {89 $this->normalizer->denormalize(1234, \DateInterval::class);90 }91 /**92 * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException93 * @expectedExceptionMessage Expected a valid ISO 8601 interval string.94 */95 public function testDenormalizeNonISO8601IntervalStringThrowsException()96 {97 $this->normalizer->denormalize('10 years 2 months 3 days', \DateInterval::class, null);98 }99 /**100 * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException101 */102 public function testDenormalizeInvalidDataThrowsException()103 {104 $this->normalizer->denormalize('invalid interval', \DateInterval::class);105 }106 /**107 * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException108 */109 public function testDenormalizeFormatMismatchThrowsException()110 {111 $this->normalizer->denormalize('P00Y00M00DT00H00M00S', \DateInterval::class, null, array(DateIntervalNormalizer::FORMAT_KEY => 'P%yY%mM%dD'));112 }113 private function assertDateIntervalEquals(\DateInterval $expected, \DateInterval $actual)114 {115 $this->assertEquals($expected->format('%RP%yY%mM%dDT%hH%iM%sS'), $actual->format('%RP%yY%mM%dDT%hH%iM%sS'));116 }117}...
dateInterval
Using AI Code Generation
1$interval = new dateInterval('P1Y2M3DT10H30M');2var_dump($interval->format('%Y'));3var_dump($interval->format('%M'));4var_dump($interval->format('%D'));5var_dump($interval->format('%H'));6var_dump($interval->format('%I'));7string(1) "1"8string(2) "02"9string(2) "03"10string(2) "10"11string(2) "30"12$interval = new dateInterval('P1Y2M3DT10H30M');13var_dump($interval->format('%Y'));14var_dump($interval->format('%M'));15var_dump($interval->format('%D'));16var_dump($interval->format('%H'));17var_dump($interval->format('%I'));18string(1) "1"19string(1) "2"20string(1) "3"21string(1) "10"22string(1) "30"23I want to import this data to my database. I have created a form to import the file and I have used the following code to read the file:24$handle = fopen($file, "r");25while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {26 $num = count($data);27 for ($c=0; $c < $num; $c++) {28 $col[$c] = $data[$c];29 }30 $col = array_combine($header, $col);31 $sql = "INSERT INTO products (name, description, category, subcategory, subsubcategory, price, quantity, image, sku, status) VALUES ('".$col['name']."', '".$col['description']."', '".$col['category']."', '".$col['subcategory']."', '".$col['subsubcategory']."', '".$col['price']."', '".$col['quantity']."', '".$col['image']."', '".$col['sku']."', '".$col['status']."')";32 if (mysqli_query($conn, $sql)) {33 echo "New record created successfully";34 } else {
dateInterval
Using AI Code Generation
1use mageekguy\atoum\asserters\dateInterval as dateIntervalAsserter;2{3 public function testDateInterval()4 {5 ->dateInterval(new \DateInterval('P1D'))6 ->isPositive()7 ->hasDays(1)8 ->hasHours(0)9 ->hasMinutes(0)10 ->hasSeconds(0)11 ->hasWeeks(0)12 ->dateInterval(new \DateInterval('P1DT1H'))13 ->isPositive()14 ->hasDays(1)15 ->hasHours(1)16 ->hasMinutes(0)17 ->hasSeconds(0)18 ->hasWeeks(0)19 ->dateInterval(new \DateInterval('P1DT1H1M'))20 ->isPositive()21 ->hasDays(1)22 ->hasHours(1)23 ->hasMinutes(1)24 ->hasSeconds(0)25 ->hasWeeks(0)26 ->dateInterval(new \DateInterval('P1DT1H1M1S'))27 ->isPositive()28 ->hasDays(1)29 ->hasHours(1)30 ->hasMinutes(1)31 ->hasSeconds(1)32 ->hasWeeks(0)33 ->dateInterval(new \DateInterval('P1W'))34 ->isPositive()35 ->hasDays(0)36 ->hasHours(0)37 ->hasMinutes(0)38 ->hasSeconds(0)39 ->hasWeeks(1)40 ->dateInterval(new \DateInterval('P1W1D1H1M1S'))41 ->isPositive()42 ->hasDays(1)43 ->hasHours(1)44 ->hasMinutes(1)45 ->hasSeconds(1)46 ->hasWeeks(1)47 ->dateInterval(new \DateInterval('P1M'))48 ->isPositive()49 ->hasDays(0)50 ->hasHours(0)51 ->hasMinutes(0)52 ->hasSeconds(0)53 ->hasWeeks(4)54 ->dateInterval(new \DateInterval('P1M1W1D1H1M1S'))55 ->isPositive()56 ->hasDays(1)57 ->hasHours(1)
dateInterval
Using AI Code Generation
1$interval = new DateInterval('P1Y2M3DT4H5M6S');2echo $interval->format('%Y-%M-%D %H:%I:%S');3$interval = new DateInterval('P1Y2M3DT4H5M6S');4echo $interval->format('%Y-%M-%D %H:%I:%S');5$interval = new DateInterval('P1Y2M3DT4H5M6S');6echo $interval->format('%Y-%M-%D %H:%I:%S');7$interval = new DateInterval('P1Y2M3DT4H5M6S');8echo $interval->format('%Y-%M-%D %H:%I:%S');9$interval = new DateInterval('P1Y2M3DT4H5M6S');10echo $interval->format('%Y-%M-%D %H:%I:%S');11$interval = new DateInterval('P1Y2M3DT4H5M6S');12echo $interval->format('%Y-%M-%D %H:%I:%S');13$interval = new DateInterval('P1Y2M3DT4H5M6S');14echo $interval->format('%Y-%M-%D %H:%I:%S');
dateInterval
Using AI Code Generation
1$interval = new dateInterval('P1M');2$interval->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');3$interval = new dateInterval('P1M');4$interval->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');5$interval = new dateInterval('P1M');6$interval->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');7$interval = new dateInterval('P1M');8$interval->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');9$interval = new dateInterval('P1M');10$interval->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');11$interval = new dateInterval('P1M');12$interval->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');
dateInterval
Using AI Code Generation
1$interval = new \DateInterval('P1D');2$interval->invert = 1;3$datetime = new \DateTime('2018-09-26 00:00:00');4$datetime->add($interval);5echo $datetime->format('Y-m-d H:i:s');6$interval = new \DateInterval('P1D');7$interval->invert = 1;8$datetime = new \DateTime('2018-09-26 00:00:00');9$datetime->add($interval);10echo $datetime->format('Y-m-d H:i:s');11$interval = new \DateInterval('P1D');12$interval->invert = 1;13$datetime = new \DateTime('2018-09-26 00:00:00');14$datetime->add($interval);15echo $datetime->format('Y-m-d H:i:s');16$interval = new \DateInterval('P1D');17$interval->invert = 1;18$datetime = new \DateTime('2018-09-26 00:00:00');19$datetime->add($interval);20echo $datetime->format('Y-m-d H:i:s');21$interval = new \DateInterval('P1D');22$interval->invert = 1;23$datetime = new \DateTime('2018-09-26 00:00:00');24$datetime->add($interval);25echo $datetime->format('Y-m-d H:i:s');26$interval = new \DateInterval('P1D');27$interval->invert = 1;28$datetime = new \DateTime('2018-09-26 00:00:00');29$datetime->add($interval);30echo $datetime->format('Y-m-d H:i:s');31$interval = new \DateInterval('P1D');32$interval->invert = 1;33$datetime = new \DateTime('2018-09-26 00:
dateInterval
Using AI Code Generation
1namespace Atoum\DateInterval ;2{3 public function __construct($interval_spec)4 {5 parent ::__construct($interval_spec);6 }7}8 $interval = new DateInterval( 'P1Y2M3DT4H5M6S' );9 echo $interval ->format( '%Y years, %M months, %D days, %H hours, %M minutes, %S seconds' );10 $interval = new DateInterval( 'P1Y2M3DT4H5M6S' );11 echo $interval ->format( '%Y years, %M months, %D days, %H hours, %M minutes, %S seconds' );
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!