def __init__(self,config): logging.info("START dialib") self.dbf=join(config["rootpath"],config["dbfile"]) self.htmlconf=config["html"] self.html={} self.photo={} self.langconfig=join(config["rootpath"], config["conf_lang"]+"_"+config['lang']+'.conf') f=open(self.htmlconf,'r') try: for ligne in f: if ligne[:2] == '[*': label=ligne[2:] label=label[:-1].strip() label=label[:-2] logging.debug("label=%s",label) text="" else: if ligne[:5]=="#####": self.html[label]=text else: text+=ligne finally: f.close() chdir(config["photopath"]) db=SQLite(self.dbf) req='select rowid from groups where name="all"' res=db.select(req) self.id_group_all=res[0][0]
def usermgt(self,name='',pwd='',group=''): m=hmenu(self.langconfig,self.dbf) db=SQLite(self.dbf) ### parameter treatment if name=='': if group!='': req='insert into groups values("{}")'.format(group) status=db.upd_ins(req) else: req='select rowid from groups where name="{}"'.format(group) idgroup=db.select(req) hashpwd=bcrypt.hashpw(pwd,bcrypt.gensalt()) req='insert into users (name,hashpass,id_group)' req+=' values("{}","{}",{})'.format(name,hashpwd,idgroup[0][0]) status=db.upd_ins(req) try: sname=cherrypy.session['name'] [actions,contenu]=m.usersAndGroup() except Exception as err: logging.error("in usermgt: %s",err) contenu=m.unknown() HTMLpage=self.html["globalTemplate"].format(actions,contenu) return HTMLpage
def __init__(self,name,pwd,dbfile): db=SQLite(dbfile) logging.debug("account:dbfile:%s",dbfile) req="select rowid,hashpass,id_group from users " req+='where name="{}"'.format(name) result=db.select(req) if result==[]: logging.info("account:user %s does not exist",name) cherrypy.session['mess']="userKO" else: id_name=result[0][0] hashpass=result[0][1] id_group=result[0][2] if bcrypt.hashpw(pwd,hashpass) == hashpass: ## password has been verified cherrypy.session['name']=name cherrypy.session['id_name']=id_name cherrypy.session['id_group']=id_group cherrypy.session['mess']="OK" logging.info("account:user %s:loged in",name) else: logging.info("account:user %s:wrong password",name) cherrypy.session['mess']="pwdKO"
def __init__(self,langconfig,dbfile): messagefile=getconfig(langconfig) self.messages=messagefile.getconfig() messagefile.close() self.db=SQLite(dbfile)
class hmenu(object): def __init__(self,langconfig,dbfile): messagefile=getconfig(langconfig) self.messages=messagefile.getconfig() messagefile.close() self.db=SQLite(dbfile) def menuButton(self,message,link,anchor=""): ''' create a button to navigate in the menu parameters: 1 : message to print in the button (to be found in lang config files) 2 : link to next web page ''' htmlpage='<td class="hmenu_left" width="10" height="32"></td>\n' htmlpage+='<td class="hmenu_center"><a href="{}"'.format(link) if anchor!="": htmlpage+=' class="highslide" id="{}" '.format(anchor) htmlpage+='onclick="return hs.htmlExpand(this,' htmlpage+='{objectType: \'iframe\', outlineType: ' htmlpage+='\'rounded-white\'})"\n' htmlpage+='>{}</a></td>\n'.format(self.messages[message]) htmlpage+='<td class="hmenu_right" width="10"></td>\n' htmlpage+='<td width="10"></td>\n' return htmlpage def actionfor(self,name): ''' will create the appropriate menu for 'name' depending on its right firstly for admin user ... ''' logging.debug('menu:actionfor %s',cherrypy.session['name']) buttons='<table border="0" cellspacing="0">\n<tr>\n' buttons+='<td>{} : </td>'.format(cherrypy.session['name']) if name=="admin": ### return to main menu buttons+=self.menuButton('retour','/') ### user manangement buttons+=self.menuButton('usermgt','/usermgt') ### folder management buttons+=self.menuButton('foldermgt','/foldermgt') buttons+='</tr>\n</table>\n' return buttons def manageList(self,message,req): ''' manage a list of element (allow to list, add, delete element) ''' List=self.db.select(req) htmlpage='<h3>{}</h3>\n'.format(self.messages[message]) for element in List: htmlpage+='<p><a href="highslide/users.html" class="highslide"' htmlpage+=' onclick="return hs.htmlExpand(this,' htmlpage+='{objecType:\'iframe\', outlineType: \'rounded-white\'})">\n' try: htmlpage+='{}</a> [{}]</p>\n'.format(element[0],element[1]) except: htmlpage+='{}</a></p>\n'.format(element[0]) ### table for action button htmlpage+='<table border="0" cellspacing="0">\n<tr>\n' link="/highslide/{}.html".format(message) htmlpage+=self.menuButton('create',link,message) htmlpage+='</tr>\n</table>\n' return htmlpage def usersAndGroup(self): ''' page to manage users and group ''' ### menu for userAndGroup page logging.debug("in usersAndGroup[%s]",cherrypy.session['name']) actions='<table border="0" cellspacing="0">\n<tr>\n' actions+='<td>{} : </td>'.format(cherrypy.session['name']) actions+=self.menuButton('retour','/') actions+='</tr>\n</table>\n' ### user manangement htmlpage='<td valign="top">\n' ### get list of users from db req='select users.name,groups.name from users,groups ' req+='where users.id_group=groups.rowid' htmlpage+=self.manageList('listuser',req) ### end of user management htmlpage+='</td>\n' htmlpage+='<td width="20"></td>' ### group management htmlpage+='<td valign="top">\n' ### get list of groups from db req='select name from groups' htmlpage+=self.manageList('listgroup',req) ### end of folder management htmlpage+='</td>\n' return [actions,htmlpage] def foldersAndGroup(self): ''' page to folder and group ''' ### menu for folderAndGroup page logging.debug("in foldersAndGroup[%s]",cherrypy.session['name']) actions='<table border="0" cellspacing="0">\n<tr>\n' actions+='<td>{} : </td>'.format(cherrypy.session['name']) actions+=self.menuButton('retour','/') actions+='</tr>\n</table>\n' ### folder manangement htmlpage='<table border="0" cellspacing="0">\n<tr>\n' htmlpage+='<td>{} : </td>'.format(cherrypy.session['name']) htmlpage+='</tr>\n</table>\n' return htmlpage def unknown(self): ''' only return button for unknown users ''' htmlpage='<table border="0" cellspacing="0">\n<tr>\n' htmlpage+='<p class="error">{}</p>'.format(self.messages['notconnect']) htmlpage+=self.menuButton('retour','/') htmlpage+='</tr>\n</table>\n' return htmlpage
def insertPathInDb(path): ### insert folder into db reqi="insert into folder values ('{}',0)".format(path) db=SQLite(join(config["rootpath"],config["dbfile"])) return db.upd_ins(reqi)
def getPathInDb(path): ### check folder into db reqs="select rowid from folder where dirname='{}'".format(path) db=SQLite(join(config["rootpath"],config["dbfile"])) return db.select(reqs)
def insertPathInDb(path): ### insert folder into db reqi="insert into folder values ('{}',0)".format(path) db=SQLite(join(config["rootpath"],config["dbfile"])) return db.upd_ins(reqi) logging.info("START searchPhoto") logging.info("searchPhoto:config file: %s",args.config) ### -t args have been passed : if args.createTables: logging.info("searchPhoto:createTable will run") db=SQLite(join(config["rootpath"],config["dbfile"])) res=db.create(join(config["rootpath"],config["tables"])) if res=="createOK": logging.info("searchPhoto:createTable run successfully") else: logging.error("searchPhoto:createTable run with error") ### start searching for files from photopath bl=[] filebl=open(join(config["rootpath"],config["blacklist"]),'r') for l in filebl: bl.append(l[:-1]) chdir(config["photopath"]) ### first, check/insert for "." path presence in db res=getPathInDb(".")
def index(self,path='.',uname='',pwd=''): messagefile=getconfig(self.langconfig) messages=messagefile.getconfig() messagefile.close() ### affichage de la colonne menu: login, arbo, timeline actions="" contenu='<td valign="top">\n' bouton='<p><a href="/highslide/login.html" \ class="highslide" id="login" ' bouton+='onclick="return hs.htmlExpand(this,\ {objectType: \'iframe\', outlineType: \'rounded-white\'})">\n' bouton+='login</a></p>\n' #### checking for the user connection m=hmenu(self.langconfig,self.dbf) if uname!='': try: sname=cherrypy.session['name'] contenu+='<p class="error">{}</p>\n'.format( messages['alreadyconnected']) actions+=m.actionfor(sname) except: userac=account(uname,pwd,self.dbf) if cherrypy.session['mess']=="userKO": contenu+='<p class="error">{}</p>\n'.format( messages['userko']) contenu+=bouton elif cherrypy.session['mess']=="pwdKO": contenu+='<p class="error">{}</p>\n'.format( messages['passwordko']) contenu+=bouton else: sname=cherrypy.session['name'] actions+=m.actionfor(sname) else: try: sname=cherrypy.session['name'] actions+=m.actionfor(sname) except: contenu+=bouton #### getting list of directory in current folder db=SQLite(self.dbf) req='select dirname,rowid from folder where folder.rowid in\n' req+='(select id_folder_son from folderParent\n' req+='inner join folder on id_folder_father=folder.rowid\n' req+='and dirname="{}")'.format(path) res=db.select(req) #### getting access right on the list of folders listidfolder='' for r in res: listidfolder+="{},".format(r[1]) listidfolder=listidfolder[:1] ### delete last comma try: req='select id_folder from folderByGroup ' req+='where id_group={} '.format(self.id_group_all) req+='or id_group={}'.format(cherrypy.session['id_group']) access=db.select(req) except: req='select id_folder from folderByGroup ' req+='where id_group={}'.format(self.id_group_all) access=db.select(req) aright=[] for i in access: aright.append(i[0]) affpath="/"+path[2:] contenu+='<div class="menu">\n' contenu+='<a href="index?path=.">\ <img src="/highslide/home.png" width=25 height=25></a>\n' contenu+='{}\n<ul>\n'.format(affpath) for r in res: if r[1] in aright: contenu+='<li class="open">' contenu+='<a href="index?path={}">{}</a></li>\n'.\ format(r[0],basename(r[0])) else: contenu+='<li class="lock"><a href="/highslide/login.html" ' contenu+='class="highslide" id="login" ' contenu+='onclick="return hs.htmlExpand(this,' contenu+='{objectType: \'iframe\', outlineType: ' contenu+='\'rounded-white\'})">\n' contenu+='{}</a></li>\n'.format(basename(r[0])) contenu+='</ul>\n</td>\n' contenu+='</div>\n' #### getting list of image in current folder db=SQLite(self.dbf) req='select filename from files where id_dir=\n' req+='(select rowid from folder where dirname="{}")'.format(path) res=db.select(req) #### affichage des thumbs contenu+='<td>\n' contenu+='<div class="highslide-gallery">\n' if res!=[]: for p in res: contenu+='<a class="highslide" ' contenu+='href="/photos/{}/{}" '.format(path,p[0]) contenu+='onclick="return hs.expand(this,config1)">\n' contenu+='<img \ src="/photos/{}/.Thumbnails/{}"/>'.format(path,p[0]) contenu+='</a>' contenu+="</td>\n" HTMLpage=self.html["globalTemplate"].format(actions,contenu) return HTMLpage