Announcement

Collapse
No announcement yet.

Javascript Writer - Creating file then modifying its file permissions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Javascript Writer - Creating file then modifying its file permissions

    Within a destination Javascript Writer;

    I need a batch file created with dynamic contents and then file permissions modified
    the first half of the code works to create the file and its contents;
    ($('test') being the file location and the file extention (.bat) on the C:
    $('messagetext') being the the string inside of the .bat


    Though it doesn't modify the files permissions, where am I going wrong?

    Code:
    //working
    org.apache.commons.io.FileUtils.write
    (new java.io.File
    ($('test')
    .toString()),
    $('messagetext')
    .toString(),
    true);
    //working
    //
    //not working
    var runtime = new Packages.java.lang.Runtime.getRuntime();
    runtime.exec(["cmd.exe", "/c", "cd ($('test') && icacls "+"\"($('test')"+ " /deny \"domain\Users\":F "]);
    //not working

    Thanks in advance

    Ruffdraft
    Last edited by Ruffdraft; 06-25-2020, 03:33 AM.

  • #2
    Just a thought:

    When I shell out to OS to run a command the command I run is always a shell script that accepts one or more input parameters.

    The primary reason for this is I can test that shell script at the command line to verify it works and also return a message or status to Mirth.

    So (linux here but that should not be relevant):
    Code:
    var shell_to_command_line = java.lang.Runtime.getRuntime().exec(["/home/mirth/bin/billable_claims_csv_export/export_one_site.sh", $('site_code')]);
    shell_to_command_line.waitFor();
    var the_command_output = shell_to_command_line.getInputStream();
    $c($('site_code')+'_cmd_output', org.apache.commons.io.IOUtils.toString(the_command _output));


    Code:
    /home/mirth/bin/billable_claims_csv_export/export_one_site.sh
    accepts a single parameter in this case and returns output to the console for Mirth to view.

    You can also add debug output to the shell script to make sure you even ran the script.





    Mirth 3.8.0 / PostgreSQL 11 / Ubuntu 18.04
    Diridium Technologies, Inc.
    https://diridium.com

    Comment


    • #3
      Thanks Pacmano,

      Sorry I didn't fully understand, probably lacking in some Mirth understanding on the use of inputstreams. alslo not using Linux so directory not relevent.

      However I have tested the following

      This works;

      Code:
      var command = 'cmd /c copy "C:\\tmp\\test.bat" "C:\\tmp\\test2.bat"';
      var pr = Packages.java.lang.Runtime.getRuntime().exec(command);
      but this doesn't: suspect this is due to the icacls not working in getRuntime()

      Code:
      var command = 'cmd /c icacls "C:\\tmp\\test.bat" /grant domain\testuser:F';
      var pr = Packages.java.lang.Runtime.getRuntime().exec(command);

      Following work in cmd
      Code:
      cmd /c C:\\Windows\\System32\\icacls.exe "C:\\tmp\\test.bat" /grant domain\testuser:F
      Code:
      cmd /c icacls.exe "C:\\tmp\\test.bat" /grant domain\testuser:F
      Code:
      icacls.exe "C:\\tmp\\test.bat" /grant domain\testuser:F
      thanks

      Comment


      • #4
        I know you are on windows. My point is in your case to create a powershell script that accepts an input parameter and echos a result that mirth can see - this way you can test that script interactively on the command line and then call it from Mirth. If Mirth does not receive a result it likely means there is some permission error on running your powershell script.

        Obviously paths are specified differently in Linux and Windows, I assumed you knew that and would revise accordingly.
        Mirth 3.8.0 / PostgreSQL 11 / Ubuntu 18.04
        Diridium Technologies, Inc.
        https://diridium.com

        Comment


        • #5
          Thanks again Pacmano, I added an output file to the command line for the status in a command line, though not ideal as sometimes it would not report anything if the prevouse commands had failed. I still am unsure exsactly how to approach your method, I think it might of been easier to debug in the end with your method.

          Anyway I've made some progress and this works for me;

          MIrth varablables are for the vPID and vUseraccount is driven from the Dicom tags.all other $ varaables are set the transformer

          Code:
          var path = $('BatFile') + $('vPID') + $('BatchFileExtension');                                                                        //    e.g  "C:\\tmp\0123456\file.bat"
          var permision = ('domain\\' + $('vUserAccount') + ':F');                                                                                            //    e.g  "domain\user.account:F"
          var command = new Array('cmd', '/c', 'icacls', path, '/inheritance:r', '/grant', permision, '>C:\\tmp\\log.txt');            
                                                                                                                                        //    e.g  "cmd /c icacls C:\\tmp\0123456\file.bat /inheritance:r /grant domain\user.account:F >C:\\tmp\\log.txt"
          var pr = Packages.java.lang.Runtime.getRuntime().exec(command);
          This does exsactly what I wanted initally, though now trying to get this to work over SMB.

          Code:
          var dir = String($('path'));
          var fn = "smb://" + "domain" + ";" + "testname" + ":" + "password" + "@" + dir.substring(6) + '//' + $('path');
          var file = new Packages.jcifs.smb.SmbFile(fn);
          Could this work?

          Comment

          Working...
          X