Advertisement
thisroot

Untitled

Sep 6th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 29.46 KB | None | 0 0
  1. <?
  2. $error = false;
  3.  
  4. if (isset($_POST['action'])) {
  5.     switch ($_POST['action']) {
  6.         case 'users_set_connection': $_SESSION['core']['install']['users']['connection'] = $_POST['connection']; break;
  7.        
  8.         case 'module_backup_ssh_connection':
  9.             if (isset($_POST['module_backup_ssh_connection'])) {
  10.                 $_SESSION['core']['install']['backup']['module_backup_ssh_connection'] = $_POST['module_backup_ssh_connection'];
  11.                 $_SESSION['core']['install']['backup']['module_backup_ssh_add_connection'] = 'module_backup_ssh_add_connection';
  12.             } else {
  13.                 $_SESSION['core']['install']['backup']['module_backup_ssh_connection'] = 0;
  14.             }
  15.             break;
  16.  
  17.         case 'add-ssh':
  18.             $_SESSION['core']['install']['backup']['module_backup_ssh_connection'] = 0;
  19.             unset($_SESSION['core']['install']['backup']['module_backup_ssh_add_connection']);
  20.             break;
  21.        
  22.         case 'select-ssh':
  23.             unset($_SESSION['core']['install']['backup']['module_backup_ssh_connection']);
  24.             break;
  25.        
  26.         case 'back-to-ssh':
  27.             unset($_SESSION['core']['install']['backup']['module_backup_ssh_connection']);
  28.             break;
  29.        
  30.         case 'login-link':
  31.             unset($_SESSION['core']['install']['backup']['module_backup_remote_host']);
  32.             break;
  33.  
  34.         case 'login':
  35.             if (isset($_POST['host'])) {
  36.                 $_SESSION['core']['install']['backup']['module_backup_remote_host'] = $_POST['host'];
  37.                 $_SESSION['core']['install']['backup']['module_backup_remote_email'] = $_POST['email'];
  38.                 $_SESSION['core']['install']['backup']['module_backup_remote_pass'] = APP::Module('Crypt')->Encode($_POST['password']);
  39.                 $_SESSION['core']['install']['backup']['module_backup_server_mode'] = isset($_POST['server-mode'])?$_POST['server-mode']:FALSE;
  40.                 $_SESSION['core']['install']['backup']['register'] = 'register';
  41.             } else {
  42.                 $_SESSION['core']['install']['backup']['module_backup_remote_host'] = 0;
  43.             }
  44.             break;
  45.  
  46.         case 'add-registration':
  47.             $_SESSION['core']['install']['backup']['module_backup_remote_host'] = 0;
  48.             unset($_SESSION['core']['install']['backup']['register']);
  49.             break;
  50.  
  51.             break;
  52.         case 'add-cronjob':
  53.             $_SESSION['core']['install']['backup']['add-cronjob'] = $_POST['action'];
  54.             $_SESSION['core']['install']['backup']['module_backup_id_ssh'] = APP::Module('Crypt')->Decode($_POST['ssh_id_hash']);
  55.             $_SESSION['core']['install']['backup']['module_backup_every_jobs'] = $_POST['jobs-every'];
  56.             break;
  57.     }
  58. }
  59.  
  60. ob_start();
  61. ?>
  62. <!DOCTYPE html>
  63. <html lang="en-US">
  64.     <head>
  65.         <title>Install BackUp</title>
  66.         <meta charset="UTF-8">
  67.         <meta name="robots" content="none">
  68.          <!-- Vendor CSS -->
  69.         <link href="<?= APP::Module('Routing')->root ?>public/ui/vendors/bower_components/animate.css/animate.min.css" rel="stylesheet">
  70.         <link href="<?= APP::Module('Routing')->root ?>public/ui/vendors/bower_components/material-design-iconic-font/dist/css/material-design-iconic-font.min.css" rel="stylesheet">
  71.         <link href="<?= APP::Module('Routing')->root ?>public/ui/vendors/bower_components/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.min.css" rel="stylesheet">        
  72.         <link href="<?= APP::Module('Routing')->root ?>public/ui/vendors/bower_components/google-material-color/dist/palette.css" rel="stylesheet">
  73.         <link href="<?= APP::Module('Routing')->root ?>public/ui/vendors/bower_components/bootstrap-sweetalert/lib/sweet-alert.css" rel="stylesheet">
  74.        
  75.         <!-- Javascript Libraries -->
  76.         <script src="<?= APP::Module('Routing')->root ?>public/ui/vendors/bower_components/jquery/dist/jquery.min.js"></script>
  77.         <script src="<?= APP::Module('Routing')->root ?>public/ui/vendors/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
  78.         <script src="<?= APP::Module('Routing')->root ?>public/ui/vendors/bower_components/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.concat.min.js"></script>
  79.         <script src="<?= APP::Module('Routing')->root ?>public/ui/vendors/bower_components/Waves/dist/waves.min.js"></script>
  80.         <script src="<?= APP::Module('Routing')->root ?>public/ui/vendors/bower_components/bootstrap-sweetalert/lib/sweet-alert.min.js"></script>
  81.         <script src="<?= APP::Module('Routing')->root ?>public/ui/vendors/fileinput/fileinput.min.js"></script>
  82.     </head>
  83.     <body>
  84.  
  85.         <?
  86.         if (!$error) {
  87.         if (!isset($_SESSION['core']['install']['users']['connection'])) {
  88.             $error = true;
  89.             ?>
  90.             <h3>Select connection</h3>
  91.             <form method="post">
  92.                 <input type="hidden" name="action" value="users_set_connection">
  93.                 <select name="connection">
  94.                     <? foreach (array_keys(APP::Module('DB')->conf['connections']) as $connection) { ?><option value="<?= $connection ?>"><?= $connection ?></option><? } ?>
  95.                 </select>
  96.                 <br><br>
  97.                 <input type="submit" value="Next">
  98.             </form>
  99.             <?
  100.         }
  101.     }
  102.        
  103.        
  104.         if (!$error) {
  105.             if (!isset($_SESSION['core']['install']['backup']['module_backup_ssh_connection'])) {
  106.  
  107.                 $error = true;
  108.  
  109.                 if (APP::Module('Registry')->Get(['module_ssh_connection'], ['id', 'value'])) {
  110.                     $_SESSION['core']['install']['backup']['module_backup_ssh_add_connection'] = 'module_backup_ssh_add_connection';
  111.                     $data = APP::Module('Registry')->Get(['module_ssh_connection'], ['id', 'value']);
  112.                     ?>
  113.                     <h1>Select SSH</h1>
  114.  
  115.                     <form method="post">
  116.                         <input type="hidden" name="action" value="module_backup_ssh_connection">
  117.                         <label for="module_backup_ssh_connection">SSH connection</label>
  118.                         <br>
  119.  
  120.                         <select id="module_backup_ssh_connection" type="text" name="module_backup_ssh_connection">
  121.                             <? foreach ($data['module_ssh_connection'] as $ssh_con) { ?>
  122.                                 <option   value="<?= $ssh_con['id'] ?>"><?= json_decode($ssh_con['value'])[2] . '@' . json_decode($ssh_con['value'])[0] . ':' . json_decode($ssh_con['value'])[1] ?></option><? } ?>
  123.                         </select>
  124.                         <div class="error"></div>
  125.                         <br><br>
  126.  
  127.  
  128.                         <input type="submit" value="Next">
  129.                     </form>
  130.                     <br><br>
  131.                     <form method="POST">
  132.                         <input type="hidden" name="action" value="add-ssh">
  133.                         <input type="submit" value="Add SSH">
  134.                     </form>
  135.  
  136.                     <?
  137.                 } else {
  138.                     $error = false;
  139.                 }
  140.             }
  141.         }
  142.  
  143.         if (!$error) {
  144.             if (!isset($_SESSION['core']['install']['backup']['module_backup_ssh_add_connection'])) {
  145.                 unset($_SESSION['core']['install']['backup']['module_backup_ssh_connection']);
  146.                 ?><h1>Add SSH</h1><? $error = true;
  147.                
  148.                 if (APP::Module('Registry')->Get(['module_ssh_connection'], ['id', 'value'])) { ?>
  149.                  <form method="POST">
  150.                         <input type="hidden" name="action" value="select-ssh">
  151.                         <input type="submit" value="Select SSH">
  152.                  </form><br><br> <?
  153.                 } ?>
  154.                
  155.                 <form method="POST" id="add-connection">
  156.                     <input id="module_backup_ssh_connection" type="hidden" name="module_backup_ssh_connection" value="">
  157.                     <label for="host">Host</label>
  158.                     <br>
  159.                     <input id="host" type="text" name="host" value="127.0.0.1">
  160.                     <div class="error"></div>
  161.                     <br><br>
  162.  
  163.                     <label for="port">Port</label>
  164.                     <br>
  165.                     <input id="port" type="text" name="port" value="22" style="width: 50px">
  166.                     <div class="error"></div>
  167.                     <br><br>
  168.  
  169.                     <label for="user">User</label>
  170.                     <br>
  171.                     <input id="user" type="text" name="user" value="">
  172.                     <div class="error"></div>
  173.                     <br><br>
  174.  
  175.                     <label for="password">Password</label>
  176.                     <br>
  177.                     <input id="password" type="password" name="password" value="">
  178.                     <a href="javascript:void(0);" class="hide-password">Show</a>
  179.                     <div class="error"></div>
  180.                     <br><br>
  181.  
  182.                     <input type="submit" value="Add">            
  183.                 </form>
  184.                
  185.                  
  186.                
  187.                 <script>
  188.                     $('.hide-password').on('click', function () {
  189.                         var $this = $(this),
  190.                                 $password_field = $this.prev('input');
  191.  
  192.                         ('password' == $password_field.attr('type')) ? $password_field.attr('type', 'text') : $password_field.attr('type', 'password');
  193.                         ('Hide' == $this.text()) ? $this.text('Show') : $this.text('Hide');
  194.                     });
  195.  
  196.                     $('#add-connection').submit(function (event) {
  197.                         event.preventDefault();
  198.  
  199.                         var host = $(this).find('#host');
  200.                         host.removeClass('has-error').nextAll('.error').eq(0).removeClass('is-visible').empty();
  201.                         if (host.val() === '') {
  202.                             host.addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Not specified');
  203.                             return false;
  204.                         }
  205.  
  206.                         var port = $(this).find('#port');
  207.                         port.removeClass('has-error').nextAll('.error').eq(0).removeClass('is-visible').empty();
  208.                         if (port.val() === '') {
  209.                             port.addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Not specified');
  210.                             return false;
  211.                         }
  212.  
  213.                         var user = $(this).find('#user');
  214.                         user.removeClass('has-error').nextAll('.error').eq(0).removeClass('is-visible').empty();
  215.                         if (user.val() === '') {
  216.                             user.addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Not specified');
  217.                             return false;
  218.                         }
  219.  
  220.                         var password = $(this).find('#password');
  221.                         password.removeClass('has-error').nextAll('.error').eq(0).removeClass('is-visible').empty();
  222.                         if (password.val() === '') {
  223.                             password.addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Not specified');
  224.                             return false;
  225.                         }
  226.  
  227.                         $(this).find('[type="submit"]').attr('disabled', true);
  228.  
  229.                         $.ajax({
  230.                             type: 'post',
  231.                             url: '<?= APP::Module('Routing')->root ?>admin/ssh/api/add.json',
  232.                             data: $(this).serialize(),
  233.                             success: function (result) {
  234.                                 switch (result.status) {
  235.                                     case 'success':
  236.                                         alert('Connection "' + user.val() + '@' + host.val() + ':' + port.val() + '" has been added');
  237.                                         $('#add-connection').unbind();
  238.                                         $(this).find('#host').val(result.connection_id);
  239.                                         $('#add-connection').submit();
  240.  
  241.                                         break;
  242.                                     case 'error':
  243.                                         $.each(result.errors, function (i, error) {
  244.                                             switch (error) {
  245.                                                 case 1:
  246.                                                     $('#host').addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Not specified');
  247.                                                     break;
  248.                                                 case 2:
  249.                                                     $('#port').addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Not specified');
  250.                                                     break;
  251.                                                 case 3:
  252.                                                     $('#user').addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Not specified');
  253.                                                     break;
  254.                                                 case 4:
  255.                                                     $('#password').addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Not specified');
  256.                                                     break;
  257.                                             }
  258.                                         });
  259.                                         break;
  260.                                 }
  261.  
  262.                                 $('#add-connection').find('[type="submit"]').attr('disabled', false);
  263.                             }
  264.                         });
  265.                     });
  266.                 </script>
  267.                 <?
  268.             }
  269.         }
  270.  
  271.         if (!$error) {
  272.             if (!isset($_SESSION['core']['install']['backup']['module_backup_remote_host'])) {
  273.                 ?><h1>Backup server</h1>
  274.                 <? $error = true; ?>
  275.                 <form method="POST">
  276.                     <input type="hidden" name="action" value="back-to-ssh">
  277.                     <input type="submit" value="back">
  278.                 </form>
  279.                
  280.                 <form method="POST">
  281.                     <input type="hidden" name="action" value="add-registration">
  282.                     <input type="submit" value="Register">
  283.                 </form>
  284.                 <br><br>
  285.  
  286.                 <form method="POST" id="login">
  287.                     <input type="hidden" name="action" value="login">
  288.                     <label for="host">Host</label>
  289.                     <br>
  290.                     <input id="host" name="host" value="https://default.com">
  291.                     <br><br>
  292.                     <label for="email">E-mail</label>
  293.                     <br>
  294.                     <input id="email" type="email" name="email">
  295.                     <div class="error"></div>
  296.                     <br>
  297.  
  298.                     <label for="password">Password</label>
  299.                     <br>
  300.                     <input id="password" type="password" name="password">
  301.                     <a href="javascript:void(0);" class="hide-password">Show</a>
  302.                     <div class="error"></div>
  303.                     <br>
  304.                     <label><input name="server-mode"  value="true" type="checkbox">Enable server mode</label><br><br>
  305.                     <input hidden="true" type="checkbox" name="remember-me" checked="checked">
  306.                     <input type="submit" value="Login">
  307.                 </form>
  308.  
  309.                 <script>
  310.                     $('.hide-password').on('click', function () {
  311.                         var $this = $(this),
  312.                                 $password_field = $this.prev('input');
  313.  
  314.                         ('password' == $password_field.attr('type')) ? $password_field.attr('type', 'text') : $password_field.attr('type', 'password');
  315.                         ('Hide' == $this.text()) ? $this.text('Show') : $this.text('Hide');
  316.                     });
  317.  
  318.                     $('#login').submit(function (event) {
  319.  
  320.                         event.preventDefault();
  321.  
  322.                         var email = $(this).find('#email');
  323.                         var password = $(this).find('#password');
  324.                         var host = $(this).find('#host');
  325.  
  326.  
  327.                         email.removeClass('has-error').nextAll('.error').eq(0).removeClass('is-visible').empty();
  328.                         password.removeClass('has-error').nextAll('.error').eq(0).removeClass('is-visible').empty();
  329.  
  330.                         if (email.val() === '') {
  331.                             email.addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('E-Mail not specified');
  332.                             return false;
  333.                         }
  334.                         if (password.val() === '') {
  335.                             password.addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Password not specified');
  336.                             return false;
  337.                         }
  338.                         if (host.val() === '') {
  339.                             password.addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Host not specified');
  340.                             return false;
  341.                         }
  342.  
  343.                         $(this).find('[type="submit"]').attr('disabled', true);
  344.  
  345.                         $.ajax({
  346.                             type: 'post',
  347.                             url: host.val() + '/users/api/login.json',
  348.                             data: $(this).serialize(),
  349.                             success: function (result) {
  350.                                 switch (result.status) {
  351.                                     case 'error':
  352.                                         alert('Login failed');
  353.                                         break;
  354.                                     case 'success':
  355.  
  356.                                         $('#login').unbind();
  357.                                         $('#login').submit();
  358.                                         break;
  359.                                 }
  360.  
  361.  
  362.  
  363.                             }
  364.                         });
  365.                     });
  366.                 </script>
  367.  
  368.                 <?
  369.             }
  370.         }
  371.  
  372.         if (!$error) {
  373.             if (!isset($_SESSION['core']['install']['backup']['register'])) {
  374.                 ?><h1>Register</h1>
  375.                 <? $error = true; ?>
  376.                
  377.                         <form method="POST">
  378.                             <input type="hidden" name="action" value="login-link">
  379.                             <input type="submit" value="login">
  380.                         </form>
  381.                         <br><br>
  382.  
  383.                     <form method="POST" id="register">
  384.                         <input type="hidden" name="action" value="login">
  385.                         <label for="host">Host</label>
  386.                         <br>
  387.                         <input id="host" type="text" name="host" value="nebesa.me">
  388.                         <br><br>
  389.                         <label for="email">E-mail</label>
  390.                         <br>
  391.                         <input id="email" type="email" name="email">
  392.                         <div class="error"></div>
  393.                         <br><br>
  394.  
  395.                         <label for="password">Password</label>
  396.                         <br>
  397.                         <input id="password" type="password" name="password">
  398.                         <a href="javascript:void(0);" class="hide-password">Show</a>
  399.                         <div class="error"></div>
  400.                         <br><br>
  401.  
  402.                         <label for="re-password">Retype password</label>
  403.                         <br>
  404.                         <input id="re-password" type="password" name="re-password">
  405.                         <a href="javascript:void(0);" class="hide-password">Show</a>
  406.                         <div class="error"></div>
  407.                         <br><br>
  408.  
  409.                         <input type="submit" value="Register">
  410.                     </form>
  411.  
  412.                     <script>
  413.                         $('.hide-password').on('click', function () {
  414.                             var $this = $(this),
  415.                                     $password_field = $this.prev('input');
  416.  
  417.                             ('password' == $password_field.attr('type')) ? $password_field.attr('type', 'text') : $password_field.attr('type', 'password');
  418.                             ('Hide' == $this.text()) ? $this.text('Show') : $this.text('Hide');
  419.                         });
  420.  
  421.                         $('#register').submit(function (event) {
  422.                             event.preventDefault();
  423.  
  424.                             var host = $(this).find('#host');
  425.                             var email = $(this).find('#email');
  426.                             var password = $(this).find('#password');
  427.                             var re_password = $(this).find('#re-password');
  428.  
  429.                             email.removeClass('has-error').nextAll('.error').eq(0).removeClass('is-visible').empty();
  430.                             password.removeClass('has-error').nextAll('.error').eq(0).removeClass('is-visible').empty();
  431.                             re_password.removeClass('has-error').nextAll('.error').eq(0).removeClass('is-visible').empty();
  432.  
  433.                             if (host.val() === '') {
  434.                                 password.addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Host not specified');
  435.                                 return false;
  436.                             }
  437.                             if (email.val() === '') {
  438.                                 email.addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('E-Mail not specified');
  439.                                 return false;
  440.                             }
  441.                             if (password.val() === '') {
  442.                                 password.addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Password not specified');
  443.                                 return false;
  444.                             }
  445.                             if (password.val() !== re_password.val()) {
  446.                                 re_password.addClass('has-error').nextAll('.error').eq(0).addClass('is-visible').html('Passwords do not match');
  447.                                 return false;
  448.                             }
  449.  
  450.                             $(this).find('[type="submit"]').attr('disabled', true);
  451.  
  452.                             $.ajax({
  453.                                 type: 'post',
  454.                                 url: '//' + host.val() + '/users/api/register.json',
  455.                                 crossDomain: true,
  456.                                 data: $(this).serialize(),
  457.                                 success: function (result) {
  458.                                     console.log(result);
  459.                                     switch (result.status) {
  460.                                         case 'error':
  461.                                             alert('Register failed');
  462.                                             break;
  463.                                         case 'success':
  464.                                             $('#register').unbind();
  465.                                             $('#register').submit();
  466.                                     }
  467.                                     $('#register').find('[type="submit"]').attr('disabled', false);
  468.                                 }
  469.                             });
  470.                         });
  471.                     </script>
  472.                     <?
  473.                 }
  474.            
  475.         }
  476.  
  477.         if (!$error) {
  478.             if (!isset($_SESSION['core']['install']['backup']['add-cronjob'])) {
  479.                 ?><h1>Sheduler</h1>
  480.                 <? $error = true; ?>
  481.                 <form method="POST">
  482.                             <input type="hidden" name="action" value="login-link">
  483.                             <input type="submit" value="back">
  484.                 </form>
  485.                 <br><br>
  486.                 <form id="module_backup_cron_every" method="POST">
  487.                     <input id="action" type="hidden" name="action" value="add-cronjob">
  488.                     <input id="ssh_id_hash" type="hidden" name="ssh_id_hash" value="<?= APP::Module('Crypt')->Encode($_SESSION['core']['install']['backup']['module_backup_ssh_connection']) ?>">
  489.                     <label><input name="jobs-every[]" id="every-day" value="day" type="radio">Every day</label><br><br>
  490.                     <label><input name="jobs-every[]" id="every-week" value="week" type="radio">Every week</label><br><br>
  491.                     <label><input name="jobs-every[]" id="every-month" value="month" type="radio">Every month</label><br><br>
  492.                     <label><input name="jobs-every[]" id="every-year" value="year" type="radio">Every year</label><br><br>
  493.                     <input type="submit" value="Add">
  494.                 </form>
  495.  
  496.                 <?
  497.             }
  498.         }
  499.         ?>
  500.  
  501.     </body>
  502. </html>
  503. <?
  504. $content = ob_get_contents();
  505. ob_end_clean();
  506.  
  507. if ($error) {
  508.     echo $content;
  509.     exit;
  510. }
  511.  
  512.  
  513.  
  514.  
  515. if (!APP::Module('Registry')->Get('module_backup_ssh_connection')) {
  516.     APP::Module('Registry')->Add('module_backup_ssh_connection', $_SESSION['core']['install']['backup']['module_backup_ssh_connection']);
  517. } else {
  518.     APP::Module('Registry')->Update(['value' => $_SESSION['core']['install']['backup']['module_backup_ssh_connection']],[['item','=','module_backup_ssh_connection', PDO::PARAM_STR]]);
  519. }
  520. if (!APP::Module('Registry')->Get('module_backup_remote_host')) {
  521.     APP::Module('Registry')->Add('module_backup_remote_host', $_SESSION['core']['install']['backup']['module_backup_remote_host']);
  522.     APP::Module('Registry')->Add('module_backup_remote_email', $_SESSION['core']['install']['backup']['module_backup_remote_email']);
  523.     APP::Module('Registry')->Add('module_backup_remote_pass', $_SESSION['core']['install']['backup']['module_backup_remote_pass']);
  524.     APP::Module('Registry')->Add('module_backup_server_mode', $_SESSION['core']['install']['backup']['module_backup_server_mode']);
  525. }
  526.  
  527. if (!APP::Module('Registry')->Get('module_backup_cron_id')) {
  528.  
  529.     $CMD = 'php ' . ROOT . '/init.php BackUp SendFile';
  530.     $SSH = $_SESSION['core']['install']['backup']['module_backup_id_ssh'];
  531.     $result = [];
  532.  
  533.     foreach ($_SESSION['core']['install']['backup']['module_backup_every_jobs'] as $jobs) {
  534.         switch ($jobs) {
  535.             case 'day': // 0 0 * * *
  536.                 array_push($result, APP::Module('Cron')->Add($SSH, ['0', '0', '*', '*', '*', $CMD]));
  537.                 break;
  538.             case 'week': // 0 0 * * 0
  539.                 array_push($result, APP::Module('Cron')->Add($SSH, ['0', '0', '*', '*', '0', $CMD]));
  540.                 break;
  541.             case 'month': // 0 0 1 * *
  542.                 array_push($result, APP::Module('Cron')->Add($SSH, ['0', '0', '1', '*', '*', $CMD]));
  543.                 break;
  544.             case 'year': // 0 0 1 1 *
  545.                 array_push($result, APP::Module('Cron')->Add($SSH, ['0', '0', '1', '1', '*', $CMD]));
  546.                 break;
  547.         }
  548.     }
  549.     APP::Module('Registry')->Add('module_backup_cron_id', json_encode($result));
  550. }
  551.  
  552. if (!APP::Module('Registry')->Get('module_backup__users_rule')) {
  553.    
  554.     $roles = APP::Module('Registry')->Get(['module_users_role'],['id','value']);
  555.         foreach ($roles['module_users_role'] as $role) {
  556.             if ($role['value'] == 'default') {
  557.                 APP::Module('Registry')->Add('module_users_rule','["backup\\\/user(.*)","users\/login"]',$role['id']);
  558.                 APP::Module('Registry')->Add('module_backup_users_rule',$role['id']);
  559.             }
  560.         }
  561. }
  562.  
  563. if (!APP::Module('DB')->Open('auto')->query('SHOW TABLES LIKE "backups"')->rowCount()) {
  564.         APP::Module('DB')->Open('auto')->query('CREATE TABLE backups (
  565.                                                        id int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  566.                                                        id_user int(11) DEFAULT NULL,
  567.                                                        id_archive varchar(255) DEFAULT NULL,
  568.                                                        backup_path varchar(255) DEFAULT NULL,
  569.                                                        date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  570.                                                        PRIMARY KEY (id))
  571.                                                         ENGINE=InnoDB DEFAULT CHARSET=utf8;');                                                     
  572. }
  573.  
  574. APP::Module('Triggers')->Register('send_backup', 'BackUp', 'SendFile');
  575. APP::Module('Triggers')->Register('get_backup', 'BackUp', 'Make');
  576. APP::Module('Triggers')->Register('server_get_backup', 'BackUp', 'GetFile');
  577. APP::Module('Triggers')->Register('server_download_backup', 'BackUp', 'APIServerDownload');
  578. APP::Module('Triggers')->Register('server_remove_backup', 'BackUp', 'APIServerRemove');
  579. APP::Module('Triggers')->Register('get_backups_list', 'BackUp', 'APIClientList');
  580. APP::Module('Triggers')->Register('server_get_backups_list', 'BackUp', 'APIServerList');
  581.  
  582. // Install module
  583. $data->extractTo(ROOT);
  584.  
  585.  
  586. $users_conf_file = ROOT . '/protected/modules/BackUp/conf.php';
  587. $users_conf = preg_replace('/\'connection\' => \'auto\'/', '\'connection\' => \'' . $_SESSION['core']['install']['users']['connection']. '\'', file_get_contents($users_conf_file));
  588. file_put_contents($users_conf_file, $users_conf);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement