This file is indexed.

/usr/share/pyshared/ControlAula/Plugins/Handler.py is in ltsp-controlaula 1.8.0-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
##############################################################################
# -*- coding: utf-8 -*-
# Project:     Controlaula
# Module:    Handler.py
# Purpose:     Handler of the different Plugins
# Language:    Python 2.5
# Date:        3-Feb-2010.
# Ver:        31-Oct-2010.
# Author:    José L.  Redrejo Rodríguez
# Copyright:    2009-2010 - José L. Redrejo Rodríguez       <jredrejo @nospam@ debian.org>
#
# ControlAula is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# ControlAula is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with ControlAula. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging,os
import urllib,mimetypes
from ControlAula.Utils import Configs,MyUtils,NetworkUtils
from ControlAula.Plugins import Actions
from ControlAula.Desktop import Desktop
from locale import getdefaultlocale
import simplejson as json

class Plugins(object):
    
    def __init__(self,classroom):
        self.args=[]
        self.targets=[]    
        self.classroom=classroom
        self.myteacher=None
        self.handlers = {
                'classroomConfig':self.classroomConfig,    
                'deleteComputer':self.deleteComputer,
                'bigbrother':self.bigBrother,
                'disableBigBrother':self.disableBigBrother,
                'enableProjector':self.enableProjector,
                'enableChat':self.enableChat,
                'disableChat':self.disableChat,                
                'disableProjector':self.disableProjector,
                'enableInternet':self.enableInternet,
                'disableInternet':self.disableInternet,
                'enableMouse':self.enableMouse,
                'disableMouse':self.disableMouse,
                'enableSound':self.enableSound,
                'disableSound':self.disableSound,
                'enableMessages':self.enableMessages,
                'disableMessages':self.disableMessages,
                'wakeup':self.wakeup,
                'sleep':self.sleep,        
                'openVNC':self.openVNC,
                'broadcast':self.broadcast,
                'broadcastDVD':self.broadcastDVD,
                'sendMessage':self.sendMessage,
                'sendFile':self.sendFile,
                'startapplication':self.startApp,
                'launchweb':self.launchUrl ,
                'launchwebToAll':self.launchUrlAll,
                'disableSound':self.disableSound,
                'enableSound':self.enableSound,
                'getVideoNodes':self.fileBrowserVideo,
                'getAllNodes':self.fileBrowserAll,
                'getCaptures':self.getCaptures,
                'getLoginTeacher':self.getLogin,
                'errorLog':self.errorLog,
                'openFile':self.openSendFiles,
                'language':self.language,
                'newtheme':self.save_theme,
                'gettheme':self.recover_theme
                }  
        
    def existCommand(self,command):
        return self.handlers.has_key(command)  
    
    def process(self,command):        
        if self.handlers.has_key(command):                   
            handler=self.handlers[command]
            logging.getLogger().debug('The action is %s with params: %s' %   (str(handler),str(self.args)))
            s=handler(*self.args)
            if s==None:
                s={'result':'ack'}
            return s
            
    def usersCommand(self,func,args=[]):
        for i in self.classroom.Desktops:
            if i.hostname in self.targets:
                func(i,*args)
        self.classroom.getJSONFrontend("")
                        
    def enableInternet(self):
        self.usersCommand(Desktop.enableInternet)
                
    def disableInternet(self):
        self.usersCommand(Desktop.disableInternet)
                
                
    def enableMouse(self):
        self.usersCommand(Desktop.enableKeyboardMouse)
              
    def disableMouse(self):
        self.usersCommand(Desktop.disableKeyboardMouse)
                                    
    def enableMessages(self):
        self.usersCommand(Desktop.enableMessages)
                
    def disableMessages(self):
        self.usersCommand(Desktop.disableMessages)
   

    def bigBrother(self):
        #self.usersCommand(Desktop.setBigBrother)
        for i in self.classroom.Desktops:            
                i.setBigBrother()     
        #MyUtils.backupDir (Configs.IMAGES_DIR,Configs.IMAGES_DIR + '_bb')               
        self.classroom.myVNC.activeBB=True
        
    def disableBigBrother(self):
        self.classroom.myVNC.activeBB=False
        for i in self.classroom.Desktops:            
                i.resetBigBrother()              
        #MyUtils.restoreDir (Configs.IMAGES_DIR + '_bb',Configs.IMAGES_DIR)  
        
    def openVNC(self,computer):
        for i in self.classroom.Desktops:
            if i.hostname==computer:
                self.classroom.myVNC.startViewer( i.hostname,i.ltsp,i.hostkey)
                break 
                        
    def enableProjector(self):
        self.classroom.myVNC.startServer()
        self.usersCommand(Desktop.setProjector)            
        
    def disableProjector(self):
        self.usersCommand(Desktop.resetProjector)  
        self.classroom.myVNC.stop()

    def disableSound(self):
        self.usersCommand(Desktop.disableSound)
                
    def enableSound(self):
        self.usersCommand(Desktop.enableSound)                   

    def enableChat(self):
        self.usersCommand(Desktop.enableChat) 
            
    def disableChat(self):
        self.usersCommand(Desktop.disableChat)                    
        
    def wakeup(self):
        macs=[]
        for i in self.targets:
            mac=Configs.MonitorConfigs.GetMAC(i)
            if mac !='':                
                macs.append(mac)                
        Actions.sendWOLBurst(macs, 4)                         
                
    def sleep(self):
        self.usersCommand(Desktop.sleep)
                                  
    def broadcastDVD(self):
        return self.broadcast('',True)
                        
    def broadcast(self, url='', isDVD=False):
        from os.path import isfile
        if url=='DVD':
            isDVD=True
            url=''
        if not isDVD:
            if not isfile(url):
                return {'result':'Bad file'} 

        for i in NetworkUtils.all_interfaces():
            if i[0]!='lo':
                try:
                    self.classroom.CommandStack[i[1]].append(['rootClean','239.255.255.0',NetworkUtils.ltspGW()])
                except: #host not avaialble
                    pass              
        self.classroom.broadcast.clean_callbacks() 
        self.classroom.broadcast.add_callback('started',self.startbcast)
        self.classroom.broadcast.add_callback('ended',self.stopbcast)
        result=self.classroom.broadcast.transmit(url,isDVD)
        if result!=True:
            self.stopbcast
            return {'result':result} 

    def startbcast(self,url,isDVD):      
        self.usersCommand(Desktop.sendBroadcast,[url,isDVD,self.classroom.broadcast.codec_h264])

    def stopbcast(self):
        for i in self.classroom.Desktops:
            i.stopBroadcast()
        self.classroom.getJSONFrontend("")
   
    def sendFile(self,url):
        import os.path
        from os import symlink
        filename=os.path.basename(url)
        filepath=os.path.join(Configs.FILES_DIR,filename)
        if not os.path.exists(filepath):
            symlink(url,filepath)   
        if os.path.isdir(url):
            command='receiveDir'
            filelist=''
            for f in os.listdir(url):
                if f[:1]=='.':#skip hidden files and dirs
                    continue
                ff=os.path.join(filepath,f)
                if os.path.isdir(ff):#skip inner dirs to avoid recursion
                    continue
                filelist+=f +'\n'
            thelist = open(os.path.join(Configs.FILES_DIR,'_dirlist_' +filename), "w")
            thelist.write(filelist)
            thelist.close()           
        else:
            command='receiveFile'
        
        self.usersCommand(Desktop.sendFile,[command,filename])        

                
    def launchUrl(self,url):
        self.usersCommand(Desktop.launchWeb,[url])

    def launchUrlAll(self,url):
        self.targets=[]
        for desk in self.classroom.Desktops:
            self.targets.append(desk.hostname)
   
        self.usersCommand(Desktop.launchWeb,[url])         
          
    def classroomConfig(self,rows=0,cols=0,computers=0):
        for i in range(0, len(self.targets)-1):
            if self.targets[i]=='Sin equipo':
                self.targets[i]='Unknown'
                

        if rows!=0 or cols!=0:
            if self.classroom.rows==rows and self.classroom.cols==cols:
                self.classroom.redistributeDesktops(self.targets,False)
            else:
                while  self.classroom.rows <rows:                
                    self.classroom.addDesktopsRow()
                while self.classroom.rows >rows:
                    self.classroom.removeDesktopsRow()
                while self.classroom.cols <cols:
                    self.classroom.addDesktopsCol()
                while self.classroom.cols >cols:
                    self.classroom.removeDesktopsCol()

        self.classroom.computers = computers
                              
        #place empty desktops:
        nones=0
        for i in self.classroom.Desktops:
            if i.hostname=='none':
                nones +=1
        empty_needed=rows*cols-computers-nones
        
        if empty_needed >0:        #if holes must be placed.  
            #first try to place empties in unknown positions            
            for host in reversed(self.classroom.Desktops):
                if host.hostname=='Unknown':
                    host.hostname='none'
                    empty_needed -=1
                    if empty_needed==0:break
            #then remove any one of the latests
            if empty_needed>0:
                for host in reversed(self.classroom.Desktops):
                    if host.hostname!='none':
                        host.hostname='none'
                        empty_needed -=1
                        if empty_needed==0:break                    
        elif empty_needed<0: #if holes must be filled:   
            for host in self.classroom.Desktops:
                if host.hostname=='none':
                    host.hostname='Unknown'
                    empty_needed+=1
                    if empty_needed==0:break           
                            
        self.classroom.oldJSON=''                                 
        self.classroom.saveClassLayout()

        
    def deleteComputer(self):
            if self.targets[:2]=='pc':
                index=int(self.targets[2:])
            else:
                index=int(self.targets)
            self.classroom.Desktops[index].hostname='none'
            self.classroom.saveClassLayout()
            
    def fileBrowserVideo(self,node):

        return self.fileBrowserAll(node, True)
 
       
    def fileBrowserAll(self,node,video=False):
        path=urllib.unquote(unicode(node[0])).encode( "utf-8" )

        if path=='home':
            return self.getTreeHome()

        if path=='receivedFiles':
            path=Configs.FILES_DIR
            
        r=['<ul class="jqueryFileTree" style="display: none;">']
        try:

            files_and_dirs=os.listdir(path)
            sorted_files_and_dirs=sorted(files_and_dirs,key=lambda x: (x.lower(),x.swapcase()))
            for f in sorted_files_and_dirs:
                if f[:1]=='.':#skip hidden files and dirs
                    continue
                ff=os.path.join(path,f)  
                       
                if os.path.isdir(ff):
                    r.append('<li class="directory collapsed"><a href="#" rel="%s/">%s</a></li>' % (ff,f))
                    
                else:
                    if video:
                        mtype=mimetypes.guess_type(f,True)[0]
                        type=''
                        if mtype!=None:
                            type=mtype[:5] 
                        if type not in ['audio','video']:#skip non-multimedia files
                            continue                                 
                    
                    e=os.path.splitext(f)[1][1:] # get .ext and remove dot
                    r.append('<li class="file ext_%s"><a href="#" rel="%s">%s</a></li>' % (e,ff,f))
              
        except Exception,e:
            r.append('Could not load directory: %s' % str(e))
        r.append('</ul>')
        
        return  ''.join(r)

    def getTreeHome(self):
        path=MyUtils.getHomeUser()
        user=MyUtils.getLoginName()
        r=['<ul class="jqueryFileTree" style="display: none;">']
        r.append('<li class="directory collapsed"><a href="#" rel="%s/">%s</a></li>' % (path,user))
        r.append('<li class="directory collapsed"><a href="#" rel="/media/">Media</a></li>' )        
        r.append('</ul>')
        
        return  ''.join(r)        

 
    def sendMessage(self, text):
        self.usersCommand(Desktop.sendMessage,[text])
        
    def startApp(self,command):
        pass 

    def getCaptures(self):

        self.bigBrother()
        shots=[]    
        for i in self.classroom.Desktops:
            shots.append(i.getScreenshotInfo())
            
        return {"images":shots}
    
    def getLogin(self):
        return {'login':MyUtils.getLoginName() }

    def errorLog(self,error_msg):
        logging.getLogger().debug('Error report from Frontend: %s ' %   (error_msg))
        
    def openSendFiles(self,path):
        import os.path,subprocess            
        commands={'gnome':'nautilus','kde':'konqueror','xfce':'thunar','lxde':'pcmanfm'}
        desktop=MyUtils.guessDesktop()            
        if desktop in commands:
            command=commands[desktop]
        else:
            command='thunar'

        if path=='dirReceivedTeacher':
            file_path=Configs.FILES_DIR
        else:
            file_path=os.path.dirname( os.path.join(Configs.FILES_DIR,path))
                   
        try:
            subprocess.Popen([command,file_path])
        except:
            pass #not recognized file browser
                
    def language(self):      
        mylocale=getdefaultlocale()[0]
        if mylocale is None:
            mylocale = 'en_EN'
        if mylocale.strip()  == '':
            mylocale = 'en_EN'
            
        locale_file=os.path.join(Configs.LANG,mylocale + '.json')
        if not os.path.exists(locale_file):
            mylocale = 'en_EN'
            locale_file=os.path.join(Configs.LANG,mylocale + '.json')
            
        try:
            translation=json.loads(open(locale_file, "r").read())
        except:
            translation='{}'
        return translation
    
    def save_theme(self,theme_path):
        Configs.MonitorConfigs.SetGeneralConfig('theme', theme_path)
        
    def recover_theme(self):
        return Configs.MonitorConfigs.GetGeneralConfig('theme')