File: include.pl

package info (click to toggle)
gforge 4.5.14-22etch13
  • links: PTS
  • area: main
  • in suites: etch
  • size: 13,004 kB
  • ctags: 11,918
  • sloc: php: 36,047; sql: 29,050; sh: 10,538; perl: 6,496; xml: 3,810; makefile: 341; python: 263; ansic: 256
file content (83 lines) | stat: -rwxr-xr-x 2,425 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl -w
#
# SourceForge: Breaking Down the Barriers to Open Source Development
# Copyright 1999-2000 (c) The SourceForge Crew
# http://sourceforge.net
#
# $Id: include.pl 2683 2004-02-18 09:18:27Z gsmet $
#

########################
# global configuration #
########################
$config{'database_include'} 	= '/etc/gforge/database.inc';		# database include file
$config{'lock_file'}		= '/tmp/sf-backend';		# lockfile location
$config{'log_file'}		= '/home/dummy/backend.log';	# logfile location
$config{'group_dir_prefix'} 	= '/home/groups';		# prefix for group directories
$config{'user_dir_prefix'} 	= '/home/users';		# prefix for user directories
$config{'database_dump_dir'}	= '/home/dummy/dumps';		# where are the database dumps kept
$config{'delete_tar_dir'}	= '/tmp';			# place to stick tarballs of deleted accounts/groups
$config{'dummy_uid'}		= getpwnam('dummy');		# userid of the dummy user
$config{'days_since_epoch'} 	= int(time()/3600/24);		# number of days since the epoch
$config{'hostname'}		= hostname();			# machine hostname

####################
# open the logfile #
####################
sub open_log_file {
	open(Log, ">>$config{'log_file'}") || die "Couldn't Open Logfile: $!\n";
	select(Log);
	$| = 1;
	return;
}

##############################
# log message to the logfile #
##############################
sub logme {
	my $msg = shift(@_);
	my $time = strftime "%Y-%m-%d - %T", localtime;
	print "$time\t$msg\n";
	return;
}

##########################
# exit the script nicely #
##########################
sub exit_nicely {
	&logme("------ Script Ended -------\n");
	close(Log);
	exit 0;
}

#########################################
# open a file and read it into an array #
#########################################
sub open_array {
	my $filename = shift(@_);

	# Now read in the file as a big array
	open (FD, $filename) || die &logme("Can't open $filename: $!");
	@tmp_array = <FD>;
        close(FD);

	&logme("Opened $filename with $@tmp_array Lines");
        return @tmp_array;
}               

################################
# write an array out to a file #
################################
sub write_array {
	my ($filename, @filearray) = @_;

	# Write this array out to $filename
	open(FD, ">$filename") || die &logme("Can't open $filename: $!");
	foreach (@filearray) {
		if ($_ ne '') {
			print FD;
		}
	}
	&logme("Wrote $filename with $#filearray Lines");
	close(FD);
}