history.go(-1);"; exit(); } } } //check allow rule if($allow_ips){//be sure was a record at db $allow_ips_arr=explode(",",$allow_ips); foreach($allow_ips_arr as $single_ip2){ if(!preg_match ("/^$single_ip2\b/i", "$myip")) { echo " "; exit(); } } } } //---------------------------------------------------------------------------------------------------------------- function account_online_check() { global $this_time,$uid,$cookies_time_out,$myip,$localhost_no_protect; $check_file_name=_check_file_name(); $go=0; _update_online_db(); //check wherether login if($uid){ $db_account=update_db('erp_surveillance_cam_online','COUNT(*)'," WHERE uid='$uid'",3); if((!$db_account)&&($check_file_name != "index")&&($check_file_name!="login")&&($check_file_name!="check_disk")){//noy yet login status $go=1; }else{// in login status session($uid,1);//1=write, 2=read only //setcookie("uid", "$uid", $cookies_time_out); //must send before any out put } }elseif(($check_file_name != "index")&&($check_file_name != "login")&&($check_file_name != "check_disk")&&($check_file_name != "cam_status")){ $go=1; } //check page permit $function_val=update_db('erp_surveillance_group','id'," WHERE title='$check_file_name' AND active='1'",3); // (1=add, 2=modify, 3=ask, 4=delete, 5=array, 6=item_array) $g_array=update_db('erp_surveillance_group_users','gid'," WHERE uid='$uid'",6); // (1=add, 2=modify, 3=ask, 4=delete, 5=array, 6=item_array) $gid_array=explode(',',$g_array); $ok=0; foreach($gid_array as $val){ if(($val==$function_val)AND($val)AND($function_val)){//match val $ok=1; } } if(($function_val==$superadmin)OR($function_val=='open')OR($name[0]=='index')){//no permit $ok=1; } if((!$ok)&&($check_file_name != "index")&&($check_file_name != "login")&&($check_file_name != "check_disk")&&($check_file_name != "cam_status")){ $go=1; } // check localhost if protect. if($myip=='127.0.0.1'){ $no_protect=explode(",",$localhost_no_protect); foreach($no_protect as $qq){ if($qq==$check_file_name){ $go=0; } } } if($go){ if($check_file_name == "admin"){ redirect_header('../login.php',$time,'sorry you are not allow to operation!'); }else{ redirect_header('login.php',$time,'sorry you are not allow to operation!'); } } $var="&id=$id&online_time=$this_time"; } //---------------------------------------------------------------------------------------------------------------- function _update_online_db() { global $uid,$cookies_time_out,$this_time,$os,$myip,$browser; $online_id= $_SESSION['sn']; $check_file_name=_check_file_name(); $db_table="erp_surveillance_cam_online"; $uid_online=update_db($db_table,'COUNT(*)'," WHERE uid='$uid' AND online_id='$online_id'",3); if($uid_online){ update_db($db_table,''," SET online_time='$cookies_time_out', now_place='$check_file_name' WHERE uid='$uid' AND online_id='$online_id'",2); }else{ $db_save=" SET"; $db_save.=" uid='$uid'"; $db_save.=", online_time='$cookies_time_out'"; $db_save.=", os='$os'"; $db_save.=", browser='$browser'"; $db_save.=", ip='$myip'"; $db_save.=", online_id='$online_id'"; $db_save.=", now_place='$check_file_name'"; update_db($db_table,'',$db_save,1); } update_db($db_table,''," WHERE online_time <= '$this_time'",4); //clean all time out emtry } //---------------------------------------------------------------------------------------------------------------- function _check_ptz_permit() { global $uid,$superadmin,$id; $ok=0; $is_ptz=update_db('erp_surveillance_cam','COUNT(*)'," WHERE cam_type!='general' AND id='$id' AND active='1'",3); // (1=add, 2=modify, 3=ask, 4=delete, 5=array, 6=item_array) if($is_ptz){ $function_val=update_db('erp_surveillance_group','id'," WHERE title='ptz' AND active='1'",3); // (1=add, 2=modify, 3=ask, 4=delete, 5=array, 6=item_array) $g_array=update_db('erp_surveillance_group_users','gid'," WHERE uid='$uid'",6); // (1=add, 2=modify, 3=ask, 4=delete, 5=array, 6=item_array) $gid_array=explode(',',$g_array); foreach($gid_array as $val){ if(($val==$function_val)AND($val)AND($function_val)){//match val $ok=1; } } if(($function_val==$superadmin)OR($function_val=='open')){//no permit $ok=1; } } return $ok; } //---------------------------------------------------------------------------------------------------------------- function _check_video_permit() { global $uid,$superadmin,$id; //check group id $function_s=update_db('erp_surveillance_cam','cam_group'," WHERE id='$id' AND active='1'",3); // (1=add, 2=modify, 3=ask, 4=delete, 5=array, 6=item_array) //check group id be active $function_val=update_db('erp_surveillance_group','id'," WHERE id='$function_s' AND active='1'",3); // (1=add, 2=modify, 3=ask, 4=delete, 5=array, 6=item_array) $g_array=update_db('erp_surveillance_group_users','gid'," WHERE uid='$uid'",6); // (1=add, 2=modify, 3=ask, 4=delete, 5=array, 6=item_array) $gid_array=explode(',',$g_array); $ok=0; foreach($gid_array as $val){ if(($val==$function_val)AND($val)AND($function_val)){//match val $ok=1; } } if(($function_val==$superadmin)OR($function_val=='open')){//no permit $ok=1; } return $ok; } //---------------------------------------------------------------------------------------------------------------- function _check_file_name() { $script_name=explode("/",$_SERVER["PHP_SELF"]); $total=count($script_name); $name=explode(".",$script_name[$total - 1]); $admin_file=$script_name[$total - 2]; if($admin_file=="admin"){//be sure this is a admin function $oo= $admin_file; }else{//another file permit $oo= $name[0]; } return $oo; } //---------------------------------------------------------------------------------------------------------------- function session($uid,$method)//1=write, 2=read only { global $id; session_start(); $script_name=explode("/",$_SERVER["PHP_SELF"]); $total=count($script_name); $name=explode(".",$script_name[$total - 1]); if($method == 1){ $time=time(); session_register("uid"); $_SESSION['uid'] = $uid; if(!$_SESSION['sn']){ $_SESSION['sn']= time(); } $_SESSION['page']= $name[0]; // $_SESSION['cam_id']= $id; //請勿使用cam_id 這會影響電視牆的運作 }else{ return $_SESSION['uid']; } } //---------------------------------------------------------------------------------------------------------------- function cookies($uid,$method) //0=set, 1=read { global $cookies_time_out; if(!$method){ $oo=setcookie("uid", "$uid", $cookies_time_out); //must send before any out put }else{ $oo=$_COOKIE["uid"]; } return $oo; } //---------------------------------------------------------------------------------------------------------------- function comm($ip,$port,$cgi,$user,$pass,$method) { $fp = fsockopen($ip, $port, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)
\n"; }else{ $out = "$method /$cgi HTTP/1.1\r\n"; $out .= "Host: www.example.com\r\n"; $out .= "Authorization: Basic ".base64_encode("$user:$pass")."\r\n"; $out .= "Connection: Close\r\n\r\n"; // $out .= "Connection: keep-alive\r\n"; $data=''; fwrite($fp, $out); //recieve data while (!feof($fp)) { $data.=fgets($fp, 1024); } fclose($fp); return $data; } } //---------------------------------------------------------------------------------------------------------------- function sendmail($from,$to,$subject,$body) { include("Mail.php"); //pear modules $recipients = "mail_to@domain.mail"; $headers["From"] = "mail_from@domain.mail"; $headers["To"] = "mail_to@domain.mail"; $headers["Subject"] = "Test message"; $body = "TEST MESSAGE!!!"; $params["host"] = "smtp.server"; $params["port"] = "25"; $params["auth"] = true; $params["username"] = "user"; $params["password"] = "password"; // Create the mail object using the Mail::factory method $mail_object =& Mail::factory("smtp", $params); $mail_object->send($recipients, $headers, $body); } //---------------------------------------------------------------------------------------------------------------- function update_db($db_table,$item,$sql,$method) // (1=add, 2=modify, 3=ask, 4=delete, 5=array, 6=item_array, 7=distinct item array) { global $db, $prefix; $_dot_=','; $i=0; $rr = $db->sql_query("SELECT COUNT(*) FROM ".$prefix."_".$db_table.$sql); list($total) = $db->sql_fetchrow($rr); if($method=='1'){ $oo=$db->sql_query("INSERT INTO ".$prefix."_".$db_table.$sql); }elseif($method=='2'){ $oo=$result = $db->sql_query("UPDATE ".$prefix."_".$db_table.$sql); }elseif($method=='3'){ $result = $db->sql_query("SELECT $item FROM ".$prefix."_".$db_table.$sql); list($oo) = $db->sql_fetchrow($result); }elseif($method=='4'){ $oo=$db->sql_query("DELETE FROM ".$prefix."_".$db_table.$sql); }elseif($method=='5'){ $sql = "SELECT * FROM ".$prefix."_".$db_table.$sql; $result = $db->sql_query($sql); $oo=$db->sql_fetchrow($result); }elseif($method=='6'){ $sql = "SELECT * FROM ".$prefix."_".$db_table.$sql; $result = $db->sql_query($sql); while ( $row = $db->sql_fetchrow($result) ) { if($i >= $total - 1){ $oo.=$row[$item]; }else{ $oo.=$row[$item].$_dot_; } $i++; } }elseif($method=='7'){ $sql = "SELECT $sql FROM ".$prefix."_".$db_table; $result = $db->sql_query($sql); while ( $row = $db->sql_fetchrow($result) ) { $oo[$i].=$row[$item]; $i++; } }elseif($method=='8'){ $oo=$db->sql_query("CREATE TABLE IF NOT EXISTS ".$prefix."_".$db_table." $item"); }elseif($method=='11'){ $item=explode(',',$item); $sql = "SELECT * FROM ".$prefix."_".$db_table.$sql; $result = $db->sql_query($sql); while ( $row = $db->sql_fetchrow($result) ) { foreach($item as $val){ $oo[$i][$val]=$row[$val]; } $i++; } }elseif($method=='44'){ $oo=$db->sql_query("DROP TABLE IF EXISTS ".$prefix."_".$db_table." $item"); } return $oo; } //---------------------------------------------------------------------------------------------------------------- function count_pages($db_table,$item,$op,$show,$limit,$sql) //count all data to 做分頁 { global $db, $prefix,$spacial_pam; $total=update_db($db_table,$item,$sql,3); //count per page $totalpage=ceil($total / $limit); $nowpage=intval($show/$limit)+1; $no=1; $list= ""; if($total){ $oo="
"._TOTAL.":$total"._PAGE_DATA.","._TOTAL_PAGE."$totalpage "._PAGE.","._NOW_DISPLAY." $list --"._PER_PAGE." $limit "._PAGE_DATA.""; }else{ $oo="
"._NONE_DATA; } return $oo; } //---------------------------------------------------------------------------------------------------------------- function _select($name,$max,$default_val,$default,$method) //method=add 0 like this 01,02,03 { $jj=""; $jj.=""; return $jj; } //---------------------------------------------------------------------------------------------------------------- function _str_combo($name,$data_arr,$default_val,$default) { $jj=""; return $jj; } //---------------------------------------------------------------------------------------------------------------- function _cam_server_group_combo($name,$default,$method) { global $db, $prefix; if($method==1){ $db_table="erp_surveillance_cam"; $default_title=update_db($db_table,'title'," WHERE id='$default'",3); }elseif($method==2){ $db_table="erp_surveillance_cam_server"; $default_title=update_db($db_table,'title'," WHERE id='$default'",3); }elseif($method==3){ $db_table="erp_surveillance_group"; $default_title=update_db($db_table,'title'," WHERE id='$default'",3); if(($default=='open')OR($default=='')){ $default_title='open'; $default='open'; }else{ $open=""; } } $jj=""; return $jj; } //---------------------------------------------------------------------------------------------------------------- function _date_select($dateStart,$startHour,$dateEnd,$endHour,$method) //method=0 no hour; 1=hour { if($method){ $startHour= _select('startHour','23',$startHour,$startHour,'0');//add 0 $endHour=_select('endHour','23',$endHour,$endHour,'0');//add 0 } $jj=<< EOD; return $jj; } //---------------------------------------------------------------------------------------------------------------- function map_type($path,$name,$w,$h,$var) { $m=explode(".",$name); $name1=$m[0]; if(($m[1]=='swf')AND($name)) { $oo=<< EOD; }elseif($name){ $oo=""; } return $oo; } //---------------------------------------------------------------------------------------------------------------- function _search_form_($word,$another) { $jj=<<
$another
EOD; $jj.=focus('key_word'); return $jj; } //---------------------------------------------------------------------------------------------------------------- function focus($word) { $jj=<< function focus(){ document.form1.$word.focus(); } focus(); EOD; if($word){ return $jj; } } //---------------------------------------------------------------------------------------------------------------- function update_login() { global $now,$this_time,$this_year,$this_month,$this_day,$this_hour,$browser,$os,$myip,$uid,$id; $script_name=explode("/",$_SERVER["PHP_SELF"]); $total=count($script_name); $name=explode(".",$script_name[$total - 1]); if(($name[0]=='cam')AND($name[0]!='index')AND($name[0]!='check_disk')AND($name[0]!='cam_status')AND($name[0]!='login')){ $cam_title=update_db('erp_surveillance_cam','title'," WHERE id='$id'",3); $record_session_id=update_db('erp_surveillance_cam_visit','COUNT(*)'," WHERE key_in_date='$_SESSION[sn]' AND title='$cam_title'",3); $title=$cam_title; }elseif(($name[0]!='')AND($name[0]!='index')AND($name[0]!='check_disk')AND($name[0]!='cam_status')AND($name[0]!='login')){ $title=page2name($name[0]); //converter to title name $record_session_id=update_db('erp_surveillance_cam_visit','COUNT(*)'," WHERE key_in_date='$_SESSION[sn]' AND title='$title'",3); }else{ $record_session_id=1; } if((!$record_session_id)AND($title)){ $db_table="erp_surveillance_cam_visit"; $db_save.=" SET"; $db_save.=" title='$title'"; $db_save.=", time='$now'"; $db_save.=", account='$uid'"; $db_save.=", os='$os'"; $db_save.=", browser='$browser'"; $db_save.=", ip='$myip'"; $db_save.=", year='$this_year'"; $db_save.=", month='$this_month'"; $db_save.=", day='$this_day'"; $db_save.=", hour='$this_hour'"; $db_save.=", key_in_date='$_SESSION[sn]'"; update_db($db_table,'',$db_save,1); } } //---------------------------------------------------------------------------------------------------------------- function page2name($tile) { switch ($tile) { //admin page case "cam_conf": $str=_CAM_CONFIG; break; case "cam_admin": $str=_CAM_ADMIN; break; case "cam_server": $str=_CAM_SERVER; break; case "cam_tv": $str=_CAM_TV; break; case "cam_record": $str=_CAM_RECORD; break; case "cam_log": $str=_CAM_LOG; break; case "cam_account": $str=_CAM_ACCOUNT_TITLE_FORM; break; case "cam_group": $str=_CAM_GROUP; break; case "cam_firewall": $str=_CAM_FIREWALL; break; // user page case "wall": $str=_USER_TV; break; case "record": $str=_USER_RECORD; break; case "playback": $str=_USER_PLAYBACK; break; } return $str; } //---------------------------------------------------------------------------------------------------------------- function online_check() { $sys_max=update_db('erp_surveillance_conf','sys_max','',3); $online_now=update_db('erp_surveillance_cam_online','COUNT(*)','',3); if($online_now >=$sys_max){ echo _CAM_OVER_ONLINE; exit; } } //---------------------------------------------------------------------------------------------------------------- function limit_stay_time() { $stay_time=update_db('erp_surveillance_conf','stay_time','',3); if($stay_time){ $timeOut.=""; echo $timeOut; } } //---------------------------------------------------------------------------------------------------------------- function active_check() { global $db, $prefix,$id; $active=update_db('erp_surveillance_cam','active'," WHERE id='$id'",3); if($active==2){ $oo.="
"._CAM_NO_ACTIVE.""; echo $oo; exit; } } //---------------------------------------------------------------------------------------------------------------- function redirect_header($page,$time,$text) { echo "
".$text."
"; // echo ""; header("Location: $page"); } //---------------------------------------------------------------------------------------------------------------- function mk_dir($dir="") { if(empty($dir))redirect_header($_SERVER['PHP_SELF'], 10,"error :you must be define folder name"); if (!is_dir($dir)) { umask(000); if(!mkdir($dir, 0777)){ //for linux redirect_header($_SERVER['PHP_SELF'], 10,"exc error:fail to creat a new folder!"); } } return; } //---------------------------------------------------------------------------------------------------------------- function dfs_gb($drive,$info) //0=total, 1=free space { if($drive){ if($info==1){//free return round(disk_free_space("$drive:")/1024/1024/1024,2); //To Get Human Result in GB we divid it By 1024 Byte & 1024 KiloByte & 1024 MegaByte }else{ //total return round(disk_total_space("$drive:")/1024/1024/1024,2); //To Get Human Result in GB we divid it By 1024 Byte & 1024 KiloByte & 1024 MegaByte } } } //---------------------------------------------------------------------------------------------------------------- function _disk_list($name,$default,$method)//$method-> 1=single hd, 2=add more all { global $disk_list; $jj=""; return $jj; } //---------------------------------------------------------------------------------------------------------------- function _check_disk_list($name,$default,$method)//$method-> 1=combo list, 2=list array { global $disk_list,$valid_min_space; $jj=""; }else{ $jj=$hd_list_arr; } return $jj; } //---------------------------------------------------------------------------------------------------------------- function sys_os() { $os_src=strtoupper(substr(PHP_OS, 0, 3)); if($os_src == 'WIN') { $os='win'; }elseif($os_src == 'LIN'){ $os='linux'; } return $os; } //---------------------------------------------------------------------------------------------------------------- ?>