Add support for creating files via file manager
This commit is contained in:
parent
5567269bf3
commit
91178d78a4
7 changed files with 181 additions and 4 deletions
|
@ -122,10 +122,16 @@ class ServerController extends Controller
|
|||
{
|
||||
$server = Models\Server::getByUUID($uuid);
|
||||
$this->authorize('add-files', $server);
|
||||
$node = Models\Node::find($server->node);
|
||||
|
||||
Javascript::put([
|
||||
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
|
||||
'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
|
||||
]);
|
||||
|
||||
return view('server.files.add', [
|
||||
'server' => $server,
|
||||
'node' => Models\Node::find($server->node),
|
||||
'node' => $node,
|
||||
'directory' => (in_array($request->get('dir'), [null, '/', ''])) ? '' : trim($request->get('dir'), '/') . '/',
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -18,20 +18,26 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
$(document).ready(function () {
|
||||
$('.server-files').addClass('active');
|
||||
const Editor = ace.edit('editor');
|
||||
const Modelist = ace.require('ace/ext/modelist')
|
||||
|
||||
Editor.setTheme('ace/theme/chrome');
|
||||
Editor.getSession().setMode(Modelist.getModeForPath(Pterodactyl.stat.name).mode);
|
||||
Editor.getSession().setUseWrapMode(true);
|
||||
Editor.setShowPrintMargin(false);
|
||||
|
||||
if (typeof Pterodactyl !== 'undefined' && typeof Pterodactyl.stat !== 'undefined') {
|
||||
Editor.getSession().setMode(Modelist.getModeForPath(Pterodactyl.stat.name).mode);
|
||||
}
|
||||
|
||||
Editor.commands.addCommand({
|
||||
name: 'save',
|
||||
bindKey: {win: 'Ctrl-S', mac: 'Command-S'},
|
||||
exec: function(editor) {
|
||||
save();
|
||||
if ($('#save_file').length) {
|
||||
save();
|
||||
} else if ($('#create_file').length) {
|
||||
create();
|
||||
}
|
||||
},
|
||||
readOnly: false
|
||||
});
|
||||
|
@ -41,6 +47,51 @@ $(document).ready(function () {
|
|||
save();
|
||||
});
|
||||
|
||||
$('#create_file').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
create();
|
||||
});
|
||||
|
||||
$('#aceMode').on('change', event => {
|
||||
Editor.getSession().setMode('ace/mode/' + $('#aceMode').val());
|
||||
});
|
||||
|
||||
function create() {
|
||||
if (_.isEmpty($('#file_name').val())) {
|
||||
$.notify({
|
||||
message: 'No filename was passed.'
|
||||
}, {
|
||||
type: 'danger'
|
||||
});
|
||||
return;
|
||||
}
|
||||
$('#create_file').html('<i class="fa fa-spinner fa fa-spin"></i> Creating File').addClass('disabled');
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: Router.route('server.files.save', { server: Pterodactyl.server.uuidShort }),
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
|
||||
},
|
||||
data: {
|
||||
file: $('#file_name').val(),
|
||||
contents: Editor.getValue()
|
||||
}
|
||||
}).done(function (data) {
|
||||
window.location.replace(Router.route('server.files.edit', {
|
||||
server: Pterodactyl.server.uuidShort,
|
||||
file: $('#file_name').val(),
|
||||
}));
|
||||
}).fail(function (jqXHR) {
|
||||
$.notify({
|
||||
message: jqXHR.responseText
|
||||
}, {
|
||||
type: 'danger'
|
||||
});
|
||||
}).always(function () {
|
||||
$('#create_file').html('Create File').removeClass('disabled');
|
||||
});
|
||||
}
|
||||
|
||||
function save() {
|
||||
var fileName = $('input[name="file"]').val();
|
||||
$('#save_file').html('<i class="fa fw-fw fa-spinner fa-spin"></i> Saving File').addClass('disabled');
|
||||
|
|
3
public/themes/pterodactyl/vendor/select2/select2.full.min.js
vendored
Executable file
3
public/themes/pterodactyl/vendor/select2/select2.full.min.js
vendored
Executable file
File diff suppressed because one or more lines are too long
1
public/themes/pterodactyl/vendor/select2/select2.min.css
vendored
Executable file
1
public/themes/pterodactyl/vendor/select2/select2.min.css
vendored
Executable file
File diff suppressed because one or more lines are too long
|
@ -22,6 +22,12 @@ return [
|
|||
'save' => 'Save File',
|
||||
'return' => 'Return to File Manager',
|
||||
],
|
||||
'add' => [
|
||||
'header' => 'New File',
|
||||
'header_sub' => 'Create a new file on your server.',
|
||||
'name' => 'File Name',
|
||||
'create' => 'Create File',
|
||||
],
|
||||
],
|
||||
'config' => [
|
||||
'startup' => [
|
||||
|
|
|
@ -49,4 +49,5 @@ return [
|
|||
'primary' => 'Primary',
|
||||
'make_primary' => 'Make Primary',
|
||||
'none' => 'None',
|
||||
'cancel' => 'Cancel',
|
||||
];
|
||||
|
|
109
resources/themes/pterodactyl/server/files/add.blade.php
Normal file
109
resources/themes/pterodactyl/server/files/add.blade.php
Normal file
|
@ -0,0 +1,109 @@
|
|||
{{-- Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com> --}}
|
||||
|
||||
{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
|
||||
{{-- of this software and associated documentation files (the "Software"), to deal --}}
|
||||
{{-- in the Software without restriction, including without limitation the rights --}}
|
||||
{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
|
||||
{{-- copies of the Software, and to permit persons to whom the Software is --}}
|
||||
{{-- furnished to do so, subject to the following conditions: --}}
|
||||
|
||||
{{-- The above copyright notice and this permission notice shall be included in all --}}
|
||||
{{-- copies or substantial portions of the Software. --}}
|
||||
|
||||
{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
|
||||
{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
|
||||
{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
|
||||
{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
|
||||
{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
|
||||
{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
|
||||
{{-- SOFTWARE. --}}
|
||||
@extends('layouts.master')
|
||||
|
||||
@section('title')
|
||||
@lang('server.files.add.header')
|
||||
@endsection
|
||||
|
||||
@section('scripts')
|
||||
{{-- This has to be loaded before the AdminLTE theme to avoid dropdown issues. --}}
|
||||
{!! Theme::css('vendor/select2/select2.min.css') !!}
|
||||
@parent
|
||||
@endsection
|
||||
|
||||
@section('content-header')
|
||||
<h1>@lang('server.files.add.header')<small>@lang('server.files.add.header_sub')</small></h1>
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="{{ route('index') }}">@lang('strings.home')</a></li>
|
||||
<li><a href="{{ route('server.index', $server->uuidShort) }}">{{ $server->name }}</a></li>
|
||||
<li><a href="{{ route('server.files.index', $server->uuidShort) }}">@lang('navigation.server.file_browser')</a></li>
|
||||
<li class="active">@lang('navigation.server.create_file')</li>
|
||||
</ol>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon"><code>/home/container/</code></span>
|
||||
<input type="text" class="form-control" placeholder="@lang('server.files.add.name')" id="file_name" value="{{ $directory }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-body" style="height:500px;" id="editor"></div>
|
||||
<div class="box-footer with-border">
|
||||
<div class="row">
|
||||
<div class="col-sm-8">
|
||||
<button class="btn btn-sm btn-primary" id="create_file">@lang('server.files.add.create')</button>
|
||||
<a href="{{ route('server.files.index', [ 'server' => $server->uuidShort, 'dir' => $directory ]) }}"><button class="btn btn-default btn-sm">@lang('strings.cancel')</button></a>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<select name="aceMode" id="aceMode" class="form-control">
|
||||
<option value="assembly_x86">Assembly x86</option>
|
||||
<option value="c_cpp">C/C++</option>
|
||||
<option value="coffee">CoffeeScript</option>
|
||||
<option value="csharp">C#</option>
|
||||
<option value="css">CSS</option>
|
||||
<option value="golang">Go</option>
|
||||
<option value="haml">HAML</option>
|
||||
<option value="html">HTML</option>
|
||||
<option value="ini">INI</option>
|
||||
<option value="java">Java</option>
|
||||
<option value="javascript">JavaScript</option>
|
||||
<option value="json">JSON</option>
|
||||
<option value="lua">Lua</option>
|
||||
<option value="markdown">Markdown</option>
|
||||
<option value="mysql">MySQL</option>
|
||||
<option value="objectivec">Objective-C</option>
|
||||
<option value="perl">Perl</option>
|
||||
<option value="php">PHP</option>
|
||||
<option value="properties">Properties</option>
|
||||
<option value="python">Python</option>
|
||||
<option value="ruby">Ruby</option>
|
||||
<option value="rust">Rust</option>
|
||||
<option value="smarty">Smarty</option>
|
||||
<option value="textile" selected="selected">Plain Text</option>
|
||||
<option value="xml">XML</option>
|
||||
<option value="yaml">YAML</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('footer-scripts')
|
||||
@parent
|
||||
{!! Theme::js('vendor/select2/select2.full.min.js') !!}
|
||||
{!! Theme::js('js/frontend/server.socket.js') !!}
|
||||
{!! Theme::js('js/vendor/ace/ace.js') !!}
|
||||
{!! Theme::js('js/vendor/ace/ext-modelist.js') !!}
|
||||
{!! Theme::js('js/vendor/lodash/lodash.js') !!}
|
||||
{!! Theme::js('js/frontend/files/editor.js') !!}
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#aceMode').select2();
|
||||
});
|
||||
</script>
|
||||
@endsection
|
Loading…
Reference in a new issue