Guest User

Untitled

a guest
Sep 2nd, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.76 KB | None | 0 0
  1. @extends('layouts.app_install')
  2.  
  3. @section('title_text')
  4. Installing - Step 3
  5. @endsection
  6.  
  7. @section('title')
  8. Installing - Step 3
  9. @endsection
  10.  
  11. @section('content')
  12. <style>
  13. .btn-info
  14. {
  15. background: #4c83c7 !important;
  16. border: none;
  17. outline: none;
  18. height: 40px;
  19. text-align: center;
  20. border-radius: 3px;
  21. padding: 10px;
  22. min-width: 140px;
  23. }
  24. label
  25. {
  26. margin: 0;
  27. padding: 0;
  28. color: #48545f;
  29. font-family: 'FiraSans', sans-serif;
  30. font-size: 13.0px;
  31. font-style: normal;
  32. font-stretch: normal;
  33. font-weight: 500;
  34. text-align: left;
  35. }
  36. .form-control
  37. {
  38. width: 100%;
  39. border: 1px solid #b7c5ce;
  40. color: #48545f;
  41. font-family: 'FiraSans', sans-serif;
  42. font-size: 13.0px;
  43. font-style: normal;
  44. font-stretch: normal;
  45. font-weight: 500;
  46. font-size: 20px;
  47. border: 1px solid #B7C5CE;
  48. height: 40px !important;
  49. margin-top: 10px;
  50. }
  51. </style>
  52.  
  53. <div class="con">
  54. <div class="row" style="margin-top: 20px;">
  55. <div class="col-md-8 col-md-offset-2" style="margin-top: 10px;">
  56. @if (Session::has('error'))
  57. <div class="alert alert-danger">
  58. {{ $errors->first('error_msg') == '' ? __('settings.form_error') : $errors->first('error_msg') }}
  59. </div>
  60. @endif
  61. @if ($errors->any())
  62. <div class="alert alert-success">
  63. {{ __('settings.saved_successfull') }}
  64. </div>
  65. @endif
  66. </div>
  67. <div class="col-md-8 col-md-offset-2">
  68. {{ Form::open(array('url' => 'install/step3/save')) }}
  69.  
  70. <div class="row">
  71. <div class="col-md-12">
  72. <div class="form-group">
  73. <label>Purchase key</label>
  74. {{ Form::text('product_key', '' , ['class' => 'form-control']) }}
  75. </div>
  76. </div>
  77. </div>
  78.  
  79. <button type="submit" class="btn btn-info"><i class="fa fa-angle-right"></i> Install</button>
  80.  
  81. </div>
  82. </div>
  83. </div>
  84. @endsection
  85.  
  86. <?php
  87.  
  88. namespace AppHttpControllers;
  89.  
  90. use AppFb_account;
  91. use AppFb_account_node;
  92. use AppFb_app;
  93. use AppLibCurl;
  94. use AppLibFBLib;
  95. use AppOption;
  96. use AppUser;
  97. use IlluminateHttpRequest;
  98. use IlluminateSupportFacadesApp;
  99. use IlluminateSupportFacadesAuth;
  100. use IlluminateSupportFacadesDB;
  101. use IlluminateSupportFacadesHash;
  102. use IlluminateSupportFacadesURL;
  103.  
  104.  
  105. class InstallationController extends Controller
  106. {
  107.  
  108. private function checkStep($step)
  109. {
  110. if( env('APP_VER' , '') !== '' )
  111. {
  112. redirect('update' )->send();
  113. exit();
  114. }
  115.  
  116. if( $step > 0 && $this->checkRequierments() == false )
  117. {
  118. redirect('install' )->send();
  119. exit();
  120. }
  121.  
  122. $sessStep = session('step' , '1');
  123.  
  124. if( $sessStep != $step )
  125. {
  126. redirect('install/step' . $sessStep)->send();
  127. exit();
  128. }
  129. }
  130.  
  131. public function start()
  132. {
  133. if( env('APP_VER' , '') !== '' )
  134. {
  135. redirect('update' )->send();
  136. exit();
  137. }
  138.  
  139. return view('install.start' , ['requirments' => $this->checkRequierments(true) , 'start' => $this->checkRequierments()]);
  140. }
  141.  
  142. private function checkRequierments($returnArray = false)
  143. {
  144. $requirments = [
  145. 'allow_url_fopen' => ini_get('allow_url_fopen') ? 'yes' : 'no',
  146. 'php_ver' => version_compare(PHP_VERSION, '7.1.3') >= 0 ? 'yes' : 'no',
  147. 'open_ssl' => extension_loaded('openssl') ? 'yes' : 'no',
  148. 'pdo' => class_exists('PDO') ? 'yes' : 'no',
  149. 'mbstring' => extension_loaded('mbstring') ? 'yes' : 'no',
  150. 'json' => function_exists('json_encode') ? 'yes' : 'no',
  151. 'curl' => function_exists('curl_init') ? 'yes' : 'no'
  152. ];
  153.  
  154. if( $returnArray )
  155. {
  156. return $requirments;
  157. }
  158.  
  159. foreach( $requirments AS $requirment )
  160. {
  161. if( $requirment == 'no' )
  162. {
  163. return false;
  164. }
  165. }
  166.  
  167. return true;
  168. }
  169.  
  170. public function step1()
  171. {
  172. $this->checkStep(1);
  173.  
  174. return view('install.step1');
  175. }
  176.  
  177. public function step1Save(Request $request)
  178. {
  179. $validatedData = $request->validate([
  180. 'sql_hostname' => 'required|string|max:255',
  181. 'sql_username' => 'required|string|max:255',
  182. 'sql_database' => 'required|string|max:255',
  183. 'sql_password' => 'nullable|string|max:255',
  184. ]);
  185.  
  186. config()->set('database.connections.test', [
  187. 'driver' => 'mysql',
  188. 'host' => $validatedData['sql_hostname'],
  189. 'port' => env('DB_PORT', '3306'),
  190. 'database' => $validatedData['sql_database'],
  191. 'username' => $validatedData['sql_username'],
  192. 'password' => $validatedData['sql_password'],
  193. 'unix_socket' => env('DB_SOCKET', ''),
  194. 'charset' => 'utf8mb4',
  195. 'collation' => 'utf8mb4_unicode_ci',
  196. 'prefix' => '',
  197. 'strict' => true,
  198. 'engine' => null,
  199. ]);
  200.  
  201. try
  202. {
  203. DB::connection('test')->select('SELECT 1 test');
  204. }
  205. catch (Exception $e)
  206. {
  207. return redirect()->back()->withErrors(['error_msg' => 'Connection error!'])->withInput();
  208. }
  209.  
  210. session([
  211. 'step' => 2,
  212. 'sql_hostname' => $validatedData['sql_hostname'],
  213. 'sql_username' => $validatedData['sql_username'],
  214. 'sql_database' => $validatedData['sql_database'],
  215. 'sql_password' => $validatedData['sql_password'] ?? ''
  216. ]);
  217.  
  218. return redirect('install/step2');
  219. }
  220.  
  221. public function step2()
  222. {
  223. $this->checkStep(2);
  224.  
  225. return view('install.step2');
  226. }
  227.  
  228. public function step2Save(Request $request)
  229. {
  230. $validatedData = $request->validate([
  231. 'site_title' => 'required|string|max:255',
  232. 'admin_username' => 'required|string|max:255',
  233. 'admin_email' => 'required|string|email|max:255',
  234. 'admin_password' => 'required|string|max:255|min:6|confirmed'
  235. ]);
  236.  
  237. session([
  238. 'step' => 3,
  239. 'site_title' => $validatedData['site_title'],
  240. 'admin_username' => $validatedData['admin_username'],
  241. 'admin_email' => $validatedData['admin_email'],
  242. 'admin_password' => $validatedData['admin_password']
  243. ]);
  244.  
  245. return redirect('install/step3');
  246. }
  247.  
  248. public function step3()
  249. {
  250. $this->checkStep(3);
  251.  
  252. return view('install.step3');
  253. }
  254.  
  255. public function step3Save(Request $request)
  256. {
  257. $validatedData = $request->validate([
  258. 'product_key' => 'required|string|min:5|max:255'
  259. ]);
  260.  
  261. $productKey = $validatedData['product_key'];
  262.  
  263. $checkPurchaseCodeURL = "http://api.emplenio.com/api.php?purchase_code=" . $productKey . "&version=" . config('app.version');
  264. $result = Curl::getURL($checkPurchaseCodeURL);
  265.  
  266. $result = json_decode($result , true);
  267. $result = is_array( $result ) ? $result : ['status' => 'error' , 'error_msg' => 'Error!!!'];
  268.  
  269. if( !($result['status'] == 'ok' && isset($result['sql']) && isset($result['routes'])) )
  270. {
  271. return redirect()->back()->withErrors(['error_msg' => isset($result['error_msg']) ? $result['error_msg'] : 'Error!'])->withInput();
  272. }
  273.  
  274. $requiredSessions = ['site_title','admin_username','admin_email','admin_password','sql_hostname','sql_username','sql_database','sql_password'];
  275. foreach($requiredSessions AS $rSess)
  276. {
  277. if( session($rSess , null) === null )
  278. {
  279. session()->flush();
  280. return redirect('install/step1');
  281. }
  282. }
  283.  
  284. config()->set('database.connections.test', [
  285. 'driver' => 'mysql',
  286. 'host' => session('sql_hostname'),
  287. 'port' => env('DB_PORT', '3306'),
  288. 'database' => session('sql_database'),
  289. 'username' => session('sql_username'),
  290. 'password' => session('sql_password'),
  291. 'unix_socket' => env('DB_SOCKET', ''),
  292. 'charset' => 'utf8mb4',
  293. 'collation' => 'utf8mb4_unicode_ci',
  294. 'prefix' => '',
  295. 'strict' => true,
  296. 'engine' => null,
  297. ]);
  298.  
  299. try
  300. {
  301. DB::connection('test')->select('SELECT 1 test');
  302. }
  303. catch (Exception $e)
  304. {
  305. return redirect('install/step1');
  306. }
  307.  
  308. $pdo = $pdo = DB::connection('test')->getPdo();
  309.  
  310. $siteUrl = URL::to('/');
  311.  
  312. $envData = "APP_NAME="Fb Poster"n" .
  313. "APP_ENV=localn" .
  314. "APP_KEY=base64:ZJEEMphpVNqCP7tXfnvU9vOe/EWCghoG482bOgWesck=n" .
  315. "APP_DEBUG=falsen" .
  316. "APP_LOG_LEVEL=debugn" .
  317. "APP_VER=".config('app.version')."n" .
  318. "APP_URL="" . $siteUrl . ""nn" .
  319. "DB_CONNECTION="mysql"n" .
  320. "DB_HOST="" . session('sql_hostname') . ""n" .
  321. "DB_PORT=3306n" .
  322. "DB_DATABASE="" . session('sql_database') . ""n" .
  323. "DB_USERNAME="" . session('sql_username') . ""n" .
  324. "DB_PASSWORD="" . session('sql_password') . """;
  325.  
  326. $dbb = base64_decode( $result['sql'] );
  327. $dbbArray = explode(';' , $dbb);
  328.  
  329. foreach( $dbbArray AS $queryOne )
  330. {
  331. $queryOne = trim($queryOne);
  332.  
  333. if( empty($queryOne) )
  334. continue;
  335.  
  336. $qry = $pdo->prepare( $queryOne );
  337. $qry->execute();
  338. }
  339.  
  340. DB::connection('test')->table('users')->insert([
  341. 'email' => session('admin_email'),
  342. 'username' => session('admin_username'),
  343. 'password' => Hash::make(session('admin_password')),
  344. 'timezone' => 'Asia/Baku',
  345. 'language_id' => '1',
  346. 'records_per_page' => '25',
  347. 'load_my_groups' => '1',
  348. 'load_my_pages' => '1',
  349. 'load_my_ownpages' => '1',
  350. 'max_groups_to_import' => '200',
  351. 'max_pages_to_import' => '200',
  352. 'show_open_groups_only' => '0',
  353. 'unique_post' => '0',
  354. 'unique_link' => '0',
  355. 'post_interval' => '60',
  356. 'fb_account_id' => '0',
  357. 'is_admin' => '1',
  358. 'user_role_id' => '1',
  359. 'status' => '1',
  360. 'link_customization' => '1',
  361. 'created_at' => date('Y-m-d H:i:s')
  362. ]);
  363.  
  364. DB::connection('test')->table('options')->update([
  365. 'site_name' => session('site_title')
  366. ]);
  367.  
  368. file_put_contents( base_path('.env') , $envData );
  369. file_put_contents(base_path('routes/web.php') , base64_decode( $result['routes'] ));
  370.  
  371. if( crontab_installed() )
  372. {
  373. try
  374. {
  375. $cron_file = "/tmp/crontab.txt";
  376. $cronUrl = url('/');
  377.  
  378. $cmd = "0 0,6,12,18 * * * wget -O /dev/null ".$cronUrl."/schedule/insert_schedules >/dev/null 2>&1n";
  379. $cmd .= "*/2 * * * * wget -O /dev/null ".$cronUrl."/schedule/send_posts >/dev/null 2>&1n";
  380. $cmd .= "*/5 * * * * wget -O /dev/null ".$cronUrl."/schedule/auto_resume_post >/dev/null 2>&1";
  381.  
  382. $output = shell_exec('crontab -l');
  383. file_put_contents($cron_file, $output . $cmd . PHP_EOL);
  384. exec("crontab $cron_file");
  385. }
  386. catch(Exception $e)
  387. {
  388.  
  389. }
  390. }
  391.  
  392. session()->flush();
  393.  
  394. return redirect('/');
  395. }
  396.  
  397.  
  398. public function update()
  399. {
  400. if( env('APP_VER' , '') === '' )
  401. {
  402. redirect('install' )->send();
  403. exit();
  404. }
  405.  
  406. return view('install.update');
  407. }
  408.  
  409. public function updateSave(Request $request)
  410. {
  411. $validatedData = $request->validate([
  412. 'product_key' => 'required|string|min:5|max:255'
  413. ]);
  414.  
  415. $productKey = $validatedData['product_key'];
  416.  
  417. $checkPurchaseCodeURL = "http://api.emplenio.com/api.php?act=update&purchase_code=" . $productKey . "&version1=" . env('APP_VER') . "&version2=" . config('app.version');
  418. $result = Curl::getURL($checkPurchaseCodeURL);
  419.  
  420. $result = json_decode($result , true);
  421. $result = is_array( $result ) ? $result : ['status' => 'error' , 'error_msg' => 'Error!!!'];
  422.  
  423. if( !($result['status'] == 'ok' && isset($result['sql']) && isset($result['routes'])) )
  424. {
  425. return redirect()->back()->withErrors(['error_msg' => isset($result['error_msg']) ? $result['error_msg'] : 'Error!'])->withInput();
  426. }
  427.  
  428. $pdo = $pdo = DB::connection()->getPdo();
  429.  
  430. $dbb = base64_decode( $result['sql'] );
  431. $dbbArray = explode(';' , $dbb);
  432.  
  433. foreach( $dbbArray AS $queryOne )
  434. {
  435. $queryOne = trim($queryOne);
  436.  
  437. if( empty($queryOne) )
  438. continue;
  439.  
  440. $qry = $pdo->prepare( $queryOne );
  441. $qry->execute();
  442. }
  443.  
  444. file_put_contents(base_path('routes/web.php') , base64_decode( $result['routes'] ));
  445.  
  446. session()->flush();
  447.  
  448. // update version in .env file
  449. $envFile = file_get_contents(base_path('.env'));
  450. $envFile = str_replace('APP_VER=' . env('APP_VER') , 'APP_VER='.config('app.version') , $envFile);
  451. file_put_contents(base_path('.env') , $envFile);
  452.  
  453. return redirect('/');
  454. }
  455.  
  456. }
Add Comment
Please, Sign In to add comment