1 # include.pl - Include file for all the perl scripts that contains reusable functions
4 ##############################
6 ##############################
7 $dummy_uid = getpwnam('scm-gforge'); # UserID of the dummy user that will own group's files
8 $date = int(time()/3600/24); # Get the number of days since 1/1/1970 for /etc/shadow
11 '/usr/share/gforge/bin',
12 '/usr/share/fusionforge/bin',
13 '/usr/local/share/gforge/bin',
14 '/usr/local/share/fusionforge/bin',
16 '/opt/fusionforge/bin',
19 foreach $p (@possible_paths) {
20 if (-x "$p/forge_get_config") {
21 $fgc = "$p/forge_get_config";
26 %forge_config_cache = ();
28 sub forge_get_config ($$) {
30 my $sec = shift || 'core';
32 if (!defined $forge_config_cache{$sec}{$var}) {
33 $forge_config_cache{$sec}{$var} = qx!$fgc $var $sec!;
34 chomp $forge_config_cache{$sec}{$var};
36 return $forge_config_cache{$sec}{$var};
39 $sys_default_domain = &forge_get_config ('web_host') ;
40 $sys_scm_host = &forge_get_config ('web_host') ;
41 $domain_name = &forge_get_config ('web_host') ;
42 $sys_users_host = &forge_get_config ('users_host') ;
43 $sys_lists_host = &forge_get_config ('lists_host') ;
44 $sys_name = &forge_get_config ('forge_name') ;
45 $sys_themeroot = &forge_get_config ('themes_root') ;
46 $sys_news_group = &forge_get_config ('news_group') ;
47 $sys_dbhost = &forge_get_config ('database_host') ;
48 $sys_dbport = &forge_get_config ('database_port') ;
49 $sys_dbname = &forge_get_config ('database_name') ;
50 $sys_dbuser = &forge_get_config ('database_user') ;
51 $sys_dbpasswd = &forge_get_config ('database_password') ;
52 $sys_ldap_base_dn = &forge_get_config ('ldap_base_dn') ;
53 $sys_ldap_host = &forge_get_config ('ldap_host') ;
54 $server_admin = &forge_get_config ('admin_email') ;
55 $chroot_prefix = &forge_get_config ('chroot') ;
56 $homedir_prefix = &forge_get_config ('homedir_prefix') ;
57 $grpdir_prefix = &forge_get_config ('groupdir_prefix') ;
58 $file_dir = &forge_get_config ('data_path') ;
60 ##############################
61 # Database Connect Functions
62 ##############################
64 my $str = "DBI:Pg:dbname=$sys_dbname" ;
65 if ($sys_dbhost ne '') {
66 $str .= ";host=$sys_dbhost" ;
68 if ($sys_dbport ne '') {
69 $str .= ";port=$sys_dbport" ;
71 $dbh ||= DBI->connect($str,"$sys_dbuser","$sys_dbpasswd") ;
73 die "Error while connecting to database: $!" ;
77 sub db_disconnect ( ) {
82 sub db_drop_table_if_exists {
83 my ($sql, $res, $n, $tn) ;
85 $sql = "SELECT COUNT(*) FROM pg_class WHERE relname='$tn'";
86 $res = $dbh->prepare($sql);
88 ($n) = $res->fetchrow() ;
91 $sql = "DROP TABLE $tn";
92 $res = $dbh->prepare($sql);
98 ##############################
99 # File open function, spews the entire file to an array.
100 ##############################
101 sub open_array_file {
102 my $filename = shift(@_);
104 open (FD, $filename) || die "Can't open $filename: $!.\n";
111 #############################
112 # File write function.
113 #############################
114 sub write_array_file {
115 my ($file_name, @file_array) = @_;
116 my $oldmask = umask(077);
118 use File::Temp qw(tempfile);
119 use File::Basename qw(dirname);
121 my ($fd, $filename) = tempfile( DIR => dirname($file_name), UNLINK => 0) ;
124 return 1 unless ($fd && $filename) ;
126 foreach (@file_array) {
133 unless (rename ($filename, $file_name)) {
140 #######################
141 # Display a backtrace #
142 #######################
144 debug_print_backtrace
148 print "Call Trace:\n";
149 while ((my @call_details = (caller($i++)))) {
150 print " + " . $call_details[1] . ":" . $call_details[2] .
151 " in function " . $call_details[3] . "\n";