9 use Symfony\Component\HttpFoundation\Session\Session;
11 define(
"TITLE_CORE_SMAUTH", _(
"SiteMinder_Login"));
16 var $Title = TITLE_CORE_SMAUTH;
18 var $Dependency = array();
19 var $PluginLevel = 1000;
55 $session = $container->get(
'session');
56 $session->setName(
'Login');
59 if (array_key_exists(Auth::USER_ID, $_SESSION)) {
60 $SysConf[
'auth'][Auth::USER_ID] = $_SESSION[Auth::USER_ID];
64 if (! empty($_SESSION[
'time']) && @$_SESSION[
'time'] + (60 * 480) < $Now) {
65 $_SESSION[
'User'] = NULL;
66 $_SESSION[Auth::USER_ID] = NULL;
67 $_SESSION[Auth::USER_LEVEL] = NULL;
68 $SysConf[
'auth'][Auth::USER_ID] = NULL;
69 $_SESSION[
'UserEmail'] = NULL;
70 $_SESSION[
'Folder'] = NULL;
71 $_SESSION[
'UiPref'] = NULL;
79 echo
"NO DB connection";
85 if (@$_SESSION[
'User']) {
87 if (
"X" . $_SESSION[Auth::USER_LEVEL] ==
"X") {
90 $Level = $_SESSION[Auth::USER_LEVEL];
93 if (empty($_SESSION[
'time_check'])) {
94 $_SESSION[
'time_check'] = time() + (480 * 60);
96 if (time() >= @$_SESSION[
'time_check']) {
97 $sql =
"SELECT * FROM users WHERE user_pk='" . @$_SESSION[
'UserId'] .
"';";
100 $R = pg_fetch_assoc($result);
101 pg_free_result($result);
102 $_SESSION[
'User'] = $R[
'user_name'];
103 $_SESSION[
'Folder'] = $R[
'root_folder_fk'];
104 $_SESSION[Auth::USER_LEVEL] = $R[
'user_perm'];
105 $_SESSION[
'UserEmail'] = $R[
'user_email'];
106 $_SESSION[
'UserEnote'] = $R[
'email_notify'];
107 if (empty($R[
'ui_preference'])) {
108 $_SESSION[
'UiPref'] =
'simple';
110 $_SESSION[
'UiPref'] = $R[
'ui_preference'];
112 $Level = $_SESSION[Auth::USER_LEVEL];
116 $Level = $_SESSION[Auth::USER_LEVEL];
120 plugin_disable($Level);
122 $this->
State = PLUGIN_STATE_READY;
137 $Email = str_replace(
"'",
"''", $Email);
138 $FolderName = substr($Email, 0, strpos($Email,
'@'));
139 $FolderName =
trim($FolderName);
140 if (empty($FolderName)) {
143 $FolderDes =
"Folder created for " . $FolderName;
147 $BucketPool =
'null';
148 $sql =
"SELECT typlen FROM pg_type where typname='sysconfig' limit 1";
151 if (pg_num_rows($result) > 0) {
152 pg_free_result($result);
154 $sql =
"SELECT conf_value FROM sysconfig WHERE variablename = 'UserDesc';";
157 $R = pg_fetch_assoc($result);
158 pg_free_result($result);
159 if (!empty($R[
'conf_value'])) {
160 $UserDesc =
"'".$R[
'conf_value'].
"'";
164 $sql =
"SELECT conf_value FROM sysconfig WHERE variablename = 'BucketPool';";
167 $R = pg_fetch_assoc($result);
168 pg_free_result($result);
169 if (!empty($R[
'conf_value'])) {
170 $BucketPool = $R[
'conf_value'];
172 $sql =
"SELECT bucketpool_pk FROM bucketpool WHERE bucketpool_pk=$BucketPool AND active='Y'";
175 if (pg_num_rows($result) < 1) {
176 $BucketPool =
'null';
180 $sql =
"SELECT bucketpool_pk FROM bucketpool;";
183 if (pg_num_rows($result) == 1) {
184 $R = pg_fetch_assoc($result);
185 if (!empty($R[
'bucketpool_pk'])) {
186 $BucketPool = $R[
'bucketpool_pk'];
189 $BucketPool =
'null';
192 pg_free_result($result);
194 pg_free_result($result);
198 $sql =
"SELECT * FROM users WHERE user_email = '$Email';";
201 $R = pg_fetch_assoc($result);
202 pg_free_result($result);
203 if (empty($R[
'user_name'])) {
206 $sql =
"SELECT * FROM folderlist WHERE name = '$FolderName' AND parent = '1' AND foldercontents_mode = '1';";
209 $row = pg_fetch_assoc($result);
210 pg_free_result($result);
211 if (empty($row[
'name'])) {
213 $sql =
"INSERT INTO folder (folder_name, folder_desc) VALUES ('$FolderName', '$FolderDes');";
216 pg_free_result($result);
217 $sql =
"SELECT folder_pk FROM folder WHERE folder_name='$FolderName' AND folder_desc = '$FolderDes';";
220 $row = pg_fetch_assoc($result);
221 pg_free_result($result);
223 if (empty($row[
'folder_pk'])) {
226 $FolderPk = $row[
'folder_pk'];
229 $sql =
"INSERT INTO foldercontents (parent_fk,foldercontents_mode,child_id) VALUES ('1','1','$FolderPk');";
232 pg_free_result($result);
234 $sql =
"SELECT folder_pk FROM folder WHERE folder_name='$FolderName' AND folder_desc = '$FolderDes';";
237 $row = pg_fetch_assoc($result);
238 pg_free_result($result);
240 if (empty($row[
'folder_pk'])) {
243 $FolderPk = $row[
'folder_pk'];
248 add_user($Email,$UserDesc,
null,
null,5,$Email,y,
"agent_bucket,agent_copyright",$FolderPk,$BucketPool);
253 $sql =
"SELECT * FROM users WHERE user_email = '$Email';";
256 $R = pg_fetch_assoc($result);
257 pg_free_result($result);
260 if (strcmp($Email, $R[
'user_email']) != 0) {
264 $_SESSION[
'User'] = $R[
'user_name'];
265 $_SESSION[
'UserId'] = $R[
'user_pk'];
266 $SysConf[
'auth'][Auth::USER_ID] = $R[
'user_pk'];
267 $_SESSION[
'UserEmail'] = $R[
'user_email'];
268 $_SESSION[
'UserEnote'] = $R[
'email_notify'];
269 if (empty($R[
'ui_preference'])) {
270 $_SESSION[
'UiPref'] =
'simple';
272 $_SESSION[
'UiPref'] = $R[
'ui_preference'];
274 $_SESSION[
'Folder'] = $R[
'root_folder_fk'];
275 $_SESSION[
'time_check'] = time() + (480 * 60);
277 if (
"X" . $R[
'user_perm'] ==
"X") {
280 $_SESSION[Auth::USER_LEVEL] = $R[
'user_perm'];
284 $_SESSION[
'NoPopup'] = 1;
286 $_SESSION[
'NoPopup'] = 0;
296 if ($this->
State != PLUGIN_STATE_READY) {
306 if ($this->OutputType==
"HTML") {
308 $_SESSION[
'User'] = NULL;
309 $_SESSION[Auth::USER_ID] = NULL;
310 $SysConf[
'auth'][Auth::USER_ID] = NULL;
311 $_SESSION[Auth::USER_LEVEL] = NULL;
312 $_SESSION[
'UserEmail'] = NULL;
313 $_SESSION[
'Folder'] = NULL;
314 $_SESSION[
'UiPref'] = NULL;
315 $Uri =
Traceback_uri() .
"logout.html?" . random_int(0, getrandmax());
317 $V.=
"<script language='javascript'>\n";
318 $V.=
"window.open('$Uri','_top');\n";
321 if (!$this->OutputToStdout) {
330 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
PostInitialize()
This function is called before the plugin is used and after all plugins have been initialized....
Contains the constants and helpers for authentication of user.
Output()
generate the output for this plug-in
Install()
Only used during installation. This may be called multiple times. Used to ensure the DB has the right...
CheckUser($Email)
See if a username is valid.
siteminder_check()
Check if SiteMinder is enabled.
DBconnect($sysconfdir, $options="", $exitOnFail=true)
Connect to database engine. This is a no-op if $PG_CONN already has a value.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
add_user($User, $Desc, $Hash, $Perm, $Email, $Email_notify, $Upload_visibility, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.
char * trim(char *ptext)
Trimming whitespace.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
#define PLUGIN_DB_NONE
Plugin requires no DB permission.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN