1 # include.pl - Include file for all the perl scripts that contains reusable functions
4 ##############################
6 ##############################
7 $dummy_user = 'scm-gforge'; # unix name of the dummy user
8 $dummy_uid = getpwnam($dummy_user); # uid of the dummy user that will own group's files
9 $date = int(time()/3600/24); # Get the number of days since 1/1/1970 for /etc/shadow
12 '/usr/share/gforge/bin',
13 '/usr/share/fusionforge/bin',
14 '/usr/local/share/gforge/bin',
15 '/usr/local/share/fusionforge/bin',
17 '/opt/fusionforge/bin',
20 foreach $p (@possible_paths) {
21 if (-x "$p/forge_get_config") {
22 $fgc = "$p/forge_get_config";
27 %forge_config_cache = ();
29 sub forge_get_config ($$) {
31 my $sec = shift || 'core';
33 if (!defined $forge_config_cache{$sec}{$var}) {
34 $forge_config_cache{$sec}{$var} = qx!$fgc $var $sec!;
35 chomp $forge_config_cache{$sec}{$var};
37 return $forge_config_cache{$sec}{$var};
40 $sys_default_domain = &forge_get_config ('web_host') ;
41 $sys_scm_host = &forge_get_config ('web_host') ;
42 $domain_name = &forge_get_config ('web_host') ;
43 $sys_users_host = &forge_get_config ('users_host') ;
44 $sys_lists_host = &forge_get_config ('lists_host') ;
45 $sys_name = &forge_get_config ('forge_name') ;
46 $sys_themeroot = &forge_get_config ('themes_root') ;
47 $sys_news_group = &forge_get_config ('news_group') ;
48 $sys_dbhost = &forge_get_config ('database_host') ;
49 $sys_dbport = &forge_get_config ('database_port') ;
50 $sys_dbname = &forge_get_config ('database_name') ;
51 $sys_dbuser = &forge_get_config ('database_user') ;
52 $sys_dbpasswd = &forge_get_config ('database_password') ;
53 $sys_ldap_base_dn = &forge_get_config ('ldap_base_dn') ;
54 $sys_ldap_host = &forge_get_config ('ldap_host') ;
55 $server_admin = &forge_get_config ('admin_email') ;
56 $peerrating_groupid = &forge_get_config ('peer_rating_group') ;
57 $chroot_prefix = &forge_get_config ('chroot') ;
58 $homedir_prefix = &forge_get_config ('homedir_prefix') ;
59 $grpdir_prefix = &forge_get_config ('groupdir_prefix') ;
60 $file_dir = &forge_get_config ('data_path') ;
62 ##############################
63 # Database Connect Functions
64 ##############################
66 my $str = "DBI:Pg:dbname=$sys_dbname" ;
67 if ($sys_dbhost ne '') {
68 $str .= ";host=$sys_dbhost" ;
70 if ($sys_dbport ne '') {
71 $str .= ";port=$sys_dbport" ;
73 $dbh ||= DBI->connect($str,"$sys_dbuser","$sys_dbpasswd") ;
75 die "Error while connecting to database: $!" ;
79 sub db_disconnect ( ) {
84 sub db_drop_table_if_exists {
85 my ($sql, $res, $n, $tn) ;
87 $sql = "SELECT COUNT(*) FROM pg_class WHERE relname='$tn'";
88 $res = $dbh->prepare($sql);
90 ($n) = $res->fetchrow() ;
93 $sql = "DROP TABLE $tn";
94 $res = $dbh->prepare($sql);
100 ##############################
101 # File open function, spews the entire file to an array.
102 ##############################
103 sub open_array_file {
104 my $filename = shift(@_);
106 open (FD, $filename) || die "Can't open $filename: $!.\n";
113 #############################
114 # File write function.
115 #############################
116 sub write_array_file {
117 my ($file_name, @file_array) = @_;
118 my $oldmask = umask(077);
120 use File::Temp qw(tempfile);
121 use File::Basename qw(dirname);
123 my ($fd, $filename) = tempfile( DIR => dirname($file_name), UNLINK => 0) ;
126 return 1 unless ($fd && $filename) ;
128 foreach (@file_array) {
135 unless (rename ($filename, $file_name)) {
142 #######################
143 # Display a backtrace #
144 #######################
146 debug_print_backtrace
150 print "Call Trace:\n";
151 while ((my @call_details = (caller($i++)))) {
152 print " + " . $call_details[1] . ":" . $call_details[2] .
153 " in function " . $call_details[3] . "\n";