forked from berman-lab/ymap
/
user.register_server.php
executable file
·155 lines (149 loc) · 7.02 KB
/
user.register_server.php
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
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
session_start();
require_once 'constants.php';
ini_set('display_errors', 1);
$primaryInvestigatorName = filter_input(INPUT_POST, "primaryInvestigator_name", FILTER_SANITIZE_STRING);
$primaryInvestigatorEmail = filter_input(INPUT_POST, "primaryInvestigator_email", FILTER_SANITIZE_STRING);
$researchInstitution = filter_input(INPUT_POST, "researchInstitution", FILTER_SANITIZE_STRING);
$secondaryName = filter_input(INPUT_POST, "secondary_name", FILTER_SANITIZE_STRING);
$secondaryEmail = filter_input(INPUT_POST, "secondary_email", FILTER_SANITIZE_STRING);
$userOrig = filter_input(INPUT_POST, "user", FILTER_SANITIZE_STRING);
$pwOrig = filter_input(INPUT_POST, "pwOrig", FILTER_SANITIZE_STRING);
$pwCopy = filter_input(INPUT_POST, "pwCopy", FILTER_SANITIZE_STRING);
$user = validateUser($userOrig);
$pw = validatePassword($pwOrig, $pwCopy);
// User and Password both validated as correct
if($user && $pw){
createNewUser($user, $pw);
createSecondaryInformationFile($user, $primaryInvestigatorName, $primaryInvestigatorEmail, $researchInstitution, $secondaryName, $secondaryEmail);
}
//=========================================================
// Functions used to generate user account.
//---------------------------------------------------------
function createNewUser($user, $pw){
if (!doesUserDirectoryExist($user)) {
$FTPdir = "FTP_drop/".$user;
mkdir($FTPdir);
chmod($FTPdir,0777);
$dir = "users/".$user;
mkdir($dir);
chmod($dir,0777);
mkdir($dir."/projects/"); // initialize user projects dir.
mkdir($dir."/genomes/"); // initialize user genomes dir.
chmod($dir."/projects/",0777);
chmod($dir."/genomes/", 0777);
writePassword($user, $pw);
$_SESSION['logged_on'] = 1;
$_SESSION['user'] = $user;
echo "<font color=\"green\"><b>SUCCESS: User account created.</b></font><br>";
echo "(Main page will reload shortly...)\n";
echo "<script type=\"text/javascript\">\nreload_page=function() {\n\tlocation.replace(\"panel.user.php\");\n}\n";
echo "var intervalID = window.setInterval(reload_page, 1000);\n</script>\n";
return false;
} else {
// The user directory already exists!
echo "<font color=\"red\"><b>ERROR: Invalid user name, try another.</b></font><br>";
echo "(Main page will reload shortly...)\n";
echo "<script type=\"text/javascript\">\nreload_page=function() {\n\tlocation.replace(\"user.register.php\");\n}\n";
echo "var intervalID = window.setInterval(reload_page, 1000);\n</script>\n";
return false;
}
}
function writePassword($user, $pw){
$pwFile = "users/".$user."/pw.txt";
$fh = fopen($pwFile, 'w');
fwrite($fh, $pw);
fclose($fh);
chmod($pwFile, 0644);
}
function doesUserDirectoryExist($user){
$dir = "users/".$user."/";
return file_exists($dir);
}
function createSecondaryInformationFile($user, $primaryInvestigatorName, $primaryInvestigatorEmail, $researchInstitution, $secondaryName, $secondaryEmail){
$secondaryInformationFile = "users/".$user."/info.txt";
$fileHandle = fopen($secondaryInformationFile, 'w');
fwrite($fileHandle, "User: ".$user."\n");
fwrite($fileHandle, "Primary Investigator Name: ".$primaryInvestigatorName."\n");
fwrite($fileHandle, "Primary Investigator Email: ".$primaryInvestigatorEmail."\n");
fwrite($fileHandle, "Research Institution: ".$researchInstitution."\n");
fwrite($fileHandle, "Secondary Name: ".$secondaryName."\n");
fwrite($fileHandle, "Secondary Email: ".$secondaryEmail."\n");
fclose($fileHandle);
chmod($secondaryInformationFile, 0644);
}
//=========================================================
// Functions used to validate entered user name.
//---------------------------------------------------------
function validateUser($user){
$MIN_USER_LENGTH = 6;
$MAX_USER_LENGTH = 24;
// MIN LENGTH CHECK
if (strlen($user) < $MIN_USER_LENGTH) {
echo "<font color=\"red\"><b>ERROR: Your user name is too short, minimum is $MIN_USER_LENGTH.</b></font><br>";
echo "(Main page will reload shortly...)\n";
echo "<script type=\"text/javascript\">\nreload_page=function() {\n\tlocation.replace(\"user.register.php\");\n}\n";
echo "var intervalID = window.setInterval(reload_page, 1000);\n";
echo "</script>\n";
return "";
}
// MAX LENGTH CHECK
if (strlen($user) > $MAX_USER_LENGTH) {
echo "<font color=\"red\"><b>ERROR: Your user name is too long, maximum is $MAX_USER_LENGTH.</b></font><br>";
echo "(Main page will reload shortly...)\n";
echo "<script type=\"text/javascript\">\nreload_page=function() {\n\tlocation.replace(\"user.register.php\");\n}\n";
echo "var intervalID = window.setInterval(reload_page, 1000);\n";
echo "</script>\n";
return "";
}
//CHECK FOR NON ALPHANUMERIC CHARACTERS
if (checkForAlphanumericCharacters($user)) {
echo "<font color=\"red\"><b>ERROR: You have a non-alphanumeric character in your username.</b></font><br>";
echo "(Main page will reload shortly...)\n";
echo "<script type=\"text/javascript\">\nreload_page=function() {\n\tlocation.replace(\"user.register.php\");\n}\n";
echo "var intervalID = window.setInterval(reload_page, 1000);\n";
echo "</script>\n";
return "";
}
//RETURN user
return $user;
}
function checkForAlphanumericCharacters($string){
return preg_match( "/^[a-zA-Z0-9]$/", $string);
}
//=========================================================
// Function used to validate entered user password.
//---------------------------------------------------------
function validatePassword($pwOrig, $pwCopy){
$MIN_PASSWORD_LENGTH = 6;
$MAX_PASSWORD_LENGTH = 24;
// MIN LENGTH CHECK
if (strlen($pwOrig) < $MIN_PASSWORD_LENGTH) {
echo "<font color=\"red\"><b>ERROR: Your password is too short, minimum is $MIN_PASSWORD_LENGTH.</b></font><br>";
echo "(Main page will reload shortly...)\n";
echo "<script type=\"text/javascript\">\nreload_page=function() {\n\tlocation.replace(\"user.register.php\");\n}\n";
echo "var intervalID = window.setInterval(reload_page, 1000);\n";
echo "</script>\n";
return "";
}
// MAX LENGTH CHECK
if (strlen($pwOrig) > $MAX_PASSWORD_LENGTH) {
echo "<font color=\"red\"><b>ERROR: Your password is too long, maximum is $MAX_PASSWORD_LENGTH.</b></font><br>";
echo "(Main page will reload shortly...)\n";
echo "<script type=\"text/javascript\">\nreload_page=function() {\n\tlocation.replace(\"user.register.php\");\n}\n";
echo "var intervalID = window.setInterval(reload_page, 1000);\n";
echo "</script>\n";
return "";
}
// ORIG = COPY check
if ($pwOrig != $pwCopy) {
echo "<font color=\"red\"><b>ERROR: The passwords that you entered do not match.</b></font><br>";
echo "(Main page will reload shortly...)\n";
echo "<script type=\"text/javascript\">\nreload_page=function() {\n\tlocation.replace(\"user.register.php\");\n}\n";
echo "var intervalID = window.setInterval(reload_page, 1000);\n";
echo "</script>\n";
return "";
}
return md5($pwOrig);
}
?>