mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-24 20:14:37 -04:00
173 lines
4.5 KiB
JavaScript
173 lines
4.5 KiB
JavaScript
modulejs.define('main/info', ['$', 'config'], function ($, config) {
|
|
|
|
var testsTemp =
|
|
'<ul id="tests">';
|
|
var testTemp =
|
|
'<li class="test">' +
|
|
'<span class="label"></span>' +
|
|
'<span class="result"></span>' +
|
|
'<div class="info"></div>' +
|
|
'</li>';
|
|
var loginTemp =
|
|
'<div id="login-wrapper">' +
|
|
'<input id="pass" type="password" placeholder="password"/>' +
|
|
'<span id="login">login</span>' +
|
|
'<span id="logout">logout</span>' +
|
|
'<div id="hint">' +
|
|
'The preset password is the empty string, just hit login. ' +
|
|
'Change it in \'_h5ai/conf/passhash.php\'.' +
|
|
'</div>' +
|
|
'</div>';
|
|
var setup = config.setup;
|
|
|
|
|
|
function addTest(label, info, passed, result) {
|
|
|
|
var $test = $(testTemp).appendTo('#tests');
|
|
$test.find('.label').text(label);
|
|
$test.find('.result')
|
|
.addClass(passed ? 'passed' : 'failed')
|
|
.text(result ? result : (passed ? 'yes' : 'no'));
|
|
$test.find('.info').html(info);
|
|
}
|
|
|
|
function addTests() {
|
|
|
|
$(testsTemp).appendTo('#content');
|
|
|
|
addTest(
|
|
'h5ai version', 'Only green if this is an official h5ai release',
|
|
/^\d+\.\d+\.\d+$/.test(setup.VERSION), setup.VERSION
|
|
);
|
|
|
|
addTest(
|
|
'Index file found', 'Add <code>' + setup.INDEX_HREF + '</code> to your index file list',
|
|
setup.INDEX_HREF
|
|
);
|
|
|
|
addTest(
|
|
'Options parsable', 'File <code>options.json</code> is readable and syntax is correct',
|
|
config.options !== null
|
|
);
|
|
|
|
addTest(
|
|
'Types parsable', 'File <code>types.json</code> is readable and syntax is correct',
|
|
config.types !== null
|
|
);
|
|
|
|
addTest(
|
|
'Server software', 'Server is one of apache, lighttpd, nginx or cherokee',
|
|
setup.HAS_SERVER, setup.SERVER_NAME + ' ' + setup.SERVER_VERSION
|
|
);
|
|
|
|
addTest(
|
|
'PHP version', 'PHP version >= ' + setup.MIN_PHP_VERSION,
|
|
true, setup.PHP_VERSION
|
|
);
|
|
|
|
addTest(
|
|
'Cache directory', 'Web server has write access',
|
|
setup.HAS_WRITABLE_CACHE
|
|
);
|
|
|
|
addTest(
|
|
'Image thumbs', 'PHP GD extension with JPEG support available',
|
|
setup.HAS_PHP_JPEG
|
|
);
|
|
|
|
addTest(
|
|
'Use EXIF thumbs', 'PHP EXIF extension available',
|
|
setup.HAS_PHP_EXIF
|
|
);
|
|
|
|
addTest(
|
|
'Movie thumbs', 'Command line program <code>avconv</code> or <code>ffmpeg</code> available',
|
|
setup.HAS_CMD_AVCONV || setup.HAS_CMD_FFMPEG
|
|
);
|
|
|
|
addTest(
|
|
'PDF thumbs', 'Command line program <code>convert</code> available',
|
|
setup.HAS_CMD_CONVERT
|
|
);
|
|
|
|
addTest(
|
|
'Shell tar', 'Command line program <code>tar</code> available',
|
|
setup.HAS_CMD_TAR
|
|
);
|
|
|
|
addTest(
|
|
'Shell zip', 'Command line program <code>zip</code> available',
|
|
setup.HAS_CMD_ZIP
|
|
);
|
|
|
|
addTest(
|
|
'Shell du', 'Command line program <code>du</code> available',
|
|
setup.HAS_CMD_DU
|
|
);
|
|
}
|
|
|
|
function request(data) {
|
|
|
|
$.ajax({
|
|
url: 'index.php',
|
|
type: 'post',
|
|
dataType: 'json',
|
|
data: data
|
|
})
|
|
.always(function () {
|
|
|
|
window.location.reload();
|
|
});
|
|
}
|
|
|
|
function onLogin() {
|
|
|
|
request({
|
|
action: 'login',
|
|
pass: $('#pass').val()
|
|
});
|
|
}
|
|
|
|
function onLogout() {
|
|
|
|
request({
|
|
action: 'logout'
|
|
});
|
|
}
|
|
|
|
function onKeydown(event) {
|
|
|
|
if (event.which === 13) {
|
|
onLogin();
|
|
}
|
|
}
|
|
|
|
function addLogin() {
|
|
|
|
$(loginTemp).appendTo('#content');
|
|
|
|
if (setup.AS_ADMIN) {
|
|
$('#pass').remove();
|
|
$('#login').remove();
|
|
$('#logout').on('click', onLogout);
|
|
} else {
|
|
$('#pass').on('keydown', onKeydown).focus();
|
|
$('#login').on('click', onLogin);
|
|
$('#logout').remove();
|
|
}
|
|
if (setup.HAS_CUSTOM_PASSHASH) {
|
|
$('#hint').remove();
|
|
}
|
|
}
|
|
|
|
function init() {
|
|
|
|
addLogin();
|
|
if (setup.AS_ADMIN) {
|
|
addTests();
|
|
}
|
|
}
|
|
|
|
|
|
init();
|
|
});
|