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_return_domain = &forge_get_config ('forum_return_domain') ;
42 $sys_scm_host = &forge_get_config ('web_host') ;
43 $domain_name = &forge_get_config ('web_host') ;
44 $sys_users_host = &forge_get_config ('users_host') ;
45 $sys_lists_host = &forge_get_config ('lists_host') ;
46 $sys_name = &forge_get_config ('forge_name') ;
47 $sys_themeroot = &forge_get_config ('themes_root') ;
48 $sys_news_group = &forge_get_config ('news_group') ;
49 $sys_dbhost = &forge_get_config ('database_host') ;
50 $sys_dbport = &forge_get_config ('database_port') ;
51 $sys_dbname = &forge_get_config ('database_name') ;
52 $sys_dbuser = &forge_get_config ('database_user') ;
53 $sys_dbpasswd = &forge_get_config ('database_password') ;
54 $sys_ldap_base_dn = &forge_get_config ('ldap_base_dn') ;
55 $sys_ldap_host = &forge_get_config ('ldap_host') ;
56 $server_admin = &forge_get_config ('admin_email') ;
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') ;
61 $sys_use_ssl = &forge_get_config('use_ssl');
62 $sys_urlprefix = &forge_get_config('url_prefix');
64 ##############################
65 # Database Connect Functions
66 ##############################
68 my $str = "DBI:Pg:dbname=$sys_dbname" ;
69 if ($sys_dbhost ne '') {
70 $str .= ";host=$sys_dbhost" ;
72 if ($sys_dbport ne '') {
73 $str .= ";port=$sys_dbport" ;
75 $dbh ||= DBI->connect($str,"$sys_dbuser","$sys_dbpasswd") ;
77 die "Error while connecting to database: $!" ;
81 sub db_disconnect ( ) {
86 sub db_drop_table_if_exists {
87 my ($sql, $res, $n, $tn) ;
89 $sql = "SELECT COUNT(*) FROM pg_class WHERE relname='$tn'";
90 $res = $dbh->prepare($sql);
92 ($n) = $res->fetchrow() ;
95 $sql = "DROP TABLE $tn";
96 $res = $dbh->prepare($sql);
102 ##############################
103 # File open function, spews the entire file to an array.
104 ##############################
105 sub open_array_file {
106 my $filename = shift(@_);
108 open (FD, $filename) || die "Can't open $filename: $!.\n";
115 #############################
116 # File write function.
117 #############################
118 sub write_array_file {
119 my ($file_name, @file_array) = @_;
120 my $oldmask = umask(077);
122 use File::Temp qw(tempfile);
123 use File::Basename qw(dirname);
125 my ($fd, $filename) ;
126 eval { ($fd, $filename) = tempfile( DIR => dirname($file_name), UNLINK => 0) } ;
130 return 1 unless ($fd && $filename) ;
132 foreach (@file_array) {
139 unless (rename ($filename, $file_name)) {
146 #######################
147 # Display a backtrace #
148 #######################
150 debug_print_backtrace
154 print "Call Trace:\n";
155 while ((my @call_details = (caller($i++)))) {
156 print " + " . $call_details[1] . ":" . $call_details[2] .
157 " in function " . $call_details[3] . "\n";
161 #############################
162 # Compatibility functions.
163 #############################
168 if (($sys_use_ssl eq 'true') || ($sys_use_ssl eq '1')) {
174 $url .= $sys_default_domain . $sys_urlprefix;