0) { $e = escapeshellcmd($str); $value=exec("bin/$script $e"); } else $value=exec("bin/$script"); $bin=1; } else { if($length>0) { $e = escapeshellcmd($str); $value=exec("$script $e"); } else $value=exec("$script"); } if(strlen($value)<2) { if($bin==0) { if($length>0) { $e = escapeshellcmd($str); $value=exec("bin/$script $e"); } else $value=exec("bin/$script"); } else { if($length>0) { $e = escapeshellcmd($str); $value=exec("$script $e"); } else $value=exec("$script"); } } return($value); } function ExecuteFunctions($path, $mask, $id) { $files=array(); $count=0; if ($handle2 = opendir($path)) { while (false !== ($file = readdir($handle2))) { if(strstr($file, $mask)!=FALSE) { if(strpos($file, $mask)==0) { //echo "$count: $file
"; $files[$count]=$file; $count++; } } } } sort($files); for($i=0;$i<$count;$i++) { //echo "$i/$count: $files[$i]
"; if(strstr($files[$i],"~")==NULL) { $funcname=str_replace(".php","",$files[$i]); require("$path/$files[$i]"); if($id!=1) $funcname($id); else $funcname(); } } return($files); } function about() { global $SAMSConf; print(""); print("
ICONSET/proxy_big.gif\">"); print("

SAMS v. 1.0.1

"); print("

Squid Account Management System

"); print("Copyright (C) 2003 - 2008 Dmitry Chemerik"); print("
http://sams.perm.ru"); print("

email: chemerik@mail.ru

"); } function db_connect($basename) { global $SAMSConf; // echo "
DB_TEST $basename $SAMSConf->MYSQLHOSTNAME, $SAMSConf->MYSQLUSER, $SAMSConf->MYSQLPASSWORD"; $link=@mysql_connect($SAMSConf->MYSQLHOSTNAME,$SAMSConf->MYSQLUSER,$SAMSConf->MYSQLPASSWORD) || die (mysql_error()); if($link && mysql_select_db($basename)) return($link); return(FALSE); } class SAMSCONFIG { var $SAMSPATH; var $access; var $groupauditor; var $domainusername; var $adminname; var $DELAYPOOL; var $USERACCESS; var $URLACCESS; var $SAMSDB; var $LOGDB; var $MYSQLHOSTNAME; var $MYSQLUSER; var $MYSQLPASSWORD; var $SQUIDCACHEFILE; var $SQUIDROOTDIR; var $SQUIDLOGDIR; var $SGUARDDBPATH; var $SGUARDLOGPATH; var $REDIRECTOR; var $AUTH; var $WBINFOPATH; var $ININT; var $EXINT; var $EXIP; var $LANG; var $NTLMDOMAIN; var $ICONSET; var $SHOWUTREE; var $SHOWNAME; var $LDAPUSER; var $LDAPUSERPASSWD; var $LDAPUSERSGROUP; var $LDAPSERVER; var $LDAPBASEDN; var $LDAPDOMAIN; var $MBSIZE; var $KBSIZE; var $DEFAULTDOMAIN; var $realtraffic; var $SQUIDBASE; var $SWITCHTO; var $SHOWGRAPH; var $PDFLIB; var $MYSQLVERSION; var $SHUTDOWN; var $PHPVER; var $SEPARATOR; var $PROXYCOUNT; function ReadSAMSConfFile($configfile) { $version=phpversion(); $this->PHPVER=strtok($version,"."); $finp=fopen($configfile,"rt"); if($finp==FALSE) { echo "can't open sams config file $configfile
"; exit(0); } while(feof($finp)==0) { $string=fgets($finp, 10000); $str2=trim(strtok($string,"=")); // if(!strcasecmp($str2,"SAMSPATH" )) $this->SAMSDB=trim(strtok("=")); if(!strcasecmp($str2,"SAMS_DB" )) $this->SAMSDB=trim(strtok("=")); if(!strcasecmp($str2,"SQUID_DB" )) $this->LOGDB=trim(strtok("=")); if(!strcasecmp($str2,"MYSQLHOSTNAME" )) $this->MYSQLHOSTNAME=trim(strtok("=")); if(!strcasecmp($str2,"MYSQLUSER" )) $this->MYSQLUSER=trim(strtok("=")); if(!strcasecmp($str2,"MYSQLPASSWORD" )) $this->MYSQLPASSWORD=trim(strtok("=")); if(!strcasecmp($str2,"SQUIDCACHEFILE" )) $this->SQUIDCACHEFILE=trim(strtok("=")); if(!strcasecmp($str2,"SQUIDROOTDIR" )) $this->SQUIDROOTDIR=trim(strtok("=")); if(!strcasecmp($str2,"SQUIDLOGDIR" )) $this->SQUIDLOGDIR=trim(strtok("=")); if(!strcasecmp($str2,"SQUIDGUARDLOGPATH" )) $this->SGUARDLOGPATH=trim(strtok("=")); if(!strcasecmp($str2,"SQUIDGUARDDBPATH" )) $this->SGUARDDBPATH=trim(strtok("=")); if(!strcasecmp($str2,"ININT" )) $this->ININT=trim(strtok("=")); if(!strcasecmp($str2,"EXINT" )) $this->EXINT=trim(strtok("=")); if(!strcasecmp($str2,"EXIP" )) $this->EXIP=trim(strtok("=")); if(!strcasecmp($str2,"LDAPUSER" )) $this->LDAPUSER=trim(strtok("=")); if(!strcasecmp($str2,"LDAPUSERPASSWD" )) $this->LDAPUSERPASSWD=trim(strtok("=")); if(!strcasecmp($str2,"LDAPUSERSGROUP" )) $this->LDAPUSERSGROUP=trim(strtok("=")); if(!strcasecmp($str2,"LDAPSERVER" )) $this->LDAPSERVER=trim(strtok("=")); if(!strcasecmp($str2,"MYSQLVERSION" )) $this->MYSQLVERSION=trim(strtok("=")); if(!strcasecmp($str2,"SHUTDOWNCOMMAND" )) $this->SHUTDOWN=trim(strtok("=")); if(!strcasecmp($str2,"SAMSPATH" )) $this->SAMSPATH=trim(strtok("=")); if(!strcasecmp($str2,"LDAPBASEDN" )) { $str2=trim(strtok($string,"=")); $LDAPBASEDN_=trim(strtok("=")); $LDAPDOMAIN=$LDAPBASEDN_; $this->LDAPDOMAIN=$LDAPDOMAIN; $LDAPBASEDN2=strtok($LDAPBASEDN_,"."); $this->LDAPBASEDN="DC=$LDAPBASEDN2"; while(strlen($LDAPBASEDN2)>0) { $LDAPBASEDN2=strtok("."); if(strlen($LDAPBASEDN2)>0) $this->LDAPBASEDN="$this->LDAPBASEDN,DC=$LDAPBASEDN2"; } } } fclose($finp); } function ReadSAMSSettings() { $result=mysql_query("SELECT * FROM $this->SAMSDB.sams"); $row=mysql_fetch_array($result); $this->REDIRECTOR=$row['redirector']; $this->DELAYPOOL=$row['delaypool']; $this->AUTH=$row['auth']; $this->WBINFOPATH=$row['wbinfopath']; $this->NTLMDOMAIN=$row['ntlmdomain']; $this->DEFAULTDOMAIN=$row['defaultdomain']; $this->realtraffic=$row['realsize']; $this->SQUIDBASE=$row['squidbase']; $this->SEPARATOR=$row['separator']; $result=mysql_query("SELECT * FROM $this->SAMSDB.globalsettings"); $row=mysql_fetch_array($result); $this->LANG=$row['lang']; if ($this->LANG=="EN") $this->LANGCODE = "EN"; else $this->LANGCODE = "RU"; $this->ICONSET="icon/$row[iconset]"; $this->USERACCESS=$row['useraccess']; $this->URLACCESS=$row['urlaccess']; $this->SHOWUTREE=$row['showutree']; $this->SHOWNAME=$row['showname']; $this->KBSIZE=$row['kbsize']; $this->MBSIZE=$row['mbsize']; $this->SHOWGRAPH=$row['showgraph']; $this->PDFLIB=$row['createpdf']; $result=mysql_query("SELECT MAX(id) FROM $this->SAMSDB.proxyes "); $row=mysql_fetch_array($result); $this->PROXYCOUNT=$row[0]; if($row[0]==0) $this->PROXYCOUNT++; // $result=mysql_query("USE samstraf"); // if($result==FALSE) // $this->SWITCHTO=0; // else $this->SWITCHTO=1; mysql_query("USE $this->SAMSDB"); } function SAMSCONFIG() { $error=0; require('./config.php'); $this->ReadSAMSConfFile($configfile); if(!function_exists('mysql_connect')) { echo "
ERROR: MySql for PHP is not properly installed.
Try installing mysql for php package
"; die(); } $link=mysql_connect("$this->MYSQLHOSTNAME","$this->MYSQLUSER","$this->MYSQLPASSWORD"); if($link==FALSE) { echo "Access denied for user $this->MYSQLUSER@$this->MYSQLHOSTNAME to MySQL
"; $error=1; $link=1; } $squidlogdb=mysql_select_db($this->LOGDB); if($squidlogdb==FALSE) { // echo "connect to database $this->LOGDB error
"; $error=1; $squidlogdb=1; } $squidctrldb=mysql_select_db($this->SAMSDB); if($squidctrldb==FALSE) { // echo "connect to database $this->SAMSDB error
"; $error=1; $squidctrldb=1; } if($error>0) { if(isset($_GET["function"])) $function=$_GET["function"]; if($function=="userdoc") { print(" \n"); echo "
"; echo "SAMS databases not connected
"; print("
\n"); if($squidlogdb==1) echo "The base $this->LOGDB not created or the user $this->MYSQLUSER has no rights to connection to it
"; if($squidctrldb==1) echo "The base $this->SAMSDB not created or the user $this->MYSQLUSER has no rights to connection to it
"; print("
\n"); print("
\n"); print("
\n"); print("SAMS documentation
\n"); print("english
\n"); print("
russian
\n"); } } $this->ReadSAMSSettings(); } function LoadConfig() { require('./config.php'); $this->ReadSAMSConfFile($configfile); $link=@mysql_connect($this->MYSQLHOSTNAME,$this->MYSQLUSER,$this->MYSQLPASSWORD) || die (mysql_error()); if($link && mysql_select_db($this->SAMSDB)==FALSE) echo "Error connection to database
"; $link=@mysql_connect($this->MYSQLHOSTNAME,$this->MYSQLUSER,$this->MYSQLPASSWORD) || die (mysql_error()); if($link && mysql_select_db($this->LOGDB)==FALSE) echo "Error connection to database
"; $this->ReadSAMSSettings(); } function PrintSAMSSettings() { echo "adminname = $this->adminname
"; echo "groupauditor = $this->groupauditor
"; echo "access = $this->access
"; echo "domainusername = $this->domainusername
"; echo "SAMSDB = $this->SAMSDB
"; echo "LOGDB = $this->LOGDB
"; echo "MYSQLHOSTNAME = $this->MYSQLHOSTNAME
"; echo "MYSQLUSER = $this->MYSQLUSER
"; echo "DELAYPOOL = $this->DELAYPOOL
"; echo "USERACCESS = $this->USERACCESS
"; echo "URLACCESS = $this->URLACCESS
"; echo "MYSQLPASSWORD = $this->MYSQLPASSWORD
"; echo "SQUIDCACHEFILE = $this->SQUIDCACHEFILE
"; echo "SQUIDROOTDIR = $this->SQUIDROOTDIR
"; echo "SQUIDLOGDIR = $this->SQUIDLOGDIR
"; echo "SGUARDDBPATH = $this->SGUARDDBPATH
"; echo "SGUARDLOGPATH = $this->SGUARDLOGPATH
"; echo "REDIRECTOR = $this->REDIRECTOR
"; echo "AUTH = $this->AUTH
"; echo "WBINFOPATH = $this->WBINFOPATH
"; echo "ININT = $this->ININT
"; echo "EXINT = $this->EXINT
"; echo "EXIP = $this->EXIP
"; echo "LANG = $this->LANG
"; echo "NTLMDOMAIN = $this->NTLMDOMAIN
"; echo "ICONSET = $this->ICONSET
"; echo "SHOWUTREE = $this->SHOWUTREE
"; echo "SHOWNAME = $this->SHOWNAME
"; echo "LDAPUSER = $this->LDAPUSER
"; echo "LDAPUSERPASSWD = $this->LDAPUSERPASSWD
"; echo "LDAPUSERSGROUP = $this->LDAPUSERSGROUP
"; echo "LDAPSERVER = $this->LDAPSERVER
"; echo "LDAPBASEDN = $this->LDAPBASEDN
"; echo "LDAPDOMAIN = $this->LDAPDOMAIN
"; echo "MBSIZE = $this->MBSIZE
"; echo "KBSIZE = $this->KBSIZE
"; echo "DEFAULTDOMAIN = $this->DEFAULTDOMAIN
"; echo "realtraffic = $this->realtraffic
"; echo "SQUIDBASE = $this->SQUIDBASE
"; echo "SWITCHTO = $this->SWITCHTO
"; echo "SHUTDOWN = $this->SHUTDOWN
"; } } function ReturnTrafficFormattedSize($size) { global $SAMSConf; $str=""; $gsize=floor($size/($SAMSConf->KBSIZE*$SAMSConf->KBSIZE*$SAMSConf->KBSIZE)); $ostatok=$size-$gsize*$SAMSConf->KBSIZE*$SAMSConf->KBSIZE*$SAMSConf->KBSIZE; $msize=floor($ostatok/($SAMSConf->KBSIZE*$SAMSConf->KBSIZE)); $ostatok=$ostatok-$msize*$SAMSConf->KBSIZE*$SAMSConf->KBSIZE; $ksize=floor($ostatok/$SAMSConf->KBSIZE); if($gsize>0) $str="$gsize Gb"; $out="$str $msize Mb $ksize kb "; return($out); } function PrintTrafficSize($size) { $str=ReturnTrafficFormattedSize($size); print($str); } function ReturnGroupNick($groupname) { global $SAMSConf; $result=mysql_query("SELECT * FROM $SAMSConf->SAMSDB.groups WHERE name=\"$groupname\""); $row=mysql_fetch_array($result); return($row['nick']); } function TestWI() { global $SAMSConf; // print("

TestWI $WI

"); if($SAMSConf->access==0&&strlen($SAMSConf->domainusername)==0) exit; } function DateTimeSelect($id,$str) { global $SAMSConf; // print("NewDateSelect LANG=$LANG"); $lang="./lang/lang.$SAMSConf->LANG"; require($lang); $year=strftime("%Y"); $mon=strftime("%m"); $day=strftime("%d"); print("\n"); print(" \n"); print(" "); } function TableCell($data) { // print(""); } function RTableCell($data,$percent) { print(""); } function LTableCell($data,$percent) { print(""); } function RBTableCell($data,$percent) { print(""); } function LBTableCell($data,$percent) { print(""); } function GraphButton($url,$target,$img_small,$img_big,$title) { global $SAMSConf; print("\n"); print("ICONSET/$img_small\" BORDER=0 \n "); print("TITLE=\"$title\" border=0\n"); print("onmouseover=\"this.src='$SAMSConf->ICONSET/$img_big'\" \n"); print("onmouseout= \"this.src='$SAMSConf->ICONSET/$img_small'\" \n"); print("\n"); } function PageTop($imgname,$text) { global $SAMSConf; print("
\n"); print("
\n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print("
$DateTimeSelect_mysqltools_1:\n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); //print("
\n"); //print("\n"); print(" \n"); print("
$DateTimeSelect_mysqltools_2:\n"); print(" $DateTimeSelect_mysqltools_3 \n"); print(" $DateTimeSelect_mysqltools_4 $DateTimeSelect_mysqltools_5 \n"); print("
\n"); //print("\n"); } function NewDateSelect($id,$str) { global $SAMSConf; // print("NewDateSelect LANG=$LANG"); $lang="./lang/lang.$SAMSConf->LANG"; require($lang); $year=strftime("%Y"); $mon=strftime("%m"); $day=strftime("%d"); print("\n"); print(" \n"); print("
\n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print("
$mysqltools_dateselect1\n"); print(" \n"); print(" \n"); print(" \n"); //print(" \n"); print(" \n"); print("
\n"); print("
$mysqltools_dateselect3\n"); print(" \n"); print(" \n"); print(" \n"); print("
\n"); print("\n"); if($id==1) { print(" "); print(" "); print(" "); // print("
$str"); print(" "); } if($id==2) { print("
$str"); print(" "); } if($id==3) { print("
$str"); print(" $mysqltools_dateselect4:"); print("
$mysqltools_dateselect5"); print(" "); print(" "); print("
$mysqltools_dateselect6"); print(" "); } print("
\n"); print("
\n"); //print("\n"); } function DateSelect($id,$str) { global $LANG; $lang="./lang/lang.$LANG"; require($lang); $year=strftime("%Y"); $mon=strftime("%m"); $day=strftime("%d"); print("\n"); print(" \n"); print("
\n"); print("
\n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print("
$mysqltools_dateselect1\n"); print(" \n"); print(" \n"); print(" \n"); print(" \n"); print("
\n"); print("
$mysqltools_dateselect3\n"); print(" \n"); print(" \n"); print(" \n"); print("
\n"); print("\n"); if($id==1) { print(" "); print(" "); print(" "); // print("
$str"); print(" "); } if($id==2) { print("
$str"); print(" "); } if($id==3) { print("
$str"); print(" $mysqltools_dateselect4:"); print("
$mysqltools_dateselect5"); print(" "); print(" "); print("
$mysqltools_dateselect6"); print(" "); } print("
\n"); print("
\n"); //print("\n"); } function ATableCell($data,$url) { //print("
"); print(""); print("$data"); print(""); print(" $data "); print(" $data "); print(" $data "); print(" $data "); print(" $data 
\n"); print("\n"); print("
\n"); print("ICONSET/$imgname\" align=\"RIGHT\" valign=\"middle\" >\n"); print("\n"); print("

$text

\n"); print("
\n"); print("\n"); print("
\n"); } function TempName() { // $str=tempnam("",""); // unlink($str); // $str=strtr($str,"/","0"); $str=strtok(uniqid(""),"."); return($str); } function FormattedString($size) { $count=0; $newsize=""; $len=strlen(trim($size)); for($i=$len-1;$i>-1;$i--) { $newsize=sprintf("%s%s",substr($size,$i,1),$newsize); $count++; if($count==3) { $newsize=sprintf("%s%s"," ",$newsize); $count=0; } } return($newsize); } function PrintFormattedSize($size) { global $SAMSConf; $kbsize=$SAMSConf->KBSIZE; $gsize=floor($size/($kbsize*$kbsize*$kbsize)); $ostatok=$size-$gsize*$kbsize*$kbsize*$kbsize; $msize=floor($ostatok/($kbsize*$kbsize)); $ostatok=$size-$gsize*$kbsize*$kbsize*$kbsize-$msize*$kbsize*$kbsize; $ksize=floor($ostatok/$kbsize); if($msize<10&&$gsize>0) $msize="0$msize"; if($msize<100&&$gsize>0) $msize="0$msize"; if($ksize<10&&$msize>0) $ksize="0$ksize"; if($ksize<100&&$msize>0) $ksize="0$ksize"; print(" "); if($gsize>0) print("$gsize Gb "); if($gsize>0||$msize>0) print("$msize Mb"); print(" $ksize kb\n"); } function ReturnDate($string) { $newstring=sprintf("%s.%s.%s",substr($string,8,2),substr($string,5,2),substr($string,0,4)); return($newstring); } ?>