diff --git a/plugins/cookiex/cookiex.c b/plugins/cookiex/cookiex.c new file mode 100644 index 0000000..26f74aa --- /dev/null +++ b/plugins/cookiex/cookiex.c @@ -0,0 +1,32 @@ +#include "../plugin.h" + +void init(); +call __init__ = init; + +void init() +{ + printf("Finish init\n"); +} + +void execute(int client,const char* method,dictionary rq) +{ + + /** + * Set cookie to the browser + */ + char* c = server_time(); + dictionary d = dict(); + dput(d,"test",c); + dput(d,"test1","This is another cookie"); + set_cookie(client,d); + + LOG("%s",c); + __t(client,"

Set the cookie

"); + freedict(d); +} + +void get(int client,const char* method,dictionary rq) +{ + + +} \ No newline at end of file diff --git a/plugins/cookiex/cookiex.c.o b/plugins/cookiex/cookiex.c.o new file mode 100644 index 0000000..fb3f9d4 Binary files /dev/null and b/plugins/cookiex/cookiex.c.o differ diff --git a/plugins/fileman/.DS_Store b/plugins/fileman/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/plugins/fileman/.DS_Store differ diff --git a/plugins/fileman/fileman.c b/plugins/fileman/fileman.c new file mode 100644 index 0000000..f7c51d5 --- /dev/null +++ b/plugins/fileman/fileman.c @@ -0,0 +1,188 @@ +#include "../plugin.h" +#define MAXSIZE 500000 +#define FRECORD "{\"recid\":%d,\"name\":\"%s\",\"size\":%d,\"changed\":\"%s\",\"type\":%d,\"style\":\"%s\",\"mime\":\"%s\"}" +#define RRECORD "{ \"records\":[%s], \"total\":%d,\"folder\":\"%s\",\"router\":[%s]}" +#define FOLLIST "{ \"name\":\"%s\", \"path\":\"%s\"}" + +char* folder_list_from(const char* aPath) +{ + if(aPath == NULL || strlen(aPath)==0 || strcmp(aPath,DIR_SEP)==0) + return __s(FOLLIST,"HTDOCS",DIR_SEP); + list path = split(aPath,DIR_SEP); + char* flist=__s(FOLLIST,"HTDOCS",DIR_SEP); + char* route = ""; + if(path) + { + for(list np = path; np != NULL; np=np->next) + { + route = __s("%s%s%s", route, DIR_SEP, np->e.value.s); + if(flist == NULL) + flist = __s(FOLLIST, np->e.value.s,route); + else + flist = __s("%s,%s", flist,__s(FOLLIST,np->e.value.s,route)); + } + } + free(path); + //free(route); + return flist; +} + +void execute(int client,const char* method,dictionary rq) +{ + DIR *d; + struct dirent *dir; + struct stat st; + int frec=0,rrec = 0, id =0; + char* flist = "",*dlist = ""; + char* tmp= NULL; + char* rpath = R_STR(rq,"path"); + if(!rpath || strlen(rpath) == 0) rpath = DIR_SEP; + char* path = __s("%s%s",__plugin__.htdocs,rpath); + d = opendir(path); + + if (d) + { + while ((dir = readdir(d)) != NULL) + { + //ignore curent directory, parent directory and hidden files and folders + if(strcmp(dir->d_name,".") == 0 || + strcmp(dir->d_name,"..")==0|| *(dir->d_name)=='.') continue; + if( stat(__s("%s%s%s",path,DIR_SEP,dir->d_name), &st) == 0 ) + { + if(S_ISDIR(st.st_mode)) + { + tmp = __s(FRECORD,id, + dir->d_name, + (int)st.st_size, + __time(st.st_mtime), + 0, + "font-weight: bold;", + "folder"); + if(rrec != 0) + dlist = __s("%s,%s",dlist,tmp); + else + dlist = tmp; + rrec++; + //free(tmp); + + } else + { + tmp = __s(FRECORD, id, + dir->d_name, + (int)st.st_size, + __time(st.st_mtime),1,"", + mime(dir->d_name)); + if(frec != 0) + flist = __s("%s,%s",flist,tmp); + else + flist = tmp; + frec++; + //free(tmp); + } + id++; + } + } + closedir(d); + if(strlen(dlist) == 0) + dlist = flist; + else if(strlen(flist) > 0) + dlist = __s("%s,%s",dlist,flist); + } + json(client); + __t(client,RRECORD,dlist,frec+rrec,rpath,folder_list_from(rpath)); + if(path) free(path); + //if(rpath) free(rpath); + if(tmp) free(tmp); + +} + +void add(int c, const char* m, dictionary rq) +{ + json(c); + if(IS_GET(m)) + { + __t(c,__RESULT__,0,"Bad request:GET"); + return; + } + char* rpath = R_STR(rq,"path"); + if(!rpath) + { + __t(c,__RESULT__,0,"Unknow path"); + return; + } + + char * file_name = R_STR(rq,"pfile.file"); + if(file_name == NULL) + { + __t(c,__RESULT__,0,"Cannot send file to server"); + return; + } + + int size = R_INT(rq,"pfile.size"); + if(size>MAXSIZE) + { + __t(c,__RESULT__,0,"Cannot accept file more than 500Kb"); + return; + } + if(!upload(R_STR(rq,"pfile.tmp"),__s("%s/%s/%s",__plugin__.htdocs,rpath,file_name))) + { + __t(c,__RESULT__,0,"Cannot move file to plugin dir"); + return; + } + __t(c,__RESULT__,1,"OK"); + return; +} + +void mkfolder(int c, const char* m, dictionary rq) +{ + json(c); + if(IS_GET(m)) + { + __t(c,__RESULT__,0,"Bad request:GET"); + return; + } + char* dname = R_STR(rq,"dname"); + char* rpath = R_STR(rq, "path"); + if(!dname) + { + __t(c,__RESULT__,0,"Folder name is empty"); + return; + } + if(!rpath) + { + __t(c,__RESULT__,0,"Unknow path"); + return; + } + if(mkdir(__s("%s%s%s%s",__plugin__.htdocs,rpath,DIR_SEP,dname), 0755)) + { + __t(c,__RESULT__,0,"Error when create directory."); + return; + } + __t(c,__RESULT__,1,"OK"); +} + +void rmfolder(int c, const char* m, dictionary rq) +{ + json(c); + if(IS_GET(m)) + { + __t(c,__RESULT__,0,"Bad request:GET"); + return; + } + char* name = R_STR(rq,"name"); + char* rpath = R_STR(rq, "path"); + if(!name) + { + __t(c,__RESULT__,0,"Folder name is empty"); + return; + } + if(!rpath) + { + __t(c,__RESULT__,0,"Unknow path"); + return; + } + removeAll(__s("%s%s%s%s",__plugin__.htdocs,rpath,DIR_SEP,name),1); + //LOG("%s\n",name ); + //LOG("%s\n",rpath ); + __t(c,__RESULT__,1,"OK"); +} diff --git a/plugins/fileman/fileman.c.o b/plugins/fileman/fileman.c.o new file mode 100644 index 0000000..24ac80d Binary files /dev/null and b/plugins/fileman/fileman.c.o differ diff --git a/plugins/pluginsman/.DS_Store b/plugins/pluginsman/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/plugins/pluginsman/.DS_Store differ diff --git a/plugins/pluginsman/pluginsman.c b/plugins/pluginsman/pluginsman.c new file mode 100644 index 0000000..bb9aff0 --- /dev/null +++ b/plugins/pluginsman/pluginsman.c @@ -0,0 +1,76 @@ +#include "../plugin.h" +#define PEXT "dylib" +#define MAXSIZE 500000 + +void execute(int client,const char* method,dictionary rq) +{ + //all plugin file + DIR *d; + struct dirent *dir; + struct stat st; + d = opendir(__plugin__.pdir); + json(client); + __t(client,"{ \"records\":["); + int nrec = 0; + if (d) + { + while ((dir = readdir(d)) != NULL) + { + if(strcmp(dir->d_name,".") == 0 || + strcmp(dir->d_name,"..")==0 || *(dir->d_name)=='.') continue; + if( stat(__s("%s%s",__plugin__.pdir,dir->d_name), &st) == 0 ) + { + if(nrec != 0) + __t(client,","); + __t(client,"{\"name\":\"%s\",\"size\":%d,\"changed\":\"%s\"}", + dir->d_name, + (int)st.st_size, + __time(st.st_mtime) + ); + nrec++; + } + } + closedir(d); + } + __t(client,"], \"total\":%d}",nrec); + +} + +void install(int c, const char* m, dictionary rq) +{ + char * result = "{\"result\":%d,\"msg\":\"%s\"}"; + json(c); + if(IS_GET(m)) + { + __t(c,result,0,"Bad request:GET"); + return; + } + if(R_INT(rq,"test") != NULL) + LOG("Test is :%d \n",R_INT(rq,"test")); + char * file_name = R_STR(rq,"pfile.file"); + char* file_ext = R_STR(rq,"pfile.ext"); + if(file_name == NULL) + { + __t(c,result,0,"Cannot send file to server"); + return; + } + + if(strcasecmp(file_ext,PEXT) == 0) + { + int size = R_INT(rq,"pfile.size"); + if(size>MAXSIZE) + { + __t(c,result,0,"Cannot accept file more than 500Kb"); + return; + } + if(!upload(R_STR(rq,"pfile.tmp"),__s("%s/%s",__plugin__.pdir,file_name))) + { + __t(c,result,0,"Cannot move file to plugin dir"); + return; + } + __t(c,result,1,"OK"); + return; + } + + __t(c,result,0,"This is not a plugin file"); +} diff --git a/plugins/pluginsman/pluginsman.c.o b/plugins/pluginsman/pluginsman.c.o new file mode 100644 index 0000000..a6a15ff Binary files /dev/null and b/plugins/pluginsman/pluginsman.c.o differ