PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/Supportworks Server/html/_phpinclude/itsm_default/xmlmc/sessioncheck.php

https://bitbucket.org/bittercreek_projects/supportworks
PHP | 319 lines | 251 code | 20 blank | 48 comment | 37 complexity | f64873283b3d648bb6e5389e5a366603 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. <?php //-- start php session
  2. @session_start();
  3. //--
  4. //-- set the install portal common files path - used for loading files
  5. //-- have option to override install path i.e. webserver or something similar
  6. //-- include php file that can be edited by consultant to point ot pat
  7. include("installpath.php");
  8. //-- NWJ - make sure session save path exists
  9. $savepath = ini_get('session.save_path');
  10. if (file_exists($savepath)==false)
  11. {
  12. RecursiveMkdir($savepath);
  13. }
  14. //--
  15. //-- determine the mode we are running in
  16. if(isAnalystPortal()==true)
  17. {
  18. //-- ANALYST PORTAL
  19. //-- check analyst session
  20. if(check_analyst_session_state()==false)
  21. {
  22. //-- analyst session expired or invalide
  23. if(gv("httpreqid")!="")
  24. {
  25. //-- being called by xmlhttp request so return session message
  26. echo "SESSION:Your Supportworks session has expired or is invalid. Please log on again.";
  27. }
  28. else
  29. {
  30. //-- being called in an include so goto index
  31. ?>
  32. <script>
  33. var undefined;
  34. if(portalroot==undefined)
  35. {
  36. //-- more than likely a popup page
  37. if(opener)
  38. {
  39. opener.create_submit_form("index.php?errorid=1702", "_self");
  40. //opener.document.location.href="index.php?errormsg=Your Supportworks session has expired or is invalid. Please log on again.";
  41. }
  42. self.close();
  43. }
  44. else
  45. {
  46. create_submit_form("index.php?errorid=1702", "_self");
  47. //document.location.href="index.php?errormsg=Your Supportworks session has expired or is invalid. Please log on again.";
  48. }
  49. </script>
  50. <?php }
  51. exit;
  52. }
  53. else
  54. {
  55. //-- analyst portal specific includes
  56. swdti_load($_SESSION['wc_dd']);
  57. //-- load app rights into session so we can do checks for menu options etc
  58. if(!isSet($_SESSION['wc_apprights']))
  59. {
  60. $xmlmc = new XmlMethodCall();
  61. $xmlmc->Invoke("session","getSessionInfo2");
  62. $strLastError = $xmlmc->GetLastError();
  63. $appRights = Array();
  64. if($strLastError=="")
  65. {
  66. $sessionok = true;
  67. $arrRows = $xmlmc->xmlDom->get_elements_by_tagname("params");
  68. foreach($arrRows as $cats)
  69. {
  70. $children = $cats->child_nodes();
  71. $dTotal = count($children);
  72. $catItem = array();
  73. for ($i=0;$i<$dTotal;$i++)
  74. {
  75. $colNode = $children[$i];
  76. if($colNode->node_name()!="#text" && $colNode->node_name()!="#comment")
  77. {
  78. $strColName = $colNode->tagname();
  79. $strColName = strtolower($strColName);
  80. if($strColName=="appright")
  81. {
  82. $appDD = _getxml_childnode_content($colNode,"appName");
  83. $appRights[$appDD] = Array();
  84. $appRights[$appDD]["A"] = _getxml_childnode_content($colNode,"rightA");
  85. $appRights[$appDD]["B"] = _getxml_childnode_content($colNode,"rightB");
  86. $appRights[$appDD]["C"] = _getxml_childnode_content($colNode,"rightC");
  87. $appRights[$appDD]["D"] = _getxml_childnode_content($colNode,"rightD");
  88. $appRights[$appDD]["E"] = _getxml_childnode_content($colNode,"rightE");
  89. $appRights[$appDD]["F"] = _getxml_childnode_content($colNode,"rightF");
  90. $appRights[$appDD]["G"] = _getxml_childnode_content($colNode,"rightG");
  91. $appRights[$appDD]["H"] = _getxml_childnode_content($colNode,"rightH");
  92. continue;
  93. }
  94. }
  95. }
  96. }
  97. $_SESSION['wc_apprights'] = $appRights[$_SESSION['dd']];
  98. }
  99. }
  100. }
  101. }
  102. else if ($_SESSION['portalmode'] == "FATCLIENT")
  103. {
  104. //--
  105. //-- reset portal instance path to be portal when using the fat client
  106. $GLOBALS['instance_path'] = sw_getcfgstring("InstallPath");
  107. $GLOBALS['instance_path'] .= "\html\_phpinclude\\". APPCODE ."\xmlmc\\";
  108. }
  109. else if ($_SESSION['portalmode'] == "CUSTOMER")
  110. {
  111. //-- ASSUME SELFSERVICE / CUSTOMER LOGIN BASED
  112. //-- include any self service specific stuff here
  113. //include_once("_ssconfig.php");
  114. // Load Application System Setting to check for a single selfservice root being used
  115. $_SESSION['use_single_portal_root'] = false;
  116. $sql = "select * from sw_sbs_settings where setting_name = 'SELFSERVICE.USE_SINGLE_PORTAL_ROOT' and appcode = '".$_SESSION['dataset']."'";
  117. $con = database_connect("swdata");
  118. if($con)
  119. {
  120. $oRS = $con->Query($sql,true);
  121. if($oRS)
  122. {
  123. if(!$oRS->eof)
  124. {
  125. if($oRS->f('setting_value')=="True")
  126. $_SESSION['use_single_portal_root'] = true;
  127. }
  128. }
  129. }
  130. include_once("classCustomerSession.php"); //-- class to handle customer session (setup session vars)
  131. if(!$_SESSION['use_single_portal_root']) //-- No need to perform checks for alternative selfservice portal if one portal being used
  132. {
  133. if(preg_match("/" . $_SESSION['app_path'] . "/i",$_SERVER['SCRIPT_URL'])===false)
  134. {
  135. $strDest = $_SERVER['HTTP_REFERER'];
  136. $strURL = $_SERVER['SCRIPT_URL'];
  137. $strDest = str_replace('portal.php' , '' , $strDest);
  138. //-- being called in an include so goto index
  139. if(gv("httpreqid")!="")
  140. {
  141. //-- being called by xmlhttp request so return session message
  142. echo "SESSION:" . $strSessionResult;
  143. }
  144. else
  145. {
  146. ?>
  147. <html>
  148. <head>
  149. <script>
  150. //-- F0098407
  151. if(!opener)
  152. opener = window.opener;
  153. //-- F0
  154. //-- more than likely a popup page
  155. if(opener)
  156. {
  157. //opener.document.location.href="index.php?errormsg=Your Supportworks session has expired or is invalid. Please log on again.";
  158. alert("Your Supportworks session has expired or is invalid. Please log on again");
  159. opener.create_submit_form("index.php?errorid=1702", "_self");
  160. //opener.location.href="<?php echo $strDest;?>index.php?errormsg=6Your Supportworks session has expired or is invalid. Please log on again";
  161. self.close();
  162. }else
  163. {
  164. alert("Your Supportworks session has expired or is invalid. Please log on again");
  165. parent.window.location.href="index.php?errorid=1702";
  166. }
  167. </script>
  168. </head>
  169. <body>
  170. <p>Please go <a href="index.php">here</a>.</p>
  171. </body>
  172. </html>
  173. <?php }
  174. exit;
  175. }
  176. }
  177. //--
  178. //-- check we have a valid session
  179. GLOBAL $customer_session;
  180. $customer_session = new classCustomerSession;
  181. $strSessionResult = check_customer_session_state();
  182. if($strSessionResult!="OK")
  183. {
  184. //-- we are using sspi
  185. if(($_SESSION['SSPION']) && ($_SERVER['HTTP_REFERER'] != 'sspi/index.php'))
  186. {
  187. // header('Location: index.php?errormsg=' . $strSessionResult , 303);
  188. header('Location: index.php?errorid=1702' , 303);
  189. exit;
  190. }
  191. if(gv("httpreqid")!="")
  192. {
  193. //-- being called by xmlhttp request so return session message
  194. echo "SESSION:" . $strSessionResult;
  195. }
  196. else
  197. {
  198. $strURL = $_SERVER['SCRIPT_URL'];
  199. if(strpos($strURL,'/action.php')!==false)
  200. {
  201. }
  202. else
  203. {
  204. //-- being called in an include so goto index
  205. ?>
  206. <script>
  207. //-- F0098407
  208. if(!opener)
  209. opener = window.opener;
  210. if(opener)
  211. {
  212. //opener.document.location.href="index.php?errormsg=Your Supportworks session has expired or is invalid. Please log on again.";
  213. alert("Your Supportworks session has expired or is invalid. Please log on again");
  214. opener.location.href="<?php echo $_SESSION['www_portalroot'];?>index.php?errorid=17021234";
  215. self.close();
  216. }
  217. else
  218. {
  219. alert("Your Supportworks session has expired or is invalid. Please log on again");
  220. parent.window.location.href="index.php?errorid=1702";
  221. }
  222. </script>
  223. <?php exit;
  224. }
  225. }
  226. }
  227. //-- load customer ss ddf info (so we can use swdti_getcolname etc0
  228. swdti_load($_SESSION['config_dd']);
  229. }
  230. else
  231. {
  232. if(gv("httpreqid")!="")
  233. {
  234. //-- being called by xmlhttp request so return session message
  235. echo "SESSION:Your Supportworks session has expired or is invalid. Please log on again";// . $strSessionResult;
  236. exit;
  237. }
  238. else
  239. {
  240. //-- not a recognised session
  241. ?>
  242. <html>
  243. <head>
  244. <script>
  245. //-- more than likely a popup page
  246. if(!opener)
  247. opener = window.opener;
  248. if(opener)
  249. {
  250. alert("Your Supportworks session has expired or is invalid. Please log on again");
  251. opener.location.href="index.php?errorid=1702";
  252. //opener.document.location.href="index.php?errormsg=Your Supportworks session has expired or is invalid. Please log on again.";
  253. self.close();
  254. }
  255. else
  256. {
  257. alert("Your Supportworks session has expired or is invalid. Please log on again");
  258. parent.window.location.href="index.php?errorid=1702";
  259. }
  260. </script>
  261. </head>
  262. <body>
  263. <p>Please go <a href="index.php">here</a>.</p>
  264. </body>
  265. </html>
  266. <?php die();
  267. }
  268. }
  269. //--
  270. //-- get customer session state message
  271. function check_customer_session_state()
  272. {
  273. $strResult="OK";
  274. GLOBAL $customer_session;
  275. switch($customer_session->check_session_state())
  276. {
  277. case SW_SESSION_INVALID: // Invalid session ID string
  278. $strResult= "Invalid Session ID found. Please log in again";
  279. break;
  280. case SW_SESSION_TIMEOUT: // Session ID has expired
  281. $strResult= "Your session has timed out. Please log in again";
  282. break;
  283. case SW_SESSION_OK: // We are a valid session
  284. break;
  285. }//end switch/case on session
  286. return $strResult;
  287. }
  288. //--
  289. //-- get analyst session state message
  290. function check_analyst_session_state()
  291. {
  292. return $_SESSION['wcsession']->IsValidSession($_SESSION['sw_sessionid']);
  293. }
  294. //-- t / f if running in webportal mode
  295. function isAnalystPortal()
  296. {
  297. return ($_SESSION['portalmode']=="WEBPORTAL");
  298. }
  299. ?>