enhanced file download handling to consume less memory

This commit is contained in:
hyung-hwan 2010-04-11 14:30:49 +00:00
parent bf8c654957
commit b41a102353
13 changed files with 216 additions and 100 deletions

View File

@ -29,6 +29,9 @@ ldap_server_port = "389"
ldap_server_protocol_version = "3" ldap_server_protocol_version = "3"
ldap_userid_format = "${userid}" ldap_userid_format = "${userid}"
ldap_password_format = "${password}" ldap_password_format = "${password}"
ldap_mail_attribute_name = ""
ldap_admin_binddn = ""
ldap_admin_password = ""
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; default langage to use. set it to 'auto' to detect it automatically. ; default langage to use. set it to 'auto' to detect it automatically.

View File

@ -20,7 +20,6 @@ class API extends Controller
if (!isset($projectid) || !isset($userid)) return 'NO'; if (!isset($projectid) || !isset($userid)) return 'NO';
// TODO: access control - may allow localhost only
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
print ($this->projects->projectHasMember ($projectid, $userid) === FALSE)? 'NO': 'YES'; print ($this->projects->projectHasMember ($projectid, $userid) === FALSE)? 'NO': 'YES';
} }
@ -31,7 +30,6 @@ class API extends Controller
if (!isset($projectid) || !isset($userid)) return 'NO'; if (!isset($projectid) || !isset($userid)) return 'NO';
// TODO: access control - may allow localhost only
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
print ($this->projects->projectIsOwnedBy ($projectid, $userid) === FALSE)? 'NO': 'YES'; print ($this->projects->projectIsOwnedBy ($projectid, $userid) === FALSE)? 'NO': 'YES';
} }
@ -42,9 +40,18 @@ class API extends Controller
if (!isset($repo) || !isset($rev)) return; if (!isset($repo) || !isset($rev)) return;
// TODO: access control - may allow localhost only
$this->load->model ('LogModel', 'logs'); $this->load->model ('LogModel', 'logs');
$this->logs->writeCodeCommit ($type, $repo, $rev, ''); $this->logs->writeCodeCommit ($type, $repo, $rev, '');
/*
$this->load->library ('email');
$this->email->from ('xxxx');
$this->email->to ('xxxx');
$this->email->subject ('xxxx');
$this->email->message ('xxxx');
$this->email->send ();
*/
} }
} }

View File

@ -153,6 +153,24 @@ class File extends Controller
} }
else else
{ {
$path = CODEPOT_FILE_DIR . '/' . $file->encname;
$mtime = @filemtime ($path);
if ($mtime === FALSE) $mtime = time();
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $mtime) . " GMT");
//header("Expires: 0");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename={$name}");
header("Content-Transfer-Encoding: binary");
flush ();
$x = @readfile($path);
if ($x === FALSE)
{
$data['project'] = $project;
$data['message'] = "CANNOT GET FILE - {$file->name}";
$this->load->view ($this->VIEW_ERROR, $data);
}
/*
$this->load->helper('download'); $this->load->helper('download');
$path = CODEPOT_FILE_DIR . '/' . $file->encname; $path = CODEPOT_FILE_DIR . '/' . $file->encname;
$data = @file_get_contents ($path); $data = @file_get_contents ($path);
@ -166,6 +184,7 @@ class File extends Controller
{ {
force_download ($name, $data); force_download ($name, $data);
} }
*/
} }
} }
} }

View File

