juci-core: juci only writes to /tmp/juci folder refs #15495
authorReidar Cederqvist <reidar.cederqvist@gmail.com>
Tue, 24 Jul 2018 13:01:45 +0000 (15:01 +0200)
committerSukru Senli <sukru.senli@iopsys.eu>
Sat, 8 Sep 2018 11:40:39 +0000 (13:40 +0200)
juci/src/factories/files.js
plugins/juci-dropbear/src/pages/settings-management-dropbear.js
plugins/juci-event/src/pages/status-events.js
plugins/juci-iup/src/pages/settings-provisioning-iup.js
plugins/juci-iup/ubus/juci.iup
plugins/juci-mod-system/src/pages/settings-configuration.js
plugins/juci-netmode/src/pages/netmode-wizard.js
plugins/juci-openvpn/src/pages/internet-services-openvpn.js
plugins/juci-openvpn/ubus/juci.openvpn
plugins/juci-sysupgrade/src/pages/settings-upgrade.js
plugins/juci-sysupgrade/ubus/juci.sysupgrade

index 0545cab..b70f314 100644 (file)
@@ -74,7 +74,14 @@ JUCI.app.factory("$file", function($rpc, $tr, gettext, $rootScope){
                downloadFile: function(fileName, filetype, downloadName){
                        $rootScope.downloadFile = true;
                        var def = $.Deferred();
-                       if(!fileName || fileName.match("/")){
+                       if(!fileName){
+                               $rootScope.downloadFile = false;
+                               return def.reject();
+                       }
+                       if(fileName.startsWith("/tmp/juci/"))
+                               fileName = fileName.substring(10);
+
+                       if(fileName.match("/")){
                                $rootScope.downloadFile = false;
                                return def.reject();
                        }
@@ -86,7 +93,7 @@ JUCI.app.factory("$file", function($rpc, $tr, gettext, $rootScope){
                        }
                        var name = (downloadName)?downloadName:fileName;
                        var filetype = filetype || "application/gzip";
-                       $rpc.$call("file", "read_tmp", {path:"/tmp/"+fileName, base64:true}).done(function(result){
+                       $rpc.$call("file", "read_tmp", {path:"/tmp/juci/"+fileName, base64:true}).done(function(result){
                                $rootScope.downloadFile = false;
                                def.resolve(saveByteArray(result.data, name, filetype, link));
                        }).fail(function(e){ $rootScope.downloadFile = false; def.reject(e);});
index 0c00f39..6796dc7 100644 (file)
@@ -20,7 +20,7 @@
 
 JUCI.app
 .controller("dropbearSettings", function($scope, $uci, $rpc, $systemService, $network, $tr, gettext, $file, $juciDialog, $juciConfirm){
-       var filename = "/tmp/tmpSshKey";
+       var filename = "/tmp/juci/tmpSshKey";
        $scope.data = {
 
        };
index 4c0b378..1f2f862 100644 (file)
@@ -133,7 +133,7 @@ JUCI.app
 
        $events.subscribe("system-report", function(res){
                if(res && res.data && res.data.filename && res.data.filename.length > 5) {
-               var filename=res.data.filename.substring(5);
+                       var filename=res.data.filename;
                        $file.downloadFile(filename,"application/gzip",filename).done( function() {
                                if($scope.report.timeout != null)
                                        clearTimeout($scope.report.timeout);
index 8dc7093..c693925 100644 (file)
@@ -53,7 +53,7 @@ JUCI.app
        };
        $scope.onExportFile = function() {
                $rpc.$call("juci.iup", "backup", {"filename":"iup-backup"}).done(function(){
-                       $file.downloadFile("iup-backup", "application/gzip", "provisioning-" + $config.filename + ".tar.gz").fail(function(e){
+                       $file.downloadFile("/tmp/juci/iup-backup", "application/gzip", "provisioning-" + $config.filename + ".tar.gz").fail(function(e){
                                alert("error: " + JSON.stringify(e));
                        });
                }).fail(function(e){
index ff6c208..941607f 100755 (executable)
@@ -15,9 +15,9 @@ case "$1" in
                                json_get_var filename filename
 
                                if [ -n "$filename" ]; then
-                                       filename="/tmp/$filename"
+                                       filename="/tmp/juci/$filename"
                                else
-                                       filename="/tmp/iup-backup.tmp"
+                                       filename="/tmp/juci/iup-backup.tmp"
                                fi
                                
                                json_init
index 84fc3cf..028a2f5 100644 (file)
@@ -23,6 +23,7 @@ JUCI.app
        $scope.resetPossible = 0;
        $scope.resetPossible = 1;
        $scope.passwordError = false;
+       var filename = "/tmp/juci/backup.tar.gz";
 
        $events.subscribe("defaultreset", function(e){ window.location = "/reboot.html"; });
        $rpc.$call("juci.sysupgrade", "features", {}).done(function(features){
@@ -105,7 +106,7 @@ JUCI.app
        $scope.onUploadConfig = function(){
                var upfile = document.getElementById("upload");
                if(!upfile.name || upfile.size < 1) return;
-               $file.uploadFile("backup.tar.gz", upfile.files[0]).done(function(){
+               $file.uploadFile(filename, upfile.files[0]).done(function(){
                        onUploadComplete(upfile.name);
                }).fail(function(e){console.log(e);});
        }
@@ -145,7 +146,7 @@ JUCI.app
                $rpc.$call("juci.sysupgrade", "create-backup",
                        ($scope.data.pass ? {"pass": $scope.data.pass} : undefined)
                ).done(function(){
-                       $file.downloadFile("backup.tar.gz", "application/gzip", "backup-" + $config.filename + ".tar.gz").fail(function(e){
+                       $file.downloadFile(filename, "application/gzip", "backup-" + $config.filename + ".tar.gz").fail(function(e){
                                alert($tr(gettext("Was not able to download backup. Please check access!")));
                                console.log(e);
                        }).always(function(){
index 32e13a8..6bc740a 100644 (file)
@@ -3,7 +3,7 @@
 
 JUCI.app.controller("netmodeWizardPageCtrl", function($scope, $uci, $languages, $tr, gettext, $wireless, $file){
        var SCAN_RESLUT_TIMEOUT = 3000;
-       var filename = "/tmp/netmode-wizard.json";
+       var filename = "/tmp/juci/netmode-wizard.json";
        $scope.config = {
                as_extender: true,
                separate_ssids: false,
index 8a4b6b6..3e73556 100644 (file)
@@ -20,7 +20,7 @@
 
 JUCI.app
 .controller("OpenVPNController", function($scope, $tr, gettext, $uci, $rpc, $juciDialog, $file){
-       var filename = "/tmp/tmpOpenvpnConfiguration";
+       var filename = "/tmp/juci/tmpOpenvpnConfiguration";
 
        $scope.data = {
                ovpn: ""
index d322a4a..ee9587c 100755 (executable)
@@ -17,7 +17,7 @@ case "$1" in
                        ;;
                        set_config)
                                json_init
-                               json_add_boolean success $(mv /tmp/tmpOpenvpnConfiguration $OVPN && {sync; echo 1} || echo 0)
+                               json_add_boolean success $(mv /tmp/juci/tmpOpenvpnConfiguration $OVPN && {sync; echo 1} || echo 0)
                                json_dump
                        ;;
                esac
index 1e4106a..4c61c31 100644 (file)
 JUCI.app
 .controller("SettingsUpgradeCtrl", function($scope, $uci, $config, $rpc, $tr, gettext, $juciDialog, $events, $file){
        $scope.sessionID = $rpc.$sid();
-       $scope.uploadFilename = "/tmp/firmware.bin";
        $scope.usbFileName = "()";
        $scope.data = { upUrl: ""};
        $scope.usbUpgradeAvailable = false;
        $scope.upfile = {};
+       var uploadFilename = "/tmp/juci/firmware.bin";
 
        $scope.current_version = $config.get("board.system.firmware");
 
@@ -144,7 +144,7 @@ JUCI.app
                        $scope.showUpgradeStatus = true;
                        $scope.message = $tr(gettext("Downloading and verifying image..."));
                        $scope.progress = $tr(gettext("Uploading"));
-                       console.log("testing image: "+ $scope.uploadFilename);
+                       console.log("testing image: "+ uploadFilename);
                        $rpc.$call("juci.sysupgrade", "start", {"path":$scope.onlineUpgrade, "keep":(keep)?1:0});
                });
        }
@@ -186,14 +186,14 @@ JUCI.app
        function startUpload(keep){
                var upfile = $scope.upfile;
                if(!upfile.name || upfile.size < 1) return;
-               $file.uploadFile("firmware.bin", upfile.files[0], function(progress, total){
+               $file.uploadFile(uploadFilename, upfile.files[0], function(progress, total){
                        $scope.progress_byte = progress;
                        $scope.progress_total = total;
                        $scope.$apply();
                }).done(function(){
                        $scope.progress_byte = $scope.progress_total;
                        $scope.$apply();
-                       $rpc.$call("juci.sysupgrade", "start", {"path":$scope.uploadFilename, "keep":(keep)?1:0});
+                       $rpc.$call("juci.sysupgrade", "start", {"path":uploadFilename, "keep":(keep)?1:0});
                }).fail(function(e){
                        $scope.error =  $tr(gettext("The server returned an error"))+" ("+JSON.stringify(e)+")";
                        $scope.$apply();
index d871efd..afd5005 100755 (executable)
@@ -26,9 +26,9 @@ case "$1" in
                                json_get_var pass pass ""
 
                                if [ -n "$pass" ]; then
-                                       output="$(sysupgrade --create-backup /tmp/backup.tar.gz -p $pass)"
+                                       output="$(sysupgrade --create-backup /tmp/juci/backup.tar.gz -p $pass)"
                                else
-                                       output="$(sysupgrade --create-backup /tmp/backup.tar.gz)"
+                                       output="$(sysupgrade --create-backup /tmp/juci/backup.tar.gz)"
                                fi
 
                                json_init
@@ -44,15 +44,15 @@ case "$1" in
                                json_get_var pass pass ""
 
                                if [ -n "$pass" ]; then
-                                       decrypt="$(openssl des3 -d -in /tmp/backup.tar.gz -out /tmp/backup.tar.gz.dec -pass pass:$pass 2>/dev/null && echo OK)"
+                                       decrypt="$(openssl des3 -d -in /tmp/juci/backup.tar.gz -out /tmp/juci/backup.tar.gz.dec -pass pass:$pass 2>/dev/null && echo OK)"
                                        if [ "$decrypt" == "OK" ]; then
-                                               mv /tmp/backup.tar.gz.dec /tmp/backup.tar.gz
-                                               stdout="$(sysupgrade --restore-backup /tmp/backup.tar.gz)"
+                                               mv /tmp/juci/backup.tar.gz.dec /tmp/juci/backup.tar.gz
+                                               stdout="$(sysupgrade --restore-backup /tmp/juci/backup.tar.gz)"
                                        else
                                                error="Invalid Password!"
                                        fi
                                else
-                                       result="$(sysupgrade --restore-backup /tmp/backup.tar.gz)"
+                                       result="$(sysupgrade --restore-backup /tmp/juci/backup.tar.gz)"
                                        if [ "result" == "" ]; then
                                                stdout="$result"
                                        else
@@ -98,7 +98,7 @@ case "$1" in
                                read input
                                json_load "$input"
                                json_get_var keep keep 1
-                               json_get_var path path "/tmp/firmware.bin"
+                               json_get_var path path "/tmp/juci/firmware.bin"
 
                                [ "$keep" == "1" ] && keep="" || keep="-n"
                                sysupgrade $keep $path >/dev/null 2>&1 &
@@ -110,7 +110,7 @@ case "$1" in
                        test)
                                read input
                                json_load "$input"
-                               json_get_var path path "/tmp/firmware.bin"
+                               json_get_var path path "/tmp/juci/firmware.bin"
 
                                sysupgrade --test $path >/dev/null 2>&1 &