Welcome to mirror list, hosted at ThFree Co, Russian Federation.

JS.js « ncp-activation - github.com/nextcloud/nextcloudpi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3432dbe17738dac25c364da4ca946c83c3a31164 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
///
// NextCloudPi Web Panel javascript library
//
// Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
// GPL licensed (see end of file) * Use at your own risk!
//
// More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/
///

var MINI = require('minified');
var $ = MINI.$, $$ = MINI.$$, EE = MINI.EE;
var selectedID = null;
var confLock   = false;

function errorMsg()
{ 
  $('#error-box').fill( "Something went wrong. Try refreshing the page" ); 
}

function launch_nc_passwd()
{
  // request
  $.request('post', '../ncp-launcher.php', { action: 'launch',
                                             ref   : 'nc-passwd',
                                             config: '{ "PASSWORD":"' + $('#ncp-pwd').get('.value') + '",'
                                                     + '"CONFIRM" :"' + $('#ncp-pwd').get('.value') + '"}',
                                             csrf_token: $( '#csrf-token' ).get( '.value' ) }).then(

    function success( result )
    {
      var ret = $.parseJSON( result );
      if ( ret.ret == '0' )
      {
        setTimeout( function(){ 
          $('#loading-gif').hide();
          $('#error-box').fill( "ACTIVATION SUCCESSFUL" ); 
          var url = window.location.protocol + '//' + window.location.hostname + ':4443';
          if ( !window.open( url, '_blank' ) ) // try to open in a new tab first
            window.location.replace( url );
        }, 4000 );
      } else {
        $('#error-box').fill( "nc-passwd error" ); 
      }
  } ).error( errorMsg );
}

function nc_admin_ok_cb( result ) 
{
  var ret = $.parseJSON( result );
  if ( ret.token )
    $('#csrf-token').set( { value: ret.token } );
  if ( ret.ret == '0' ) {
    launch_nc_passwd();
  } else {
    $('#error-box').fill( "NextCloudPi not yet initialized, trying again in a few seconds ..." ); 
    setTimeout( launch_activation, 10000 );
  }
}

function launch_activation()
{
  // request
  $.request('post', '../ncp-launcher.php', { action: 'launch',
                                             ref   : 'nc-admin', 
                                             config: '{ "PASSWORD":"' + $('#nc-pwd').get('.value') + '",'
                                                     + '"CONFIRM" :"' + $('#nc-pwd').get('.value') + '",'
                                                     + '"USER"    : "ncp" }',
                                             csrf_token: $( '#csrf-token' ).get( '.value' ) } 
  ).then( nc_admin_ok_cb ).error( errorMsg );
}

$(function() 
{
  // print info page
  $( '#print-pwd' ).on( 'click', function(e) { window.print(); } );

  // copy to clipboard
  $( '#cp-ncp' ).on( 'click', function(e)
    {
      var input = document.getElementById('ncp-pwd');
      input.focus();
      input.select();
      var res =document.execCommand( 'copy' );
      $('#cp-ncp-ok').fill( res ? "✓" : "✘" );
      input.selectionStart = input.selectionEnd;
    } );

  // copy to clipboard
  $( '#cp-nc' ).on( 'click', function(e)
    {
      var input = document.getElementById('nc-pwd');
      input.focus();
      input.select();
      var res =document.execCommand( 'copy' );
      $('#cp-nc-ok').fill( res ? "✓" : "✘" );
      input.selectionStart = input.selectionEnd;
    } );

  // activate NextCloudPi
  $( '#activate-ncp' ).on( 'click', function(e)
  {
    $( '#activate-ncp' ).hide();
    $( '#print-pwd'    ).hide();
    $('#loading-gif').set( { $display: 'inline' } );
    launch_activation();
  } );
} );

// License
//
// This script is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This script is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this script; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330,
// Boston, MA  02111-1307  USA