diff --git a/codepot/README b/codepot/README index 12db9c07..7a321036 100644 --- a/codepot/README +++ b/codepot/README @@ -14,6 +14,7 @@ UPGRADING FROM 0.2.0 mysql> ALTER TABLE user_settings CHANGE code_hide_details code_hide_metadata CHAR(1) NOT NULL; mysql> ALTER TABLE site ADD COLUMN(summary VARCHAR(255) NOT NULL); + mysql> RENAME TABLE user TO user_account; INSTALLATION ON CENTOS diff --git a/codepot/etc/codepot.ini.in b/codepot/etc/codepot.ini.in index c1ab8972..d1de0ea3 100644 --- a/codepot/etc/codepot.ini.in +++ b/codepot/etc/codepot.ini.in @@ -11,7 +11,34 @@ default_site_name = "@PACKAGE@" ;------------------------------------------------------------------------------ ; database settings ; -; database_driver: mysql for MySQL, postgre for PostgreSQL +; database_driver: mysql, mysqli, postgre, oci8 +; +; == MySQL == +; database_hostname = "localhost" +; database_port = "" +; database_username = "codepot" +; database_password = "codepot" +; database_name = "codepot" +; database_driver = "mysql" +; database_prefix = "" +; +; == PostgresSQL == +; database_hostname = "" +; database_port = "" +; database_username = "codepot" +; database_password = "codepot" +; database_name = "codepot" +; database_driver = "postgre" +; database_prefix = "" +; +; == Oracle +; database_hostname = "(DESCRIPTION=(ADDRESS=(COMMUNITY=tcp.world)(PROTOCOL=TCP)(HOST=192.168.1.126)(PORT=1521))(CONNECT_DATA=(SID=ORCL)))" +; database_port = "" +; database_username = "scott" +; database_password = "tiger" +; database_name = "" +; database_driver = "oci8" +; database_prefix = "cpot_" ;------------------------------------------------------------------------------ database_hostname = "localhost" database_port = "" diff --git a/codepot/etc/codepot.mysql b/codepot/etc/codepot.mysql index 670c8e09..5c04914d 100644 --- a/codepot/etc/codepot.mysql +++ b/codepot/etc/codepot.mysql @@ -125,7 +125,7 @@ CREATE TABLE issue_change ( status VARCHAR(32) NOT NULL, owner VARCHAR(255) NOT NULL, priority VARCHAR(32) NOT NULL, - comment TEXT NOT NULL, + comment TEXT NOT NULL, updatedon DATETIME NOT NULL, updatedby VARCHAR(32) NOT NULL, @@ -183,7 +183,7 @@ CREATE TABLE code_review ( projectid VARCHAR(32) NOT NULL, rev BIGINT NOT NULL, sno BIGINT NOT NULL, - comment TEXT NOT NULL, + comment TEXT NOT NULL, createdon DATETIME NOT NULL, createdby VARCHAR(32) NOT NULL, @@ -215,7 +215,7 @@ CREATE TABLE user_settings ( icon_name VARCHAR(255) UNIQUE NULL ) charset=utf8 engine=InnoDB; -CREATE TABLE user ( +CREATE TABLE user_account ( userid VARCHAR(32) PRIMARY KEY, passwd VARCHAR(255) NOT NULL, email VARCHAR(255), diff --git a/codepot/etc/codepot.oracle b/codepot/etc/codepot.oracle index 978d2bd1..ed3760fe 100644 --- a/codepot/etc/codepot.oracle +++ b/codepot/etc/codepot.oracle @@ -9,7 +9,7 @@ -- -- -- DROP SEQUENCE "cpot_log_id_seq"; --- DROP TABLE "cpot_user"; +-- DROP TABLE "cpot_user_account"; -- DROP TABLE "cpot_user_settings"; -- DROP TABLE "cpot_log"; -- DROP TABLE "cpot_code_review"; @@ -202,7 +202,7 @@ CREATE TABLE "cpot_user_settings" ( "icon_name" VARCHAR(255) UNIQUE NULL ); -CREATE TABLE "cpot_user" ( +CREATE TABLE "cpot_user_account" ( "userid" VARCHAR(32) PRIMARY KEY, "passwd" VARCHAR(255) NOT NULL, "email" VARCHAR(255), diff --git a/codepot/etc/codepot.pgsql b/codepot/etc/codepot.pgsql index 65f0afa4..652de29f 100644 --- a/codepot/etc/codepot.pgsql +++ b/codepot/etc/codepot.pgsql @@ -143,7 +143,7 @@ CREATE TABLE issue_change ( status VARCHAR(32) NOT NULL, owner VARCHAR(255) NOT NULL, priority VARCHAR(32) NOT NULL, - comment TEXT NOT NULL, + comment TEXT NOT NULL, updatedon TIMESTAMP NOT NULL, updatedby VARCHAR(32) NOT NULL, @@ -203,7 +203,7 @@ CREATE TABLE code_review ( projectid VARCHAR(32) NOT NULL, rev BIGINT NOT NULL, sno BIGINT NOT NULL, - comment TEXT NOT NULL, + comment TEXT NOT NULL, createdon TIMESTAMP NOT NULL, createdby VARCHAR(32) NOT NULL, @@ -236,7 +236,7 @@ CREATE TABLE user_settings ( icon_name VARCHAR(255) UNIQUE NULL ); -CREATE TABLE "user" ( +CREATE TABLE user_account ( userid VARCHAR(32) PRIMARY KEY, passwd VARCHAR(255) NOT NULL, email VARCHAR(255), diff --git a/codepot/etc/perl/Codepot/AccessHandler.pm b/codepot/etc/perl/Codepot/AccessHandler.pm index e00b450b..f566a85e 100644 --- a/codepot/etc/perl/Codepot/AccessHandler.pm +++ b/codepot/etc/perl/Codepot/AccessHandler.pm @@ -162,15 +162,9 @@ sub authenticate_ldap sub authenticate_database { - my ($dbh, $prefix, $userid, $password, $driver) = @_; + my ($dbh, $prefix, $userid, $password, $qc) = @_; - my $user_table_name = "${prefix}user"; - if ($driver eq 'postgre' && length($prefix) <= 0) - { - $user_table_name = '"user"'; - } - - my $query = $dbh->prepare ("SELECT userid,passwd FROM ${user_table_name} WHERE userid=? and enabled='Y'"); + my $query = $dbh->prepare ("SELECT ${qc}userid${qc},${qc}passwd${qc} FROM ${qc}${prefix}user_account${qc} WHERE ${qc}userid${qc}=? and ${qc}enabled${qc}='Y'"); if (!$query || !$query->execute ($userid)) { return (-1, $dbh->errstr()); @@ -201,15 +195,30 @@ sub open_database my $dbport = $cfg->{database_port}; if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; } + elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; } - my $dbstr = "DBI:$dbtype:database=$dbname;"; - if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } - if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + my $dbstr; + my $dbuser; + my $dbpass; + if ($dbtype eq 'Oracle') + { + $dbstr = "DBI:$dbtype:"; + $dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost; + $dbpass = ''; + } + else + { + $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + + $dbuser = $cfg->{database_username}; + $dbpass = $cfg->{database_password}; + } my $dbh = DBI->connect( - $dbstr, - $cfg->{database_username}, - $cfg->{database_password}, + $dbstr, $dbuser, $dbpass, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } ); @@ -224,9 +233,9 @@ sub close_database sub is_project_member { - my ($dbh, $prefix, $projectid, $userid) = @_; + my ($dbh, $prefix, $projectid, $userid, $qc) = @_; - my $query = $dbh->prepare ("SELECT projectid FROM ${prefix}project_membership WHERE userid=? AND projectid=?"); + my $query = $dbh->prepare ("SELECT ${qc}projectid${qc} FROM ${qc}${prefix}project_membership${qc} WHERE ${qc}userid${qc}=? AND ${qc}projectid${qc}=?"); if (!$query || !$query->execute ($userid, $projectid)) { return (-1, $dbh->errstr()); @@ -239,9 +248,9 @@ sub is_project_member sub is_project_public { - my ($dbh, $prefix, $projectid) = @_; + my ($dbh, $prefix, $projectid, $qc) = @_; - my $query = $dbh->prepare ("SELECT public FROM ${prefix}project WHERE id=?"); + my $query = $dbh->prepare ("SELECT ${qc}public${qc} FROM ${qc}${prefix}project${qc} WHERE ${qc}id${qc}=?"); if (!$query || !$query->execute ($projectid)) { return (-1, $dbh->errstr()); @@ -275,6 +284,9 @@ sub __handler my $member = undef; my $errmsg = undef; + my $qc = ''; + if ($cfg->{database_driver} eq 'oci8') { $qc = '"'; } + if ($r->proxyreq() == Apache2::Const::PROXYREQ_PROXY) { $author = $r->headers_in->{'Proxy-Authorization'}; @@ -301,7 +313,7 @@ sub __handler if ($is_method_r) { - ($public, $errmsg) = is_project_public ($dbh, $cfg->{database_prefix}, $repo); + ($public, $errmsg) = is_project_public ($dbh, $cfg->{database_prefix}, $repo, $qc); if ($public <= -1) { # failed to contact the authentication server @@ -326,7 +338,7 @@ sub __handler elsif ($cfg->{login_model} eq 'DbLoginModel') { ($auth, $errmsg) = authenticate_database ( - $dbh, $cfg->{database_prefix}, $userid, $password, $cfg->{database_driver}); + $dbh, $cfg->{database_prefix}, $userid, $password, $qc); if ($auth <= -1) { $r->log_error ("Database error - $errmsg"); @@ -352,7 +364,7 @@ sub __handler return Apache2::Const::OK; } - ($member, $errmsg) = is_project_member ($dbh, $cfg->{database_prefix}, $repo, $userid); + ($member, $errmsg) = is_project_member ($dbh, $cfg->{database_prefix}, $repo, $userid, $qc); if ($member <= -1) { $r->log_error ("Cannot check project membership - $errmsg"); diff --git a/codepot/etc/post-commit.in b/codepot/etc/post-commit.in index 731f0132..616dacd2 100644 --- a/codepot/etc/post-commit.in +++ b/codepot/etc/post-commit.in @@ -12,6 +12,8 @@ my $REPO = $ARGV[0]; my $REPOBASE = basename($REPO); my $REV = $ARGV[1]; +my $QC = ''; + sub get_config { my $cfg = new Config::Simple(); @@ -44,15 +46,31 @@ sub open_database my $dbport = $cfg->{database_port}; if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; } + elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; } - my $dbstr = "DBI:$dbtype:database=$dbname;"; - if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } - if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + my $dbstr; + my $dbuser; + my $dbpass; + if ($dbtype eq 'Oracle') + { + $QC = '"'; + $dbstr = "DBI:$dbtype:"; + $dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost; + $dbpass = ''; + } + else + { + $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + + $dbuser = $cfg->{database_username}; + $dbpass = $cfg->{database_password}; + } my $dbh = DBI->connect( - $dbstr, - $cfg->{database_username}, - $cfg->{database_password}, + $dbstr, $dbuser, $dbpass, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } ); @@ -75,12 +93,21 @@ sub write_commit_log #| 895 | code | codepot | svn,codepot,72 | 2011-10-10 14:26:43 | commit | hyunghwan.chung | my $message = "svn,$projectid,$revision"; - my $createdon = strftime ('%Y-%m-%d %H:%M:%S', localtime()); + + + # the PHP side is executing ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS.FF. + # do i have to do it here or use the database time (CURRENT_TIMESTAMP) instead? + # make sure that you have the same time between the app server and the data server. + # to minize side-effect of using the time of data server. + #my $createdon = strftime ('%Y-%m-%d %H:%M:%S', localtime()); $dbh->begin_work (); - my $query = $dbh->prepare ("INSERT INTO ${prefix}log (type,projectid,message,createdon,action,userid) VALUES (?,?,?,?,?,?)"); - if (!$query || !$query->execute ('code', $projectid, $message, $createdon, 'commit', $userid)) + #my $query = $dbh->prepare ("INSERT INTO ${QC}${prefix}log${QC} (${QC}type${QC},${QC}projectid${QC},${QC}message${QC},${QC}createdon${QC},${QC}action${QC},${QC}userid${QC}) VALUES (?,?,?,?,?,?)"); + #if (!$query || !$query->execute ('code', $projectid, $message, $createdon, 'commit', $userid)) + + my $query = $dbh->prepare ("INSERT INTO ${QC}${prefix}log${QC} (${QC}type${QC},${QC}projectid${QC},${QC}message${QC},${QC}createdon${QC},${QC}action${QC},${QC}userid${QC}) VALUES (?,?,?,CURRENT_TIMESTAMP,?,?)"); + if (!$query || !$query->execute ('code', $projectid, $message, 'commit', $userid)) { my $errstr = $dbh->errstr(); $query->finish (); diff --git a/codepot/etc/post-revprop-change.in b/codepot/etc/post-revprop-change.in index c28c11af..c9e25be9 100644 --- a/codepot/etc/post-revprop-change.in +++ b/codepot/etc/post-revprop-change.in @@ -15,6 +15,8 @@ my $USER = $ARGV[2]; my $PROPNAME = $ARGV[3]; my $ACTION = $ARGV[4]; +my $QC = ''; + # [STDIN] PROPVAL ** the old property value is passed via STDIN. sub get_config @@ -49,15 +51,31 @@ sub open_database my $dbport = $cfg->{database_port}; if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; } + elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; } - my $dbstr = "DBI:$dbtype:database=$dbname;"; - if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } - if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + my $dbstr; + my $dbuser; + my $dbpass; + if ($dbtype eq 'Oracle') + { + $QC = '"'; + $dbstr = "DBI:$dbtype:"; + $dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost; + $dbpass = ''; + } + else + { + $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + + $dbuser = $cfg->{database_username}; + $dbpass = $cfg->{database_password}; + } my $dbh = DBI->connect( - $dbstr, - $cfg->{database_username}, - $cfg->{database_password}, + $dbstr, $dbuser, $dbpass, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } ); @@ -84,7 +102,7 @@ sub write_revprop_change_log $dbh->begin_work (); - my $query = $dbh->prepare ("INSERT INTO ${prefix}log (type,projectid,message,createdon,action,userid) VALUES (?,?,?,?,?,?)"); + my $query = $dbh->prepare ("INSERT INTO ${QC}${prefix}log${QC} (${QC}type${QC},${QC}projectid${QC},${QC}message${QC},${QC}createdon${QC},${QC}action${QC},${QC}userid${QC}) VALUES (?,?,?,?,?,?)"); if (!$query || !$query->execute ('code', $projectid, $message, $createdon, 'revpropchange', $userid)) { my $errstr = $dbh->errstr(); diff --git a/codepot/etc/pre-commit.in b/codepot/etc/pre-commit.in index 781db783..8e4ec4d8 100644 --- a/codepot/etc/pre-commit.in +++ b/codepot/etc/pre-commit.in @@ -15,6 +15,8 @@ my $REPOFS = $ARGV[0]; my $REPOBASE = basename($REPOFS); my $TRANSACTION = $ARGV[1]; +my $QC = ''; + my %SVN_ACTIONS = ( 'A ' => 'add', @@ -69,15 +71,31 @@ sub open_database my $dbport = $cfg->{database_port}; if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; } + elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; } - my $dbstr = "DBI:$dbtype:database=$dbname;"; - if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } - if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + my $dbstr; + my $dbuser; + my $dbpass; + if ($dbtype eq 'Oracle') + { + $QC = '"'; + $dbstr = "DBI:$dbtype:"; + $dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost; + $dbpass = ''; + } + else + { + $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + + $dbuser = $cfg->{database_username}; + $dbpass = $cfg->{database_password}; + } my $dbh = DBI->connect( - $dbstr, - $cfg->{database_username}, - $cfg->{database_password}, + $dbstr, $dbuser, $dbpass, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } ); @@ -94,7 +112,7 @@ sub is_project_member { my ($dbh, $prefix, $projectid, $userid) = @_; - my $query = $dbh->prepare ("SELECT projectid FROM ${prefix}project_membership WHERE userid=? AND projectid=?"); + my $query = $dbh->prepare ("SELECT ${QC}projectid${QC} FROM ${QC}${prefix}project_membership${QC} WHERE ${QC}userid${QC}=? AND ${QC}projectid${QC}=?"); if (!$query || !$query->execute ($userid, $projectid)) { return (-1, $dbh->errstr()); @@ -109,7 +127,7 @@ sub is_project_commitable { my ($dbh, $prefix, $projectid) = @_; - my $query = $dbh->prepare ("SELECT commitable FROM ${prefix}project WHERE id=?"); + my $query = $dbh->prepare ("SELECT ${QC}commitable${QC} FROM ${QC}${prefix}project${QC} WHERE ${QC}id${QC}=?"); if (!$query || !$query->execute ($projectid)) { return (-1, $dbh->errstr()); diff --git a/codepot/etc/pre-revprop-change.in b/codepot/etc/pre-revprop-change.in index 397560a8..95a5a951 100644 --- a/codepot/etc/pre-revprop-change.in +++ b/codepot/etc/pre-revprop-change.in @@ -18,6 +18,8 @@ my $USER = $ARGV[2]; my $PROPNAME = $ARGV[3]; my $ACTION = $ARGV[4]; +my $QC = ''; + sub get_config { my $cfg = new Config::Simple(); @@ -52,15 +54,31 @@ sub open_database my $dbport = $cfg->{database_port}; if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; } + elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; } - my $dbstr = "DBI:$dbtype:database=$dbname;"; - if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } - if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + my $dbstr; + my $dbuser; + my $dbpass; + if ($dbtype eq 'Oracle') + { + $QC = '"'; + $dbstr = "DBI:$dbtype:"; + $dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost; + $dbpass = ''; + } + else + { + $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + + $dbuser = $cfg->{database_username}; + $dbpass = $cfg->{database_password}; + } my $dbh = DBI->connect( - $dbstr, - $cfg->{database_username}, - $cfg->{database_password}, + $dbstr, $dbuser, $dbpass, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } ); @@ -77,7 +95,7 @@ sub is_project_member { my ($dbh, $prefix, $projectid, $userid) = @_; - my $query = $dbh->prepare ("SELECT projectid FROM ${prefix}project_membership WHERE userid=? AND projectid=?"); + my $query = $dbh->prepare ("SELECT ${QC}projectid${QC} FROM ${QC}${prefix}project_membership${QC} WHERE ${QC}userid${QC}=? AND ${QC}projectid${QC}=?"); if (!$query || !$query->execute ($userid, $projectid)) { return (-1, $dbh->errstr()); diff --git a/codepot/etc/start-commit.in b/codepot/etc/start-commit.in index a5a77119..17e5e602 100644 --- a/codepot/etc/start-commit.in +++ b/codepot/etc/start-commit.in @@ -10,6 +10,8 @@ my $CFG_FILE = '@CFGDIR@/codepot.ini'; my $REPOBASE = basename($ARGV[0]); my $USER = $ARGV[1]; +my $QC = ''; + sub get_config { my $cfg = new Config::Simple(); @@ -42,15 +44,31 @@ sub open_database my $dbport = $cfg->{database_port}; if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; } + elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; } - my $dbstr = "DBI:$dbtype:database=$dbname;"; - if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } - if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + my $dbstr; + my $dbuser; + my $dbpass; + if ($dbtype eq 'Oracle') + { + $QC = '"'; + $dbstr = "DBI:$dbtype:"; + $dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost; + $dbpass = ''; + } + else + { + $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + + $dbuser = $cfg->{database_username}; + $dbpass = $cfg->{database_password}; + } my $dbh = DBI->connect( - $dbstr, - $cfg->{database_username}, - $cfg->{database_password}, + $dbstr, $dbuser, $dbpass, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } ); @@ -67,7 +85,7 @@ sub is_project_member { my ($dbh, $prefix, $projectid, $userid) = @_; - my $query = $dbh->prepare ("SELECT projectid FROM ${prefix}project_membership WHERE userid=? AND projectid=?"); + my $query = $dbh->prepare ("SELECT ${QC}projectid${QC} FROM ${QC}${prefix}project_membership${QC} WHERE ${QC}userid${QC}=? AND ${QC}projectid${QC}=?"); if (!$query || !$query->execute ($userid, $projectid)) { return (-1, $dbh->errstr()); @@ -82,7 +100,7 @@ sub is_project_commitable { my ($dbh, $prefix, $projectid) = @_; - my $query = $dbh->prepare ("SELECT commitable FROM ${prefix}project WHERE id=?"); + my $query = $dbh->prepare ("SELECT ${QC}commitable${QC} FROM ${QC}${prefix}project${QC} WHERE ${QC}id${QC}=?"); if (!$query || !$query->execute ($projectid)) { return (-1, $dbh->errstr()); diff --git a/codepot/sbin/codepot-user.in b/codepot/sbin/codepot-user.in index e9cc0e67..1c1fc168 100644 --- a/codepot/sbin/codepot-user.in +++ b/codepot/sbin/codepot-user.in @@ -12,7 +12,7 @@ use Digest::SHA1 qw (sha1_hex); my $CFG_FILE = '@CFGDIR@/codepot.ini'; -my $USER_TABLE_NAME = 'user'; +my $QC = ''; sub get_config { @@ -48,23 +48,32 @@ sub open_database my $dbport = $cfg->{database_port}; my $dbprefix = $cfg->{database_prefix}; - if ($dbtype eq 'postgre') - { - $dbtype = 'Pg'; + if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; } + elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; } - # in postgresql, 'user' is a reserved word. - # it requires quotes for the word to be used as a normal word - if (length($dbprefix) <= 0) { $USER_TABLE_NAME = '"user"'; } + my $dbstr; + my $dbuser; + my $dbpass; + if ($dbtype eq 'Oracle') + { + $QC = '"'; + $dbstr = "DBI:$dbtype:"; + $dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost; + $dbpass = ''; + } + else + { + $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } + + $dbuser = $cfg->{database_username}; + $dbpass = $cfg->{database_password}; } - my $dbstr = "DBI:$dbtype:database=$dbname;"; - if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } - if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } - my $dbh = DBI->connect( - $dbstr, - $cfg->{database_username}, - $cfg->{database_password}, + $dbstr, $dbuser, $dbpass, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } ); @@ -104,7 +113,7 @@ sub authenticate_database { my ($dbh, $prefix, $userid, $password) = @_; - my $query = $dbh->prepare ("SELECT userid,passwd FROM ${prefix}${USER_TABLE_NAME}} WHERE userid=? and enabled='N'"); + my $query = $dbh->prepare ("SELECT ${QC}userid${QC},${QC}passwd${QC} FROM ${QC}${prefix}user_account${QC} WHERE ${QC}userid${QC}=? and ${QC}enabled${QC}='N'"); if (!$query || !$query->execute ($userid)) { return (-1, $dbh->errstr()); @@ -136,7 +145,7 @@ sub add_user $dbh->begin_work (); - my $query = $dbh->prepare ("INSERT INTO ${prefix}${USER_TABLE_NAME} (userid,passwd,email,enabled) VALUES (?, ?, ?, ?)"); + my $query = $dbh->prepare ("INSERT INTO ${QC}${prefix}user_account${QC} (${QC}userid${QC},${QC}passwd${QC},${QC}email${QC},${QC}enabled${QC}) VALUES (?, ?, ?, ?)"); if (!$query || !$query->execute ($userid, $fmt_pw, $email, 'N')) { my $errstr = $dbh->errstr(); @@ -156,7 +165,7 @@ sub delete_user $dbh->begin_work (); - my $query = $dbh->prepare ("DELETE FROM ${prefix}${USER_TABLE_NAME} WHERE userid=?"); + my $query = $dbh->prepare ("DELETE FROM ${QC}${prefix}user_account${QC} WHERE ${QC}userid${QC}=?"); if (!$query || !$query->execute ($userid) || $query->rows() <= 0) { my $errstr = $dbh->errstr(); @@ -176,7 +185,7 @@ sub toggle_user $dbh->begin_work (); - my $query = $dbh->prepare ("UPDATE ${prefix}${USER_TABLE_NAME} SET enabled=? WHERE userid=?"); + my $query = $dbh->prepare ("UPDATE ${QC}${prefix}user_account${QC} SET ${QC}enabled${QC}=? WHERE ${QC}userid${QC}=?"); if (!$query || !$query->execute ($enabled, $userid) || $query->rows() <= 0) { my $errstr = $dbh->errstr(); diff --git a/codepot/src/codepot/models/dbloginmodel.php b/codepot/src/codepot/models/dbloginmodel.php index aecff03c..465eb445 100644 --- a/codepot/src/codepot/models/dbloginmodel.php +++ b/codepot/src/codepot/models/dbloginmodel.php @@ -41,7 +41,7 @@ class DbLoginModel extends LoginModel $this->db->select ('userid,passwd,email'); $this->db->where ('userid', $userid); $this->db->where ('enabled', 'Y'); - $query = $this->db->get ('user'); + $query = $this->db->get ('user_account'); if ($this->db->trans_status() == FALSE) { @@ -64,7 +64,7 @@ class DbLoginModel extends LoginModel // the last 10 characters are the salt. $hexsalt = substr ($user->passwd, -10); $binsalt = pack('H*' , $hexsalt); - + if (strcmp ($this->format_password_with_salt($passwd,$binsalt),$user->passwd) != 0) return FALSE; return parent::authenticate ($userid, $user->passwd, $user->email); @@ -77,7 +77,7 @@ class DbLoginModel extends LoginModel $this->db->where ('userid', $userid); $this->db->set ('passwd', format_password($passwd,5)); - $this->db->update ('user'); + $this->db->update ('user_account'); if ($this->db->trans_status() === FALSE) { diff --git a/codepot/src/codepot/models/logmodel.php b/codepot/src/codepot/models/logmodel.php index 45671004..524fcec3 100644 --- a/codepot/src/codepot/models/logmodel.php +++ b/codepot/src/codepot/models/logmodel.php @@ -23,7 +23,7 @@ class LogModel extends Model if ($userid != '') $this->db->where ('userid', $userid); - $this->db->select ('count(id) as count'); + $this->db->select ('count(*) as count'); $query = $this->db->get ('log'); if ($this->db->trans_status() === FALSE) { @@ -33,7 +33,8 @@ class LogModel extends Model $result = $query->result(); - $num = empty($result)? 0: $result[0]->count; + $num = empty($result)? 0: + isset($result[0]->COUNT)? $result[0]->COUNT: $result[0]->count; $this->db->trans_complete (); if ($this->db->trans_status() === FALSE) return FALSE; diff --git a/codepot/src/system/database/DB_driver.php b/codepot/src/system/database/DB_driver.php index b2a3c2eb..2823ea8a 100644 --- a/codepot/src/system/database/DB_driver.php +++ b/codepot/src/system/database/DB_driver.php @@ -149,12 +149,25 @@ class CI_DB_driver { return FALSE; } - return TRUE; + // HYUNG-HWAN + //return TRUE; + // END HYUNG-HWAN } } + + // HYUNG-HWAN + $this->db_post_initialize (); + // END HYUNG-HWAN return TRUE; } + + // HYUNG-HWAN + function db_post_initialize () + { + return TRUE; + } + // END HYUNG-HWAN // -------------------------------------------------------------------- @@ -1363,4 +1376,4 @@ class CI_DB_driver { /* End of file DB_driver.php */ -/* Location: ./system/database/DB_driver.php */ \ No newline at end of file +/* Location: ./system/database/DB_driver.php */ diff --git a/codepot/src/system/database/drivers/oci8/oci8_driver.php b/codepot/src/system/database/drivers/oci8/oci8_driver.php index 75819235..68fccd3e 100644 --- a/codepot/src/system/database/drivers/oci8/oci8_driver.php +++ b/codepot/src/system/database/drivers/oci8/oci8_driver.php @@ -139,6 +139,13 @@ class CI_DB_oci8_driver extends CI_DB { // @todo - add support if needed return TRUE; } + + // HYUNG-HWAN + function db_post_initialize () + { + $this->query ("ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS.FF'"); + } + // END HYUNG-HWAN // -------------------------------------------------------------------- @@ -777,4 +784,4 @@ class CI_DB_oci8_driver extends CI_DB { /* End of file oci8_driver.php */ -/* Location: ./system/database/drivers/oci8/oci8_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/oci8/oci8_driver.php */ diff --git a/codepot/src/system/database/drivers/oci8/oci8_result.php b/codepot/src/system/database/drivers/oci8/oci8_result.php index cab538e2..7397b0a2 100644 --- a/codepot/src/system/database/drivers/oci8/oci8_result.php +++ b/codepot/src/system/database/drivers/oci8/oci8_result.php @@ -174,7 +174,22 @@ class CI_DB_oci8_result extends CI_DB_result { { $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - return @oci_fetch_object($id); + // BEGIN HYUNG-HWAN + //return @oci_fetch_object($id); + $x = @oci_fetch_object($id); + + if (is_object($x)) + { + foreach ($x as $k => $v) + { + if (is_object($v) && get_class($v) == 'OCI-Lob') + { + $x->$k = $v->load(); + } + } + } + return $x; + // END HYUNG-HWAN } // If PHP 4 is being used we have to build our own result @@ -246,4 +261,4 @@ class CI_DB_oci8_result extends CI_DB_result { /* End of file oci8_result.php */ -/* Location: ./system/database/drivers/oci8/oci8_result.php */ \ No newline at end of file +/* Location: ./system/database/drivers/oci8/oci8_result.php */