2014-12-26 20:18:03 +01:00
|
|
|
/* Wifi Hotspot app for YunoHost
|
|
|
|
* Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
|
2015-07-22 23:54:56 +02:00
|
|
|
* Contribute at https://github.com/labriqueinternet/hotspot_ynh
|
2014-12-26 20:18:03 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-04-26 17:18:52 +02:00
|
|
|
function wifiSecureBtn() {
|
|
|
|
if($(this).parent().hasClass('off')) {
|
|
|
|
$(this).closest('.form-group').next().hide('slow');
|
|
|
|
} else {
|
|
|
|
$(this).closest('.form-group').next().show('slow');
|
|
|
|
}
|
|
|
|
}
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2015-04-26 17:18:52 +02:00
|
|
|
function tabsClick() {
|
|
|
|
var ssid = $(this).closest('.ssid');
|
|
|
|
var tab = $(this).parent().attr('data-tab');
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2015-04-26 17:18:52 +02:00
|
|
|
ssid.find('li.active').removeClass('active');
|
|
|
|
$(this).parent().addClass('active');
|
2014-11-25 21:05:24 +01:00
|
|
|
|
2015-04-26 17:18:52 +02:00
|
|
|
ssid.find('.tabs').hide();
|
|
|
|
ssid.find('.tab' + tab).show();
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2015-04-26 17:18:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2015-05-02 17:20:45 +02:00
|
|
|
function deviceDropDownClick() {
|
2015-04-26 17:18:52 +02:00
|
|
|
var menu = $(this).parent();
|
|
|
|
var items = menu.children();
|
|
|
|
var button = menu.prev();
|
|
|
|
var input = button.prev();
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2015-04-26 17:18:52 +02:00
|
|
|
items.removeClass('active');
|
|
|
|
$(this).addClass('active');
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2015-04-26 17:18:52 +02:00
|
|
|
button.text($(this).text());
|
|
|
|
button.append(' <span class="caret"></span>');
|
|
|
|
|
|
|
|
input.val($(this).text());
|
2015-05-02 17:20:45 +02:00
|
|
|
|
|
|
|
updateNbSsidRemaining();
|
2015-04-26 17:18:52 +02:00
|
|
|
}
|
|
|
|
|
2015-05-02 15:59:42 +02:00
|
|
|
function updateNbSsidRemaining() {
|
|
|
|
multissid = $('#devlist .active').data('multissid');
|
|
|
|
current = $('.ssid').length;
|
|
|
|
remaining = multissid - current;
|
2015-09-15 22:21:27 +02:00
|
|
|
remaining = isNaN(remaining) ? 0 : remaining;
|
2015-05-02 15:59:42 +02:00
|
|
|
|
|
|
|
$('.ssid').each(function(i) {
|
|
|
|
if(i >= multissid) {
|
|
|
|
$(this).removeClass('panel-default');
|
|
|
|
$(this).addClass('panel-danger');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$(this).removeClass('panel-danger');
|
|
|
|
$(this).addClass('panel-default');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.ssid').find('.deletessid').hide();
|
|
|
|
$('.ssid').last().find('.deletessid').show();
|
|
|
|
$('.ssid').first().find('.deletessid').hide();
|
|
|
|
|
|
|
|
if(remaining <= 0) {
|
|
|
|
$('#newssid').attr('disabled', true);
|
|
|
|
$('#newssid').removeClass('btn-success');
|
|
|
|
$('#newssid').addClass('btn-danger');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$('#newssid').attr('disabled', false);
|
|
|
|
$('#newssid').removeClass('btn-danger');
|
|
|
|
$('#newssid').addClass('btn-success');
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#newssid span').text(remaining);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteClick() {
|
|
|
|
$(this).closest('.ssid').remove();
|
|
|
|
updateNbSsidRemaining();
|
|
|
|
}
|
|
|
|
|
2015-04-26 17:18:52 +02:00
|
|
|
$(document).ready(function() {
|
|
|
|
$('.btn-group').button();
|
|
|
|
$('[data-toggle="tooltip"]').tooltip();
|
|
|
|
|
2015-05-02 17:20:45 +02:00
|
|
|
$('.dropdown-menu li').click(deviceDropDownClick);
|
2014-11-09 23:49:06 +01:00
|
|
|
|
|
|
|
$('.switch').bootstrapToggle();
|
2014-11-17 23:44:18 +01:00
|
|
|
|
|
|
|
$('#save').click(function() {
|
|
|
|
$(this).prop('disabled', true);
|
|
|
|
$('#save-loading').show();
|
2014-11-25 21:05:24 +01:00
|
|
|
$('#form').submit();
|
2014-11-17 23:44:18 +01:00
|
|
|
});
|
|
|
|
|
2014-12-26 18:58:58 +01:00
|
|
|
$('#saveconfirm').click(function() {
|
|
|
|
$(this).hide();
|
|
|
|
$('#saveconfirmation').show();
|
|
|
|
});
|
|
|
|
|
2014-11-17 23:44:18 +01:00
|
|
|
$('#status .close').click(function() {
|
|
|
|
$(this).parent().hide();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#statusbtn').click(function() {
|
2014-11-20 20:03:24 +01:00
|
|
|
if($('#status-loading').is(':hidden')) {
|
|
|
|
$('#status').hide();
|
|
|
|
$('#status-loading').show();
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: '?/status',
|
|
|
|
}).done(function(data) {
|
|
|
|
$('#status-loading').hide();
|
|
|
|
$('#status-text').html('<ul>' + data + '</ul>');
|
|
|
|
$('#status').show('slow');
|
|
|
|
});
|
|
|
|
}
|
2014-11-17 23:44:18 +01:00
|
|
|
});
|
2015-01-02 02:24:30 +01:00
|
|
|
|
2015-04-26 17:18:52 +02:00
|
|
|
$('.wifiparty').click(function() {
|
2015-05-02 16:54:12 +02:00
|
|
|
var screen = $('#wifiparty_screen');
|
|
|
|
var passphrase = $(this).closest('.ssid').find('.wifiparty_passphrase').clone();
|
|
|
|
|
|
|
|
screen.find('#wifiparty_ssid span').last().text($(this).closest('.ssid').find('input[type=text]').first().val());
|
|
|
|
screen.find('.wifiparty_passphrase').remove();
|
|
|
|
screen.append(passphrase);
|
|
|
|
screen.find('.wifiparty_passphrase').show();
|
|
|
|
|
|
|
|
screen.show('slow');
|
2015-01-02 02:24:30 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#wifiparty_zoomin_ssid').mousedown(function() {
|
|
|
|
$('#wifiparty_ssid').css('fontSize', (parseInt($('#wifiparty_ssid').css('fontSize')) + 5) + "px");
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#wifiparty_zoomout_ssid').mousedown(function() {
|
|
|
|
$('#wifiparty_ssid').css('fontSize', (parseInt($('#wifiparty_ssid').css('fontSize')) - 5) + "px");
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#wifiparty_zoomin_passphrase').mousedown(function() {
|
2015-05-02 16:54:12 +02:00
|
|
|
$('#wifiparty_screen .wifiparty_passphrase').css('fontSize', (parseInt($('#wifiparty_screen .wifiparty_passphrase').css('fontSize')) + 7) + "px");
|
2015-01-02 02:24:30 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#wifiparty_zoomout_passphrase').mousedown(function() {
|
2015-05-02 16:54:12 +02:00
|
|
|
$('#wifiparty_screen .wifiparty_passphrase').css('fontSize', (parseInt($('#wifiparty_screen .wifiparty_passphrase').css('fontSize')) - 7) + "px");
|
2015-01-02 02:24:30 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#wifiparty_close').click(function() {
|
|
|
|
$('#wifiparty_screen').hide();
|
|
|
|
});
|
2015-03-14 15:44:48 +01:00
|
|
|
|
2015-04-26 17:18:52 +02:00
|
|
|
$('.wifi_secure').change(wifiSecureBtn);
|
2015-03-14 15:44:48 +01:00
|
|
|
|
|
|
|
$('#service_enabled').change(function() {
|
|
|
|
if($('#service_enabled').parent().hasClass('off')) {
|
|
|
|
$('.enabled').hide('slow');
|
|
|
|
} else {
|
|
|
|
$('.enabled').show('slow');
|
|
|
|
}
|
|
|
|
});
|
2015-04-26 17:18:52 +02:00
|
|
|
|
|
|
|
$('.nav-tabs a').click(tabsClick);
|
|
|
|
|
|
|
|
$('#newssid').click(function() {
|
|
|
|
var clone = $('#ssids').children().first().clone();
|
|
|
|
var id = parseInt($('.ssid').length);
|
|
|
|
|
|
|
|
clone.find('[name]').each(function() {
|
|
|
|
$(this).attr('name', $(this).attr('name').replace('[0]', '[' + id + ']'));
|
|
|
|
});
|
|
|
|
|
|
|
|
clone.find('[data-toggle="tooltip"]').tooltip();
|
2015-05-02 15:59:42 +02:00
|
|
|
clone.find('.deletessid').click(deleteClick);
|
2015-05-02 16:54:12 +02:00
|
|
|
clone.find('.wifiparty_passphrase').remove();
|
|
|
|
clone.find('.wifiparty').attr('disabled', true);
|
2015-04-26 17:18:52 +02:00
|
|
|
|
|
|
|
clone.find('input[type=text]').each(function() {
|
|
|
|
if($(this).attr('name').match('dns')) {
|
|
|
|
$(this).val($(this).attr('placeholder'));
|
|
|
|
|
2015-05-02 16:27:14 +02:00
|
|
|
} else if($(this).attr('name').match('ip4_nat_prefix')) {
|
|
|
|
var o1 = parseInt(Math.random() * (255 - 1) + 1);
|
|
|
|
var o2 = parseInt(Math.random() * (255 - 1) + 1);
|
|
|
|
|
|
|
|
$(this).val('10.' + o1 + '.' + o2);
|
|
|
|
|
|
|
|
} else if($(this).attr('name').match('wifi_ssid')) {
|
|
|
|
$(this).val('myNeutralNetwork' + (id + 1));
|
|
|
|
|
2015-04-26 17:18:52 +02:00
|
|
|
} else {
|
|
|
|
$(this).val('');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
clone.find('input[type=checkbox]').each(function() {
|
|
|
|
$(this).parent().after($(this));
|
|
|
|
$(this).prev().remove();
|
|
|
|
$(this).attr('checked', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
clone.find('.switch').bootstrapToggle();
|
|
|
|
clone.find('.wifi_secure').change(wifiSecureBtn);
|
|
|
|
clone.find('.nav-tabs a').click(tabsClick);
|
|
|
|
clone.find('.wifi_passphrase').hide();
|
|
|
|
|
|
|
|
clone.find('h3').each(function() {
|
|
|
|
$(this).text($(this).data('label') + ' ' + (id + 1));
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#ssids').append(clone);
|
2015-05-02 15:59:42 +02:00
|
|
|
|
|
|
|
updateNbSsidRemaining();
|
2015-04-26 17:18:52 +02:00
|
|
|
});
|
2015-05-02 15:59:42 +02:00
|
|
|
|
|
|
|
$('.deletessid').click(deleteClick);
|
|
|
|
|
|
|
|
updateNbSsidRemaining();
|
2015-01-02 02:24:30 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$(document).keydown(function(e) {
|
|
|
|
if(e.keyCode == 27) {
|
|
|
|
$('#wifiparty_close').click();
|
|
|
|
}
|
2014-11-09 22:49:07 +01:00
|
|
|
});
|