SHARE
TWEET

Untitled

a guest Jan 4th, 2019 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3.  *
  4.  * @ This file is created by http://DeZender.Net
  5.  * @ deZender (PHP5 Decoder for ionCube Encoder)
  6.  *
  7.  * @ Version        :   3.5.0.0
  8.  * @ Author         :   DeZender
  9.  * @ Release on     :   22.06.2018
  10.  * @ Official site  :   http://DeZender.Net
  11.  *
  12.  */
  13.  
  14. require_once '/opt/unetlab/html/includes/init.php';
  15. require_once BASE_DIR . '/html/includes/Slim/Slim.php';
  16. require_once BASE_DIR . '/html/includes/Slim-Extras/DateTimeFileWriter.php';
  17. require_once BASE_DIR . '/html/includes/api_authentication.php';
  18. require_once BASE_DIR . '/html/includes/api_configs.php';
  19. require_once BASE_DIR . '/html/includes/api_folders.php';
  20. require_once BASE_DIR . '/html/includes/api_labs.php';
  21. require_once BASE_DIR . '/html/includes/api_networks.php';
  22. require_once BASE_DIR . '/html/includes/api_nodes.php';
  23. require_once BASE_DIR . '/html/includes/api_pictures.php';
  24. require_once BASE_DIR . '/html/includes/api_status.php';
  25. require_once BASE_DIR . '/html/includes/api_textobjects.php';
  26. require_once BASE_DIR . '/html/includes/api_lineobjects.php';
  27. require_once BASE_DIR . '/html/includes/api_topology.php';
  28. require_once BASE_DIR . '/html/includes/api_uusers.php';
  29. require_once BASE_DIR . '/html/includes/api_capture.php';
  30. require_once BASE_DIR . '/html/includes/api_html5Desktop.php';
  31. Slim\Slim::registerAutoloader();
  32. $licprops = ioncube_license_properties();
  33. $app = new Slim\Slim(array('mode' => 'production', 'debug' => true, 'log.level' => Slim\Log::WARN, 'log.enabled' => true, 'log.writer' => new Slim\LogWriter(fopen('/opt/unetlab/data/Logs/api.txt', 'a'))));
  34. $app->hook(
  35.     'slim.after.router',
  36.     function() use ($app) {
  37.         $request = $app->request;
  38.         $response = $app->response;
  39.         $app->log->debug('Request path: ' . $request->getPathInfo());
  40.         $app->log->debug('Response status: ' . $response->getStatus());
  41.     }
  42. );
  43. $app->response->headers->set('Content-Type', 'application/json');
  44. $app->response->headers->set('X-Powered-By', 'Unified Networking Lab API');
  45. $app->response->headers->set('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0');
  46. $app->response->headers->set('Cache-Control', 'post-check=0, pre-check=0');
  47. $app->response->headers->set('Pragma', 'no-cache');
  48. $app->notFound(
  49.     function() use ($app) {
  50.         $output['code'] = 404;
  51.         $output['status'] = 'fail';
  52.         $output['message'] = $GLOBALS['messages'][60038];
  53.         $app->halt($output['code'], json_encode($output));
  54.     }
  55. );
  56. $db = checkDatabase();
  57.  
  58. if ($db === false) {
  59.     $app->map(
  60.         '/api/(:path+)',
  61.         function() use ($app) {
  62.             $output['code'] = 500;
  63.             $output['status'] = 'fail';
  64.             $output['message'] = $GLOBALS['messages'][90003];
  65.             $app->response->setStatus($output['code']);
  66.             $app->response->setBody(json_encode($output));
  67.         }
  68. )->via('DELETE', 'GET', 'POST');
  69.     $app->run();
  70. }
  71.  
  72. $html5_db = html5_checkDatabase();
  73.  
  74. if ($html5_db === false) {
  75.     $app->map(
  76.         '/api/(:path+)',
  77.         function() use ($app) {
  78.             $output['code'] = 500;
  79.             $output['status'] = 'fail';
  80.             $output['message'] = $GLOBALS['messages'][90003];
  81.             $app->response->setStatus($output['code']);
  82.             $app->response->setBody(json_encode($output));
  83.         }
  84. )->via('DELETE', 'GET', 'POST');
  85.     $app->run();
  86. }
  87.  
  88. if (updateDatabase($db) == false) {
  89.     $app->map(
  90.         '/api/(:path+)',
  91.         function() use ($app) {
  92.             $output['code'] = 500;
  93.             $output['status'] = 'fail';
  94.             $output['message'] = $GLOBALS['messages'][90006];
  95.             $app->response->setStatus($output['code']);
  96.             $app->response->setBody(json_encode($output));
  97.         }
  98. )->via('DELETE', 'GET', 'POST');
  99.     $app->run();
  100. }
  101.  
  102. $forbidden = array('code' => 401, 'status' => 'forbidden', 'message' => $GLOBALS['messages'][90032]);
  103. $app->post(
  104.     '/api/auth/login',
  105.     function() use ($app, $db, $html5_db, $licprops) {
  106.         $event = json_decode($app->request()->getBody());
  107.         $p = json_decode(json_encode($event), true);
  108.  
  109.         if (($licprops['expire']['value'] < intval(date('Ymd')) || $licprops['expire']['value'] == 'unlicensed') && isset($p['html5']) && $p['html5'] == 2) {
  110.             $output['code'] = 401;
  111.             $output['data']['reason'] = 'License expired ( ' . $licprops['expire']['value'] . ' )';
  112.             $app->response->setStatus($output['code']);
  113.             $app->response->setBody(json_encode($output));
  114.         } else {
  115.             $cookie = genUuid();
  116.             $output = apiLogin($db, $html5_db, $p, $cookie);
  117.             $mycookie = $cookie;
  118.  
  119.             if ($output['code'] == 200) {
  120.                 $app->setCookie('unetlab_session', $cookie, SESSION, '/api/', $_SERVER['SERVER_NAME'], false, false);
  121.             }
  122.  
  123.             $app->response->setStatus($output['code']);
  124.             $app->response->setBody(json_encode($output));
  125.  
  126.             if ($output['code'] == 200) {
  127.                 list($user, $tenant, $noneed) = apiAuthorization($db, $mycookie);
  128.  
  129.                 if ($user == false) {
  130.                     $output['code'] = 400;
  131.                     $output['data']['reason'] = 'Unauthorized';
  132.                     $app->response->setStatus($output['code']);
  133.                     $app->response->setBody(json_encode($output));
  134.  
  135.                     return null;
  136.                 }
  137.  
  138.                 $role = $user['role'];
  139.                 $key = $role . 's';
  140.                 $max = $licprops[$key]['value'];
  141.                 $query = "select session from users where role='" . $role . "' order by session desc limit 1 offset " . $max . ' ;';
  142.                 $statement = $db->prepare($query);
  143.                 $statement->execute();
  144.                 $result = $statement->fetch();
  145.                 $maxval = $result['session'];
  146.  
  147.                 if (0 < intval($maxval)) {
  148.                     $query = "update users set session = NULL where role = '" . $role . "' and session <= " . $maxval . ';';
  149.                     $statement = $db->prepare($query);
  150.                     $statement->execute();
  151.                 }
  152.             }
  153.  
  154.             $db = null;
  155.             $html5_db = null;
  156.         }
  157.     }
  158. );
  159. $app->get(
  160.     '/api/auth/logout',
  161.     function() use ($app, $db) {
  162.         $cookie = $app->getCookie('unetlab_session');
  163.         $app->deleteCookie('unetlab_session');
  164.         $output = apiLogout($db, $cookie);
  165.         $app->response->setStatus($output['code']);
  166.         $app->response->setBody(json_encode($output));
  167.         $db = null;
  168.         $html5_db = null;
  169.     }
  170. );
  171. $app->get(
  172.     '/api/auth',
  173.     function() use ($app, $db, $licprops) {
  174.         list($user, $tenant, $output) = apiAuthorization($db, $app->getCookie('unetlab_session'));
  175.  
  176.         if ($user === false) {
  177. .................................................................
  178. .........................................
  179. ...............
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top