Menu

[r10]: / includes / cvslib.php  Maximize  Restore  History

Download this file

142 lines (114 with data), 4.1 kB

  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
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
#Application name: PhpCollab
#Status page: 2
#Path by root: ../includes/cvslib.php
//TY
$cvs_log_level = 5;
#=============== USER AUTHORIZATION =========================
function has_access($cvs_user, $cvs_project) {
$all_cvs_users = cvs_read_passwd($cvs_project);
$cvs_fields = $all_cvs_users[$cvs_user];
if (is_null($cvs_fields)) {
return false;
} else {
return true;
}
}
#=============== ADD REPOSITORY =========================
function cvs_delete_repository($cvs_project) {
global $cvs_root;
//We really don't want to delete the repository,
//just erase the passwd file...
$cvs_passwd_file = $cvs_root."/".$cvs_project."/CVSROOT/passwd";
unlink( $cvs_passwd_file);
$cvs_deleted_file = $cvs_root."/".$cvs_project."/DELETED";
touch( $cvs_deleted_file);
}
#=============== ADD REPOSITORY =========================
function cvs_add_repository($cvs_user, $cvs_pass, $cvs_project) {
global $cvs_root, $cvs_cmd;
$cvs_dir = $cvs_root."/".$cvs_project;
exec($cvs_cmd." -d ".$cvs_dir." init");
cvs_add_user($cvs_user, $cvs_pass, $cvs_project);
}
#=============== ADD USER =========================
function cvs_add_user($cvs_user, $cvs_pass, $cvs_project) {
global $cvs_owner;
$all_cvs_users = cvs_read_passwd($cvs_project);
$cvs_fields = $all_cvs_users[$cvs_user];
if (is_null($cvs_fields)) {
$cvs_fields[0] = $cvs_pass;
$cvs_fields[1] = $cvs_owner;
$all_cvs_users[$cvs_user] = $cvs_fields;
cvs_write_file($all_cvs_users, $cvs_project);
cvs_log(1, "Added user $cvs_user");
} else {
cvs_log(3, "User $cvs_user already exists");
}
}
#=============== DELETE USER =========================
function cvs_delete_user($cvs_user, $cvs_project) {
$all_cvs_users = cvs_read_passwd($cvs_project);
$cvs_fields=$all_cvs_users[$cvs_user];
if (!is_null($cvs_fields)) {
unset($all_cvs_users[$cvs_user]);
cvs_write_file($all_cvs_users, $cvs_project);
cvs_log(1, "Deleted user $cvs_user");
} else {
cvs_log(3, "User $cvs_user does not exist");
}
}
#=============== CHANGE PASSWORD =========================
function cvs_change_password($cvs_user, $new_pass, $cvs_project){
$all_cvs_users = cvs_read_passwd($cvs_project);
$cvs_fields = $all_cvs_users[$cvs_user];
if (!is_null($cvs_fields)) {
$cvs_fields[0] = $new_pass;
$all_cvs_users[$cvs_user] = $cvs_fields;
cvs_write_file($all_cvs_users, $cvs_project);
cvs_log(1, "Updated password for $cvs_user");
} else {
cvs_log(3, "No such user- $cvs_user");
}
}
#=============== READ PASSWD FILE =========================
function cvs_read_passwd($cvs_project){
global $cvs_root;
$cvs_passwd_file = $cvs_root."/".$cvs_project."/CVSROOT/passwd";
settype($all_cvs_users,"array");
if(is_file($cvs_passwd_file)){
$fcontents = file($cvs_passwd_file, FILE_TEXT | FILE_SKIP_EMPTY_LINES);
while (list ($line_num, $line) = each ($fcontents)) {
$line = trim($line);
if(substr($line,0,1)!="#" && strlen($line) > 0) {
list($cvs_u, $cvs_p, $sys_u) = split (":", $line, 3);
$all_cvs_users[$cvs_u]=array($cvs_p,$sys_u);
}
}
cvs_log(1, "Processed $cvs_passwd_file");
} else {
cvs_log(3, "No such file- File $cvs_passwd_file!");
}
return $all_cvs_users;
}
#=============== WRITE PASSWD FILE =========================
function cvs_write_file($user_array, $cvs_project){
global $cvs_root;
$cvs_passwd_file = $cvs_root."/".$cvs_project."/CVSROOT/passwd";
$file_str="# Last update on ".date("D, M d Y H:i:s T")."\n\n";
foreach($user_array as $name => $pass){
$file_str .= "$name:$pass[0]:$pass[1]\n";
}
$fp = fopen ($cvs_passwd_file, "w");
fwrite($fp,$file_str);
fclose($fp);
}
#=============== LOGGING FUNCTION =========================
function cvs_log($level, $message) {
global $cvs_log_level;
$cvs_log_string = array("DEBUG","INFO","WARN","ERROR","FATAL");
if ($level >= $cvs_log_level) {
echo "$cvs_log_string[$level]: $message\n";
}
}
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.