@ -34,10 +34,78 @@ class LdapLoginModel extends LoginModel
return FALSE; return FALSE;
} }
$email = '';
if (CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME != '')
{
$filter = '(' . CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME . '=*)';
$r = @ldap_search ($ldap, $f_userid, $filter, array(CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME));
if ($r !== FALSE)
{
$e = @ldap_get_entries($ldap, $r);
if ($e !== FALSE && count($e) > 0 &&
array_key_exists(CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME, $e[0]))
{
$email = $e[0][CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME][0];
}
}
}
@ldap_unbind ($bind); @ldap_unbind ($bind);
@ldap_close ($ldap); @ldap_close ($ldap);
return parent::authenticate ($userid, $password); return parent::authenticate ($userid, $password, $email);
}
function queryUserInfo ($userid)
{
$ldap = @ldap_connect (
CODEPOT_LDAP_SERVER_HOST, CODEPOT_LDAP_SERVER_PORT);
if ($ldap === FALSE)
{
$this->setErrorMessage ("Can't connect to LDAP server");
return FALSE;
}
if (CODEPOT_LDAP_SERVER_PROTOCOL_VERSION !== FALSE)
{
ldap_set_option ($ldap, LDAP_OPT_PROTOCOL_VERSION, CODEPOT_LDAP_SERVER_PROTOCOL_VERSION);
}
$bind = @ldap_bind ($ldap, CODEPOT_LDAP_ADMIN_BINDDN, CODEPOT_LDAP_ADMIN_PASSWORD);
if ($bind === FALSE)
{
$this->setErrorMessage (ldap_error ($ldap));
ldap_close ($ldap);
return FALSE;
}
$f_userid = $this->formatString (CODEPOT_LDAP_USERID_FORMAT, $userid, '');
$email = '';
if (CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME != '')
{
$filter = '(' . CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME . '=*)';
$r = @ldap_search ($ldap, $f_userid, $filter, array(CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME));
if ($r !== FALSE)
{
$e = @ldap_get_entries($ldap, $r);
if ($e !== FALSE && count($e) > 0 &&
array_key_exists(CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME, $e[0]))
{
$email = $e[0][CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME][0];
}
}
}
@ldap_unbind ($bind);
@ldap_close ($ldap);
$user['id'] = $userid;
$user['email'] = $email;
return $user;
} }
} }

View File

@ -22,6 +22,7 @@ class LoginModel extends Model
if ($server1 != $server2) if ($server1 != $server2)
{ {
$userid = ''; $userid = '';
$email = '';
$issysadmin = FALSE; $issysadmin = FALSE;
} }
else else
@ -29,17 +30,21 @@ class LoginModel extends Model
$userid = $this->session->userdata('userid'); $userid = $this->session->userdata('userid');
if ($userid === NULL) $userid = ''; if ($userid === NULL) $userid = '';
$email = $this->session->userdata('email');
if ($email === NULL) $email = '';
$issysadmin = $this->session->userdata('sysadmin?'); $issysadmin = $this->session->userdata('sysadmin?');
if ($issysadmin === NULL) $issysadmin = FALSE; if ($issysadmin === NULL) $issysadmin = FALSE;
} }
return array ( return array (
'id' => $userid, 'id' => $userid,
'email' => $email,
'sysadmin?' => $issysadmin 'sysadmin?' => $issysadmin
); );
} }
function authenticate ($userid, $password) function authenticate ($userid, $password, $email = '')
{ {
$server = $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT']; $server = $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'];
@ -58,9 +63,11 @@ class LoginModel extends Model
array ( array (
'userid' => $userid, 'userid' => $userid,
'server' => $server, 'server' => $server,
'email' => $email,
'sysadmin?' => $sysadmin 'sysadmin?' => $sysadmin
) )
); );
return TRUE; return TRUE;
} }

View File

@ -3,7 +3,7 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" rel="stylesheet" href="<?=base_url()?>/css/common.css" /> <link type="text/css" rel="stylesheet" href="<?=base_url()?>/css/common.css" />
<link type="text/css" rel="stylesheet" href="<?=base_url()?>/css/project.css" /> <link type="text/css" rel="stylesheet" href="<?=base_url()?>/css/log.css" />
<?php if ($login['sysadmin?'] && isset($site)): ?> <?php if ($login['sysadmin?'] && isset($site)): ?>

View File

