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 $peerrating_groupid = &forge_get_config ('peer_rating_group') ;
58 $chroot_prefix = &forge_get_config ('chroot') ;
59 $homedir_prefix = &forge_get_config ('homedir_prefix') ;
60 $grpdir_prefix = &forge_get_config ('groupdir_prefix') ;
61 $file_dir = &forge_get_config ('data_path') ;
62 $sys_use_ssl = &forge_get_config('use_ssl');
63 $sys_urlprefix = &forge_get_config('url_prefix');
65 ##############################
66 # Database Connect Functions
67 ##############################
69 my $str = "DBI:Pg:dbname=$sys_dbname" ;
70 if ($sys_dbhost ne '') {
71 $str .= ";host=$sys_dbhost" ;
73 if ($sys_dbport ne '') {
74 $str .= ";port=$sys_dbport" ;
76 $dbh ||= DBI->connect($str,"$sys_dbuser","$sys_dbpasswd") ;
78 die "Error while connecting to database: $!" ;
82 sub db_disconnect ( ) {
87 sub db_drop_table_if_exists {
88 my ($sql, $res, $n, $tn) ;
90 $sql = "SELECT COUNT(*) FROM pg_class WHERE relname='$tn'";
91 $res = $dbh->prepare($sql);
93 ($n) = $res->fetchrow() ;
96 $sql = "DROP TABLE $tn";
97 $res = $dbh->prepare($sql);
103 ##############################
104 # File open function, spews the entire file to an array.
105 ##############################
106 sub open_array_file {
107 my $filename = shift(@_);
109 open (FD, $filename) || die "Can't open $filename: $!.\n";
116 #############################
117 # File write function.
118 #############################
119 sub write_array_file {
120 my ($file_name, @file_array) = @_;
121 my $oldmask = umask(077);
123 use File::Temp qw(tempfile);
124 use File::Basename qw(dirname);
126 my ($fd, $filename) = tempfile( DIR => dirname($file_name), UNLINK => 0) ;
129 return 1 unless ($fd && $filename) ;
131 foreach (@file_array) {
138 unless (rename ($filename, $file_name)) {
145 #######################
146 # Display a backtrace #
147 #######################
149 debug_print_backtrace
153 print "Call Trace:\n";
154 while ((my @call_details = (caller($i++)))) {
155 print " + " . $call_details[1] . ":" . $call_details[2] .
156 " in function " . $call_details[3] . "\n";
160 #############################
161 # Compatibility functions.
162 #############################
167 if (($sys_use_ssl eq 'true') || ($sys_use_ssl eq '1')) {
173 $url .= $sys_default_domain . $sys_urlprefix;