Host = $default->owl_db_host;
$this->Database = $default->owl_db_name;
$this->User = $default->owl_db_user;
$this->Password = $default->owl_db_pass;
}
// END wes changes
/**
* Create a query from the provided paramaters. The ID column
* is seleted by default
*
* @param $sTableName Table to query
* @param $aColumns Columns in table
* @param $sWhereClause Where clause (optional)
* @param $sOrderByClause Order by clause (optional)
*/
function createSQLQuery($sTableName, $aColumns, $sWhereClause = null, $sOrderByClause = null) {
$this->sLastTableName = $sTableName;
$this->sLastWhereCluase = $sWhereClause;
$this->sLastOrderByClause = $sOrderByClause;
$this->sQuery = "SELECT ID, ";
for( $i = 0; $i < count($aColumns) - 1; $i++ ) {
$this->sQuery = $this->sQuery . $aColumns[$i] . ",";
}
$this->sQuery .= $aColumns[count($aColumns) - 1] . " ";
$this->sQuery .= "FROM " . $sTableName . " ";
if (isset($sWhereClause)) {
$this->sQuery .= "WHERE " . $sWhereClause . " ";
}
if (isset($sOrderByClause)) {
$this->sQuery .= "ORDER BY " . $sOrderByClause . " ";
}
$this->query($this->sQuery);
}
/**
Create a query from the provided paramaters, specifying a limit and an offset.
The ID column is selected by default
@param $sTableName Table to query
@param $aColumns Columns in table
@param $iOffset Offset
@param $iLimit Limit
@param $sWhereClause Where clause (optional)
@param $sOrderByClause Order by clause (optional)
*/
function createSQLQueryWithOffset($sTableName, $aColumns, $iOffset, $iLimit, $sWhereClause = null, $sOrderByClause = null) {
$this->sLastTableName = $sTableName;
$this->sLastWhereCluase = $sWhereClause;
$this->sLastOrderByClause = $sOrderByClause;
$this->sQuery = "SELECT ID, ";
for( $i = 0; $i < count($aColumns) - 1; $i++ ) {
$this->sQuery = $this->sQuery . $aColumns[$i] . ",";
}
$this->sQuery .= $aColumns[count($aColumns) - 1] . " ";
$this->sQuery .= "FROM " . $sTableName . " ";
if (isset($sWhereClause)) {
$this->sQuery .= "WHERE " . $sWhereClause . " ";
}
if (isset($sOrderByClause)) {
$this->sQuery .= "ORDER BY " . $sOrderByClause . " ";
}
$this->sQuery .= "LIMIT " . $iOffset . ", " . $iLimit;
$this->query($this->sQuery);
}
/**
* Get the result count for the previously executed query. Meant
* to be used in conjuction with createSSQLQueryWithOffset so that
* the total number of results can be calculated
*
* @return int row count
*/
function & getLastQueryResultCount() {
if (isset($this->sLastTableName)) {
$sCountResultQuery = "SELECT COUNT(*) AS ResultCount FROM " . $this->sLastTableName;
if (isset($this->sLastWhereClause)) {
sCountResultQuery . " WHERE " . $this->sLastWhereClause;
}
$this->query($sCountResultQuery);
$this->next_record();
return $this->f("ResultCount");
} else {
return 0;
}
}
/**
* Execute the query and return the results
*
* @returns Results of query
*/
function & getQueryResults() {
$result = null;
if (isset($this->sQuery)) {
$result = $this->query($this->sQuery);
}
return $result;
}
/**
* Display any database errors encountered
*/
function haltmsg($msg) {
printf("Database error: %s
\n", $msg);
printf("SQL Error: %s (%s)
\n",$this->Errno, $this->Error);
}
}
/**
* class Owl_Session
*
* This class is used for opening and closing sessions
*
* @version v 1.1.1.1 2002/12/04
* @author michael
* @package Owl
*/
class Owl_Session {
var $sessid;
var $sessuid;
var $sessdata;
//------------------------------------------------------------
/**
* Function Open_Session($sessid=0, $sessuid=0)
*
* Opens a session
*
* @param $sessid
* The Session id
* @param ssessuid
* The user session id
* @return $this
* Return the session
*
*/
//------------------------------------------------------------
// Usable
function Open_Session($sessid=0, $sessuid=0) {
global $default;
$this->sessid = $sessid;
$this->sessuid = $sessuid;
// if there is no user loged in, then create a session for them
if($sessid == "0")
{
$current = time();
$random = $this->sessuid . $current;
$this->sessid = md5($random);
$sql = new Owl_DB;
if(getenv("HTTP_CLIENT_IP"))
{
$ip = getenv("HTTP_CLIENT_IP");
}
elseif(getenv("HTTP_X_FORWARDED_FOR"))
{
$forwardedip = getenv("HTTP_X_FORWARDED_FOR");
list($ip,$ip2,$ip3,$ip4)= split (",", $forwardedip);
}
else
{
$ip = getenv("REMOTE_ADDR");
}
//$result = $sql->query("insert into active_sessions values ('$this->sessid', '$this->sessuid', '$current', '$ip')");
$result = $sql->query("insert into $default->owl_sessions_table values ('$this->sessid', '$this->sessuid', '$current', '$ip')");
if(!'result')
{
die("$lang_err_sess_write");
}
}
// else we have a session id, try to validate it...
$sql = new Owl_DB;
$sql->query("select * from $default->owl_sessions_table where sessid = '$this->sessid'");
// any matching session ids?
$numrows = $sql->num_rows($sql);
if(!$numrows) die("$lang_err_sess_notvalid");
// return if we are a.o.k.
while($sql->next_record()) {
$this->sessdata["sessid"] = $sql->f("sessid");
}
return $this;
}
}
//------------------------------------------------------------
/**
* Function notify_users($groupid, $flag, $parent, $filename, $title, $desc, $type)
*
* Used to notify users
*
* @param $groupid
* The Id of the group
* @param $flag
* The relvant flag
* @param $filename
* The relevant filename
* @param $title
* The relevant title
* @param $desc
* The description
* @param $type
* the Relevant type
*/
//-------------------------------------------------------------
// Semi-Usable Some Interface based code
function notify_users($groupid, $flag, $parent, $filename, $title, $desc, $type)
{
global $default;
global $lang_notif_subject_new, $lang_notif_subject_upd, $lang_notif_msg;
global $lang_title, $lang_description;
$sql = new Owl_DB;
// BEGIN BUG 548994
// get the fileid
$path = find_path($parent);
$sql->query("select id from $default->owl_files_table where filename='$filename' AND parent='$parent'");
$sql->next_record();
$fileid = $sql->f("id");
// END BUG 548994 More Below
$sql->query("select distinct id, email,language,attachfile from $default->owl_users_table as u, $default->owl_users_grpmem_table as m where notify = 1 and (u.groupid = $groupid or m.groupid = $groupid)");
// loop through records
while($sql->next_record())
{
// BEGIN BUG 548994
// check authentication rights
if ( check_auth($fileid, "file_download", $sql->f(id)) == 1 )
{
// END BUG 548994 More Below
$newpath = ereg_replace(" ","%20",$path);
$newfilename = ereg_replace(" ","%20",$filename);
$DefUserLang = $sql->f("language");
require("$default->owl_fs_root/locale/$DefUserLang/language.inc");
$r=preg_split("(\;|\,)",$sql->f("email"));
reset ($r);
while (list ($occ, $email) = each ($r))
{
$mail = new phpmailer();
// Create a temporary session id, the user
// will need to get to this file before
// the default session timeout
$session = new Owl_Session;
$uid = $session->Open_Session(0,$sql->f("id"));
$tempsess = $uid->sessdata["sessid"];
// if flag set to 0
if ( $flag == 0 ) {
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "$default->owl_email_server"; // specify main and backup server
$mail->From = "$default->owl_email_from";
$mail->FromName = "$default->owl_email_fromname";
$mail->AddAddress($email);
$mail->AddReplyTo("$default->owl_email_replyto", "OWL Intranet");
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "$lang_notif_subject_new";
// as long as its not a url
if ($type != "url")
{
// if attachfile is true
if ($sql->f("attachfile") == 1)
{
$mail->Body = "$lang_notif_msg
" . "$lang_title: $title" . "
$lang_description: $desc";
$mail->altBody = "$lang_notif_msg\n\n" . "$lang_title: $title" . "\n\n $lang_description: $desc";
// use file system
if (!$default->owl_use_fs)
{
//check if file exits
if (file_exists("$default->owl_FileDir/$filename"))
{
unlink("$default->owl_FileDir/$filename");
}
$file = fopen("$default->owl_FileDir$filename", 'wb');
$getfile = new Owl_DB;
$getfile->query("select data,compressed from $default->owl_files_data_table where id='$fileid'");
while ($getfile->next_record())
{
//check if compressed ..and uncompress it
if ($getfile->f("compressed")) {
$tmpfile = $default->owl_FileDir . "owltmp.$fileid.gz";
$uncomptmpfile = $default->owl_FileDir . "owltmp.$fileid";
if (file_exists($tmpfile)) unlink($tmpfile);
$fp=fopen($tmpfile,"w");
fwrite($fp, $getfile->f("data"));
fclose($fp);
system($default->gzip_path . " -df $tmpfile");
$fsize = filesize($uncomptmpfile);
$fd = fopen($uncomptmpfile, 'rb');
$filedata = fread($fd, $fsize);
fclose($fd);
fwrite($file, $filedata);
unlink($uncomptmpfile);
}
else
{ // otherwise just write the file
fwrite($file, $getfile->f("data"));
}
}
fclose($file);
// add a mail attachment
$mail->AddAttachment("$default->owl_FileDir$newfilename");
} else
{
$mail->AddAttachment("$default->owl_FileDir/$newpath/$newfilename");
}
}
else
{ // set up mail body
$mail->Body = "$lang_notif_msg
" . "$lang_title: $title" . "
URL: $default->owl_notify_link" . "browse.php?sess=$tempsess&parent=$parent&expand=1&fileid=$fileid" . "
$lang_description: $desc";
$mail->altBody = "$lang_notif_msg\n\n" . "$lang_title: $title" . "\n\n $lang_description: $desc";
}
}
else
{
$mail->Body = "URL: $newfilename
$lang_notif_msg
" . "$lang_title: $title" . "
$lang_description: $desc";
$mail->altBody = "URL: $newfilename \n\n$lang_notif_msg\n\n" . "$lang_title: $title" . "\n\n $lang_description: $desc";
}
}
else
// set up mailer
{
$mail = new phpmailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "$default->owl_email_server"; // specify main and backup server
$mail->From = "$default->owl_email_from";
$mail->FromName = "$default->owl_email_fromname";
$mail->AddAddress($email);
$mail->AddReplyTo("$default->owl_email_replyto", "OWL Intranet");
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "$lang_notif_subject_upd";
// if type not a url
if ($type != "url")
{
// if attachfile is true..go through process of attaching file..simarly to previous
if ($sql->f("attachfile") == 1)
{
$mail->Body = "$lang_notif_msg
" . "$lang_title: $title" . "
$lang_description: $desc";
$mail->altBody = "$lang_notif_msg\n\n" . "$lang_title: $title" . "\n\n $lang_description: $desc";
if (!$default->owl_use_fs)
{
// check existence of file
if (file_exists("$default->owl_FileDir/$filename"))
{
unlink("$default->owl_FileDir/$filename");
}
$file = fopen("$default->owl_FileDir$filename", 'wb');
$getfile = new Owl_DB;
$getfile->query("select data,compressed from $default->owl_files_data_table where id='$fileid'");
// get file check if compressed, if so uncompress
// otherwise write away
while ($getfile->next_record())
{
if ($getfile->f("compressed")) {
$tmpfile = $default->owl_FileDir . "owltmp.$fileid.gz";
$uncomptmpfile = $default->owl_FileDir . "owltmp.$fileid";
if (file_exists($tmpfile)) unlink($tmpfile);
$fp=fopen($tmpfile,"w");
fwrite($fp, $getfile->f("data"));
fclose($fp);
system($default->gzip_path . " -df $tmpfile");
$fsize = filesize($uncomptmpfile);
$fd = fopen($uncomptmpfile, 'rb');
$filedata = fread($fd, $fsize);
fclose($fd);
fwrite($file, $filedata);
unlink($uncomptmpfile);
}
else
{
fwrite($file, $getfile->f("data"));
}
}
fclose($file);
$mail->AddAttachment("$default->owl_FileDir$newfilename");
}
else
{
$mail->AddAttachment("$default->owl_FileDir/$newpath/$newfilename");
}
}
else
{
$mail->Body = "$lang_notif_msg
" . "$lang_title: $title" . "
URL: $default->owl_notify_link" . "browse.php?sess=$tempsess&parent=$parent&expand=1&fileid=$fileid" . "
$lang_description: $desc";
$mail->altBody = "$lang_notif_msg\n\n" . "$lang_title: $title" . "\n\n $lang_description: $desc";
}
}
else
{
$mail->Body = "URL: $newfilename
$lang_notif_msg
" . "$lang_title: $title" . "
$lang_description: $desc";
$mail->altBody = "URL: $newfilename \n\n$lang_notif_msg\n\n" . "$lang_title: $title" . "\n\n $lang_description: $desc";
}
}
// send the email
$mail->Send();
if (!$default->owl_use_fs && $sql->f("attachfile") == 1)
{
unlink("$default->owl_FileDir$newfilename");
}
}
}
// BEGIN BUG 548994
}
// END BUG 548994
}
//------------------------------------------------------------
/**
* Function verify_login($username, $password)
*
* Used to verify a users login name and password
*
* @param $username
* The username to verfiy
* @param $password
* The password to verify
*/
//-------------------------------------------------------------
// Usable
function verify_login($username, $password)
{
global $default;
$sql = new Owl_DB;
$query = "select * from $default->owl_users_table where username = '$username' and password = '" . md5($password) . "'";
$sql->query("select * from $default->owl_users_table where username = '$username' and password = '" . md5($password) . "'");
$numrows = $sql->num_rows($sql);
// Bozz Begin added Password Encryption above, but for now
// I will allow admin to use non crypted password untile he
// upgrades all users
if ($numrows == "1")
{
while($sql->next_record()) {
if ( $sql->f("disabled") == 1 )
$verified["bit"] = 2;
else
$verified["bit"] = 1;
$verified["user"] = $sql->f("username");
$verified["uid"] = $sql->f("id");
$verified["group"] = $sql->f("groupid");
$maxsessions = $sql->f("maxsessions") + 1;
}
}
// Remove this else in a future version
else {
// username admin check password
if ($username == "admin")
{
$sql->query("select * from $default->owl_users_table where username = '$username' and password = '$password'");
$numrows = $sql->num_rows($sql);
if ($numrows == "1")
{
while($sql->next_record())
{
$verified["bit"] = 1;
$verified["user"] = $sql->f("username");
$verified["uid"] = $sql->f("id");
$verified["group"] = $sql->f("groupid");
$maxsessions = $sql->f("maxsessions") + 1;
}
}
}
}
// remove stale sessions from the database for the user
// that is signing on.
//
$time = time() - $default->owl_timeout;
$sql = new Owl_DB;
$sql->query("delete from $default->owl_sessions_table where uid = '".$verified["uid"]."' and lastused <= $time ");
// Check if Maxsessions has been reached
//
$sql = new Owl_DB;
$sql->query("select * from $default->owl_sessions_table where uid = '".$verified["uid"]."'");
if ($sql->num_rows($sql) >= $maxsessions && $verified["bit"] != 0) {
if ( $verified["group"] == 0)
$verified["bit"] = 1;
else
$verified["bit"] = 3;
}
return $verified;
}
//------------------------------------------------------------
/**
* Function verify_session($username, $password)
*
* Used to verify a users session
*
* @param $username
* The username to check
* @param $password
* The password to check
*/
//-------------------------------------------------------------
// Usable
function verify_session($sess) {
getprefs();
global $default, $lang_sesstimeout, $lang_sessinuse, $lang_clicklogin;
$sess = ltrim($sess);
$verified["bit"] = 0;
$sql = new Owl_DB;
$sql->query("select * from $default->owl_sessions_table where sessid = '$sess'");
$numrows = $sql->num_rows($sql);
$time = time();
if ($numrows == "1")
{
while($sql->next_record())
{
if(getenv("HTTP_CLIENT_IP"))
{
$ip = getenv("HTTP_CLIENT_IP");
}
elseif(getenv("HTTP_X_FORWARDED_FOR"))
{
$forwardedip = getenv("HTTP_X_FORWARDED_FOR");
list($ip,$ip2,$ip3,$ip4)= split (",", $forwardedip);
}
else
{
$ip = getenv("REMOTE_ADDR");
}
if ($ip == $sql->f("ip"))
{
// if timeout not exceeded
if(($time - $sql->f("lastused")) <= $default->owl_timeout)
{
$verified["bit"] = 1;
$verified["userid"] = $sql->f("uid");
$sql->query("select * from $default->owl_users_table where id = '".$verified["userid"]."'");
while($sql->next_record()) $verified["groupid"] = $sql->f("groupid");
}
else
{
// Bozz Bug Fix begin
if (file_exists("./lib/header.inc"))
{
include("./lib/header.inc");
} else {
include("../lib/header.inc");
}
// Bozz Buf Fix End
print("
");
else
print("
");
exit();
}
} else {
// Bozz Bug Fix begin
if (file_exists("./lib/header.inc")) {
include("./lib/header.inc");
} else {
include("../lib/header.inc");
}
// Bozz Bug Fix End
print("| "); print("$lang_user: "); print(""); print uid_to_name($userid); print (""); print(" $lang_logout"); print(" | "); print(" ");
print(" |
");
}
if (($checked_out == 0) || ($checked_out == $userid)) {
// *****************************************************************************
// Don't Show the delete icon if the user doesn't have delete access to the file
// *****************************************************************************
if (check_auth($fid, "file_delete", $userid) == 1)
if ($url == "1")
print("\t
");
else
print("\t
");
// *****************************************************************************
// Don't Show the modify icon if the user doesn't have modify access to the file
// *****************************************************************************
if(check_auth($fid, "file_modify", $userid) == 1)
print("
");
// *****************************************************************************
// Don't Show the move modify icon if the user doesn't have move access to the file
// *****************************************************************************
if(check_auth($fid, "file_modify", $userid) == 1)
if ($url == "1")
print("
");
// *****************************************************************************
// Don't Show the file dowload icon if the user doesn't have download access to the file
// *****************************************************************************
if(check_auth($fid, "file_download", $userid) == 1)
if ($url != "1")
print("
");
}
// *****************************************************************************
// Don't Show the email icon if the user doesn't have access to email the file
// *****************************************************************************
if(check_auth($fid, "file_modify", $userid) == 1)
if ($url == "1")
print("
");
else
print("
");
// *****************************************************************************
// Don't Show the view icon if the user doesn't have download access to the file
// *****************************************************************************
if(check_auth($fid, "file_download", $userid) == 1)
if ($url != "1") {
$imgfiles = array("jpg","gif");
if ($ext != "" && preg_grep("/$ext/", $imgfiles)) {
print("
");
}
$htmlfiles = array("html","htm",xml);
if ($ext != "" && preg_grep("/$ext/", $htmlfiles)) {
print("
");
}
$txtfiles = array("txt","text","README", "readme", "sh", "c", "cpp", "php", "php3", "pl", "perl", "sql", "py");
if ($ext != "" && preg_grep("/$ext/", $txtfiles)) {
print("
");
}
if (substr(php_uname(), 0, 7) != "Windows") {
$zipfiles = array("tar.gz", "tgz", "tar", "gz");
if ($ext != "" && preg_grep("/$ext/", $zipfiles))
print("
");
}
}
}
};
//------------------------------------------------------------
/**
* Function printgroupperm($currentval, $namevariable, $printmessage, $type)
*
* Prints group permissions
*
* @param $currentval
* The current value
* @param $namevariable
* The name of the group
* @param $printmessage
* The message to be printed
* @param $type
* The type of group
*/
//-------------------------------------------------------------
// NOT Usable INTERFACE based
function printgroupperm($currentval, $namevariable, $printmessage, $type) {
global $default;
global $lang_geveryoneread, $lang_geveryonewrite, $lang_geveryonewrite_nod, $lang_ggroupread, $lang_ggroupwrite, $lang_ggroupwrite_nod, $lang_ggroupwrite_worldread, $lang_ggroupwrite_worldread_nod, $lang_gonlyyou;
global $lang_geveryoneread_ad, $lang_geveryonewrite_ad, $lang_geveryonewrite_ad_nod, $lang_ggroupread_ad, $lang_ggroupwrite_ad, $lang_ggroupwrite_ad_nod, $lang_ggroupwrite_worldread_ad, $lang_ggroupwrite_worldread_ad_nod, $lang_gonlyyou_ad;
$group_perm[0][0] = 50;
$group_perm[1][0] = 51;
$group_perm[2][0] = 52;
$group_perm[3][0] = 53;
$group_perm[4][0] = 54;
$group_perm[5][0] = 55;
$group_perm[6][0] = 56;
$group_perm[7][0] = 57;
$group_perm[8][0] = 58;
if ($type == "admin")
{
$group_perm[0][1] = "$lang_geveryoneread_ad";
$group_perm[1][1] = "$lang_geveryonewrite_ad";
$group_perm[2][1] = "$lang_ggroupread_ad";
$group_perm[3][1] = "$lang_ggroupwrite_ad";
$group_perm[4][1] = "$lang_gonlyyou_ad";
$group_perm[5][1] = "$lang_ggroupwrite_ad_nod";
$group_perm[6][1] = "$lang_geveryonewrite_ad_nod";
$group_perm[7][1] = "$lang_ggroupwrite_worldread_ad";
$group_perm[8][1] = "$lang_ggroupwrite_worldread_ad_nod";
}
else
{
$group_perm[0][1] = "$lang_geveryoneread";
$group_perm[1][1] = "$lang_geveryonewrite";
$group_perm[2][1] = "$lang_ggroupread";
$group_perm[3][1] = "$lang_ggroupwrite";
$group_perm[4][1] = "$lang_gonlyyou";
$group_perm[5][1] = "$lang_ggroupwrite_nod";
$group_perm[6][1] = "$lang_geveryonewrite_nod";
$group_perm[7][1] = "$lang_ggroupwrite_worldread";
$group_perm[8][1] = "$lang_ggroupwrite_worldread_nod";
}
print("
");
} else {
print("
");
}
exit;
} else {
$lastused = time();
$sql = new Owl_DB;
$sql->query("update $default->owl_sessions_table set lastused = '$lastused' where uid = '$userid'");
}
}
if (!$sess && !$loginname && !$login) {
if(!isset($fileid)) {
header("Location: " . $default->owl_root_url . "/index.php?login=1");
} else {
header("Location: " . $default->owl_root_url . "/index.php?login=1&fileid=$fileid&parent=$parent");
}
}
*/
?>