@ -1,14 +1,16 @@
<?php <?php
function show_taskbar ($con, $loginid, $issysadmin) function show_taskbar ($con, $login)
{ {
print '<div class="taskbar">'; print '<div class="taskbar">';
print '<div class="boxb">'; print '<div class="boxb">';
if (isset($loginid) && $loginid != '') if (isset($login['id']) && $login['id'] != '')
{ {
print anchor ('user/home', htmlspecialchars($loginid)); $title = (isset($login['email']) && $login['email'] != '')?
('title=' . htmlspecialchars($login['email'])): '';
print anchor ('user/home', htmlspecialchars($login['id']), $title);
$hex = $con->converter->AsciiToHex (current_url()); $hex = $con->converter->AsciiToHex (current_url());
print anchor ("main/signout/{$hex}", $con->lang->line('Sign out')); print anchor ("main/signout/{$hex}", $con->lang->line('Sign out'));
@ -39,14 +41,14 @@ function show_taskbar ($con, $loginid, $issysadmin)
print '<div class="boxa">'; print '<div class="boxa">';
print anchor ('site/home', $con->lang->line('Home')); print anchor ('site/home', $con->lang->line('Home'));
print anchor ('project/catalog', $con->lang->line('Projects')); print anchor ('project/catalog', $con->lang->line('Projects'));
if ($issysadmin) if ($login['sysadmin?'])
print anchor ('site/catalog', $con->lang->line('Administration')); print anchor ('site/catalog', $con->lang->line('Administration'));
print '</div>'; print '</div>';
print '</div>'; print '</div>';
} }
show_taskbar ($this, $login['id'], $login['sysadmin?']); show_taskbar ($this, $login);
?> ?>

View File

@ -46,6 +46,9 @@ function load_ini ($file)
array ('ldap_server_protocol_version', 'integer', 3), array ('ldap_server_protocol_version', 'integer', 3),
array ('ldap_userid_format', 'string', '${userid}'), array ('ldap_userid_format', 'string', '${userid}'),
array ('ldap_password_format', 'string', '${password}'), array ('ldap_password_format', 'string', '${password}'),
array ('ldap_mail_attribute_name', 'string', ''),
array ('ldap_admin_binddn', 'string', ''),
array ('ldap_admin_password', 'string', ''),
array ('svnrepo_dir', 'string', CODEPOT_DEPOT_DIR.'/svnrepo'), array ('svnrepo_dir', 'string', CODEPOT_DEPOT_DIR.'/svnrepo'),
array ('file_dir', 'string', CODEPOT_DEPOT_DIR.'/files'), array ('file_dir', 'string', CODEPOT_DEPOT_DIR.'/files'),

View File

@ -7,6 +7,7 @@ www_DATA = \
file.css \ file.css \
issue.css \ issue.css \
jquery-ui.css \ jquery-ui.css \
log.css \
project.css \ project.css \
site.css \ site.css \
user.css \ user.css \

View File

@ -212,6 +212,7 @@ www_DATA = \
file.css \ file.css \
issue.css \ issue.css \
jquery-ui.css \ jquery-ui.css \
log.css \
project.css \ project.css \
site.css \ site.css \
user.css \ user.css \

72
codepot/src/css/log.css Normal file
View File

@ -0,0 +1,72 @@
/*
* This file contains specific IDs for furthur customization.
*/
/*-----------------------------------------------
* log view
*-----------------------------------------------*/
#log_mainarea_result {
overflow: auto;
}
#log_mainarea_result_table {
/*border-collapse: collapse;*/
width: 100%;
}
#log_mainarea_result_table a {
text-decoration: none;
}
#log_mainarea_result_table td {
vertical-align: top;
white-space: nowrap;
padding-top: 3px;
padding-bottom: 3px;
}
#log_mainarea_result_table td.break {
font-size: 0.5em;
}
#log_mainarea_result_table td.date {
font-weight: bold;
background-color: #bbccef;
}
#log_mainarea_result_table td.time {
width: 1px;
color: #777777;
}
#log_mainarea_result_table td.projectid {
width: 1px;
}
#log_mainarea_result_table td.object {
width: 1px;
}
#log_mainarea_result_table td.details {
white-space: normal;
}
#log_mainarea_result_table td.details .description {
/*font-style: italic;*/
}
#log_mainarea_result_table td.details pre.message {
border: 0;
margin: 1px;
background-color: inherit;
white-space: -moz-pre-wrap;
white-space: -o-pre-wrap;
white-space: pre-wrap;
}
#log_mainarea_result_table td.pages {
padding-top: 1em;
text-align: center;
font-weight: bold;
}

View File

