Guest User

Untitled

a guest
Jun 24th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.66 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'components/security/base_user_auth.php';
  4. require_once 'components/security/table_based_user_grants_manager.php';
  5. require_once 'components/utils/system_utils.php';
  6.  
  7. class AdminApplication
  8. {
  9. /** @var AbstractUserAuthorization */
  10. private $userAuthorizationStrategy;
  11.  
  12. public function SetUserAuthorizationStrategy($userAuthorizationStrategy)
  13. {
  14. $this->userAuthorizationStrategy = $userAuthorizationStrategy;
  15. }
  16.  
  17. public function GetUserAuthorizationStrategy()
  18. {
  19. return $this->userAuthorizationStrategy;
  20. }
  21.  
  22. public function SetDataSourceRecordPermissionRetrieveStrategy($perms)
  23. {}
  24.  
  25. public function GetCurrentUser()
  26. {
  27. return $this->GetUserAuthorizationStrategy()->GetCurrentUser();
  28. }
  29.  
  30. public function HasAdminGrant($userName)
  31. {
  32. return $this->userAuthorizationStrategy->HasAdminGrant($userName);
  33. }
  34. }
  35.  
  36. $adminApp = new AdminApplication();
  37.  
  38. /**
  39. * @return AdminApplication
  40. */
  41. function GetApplication()
  42. {
  43. global $adminApp;
  44. return $adminApp;
  45. }
  46.  
  47. require_once 'authorization.php';
  48. SetUpUserAuthorization();
  49.  
  50. class AdminPanelView
  51. {
  52. private $localizerCaptions = null;
  53.  
  54. /** @var TableBasedUserGrantsManager */
  55. private $tableBasedGrantsManager;
  56.  
  57. public function __construct($tableBasedGrantsManager)
  58. {
  59. $this->tableBasedGrantsManager = $tableBasedGrantsManager;
  60. }
  61.  
  62. public function GetContentEncoding()
  63. {
  64. return 'UTF-8';
  65. }
  66.  
  67. public function GetLocalizerCaptions()
  68. {
  69. if (!isset($this->localizerCaptions))
  70. $this->localizerCaptions = new Captions($this->GetContentEncoding());
  71. return $this->localizerCaptions;
  72. }
  73.  
  74. public function GetHeader()
  75. {
  76. return '';
  77. }
  78.  
  79. public function Render()
  80. {
  81. include_once 'libs/smartylibs/Smarty.class.php';
  82.  
  83. $smarty = new Smarty();
  84. $smarty->template_dir = 'components/templates';
  85. $smarty->assign_by_ref('Page', $this);
  86.  
  87. $users = $this->tableBasedGrantsManager->GetAllUsersAsJson();
  88. $smarty->assign_by_ref('Users', $users);
  89.  
  90. $localizerCaptions = $this->GetLocalizerCaptions();
  91. $smarty->assign_by_ref('Captions', $localizerCaptions);
  92.  
  93. /* $roles = $this->tableBasedGrantsManager->GetAllRolesAsJson();
  94. $smarty->assign_by_ref('Roles', $roles); */
  95.  
  96. $pageLinks = array();
  97. $pageInfos = GetPageInfos();
  98. foreach($pageInfos as $pageInfo)
  99. array_push(
  100. $pageLinks,
  101. array(
  102. 'Caption' => $pageInfo['caption'],
  103. 'Hint' => $pageInfo['short_caption'],
  104. 'Link' => $pageInfo['filename'],
  105. ));
  106.  
  107.  
  108. $smarty->assign_by_ref('PageLinks', $pageLinks);
  109.  
  110. $smarty->display('admin_panel.tpl');
  111. }
  112.  
  113. public function ProcessRequest()
  114. {
  115. if (isset($_GET['hname']) )
  116. {
  117. header('Content-Type: application/json');
  118.  
  119. try
  120. {
  121. if ($_GET['hname'] == 'au')
  122. {
  123. $id = $_GET['id'];
  124. $userName = $_GET['username'];
  125. $password = $_GET['password'];
  126. $descripcion = $_GET['descripcion'];
  127. $email = $_GET['email'];
  128.  
  129. $this->tableBasedGrantsManager->AddUser($id, $userName, $password, $descripcion,$email);
  130.  
  131. echo SystemUtils::ToJSON(
  132. array(
  133. 'status' => 'OK',
  134. 'result' => array(
  135. 'id' => $id,
  136. 'name' => $userName,
  137. 'password' => '******'
  138. )
  139. ));
  140. }
  141. else if ($_GET['hname'] == 'ru')
  142. {
  143. $user_id = $_GET['user_id'];
  144.  
  145. $this->tableBasedGrantsManager->RemoveUser($user_id);
  146.  
  147. echo SystemUtils::ToJSON(array('status' => 'OK'));
  148. }
  149. else if ($_GET['hname'] == 'eu')
  150. {
  151. $user_id = $_GET['user_id'];
  152. $userName = $_GET['username'];
  153.  
  154. $newUserName = $this->tableBasedGrantsManager->ChangeUserName($user_id, $userName);
  155.  
  156. echo SystemUtils::ToJSON(array('status' => 'OK', 'result' => array('username' => $newUserName)));
  157. }
  158. else if ($_GET['hname'] == 'cup')
  159. {
  160. $user_id = $_GET['user_id'];
  161. $password = $_GET['password'];
  162.  
  163. $this->tableBasedGrantsManager->ChangeUserPassword($user_id, $password);
  164.  
  165. echo SystemUtils::ToJSON(array('status' => 'OK'));
  166. }
  167. else if ($_GET['hname'] == 'gug')
  168. {
  169. $user_id = $_GET['user_id'];
  170.  
  171. echo $this->tableBasedGrantsManager->GetUserGrantsAsJson($user_id);
  172. }
  173. else if ($_GET['hname'] == 'aug')
  174. {
  175. $user_id = $_GET['user_id'];
  176. $page_name = $_GET['page_name'];
  177. $grant = $_GET['grant'];
  178.  
  179. $this->tableBasedGrantsManager->AddUserGrant($user_id, $page_name, $grant);
  180. echo SystemUtils::ToJSON(array('status' => 'OK'));
  181. }
  182. else if ($_GET['hname'] == 'rug')
  183. {
  184. $user_id = $_GET['user_id'];
  185. $page_name = $_GET['page_name'];
  186. $grant = $_GET['grant'];
  187.  
  188. $this->tableBasedGrantsManager->RemoveUserGrant($user_id, $page_name, $grant);
  189. echo SystemUtils::ToJSON(array('status' => 'OK'));
  190. }
  191. }
  192. catch (Exception $e)
  193. {
  194. echo SystemUtils::ToJSON(
  195. array(
  196. 'status' =>'error',
  197. 'result' => $e->getMessage()));
  198. }
  199. return true;
  200. }
  201. return false;
  202. }
  203. }
  204.  
  205. $tableBasedGrants = CreateTableBasedGrantsManager();
  206.  
  207. $view = new AdminPanelView($tableBasedGrants);
  208.  
  209. if (!GetApplication()->HasAdminGrant(GetApplication()->GetCurrentUser()))
  210. {
  211. include_once 'components/error_utils.php';
  212. RaiseSecurityError($view, 'You do not have permission to access this page.');
  213. }
  214.  
  215. if (!$view->ProcessRequest())
  216. $view->Render();
Add Comment
Please, Sign In to add comment