source: cprs/branches/tmg-cprs/m_files/TMGEDIT.m@ 896

Last change on this file since 896 was 796, checked in by Kevin Toppenberg, 14 years ago

Initial upload

File size: 5.0 KB
RevLine 
[796]1TMGEDIT ;TMG/kst/Interface to allow use of linux editor in Fileman ;03/25/06
2 ;;1.0;TMG-LIB;**1**;7/19/08
3
4 ;"TMG EDITOR FUNCTIONS
5
6 ;"=======================================================================
7 ;" API -- Public Functions.
8 ;"=======================================================================
9 ;"$$EDIT(Editor)
10
11 ;"=======================================================================
12 ;"PRIVATE API FUNCTIONS
13 ;"=======================================================================
14
15
16 ;"=======================================================================
17 ;"=======================================================================
18
19EDIT(Editor)
20 ;"Purpose: This will be a shell for a linux editor
21 ;"Input: Editor -- the name of the linux editor to use (i.e. vim, joe, pico etc)
22 ;" Allowed values: joe,vim,pico
23 ;"Note: When this function gets called, VistA sets up some variables
24 ;" first to tell what should be edited etc.
25 ;" DIC=The global root of the WP field where the text to be edited is
26 ;" stored (or where new text should be stored)
27 ;" e.g. "^TMG(22702,27,DV,"
28 ;" (DV is also predefined, so reference to DV in DIC is covered.)
29 ;" There are other variables set up re margins etc. I will be ignoring these.
30 ;"Results: none
31
32 new result set result=0
33 new GlobalP
34
35 ;"By limiting value to certain values, it prevents a rouge user from putting a wedged
36 ;"linux command into "Editor" and executing a system command through zsystem.
37 set Editor=$get(Editor,"rvim")
38 if (Editor'="rvim")&(Editor'="joe")&(Editor'="pico")&(Editor'="nano") goto EditAbort
39
40 ;"Only allow users with programmer access to use joe
41 if (Editor="joe") do if result=1 goto EditAbort
42 . new AccessCode set AccessCode=$get(DUZ(0))
43 . if AccessCode'["@" do
44 . . write !!,"*** Sorry. Insufficient security clearance to use insecure 'joe' editor. ***",!
45 . . write "Fileman access code of @ required, because JOE can shell out to linux prompt.",!!
46 . . write "Please enter 'User's Toolbox', then 'Edit User Characteristics' at a menu",!
47 . . write " option to change PREFERRED EDITOR to something other than JOE.",!!
48 . . set result=1
49
50 new EditErrFile set EditErrFile="/tmp/trashjoeoutput.txt"
51
52 set GlobalP=$extract(DIC,1,$length(DIC)-1)_")" ;"convert to closed form
53 new Filename set Filename=$$UNIQUE^%ZISUTL("/tmp/vistaedit.tmp")
54 set result=$$WP2HFSfp^TMGIOUTL(GlobalP,Filename)
55 if result=0 goto EditDone
56
57
58 new HookCmd
59 set HookCmd=Editor_" "_Filename_" 2>"_EditErrFile ;"use NULL instead??
60 zsystem HookCmd
61 set result=$ZSYSTEM&255 ;"get result of execution. (low byte only). 0=success
62 if result>0 goto EditDone
63
64 ;"read file back into global WP
65 set result=$$HFS2WPfp^TMGIOUTL(Filename,GlobalP)
66 ;"if result=1 do
67
68EditDone
69 new temp set temp=$$DelFile^TMGIOUTL(Filename)
70 set temp=$$DelFile^TMGIOUTL(Filename_"~") ;"joe editor copies output to filename~ as a backup
71 set temp=$$DelFile^TMGIOUTL(EditErrFile)
72EditAbort
73 quit
74
75
76
77LinuxEdit(Editor,FullPathName)
78 ;"Purpose: This will be a shell for a linux editor
79 ;"Input: Editor -- the name of the linux editor to use (i.e. vim, joe, pico etc)
80 ;" Allowed values: joe,vim,pico
81 ;" FullPathName -- the path name on the Linux HFS to edit.
82 ;"Results: none
83
84 new result set result=0
85 new GlobalP
86
87 ;"By limiting value to certain values, it prevents a rouge user from putting a wedged
88 ;"linux command into "Editor" and executing a system command through zsystem.
89 set Editor=$get(Editor,"rvim")
90 if (Editor'="rvim")&(Editor'="joe")&(Editor'="pico") goto LEditAbort
91
92 ;"Only allow users with programmer access to use joe
93 if (Editor="joe") do if result=1 goto EditAbort
94 . new AccessCode
95 . set AccessCode=$piece(^VA(200,DUZ,0),"^",4)
96 . if AccessCode'="@" do
97 . . write !!,"*** Sorry. Insufficient security clearance to use insecure 'joe' editor. ***",!
98 . . write "Please enter 'User's Toolbox', then 'Edit User Characteristics' at a menu",!
99 . . write " option to change PREFERRED EDITOR to something other than JOE.",!!
100 . . set result=1
101
102 ;"new EditErrFile set EditErrFile="/tmp/trashjoeoutput.txt"
103
104 new Filename set Filename=FullPathName
105
106 new HookCmd
107 ;"set HookCmd=Editor_" "_Filename_" 2>"_EditErrFile ;"use NULL instead??
108 set HookCmd=Editor_" "_Filename
109 zsystem HookCmd
110 set result=$ZSYSTEM&255 ;"get result of execution. (low byte only). 0=success
111 if result>0 goto LEditDone
112
113
114LEditDone
115 ;"set temp=$$DelFile^TMGIOUTL(Filename_"~") ;"joe editor copies output to filename~ as a backup
116 ;"set temp=$$DelFile^TMGIOUTL(EditErrFile)
117LEditAbort
118 quit
119
120
Note: See TracBrowser for help on using the repository browser.