@ -2,72 +2,6 @@
* This file contains specific IDs for furthur customization. * This file contains specific IDs for furthur customization.
*/ */
/*-----------------------------------------------
* log view
*-----------------------------------------------*/
#log_mainarea_result {
overflow: auto;
}
#log_mainarea_result_table {
//border-collapse: collapse;
width: 100%;
}
#log_mainarea_result_table a {
text-decoration: none;
}
#log_mainarea_result_table td {
vertical-align: top;
white-space: nowrap;
padding-top: 3px;
padding-bottom: 3px;
}
#log_mainarea_result_table td.break {
font-size: 0.5em;
}
#log_mainarea_result_table td.date {
font-weight: bold;
background-color: #bbccef;
}
#log_mainarea_result_table td.time {
width: 1px;
color: #777777;
}
#log_mainarea_result_table td.projectid {
width: 1px;
}
#log_mainarea_result_table td.object {
width: 1px;
}
#log_mainarea_result_table td.details {
white-space: normal;
}
#log_mainarea_result_table td.details .description {
/*font-style: italic;*/
}
#log_mainarea_result_table td.details pre.message {
border: 0;
margin: 1px;
background-color: inherit;
white-space: pre-wrap;
}
#log_mainarea_result_table td.pages {
padding-top: 1em;
text-align: center;
font-weight: bold;
}
/*----------------------------------------------- /*-----------------------------------------------
* project home view * project home view
*-----------------------------------------------*/ *-----------------------------------------------*/
@ -79,33 +13,32 @@
background-color: #bbccef; background-color: #bbccef;
} }
#project_home_mainarea_sidebar_log_table tr.odd td { #project_home_mainarea_sidebar_log_table tr.odd td.date {
width: 1%;
white-space: nowrap; white-space: nowrap;
} }
#project_home_mainarea_sidebar_log_table tr.odd td.date { #project_home_mainarea_sidebar_log_table tr.odd td.object {
width: 1px; white-space: nowrap;
} }
#project_home_mainarea_sidebar_log_table tr.even { #project_home_mainarea_sidebar_log_table tr.even {
background-color: inherit; background-color: inherit;
} }
#project_home_mainarea_sidebar_log_table tr.even .description { #project_home_mainarea_sidebar_log_table tr.even td.details .description {
font-style: italic; font-style: italic;
} }
#project_home_mainarea_sidebar_log_table tr.even pre.message { #project_home_mainarea_sidebar_log_table tr.even td.details pre.message {
border: 0; border: 0;
margin: 1px; margin: 1px;
background-color: inherit; background-color: inherit;
white-space: -moz-pre-wrap;
white-space: -o-pre-wrap;
white-space: pre-wrap; white-space: pre-wrap;
} }
#project_home_mainarea_sidebar_log_table td.date {
width: 1px;
}
/*----------------------------------------------- /*-----------------------------------------------
* project file edit view * project file edit view
*-----------------------------------------------*/ *-----------------------------------------------*/

View File

@ -13,37 +13,37 @@
background-color: #bbccef; background-color: #bbccef;
} }
#site_home_mainarea_sidebar_log_table tr.odd td { #site_home_mainarea_sidebar_log_table tr.odd td.date {
width: 1%;
white-space: nowrap; white-space: nowrap;
} }
#site_home_mainarea_sidebar_log_table tr.odd td.date { #site_home_mainarea_sidebar_log_table tr.odd td.project {
width: 1px; width: 1%;
white-space: nowrap;
}
#site_home_mainarea_sidebar_log_table tr.odd td.object {
white-space: nowrap;
} }
#site_home_mainarea_sidebar_log_table tr.even { #site_home_mainarea_sidebar_log_table tr.even {
background-color: inherit; background-color: inherit;
} }
#site_home_mainarea_sidebar_log_table tr.even .description { #site_home_mainarea_sidebar_log_table tr.even td.details .description {
font-style: italic; font-style: italic;
} }
#site_home_mainarea_sidebar_log_table tr.even pre.message { #site_home_mainarea_sidebar_log_table tr.even td.details pre.message {
border: 0; border: 0;
margin: 1px; margin: 1px;
background-color: inherit; background-color: inherit;
white-space: -moz-pre-wrap;
white-space: -o-pre-wrap;
white-space: pre-wrap; white-space: pre-wrap;
} }
#site_home_mainarea_sidebar_log_table td.date {
width: 1px;
}
#site_home_mainarea_sidebar_log_table td.project {
width: 1px;
}
/*----------------------------------------------- /*-----------------------------------------------
* site edit view * site edit view
*-----------------------------------------------*/ *-----------------------------------------------*/