cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.
Gregory_Robinso
F5 Employee
F5 Employee

Problem this snippet solves:

I had a need to upload SSL certificates and keys to the BIG-IP in a simple manner that was fast. I did so by creating a cli script that would accept a filename, base64 encoded file and the file type (ascii/binary), then would write out the file to disk.


How to use this snippet:

curl -sk -u username:password -X POST -H 'Content-Type: application/json' https://PRIMARY_F5/mgmt/tm/cli/script -d '{"command":"run","utilCmdArgs":"file_creation [filename] [filetype] [file_base64encoded"}'


Code :

create cli script fileupload {  
proc script::init {} {  
}  
  
proc script::run {} {  
   package require base64  
    set filename [lindex $tmsh::argv 1]  
    set filetype [lindex $tmsh::argv 2]  
    set contents [lindex $tmsh::argv 3]  
    if { [file exists $filename] == 0} {  
        if { $filetype == "binary"} {  
            set result [::base64::decode $contents]  
            set finalfile [open $filename "w"]  
            fconfigure $finalfile -encoding binary  
            puts -nonewline $finalfile [::base64::decode $contents]  
            close $finalfile  
            return 0  
        }  
        if { $filetype == "ascii"} {  
            set result [::base64::decode $contents]  
            set finalfile [open $filename "w"]  
            fconfigure $finalfile  
            puts -nonewline $finalfile [::base64::decode $contents]  
            close $finalfile  
            return 0  
        }  
    }  
    if { [file exists $filename] == 1} {  
        puts "File already exists"  
        error "File already exists"  
        return 1  
    }  
}  
  
proc script::help {} {  
}  
  
proc script::tabc {} {  
}  
    total-signing-status not-all-signed  
}

Tested this on version:

12.1
Version history
Last update:
‎13-Aug-2019 06:08
Updated by:
Contributors