diff --git a/addon/lib/querystring.tcl b/addon/lib/querystring.tcl deleted file mode 100644 index bd1f01f..0000000 --- a/addon/lib/querystring.tcl +++ /dev/null @@ -1,9 +0,0 @@ -catch { - set input $env(QUERY_STRING) - set pairs [split $input &] - foreach pair $pairs { - if {0 != [regexp "^(\[^=]*)=(.*)$" $pair dummy varname val]} { - set $varname $val - } - } -} diff --git a/addon/lib/session.tcl b/addon/lib/session.tcl deleted file mode 100644 index eb183a6..0000000 --- a/addon/lib/session.tcl +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/tclsh - -load tclrega.so - -proc check_session sid { - if {[regexp {@([0-9a-zA-Z]{10})@} $sid all sidnr]} { - set res [lindex [rega_script "Write(system.GetSessionVarStr('$sidnr'));"] 1] - if {$res != ""} { - return 1 - } - } - return 0 -} diff --git a/addon/www/index.cgi b/addon/www/index.cgi deleted file mode 100644 index 92bdf32..0000000 --- a/addon/www/index.cgi +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/tclsh - -source /usr/local/addons/rmupdate/lib/querystring.tcl -source /usr/local/addons/rmupdate/lib/session.tcl - -if {[info exists sid] && [check_session $sid]} { - set fp [open "/usr/local/addons/rmupdate/www/rmupdate.html" r] - puts -nonewline [read $fp] - close $fp -} else { - puts {error: invalid session} -} diff --git a/addon/www/rmupdate.html b/addon/www/index.html similarity index 93% rename from addon/www/rmupdate.html rename to addon/www/index.html index a564c3b..713c66a 100644 --- a/addon/www/rmupdate.html +++ b/addon/www/index.html @@ -39,6 +39,23 @@ along with this program. If not, see . var latest_firmware = '?'; var wlanScanTimer; var moving_userfs_to_device = false; + var sid = null; + + function get_url_vars() { + var vars = {}; + var params = window.location.search.substring(1).split('&'); + for(var i=0; i 1) { + vars[param[0]] = param[1]; + } + } + return vars; + } + + function get_url_var(name) { + return get_url_vars()[name]; + } function display_message(type, text, millis) { clear_message(); @@ -74,8 +91,11 @@ along with this program. If not, see . if (!error_callback) { error_callback = default_error_callback } + if (data != null) { + data = JSON.stringify(data); + } $.ajax({ - url: "rest.cgi?" + path, + url: "rest.cgi?sid=" + sid + "&path=" + path, type: method, data: data, context: document.body, @@ -207,7 +227,7 @@ along with this program. If not, see . } function delete_firmware_image(version) { - rest("POST", "/delete_firmware_image", JSON.stringify({"version":version}), + rest("POST", "/delete_firmware_image", {"version":version}, function(data) { display_message('success', i18next.t('delete_firmware_img_success', {'version': version}), 5000); get_firmware_info(); @@ -231,7 +251,7 @@ along with this program. If not, see . } if (!download_url) download_url = ""; if (!version) version = ""; - rest("POST", "/start_install_firmware", JSON.stringify({"download_url": download_url, "version":version, "language": language, "reboot":reboot, "dryrun":dryrun, "keep_download": keep_download}), + rest("POST", "/start_install_firmware", {"download_url": download_url, "version":version, "language": language, "reboot":reboot, "dryrun":dryrun, "keep_download": keep_download}, function(data) { // We are not expecting a response }, @@ -397,7 +417,7 @@ along with this program. If not, see . onApprove: function() { display_message('warning', i18next.t('moving_userfs'), 300000); if (!moving_userfs_to_device) { - rest('POST', '/move_userfs_to_device', JSON.stringify({"target_device":target_device}), + rest('POST', '/move_userfs_to_device', {"target_device":target_device}, function(data) { moving_userfs_to_device = false; display_message('success', i18next.t('userfs_moved'), 120000); @@ -423,7 +443,7 @@ along with this program. If not, see . return true; }, onApprove: function() { - rest('POST', '/delete_partition_table', JSON.stringify({"device":device}), + rest('POST', '/delete_partition_table', {"device":device}, function(data) { display_message('success', i18next.t('partiton_table_deleted'), 120000); get_partitions(); @@ -532,7 +552,7 @@ along with this program. If not, see . if (file_input) { $.ajax({ - url: 'rest.cgi?/install_addon_archive', + url: 'rest.cgi?sid=' + sid + '&path=/install_addon_archive', data: file_input.files[0], type: 'POST', processData: false, @@ -542,7 +562,7 @@ along with this program. If not, see . }); } else { - rest("POST", "/install_addon", JSON.stringify({"addon_id":addon_id, "download_url":download_url}), + rest("POST", "/install_addon", {"addon_id":addon_id, "download_url":download_url}, success_callback, error_callback ); } @@ -554,7 +574,7 @@ along with this program. If not, see . display_message('info', i18next.t('uninstalling_addon', {'addon_id': addon_id}), 180000); disable_buttons(); $('[data-uninstall-addon-id="' + addon_id + '"]').addClass('loading'); - rest("POST", "/uninstall_addon", JSON.stringify({"addon_id":addon_id}), + rest("POST", "/uninstall_addon", {"addon_id":addon_id}, function(data) { //console.info(data); display_message('success', data, 5000); @@ -672,6 +692,44 @@ along with this program. If not, see . }); } + function init() { + var form_config = { + on: 'blur', + fields: { + password: { + identifier: 'password' + } + }, + onSuccess: function(event, fields) { + if (wlanScanTimer) { + clearTimeout(wlanScanTimer); + } + wlanScanTimer = setTimeout(function(){ wlan_scan(); }, 10000); + $(event.currentTarget).closest("div.modal").modal('hide'); + var ssid = $('#form-connect-wlan').attr('data-ssid'); + var password = $(event.currentTarget).form('get value', 'password'); + $('.button[data-ssid]').addClass('loading'); + rest("POST", "/wlan_connect", {"ssid": ssid, "password": password}); + event.preventDefault(); + } + }; + $('#form-connect-wlan').form(form_config); + + rest("GET", "/version", null, function(version) { + document.title = document.title + " " + version; + }); + rest("GET", "/is_system_upgradeable", null, function(upgradeable) { + if (!upgradeable) { + display_message('error', i18next.t('system_not_upgradeable'), 10000); + } + }); + get_system_info(); + get_partitions(); + get_firmware_info(); + get_addon_info(); + wlan_scan(true); + } + $(document).ready(function() { i18next.init({ lng: language, @@ -759,6 +817,8 @@ along with this program. If not, see . password: "Password", connect: "Connect", disconnect: "Disconnect", + login: "Login", + username: "Username", } }, de: { @@ -843,6 +903,8 @@ along with this program. If not, see . password: "Passwort", connect: "Verbinden", disconnect: "Trennen", + login: "Anmelden", + username: "Benuzername", } } } @@ -858,42 +920,48 @@ along with this program. If not, see . $('#install-firmware-url-button').contents().last()[0].textContent = i18next.t('install'); $('#install-addon-file-button').contents().last()[0].textContent = i18next.t('choose_addon_file'); }); - var form_config = { - on: 'blur', - fields: { - password: { - identifier: 'password' - } - }, - onSuccess: function(event, fields) { - if (wlanScanTimer) { - clearTimeout(wlanScanTimer); - } - wlanScanTimer = setTimeout(function(){ wlan_scan(); }, 10000); - $(event.currentTarget).closest("div.modal").modal('hide'); - var ssid = $('#form-connect-wlan').attr('data-ssid'); - var password = $(event.currentTarget).form('get value', 'password'); - $('.button[data-ssid]').addClass('loading'); - rest("POST", "/wlan_connect", JSON.stringify({"ssid": ssid, "password": password})); - event.preventDefault(); - } - }; - $('#form-connect-wlan').form(form_config); - rest("GET", "/version", null, function(version) { - document.title = document.title + " " + version; - }); - rest("GET", "/is_system_upgradeable", null, function(upgradeable) { - if (!upgradeable) { - display_message('error', i18next.t('system_not_upgradeable'), 10000); + sid = get_url_var('sid'); + rest("GET", "/get_session", null, + function(data) { + init(); + }, + function(xhr, ajaxOptions, thrownError) { + if (xhr.status == 401) { + var form_config = { + on: 'blur', + fields: { + username: { + identifier: 'username' + }, + password: { + identifier: 'password' + } + }, + onSuccess: function(event, fields) { + event.preventDefault(); + var username = $(event.currentTarget).form('get value', 'username'); + var password = $(event.currentTarget).form('get value', 'password'); + rest("POST", "/login", {"username": username, "password": password}, + function(data) { + window.location.href = window.location.href.replace(/\?.*/, '?sid=@' + data + '@'); + }, + function(xhr, ajaxOptions, thrownError) { + default_error_callback(xhr, ajaxOptions, thrownError); + } + ); + } + }; + $('#form-login').form(form_config); + $('#modal-login').modal('show'); + } + else { + default_error_callback(xhr, ajaxOptions, thrownError); + } } - }); - get_system_info(); - get_partitions(); - get_firmware_info(); - get_addon_info(); - wlan_scan(true); + ); }); + @@ -1165,5 +1233,28 @@ along with this program. If not, see . + +