4949from lib .core .settings import RESTAPI_DEFAULT_ADAPTER
5050from lib .core .settings import RESTAPI_DEFAULT_ADDRESS
5151from lib .core .settings import RESTAPI_DEFAULT_PORT
52+ from lib .core .settings import VERSION_STRING
5253from lib .core .shell import autoCompletion
5354from lib .core .subprocessng import Popen
5455from lib .parse .cmdline import cmdLineParser
@@ -657,6 +658,15 @@ def download(taskid, target, filename):
657658 logger .warning ("[%s] File does not exist %s" % (taskid , target ))
658659 return jsonize ({"success" : False , "message" : "File does not exist" })
659660
661+ @get ("/version" )
662+ def version (token = None ):
663+ """
664+ Fetch server version
665+ """
666+
667+ logger .debug ("Fetched version (%s)" % ("admin" if is_admin (token ) else request .remote_addr ))
668+ return jsonize ({"success" : True , "version" : VERSION_STRING .split ('/' )[- 1 ]})
669+
660670def server (host = RESTAPI_DEFAULT_ADDRESS , port = RESTAPI_DEFAULT_PORT , adapter = RESTAPI_DEFAULT_ADAPTER , username = None , password = None ):
661671 """
662672 REST-JSON API server
@@ -760,7 +770,7 @@ def client(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, username=Non
760770 logger .critical (errMsg )
761771 return
762772
763- commands = ("help" , "new" , "use" , "data" , "log" , "status" , "option" , "stop" , "kill" , "list" , "flush" , "exit" , "bye" , "quit" )
773+ commands = ("help" , "new" , "use" , "data" , "log" , "status" , "option" , "stop" , "kill" , "list" , "flush" , "version" , " exit" , "bye" , "quit" )
764774 autoCompletion (AUTOCOMPLETE_TYPE .API , commands = commands )
765775
766776 taskid = None
@@ -849,6 +859,13 @@ def client(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, username=Non
849859 continue
850860 logger .info ("Switching to task ID '%s' " % taskid )
851861
862+ elif command in ("version" ,):
863+ raw = _client ("%s/%s" % (addr , command ))
864+ res = dejsonize (raw )
865+ if not res ["success" ]:
866+ logger .error ("Failed to execute command %s" % command )
867+ dataToStdout ("%s\n " % raw )
868+
852869 elif command in ("list" , "flush" ):
853870 raw = _client ("%s/admin/%s" % (addr , command ))
854871 res = dejsonize (raw )
@@ -873,6 +890,7 @@ def client(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, username=Non
873890 msg += "stop Stop current task\n "
874891 msg += "kill Kill current task\n "
875892 msg += "list Display all tasks\n "
893+ msg += "version Fetch server version\n "
876894 msg += "flush Flush tasks (delete all tasks)\n "
877895 msg += "exit Exit this client\n "
878896
0 commit comments