int op_qbox_get_sid(INPUT *input) { INPUT *tmp; char qbox_sid[AUTH_SIDSIZE], *sid; char comp[COMP_LENGTH]; int status = 0, device_type; if ((tmp = CGI_Find_Parameter(input, "sid"))) { sid = tmp->val; if ((tmp = CGI_Find_Parameter(input, "qbox_computer"))) { snprintf(comp, COMP_LENGTH, "Qfile-%s", tmp->val); if((tmp = CGI_Find_Parameter(input, "qbox_device_type"))) device_type = atoi(tmp->val); ///TODO: update_qsync_device_status } else { } } printf("{"); _printJsonInt(1, "status", status); ///TODO: Print correct JSON format sid _printJsonString(0, "sid", sid); //_printJsonString(0, "sid", qbox_sid); printf("}"); return 0; }
int sysinfo_req(void) { INPUT *input = CGI_INIT(); INPUT *tmp; if ((tmp = CGI_Find_Parameter(input, "appsjson"))) { FCGI_LOG("appsjson = %s\n", tmp->val); } if ((tmp = CGI_Find_Parameter(input, "sid"))) FCGI_LOG("sid = %s\n", tmp->val); Sysinfo_To_JSON(2); CGI_RELEASE(input); return 0; }
int op_get_chunked_upload_status(INPUT *input) { INPUT *tmp = NULL; int ret = 0, exist = 0, count = 0; char *upload_id = NULL, *full_path = NULL, size_str[64] = "0", size_str2[64] = "0", *upload_dir = NULL; struct stat statbuf; unsigned long long size = 0, total_len = 0; char id[32] = "---"; //char buf[BLK_SIZE], md5_str[128] = "---"; char buf[BLK_SIZE], md5_str[128] = {0}; if( (tmp=CGI_Find_Parameter(input, "upload_id")) ) { upload_id = tmp->val; } if( (tmp=CGI_Find_Parameter(input, "upload_root_dir")) ) { char uppath[1024]; snprintf(uppath, sizeof(uppath), "%s/%s", tmp->val, UPLOAD_CACHE_DIR); upload_dir = (char *)calloc(1, strlen(uppath) + MAX_FILE_LENGTH + 15); exist = check_exist(uppath, upload_dir); if (exist < 0) { ret = WFM2_FILE_NO_EXIST; goto end; } full_path = (char *)calloc(1, strlen(upload_dir) + strlen(upload_id) + 2); sprintf(full_path, "%s/%s", upload_dir, upload_id); } if(!stat(full_path, &statbuf)){ if(S_ISDIR(statbuf.st_mode)){ ret = WFM2_FILE_NO_EXIST; }else{ size = statbuf.st_size; sprintf(size_str, "%lld", statbuf.st_size); } }else ret = WFM2_FILE_NO_EXIST; end: if(full_path) free(full_path); if(upload_dir) free(upload_dir); Status_With_Size_And_MD5_To_JSON(ret, size_str, md5_str, size_str2); return ret; }
int op_delete_chunked_upload_file(INPUT *input) { INPUT *tmp = NULL; int ret = 0, exist = 0; char *upload_id = NULL, *full_path = NULL, *upload_dir = NULL; struct stat statbuf; if( (tmp=CGI_Find_Parameter(input, "upload_id")) ) { upload_id = tmp->val; } if( (tmp=CGI_Find_Parameter(input, "upload_root_dir")) ) { char uppath[1024]; snprintf(uppath, sizeof(uppath), "%s/%s", tmp->val, UPLOAD_CACHE_DIR); upload_dir = (char *)calloc(1, strlen(uppath) + MAX_FILE_LENGTH + 15); exist = check_exist(uppath, upload_dir); if (exist < 0) { ret = WFM2_FILE_NO_EXIST; goto end; } full_path = (char *)calloc(1, strlen(upload_dir) + strlen(upload_id) + 2); sprintf(full_path, "%s/%s", upload_dir, upload_id); } if(!stat(full_path, &statbuf)){ if(S_ISDIR(statbuf.st_mode)) ret = WFM2_OPEN_FILE_FAIL; else #ifdef RECYCLE_EX qnap_unlink(full_path); #else unlink(full_path); #endif }else ret = WFM2_FILE_NO_EXIST; end: if(full_path) free(full_path); if(upload_dir) free(upload_dir); Status_To_JSON(ret); return ret; }
int ej_wlv_sec_show_setting(int eid, INPUT *input, int argc, char_t **argv) { char buf_sec[TMP_LEN], buf_if[TMP_LEN], buf_vif[TMP_LEN]; int if_idx, vif_idx, num; char *secmode = NULL; INPUT *tmp; /* Get physical interface index */ if (ejArgs(argc, argv, "%d %d", &if_idx, &vif_idx) < 2) { FCGI_LOG("Insufficient args"); return FALSE; } num = atoi(nvram_safe_get("wlv_rule_num")); /* Get security mode rule */ snprintf(buf_if, TMP_LEN, "wl%d_ssid%d_secmode" , if_idx, vif_idx); if ((tmp = CGI_Find_Parameter(input, buf_if))) { secmode = tmp->val; } if (!secmode || !*secmode) { snprintf(buf_if, TMP_LEN, "wl%d_sec_rule", if_idx); ezplib_get_attr_val(buf_if, vif_idx, "secmode", buf_sec, TMP_LEN, EZPLIB_USE_CLI); } else{ sprintf(buf_sec, "%s", secmode); } /*---------------- buf_sec : security mode buf_if : interface index buf_vif : ssid index -----------------*/ snprintf(buf_if, TMP_LEN, "%d", if_idx); snprintf(buf_vif, TMP_LEN, "%d", vif_idx); if (!strcmp(buf_sec, "wep")) { do_ej("wlv_sec_wep.asp", input, buf_if, buf_vif, ""); } else if (!strcmp(buf_sec, "psk")) { do_ej("wlv_sec_psk.asp", input, buf_if, buf_vif, ""); } else if (!strcmp(buf_sec, "wpa")) { do_ej("wlv_sec_wpa.asp", input, buf_if, buf_vif, ""); } else if (!strcmp(buf_sec, "psk2")) { do_ej("wlv_sec_psk2.asp", input, buf_if, buf_vif, ""); } else if (!strcmp(buf_sec, "wpa2")) { do_ej("wlv_sec_wpa2.asp", input, buf_if, buf_vif, ""); } if (appmgr_check("guest_lan") && ( vif_idx == num - 1 )) { do_ej("guest_lan_setting.asp", input, buf_if, buf_vif, ""); } return 0; }
int qsync_prepare(INPUT *input) { INPUT *tmp; if ((tmp=CGI_Find_Parameter(input, "func"))!=NULL){ /* Here we do about other feature if( _session_auth(input) == -1) return -1; if (!strcmp(tmp->val, "qbox_get_max_log")){ Start_JSON(); op_qbox_get_max_log(input); } */ }else if((tmp=CGI_Find_Parameter(input, "user")) != NULL){ // Start_JSON(); op_qbox_get_nas_uid(input); } CGI_RELEASE(input); return 0; }
int op_get_tree(INPUT *input) { INPUT *tmp; char *inode = NULL, *sid = NULL; int is_iso = 0; int ret = 0; if((tmp = CGI_Find_Parameter(input, "sid"))) sid = tmp->val; if((tmp = CGI_Find_Parameter(input, "node"))) inode = tmp->val; if((tmp = CGI_Find_Parameter(input, "is_iso"))) is_iso = atoi(tmp->val); if((tmp = CGI_Find_Parameter(input, "hidden_file"))) g_hidden_file = atoi(tmp->val); if((tmp = CGI_Find_Parameter(input, "dir"))) strcpy(gSort_type, tmp->val); if(inode && !strcmp(inode, "share_root_path")) get_root_share(1); else if(inode && (!strcmp(inode, "share_root") || !strcmp(inode, "tree_root"))) { if(strcmp(sid, GUEST_SID)) get_root_share(0); else get_root_share(9); } else if(inode && (!strcmp(inode, "recycle_root"))) ret = get_root_share(2); else if(inode) _get_tree(inode, is_iso); else Status_To_JSON(WFM2_PERMISSION_DENY); if(ret == -1) Status_To_JSON(WFM2_RECYCLE_BIN_NOT_ENABLE); //get_root_share(0); return 0; }
int op_qbox_get_nas_uid(INPUT *input) { INPUT *tmp; char string[128], output[64], version[64] = "---"; char suid[32] = {'\0'}, mac[32] = "---"; char remote_user[64] = ""; int uid = 0; int is_booting = 1; sprintf(output, "---"); if ((tmp = CGI_Find_Parameter(input, "user")) != NULL){ snprintf(remote_user, sizeof(remote_user), "%s", tmp->val); } uid = qbox_name_to_uid(remote_user); if(uid < 0) goto end; snprintf(string, sizeof(string), "%d", uid); if (Get_Specify_ID(string, output, sizeof(output)) != 0){ snprintf(output, sizeof(output), "---"); } end: qbox_get_software_version(version, sizeof(version)); Get_Device_SUID(suid, sizeof(suid)); Get_Mac_Address(mac, sizeof(mac)); printf("{"); //_printJsonString(1, "UID", output); _printJsonString(1, "UID", "d176c9d770b0942379bc3dc7e6863f33"); _printJsonString(0, "Qsync_version", version); #ifdef LIBRSYNC _printJsonString(0, "versioning_version", Get_Versioning_Version()); #endif //if (file_is_exist("/tmp/.boot_done")) if (!strncmp("ready", nvram_safe_get("sysstat"),sizeof("ready"))) is_booting = 0; _printJsonInt(0, "is_booting", is_booting); // _printJsonString(0, "SUID", suid); _printJsonString(0, "SUID", "fc174cb804e458b621eded56fe5526c9"); _printJsonString(0, "MAC0", mac); printf("}"); return 0; }
int op_get_chunked_upload_id(INPUT *input) { INPUT *tmp; char id[32] = "---"; int euid, egid, ret = 0; int exist; char *full_path, path[1024]; char lastpath[1024] = "", *filename = NULL; int length = 0; int fd = -1; if( (tmp = CGI_Find_Parameter(input, "upload_root_dir")) ) { snprintf(path, sizeof(path), "%s/%s", tmp->val, UPLOAD_CACHE_DIR); } full_path = (char *)__ax_calloc(1, strlen(path) + MAX_FILE_LENGTH + 15); exist = check_exist(path, full_path); if (exist < 0) { if(mkdir(full_path, S_IRUSR | S_IWUSR | S_IXUSR |S_IRGRP | S_IWGRP | S_IXGRP |S_IROTH | S_IWOTH | S_IXOTH)< 0){ ret = WFM2_OPEN_FILE_FAIL; goto end; } chmod(full_path, S_IRUSR | S_IWUSR | S_IXUSR |S_IRGRP | S_IWGRP | S_IXGRP |S_IROTH | S_IWOTH | S_IXOTH); } // Create unique file strcpy(lastpath, full_path); strcat(lastpath, "/"); length = strlen(lastpath); strcat(lastpath, "XXXXXXX"); mktemp(lastpath); fd = open(lastpath, O_CREAT | O_RDWR); if (fd == -1) { ret = WFM2_OPEN_FILE_FAIL; goto end; } filename = __ax_strndup(lastpath + length, 7); end: printf("{\"status\": %d, \"upload_id\":\"%s\"}\n", ret, filename); if (filename) __ax_free(filename); if (fd != -1) close(fd); if (full_path) __ax_free(full_path); return 0; }
int op_get_file_list(INPUT *input) { INPUT *tmp; WFM2_FILE_LIST_PARAM sFileListParam; char *full_path = NULL; int nRet=0; memset(&sFileListParam, 0, sizeof(WFM2_FILE_LIST_PARAM)); if((tmp = CGI_Find_Parameter(input, "path"))) { full_path = (char *)__ax_malloc(strlen(tmp->val) + MAX_FILE_LENGTH + PATH_PREFIX_LENGTH + 256); int exist = check_exist(tmp->val, full_path); if (exist < 0) { Status_To_JSON(WFM2_FILE_NO_EXIST); if(full_path) __ax_free(full_path); return -1; } sFileListParam.node = __ax_strdup(tmp->val); } if((tmp = CGI_Find_Parameter(input, "list_mode"))) { strncpy(sFileListParam.listMode, tmp->val, WFM2_LIST_MODE_LEN); } if((tmp = CGI_Find_Parameter(input, "start"))) { sFileListParam.start = atoi(tmp->val); } else { sFileListParam.start = 0; } if((tmp = CGI_Find_Parameter(input, "limit"))) { sFileListParam.limit = atoi(tmp->val); } else { sFileListParam.limit = 0; } if((tmp = CGI_Find_Parameter(input, "is_iso"))) { sFileListParam.is_iso = atoi(tmp->val); } else { sFileListParam.is_iso = 0; } if((tmp = CGI_Find_Parameter(input, "type"))) { // 1:music, 2:video, 3:photo, 4: folder sFileListParam.filetype = atoi(tmp->val); if(sFileListParam.filetype < MUSIC || sFileListParam.filetype > MEDIA) sFileListParam.filetype = 0; } if((tmp = CGI_Find_Parameter(input, "mp4_360"))) { sFileListParam.mp4_360 = atoi(tmp->val); } else { sFileListParam.mp4_360 = 0; } if((tmp = CGI_Find_Parameter(input, "mp4_720"))) { sFileListParam.mp4_720 = atoi(tmp->val); } else { sFileListParam.mp4_720 = 0; } if((tmp = CGI_Find_Parameter(input, "mp4_240"))) { sFileListParam.mp4_240 = atoi(tmp->val); } else { sFileListParam.mp4_240 = 0; } if((tmp = CGI_Find_Parameter(input, "mp4_480"))) { sFileListParam.mp4_480 = atoi(tmp->val); } else { sFileListParam.mp4_480 = 0; } if((tmp = CGI_Find_Parameter(input, "mp4_1080"))) { sFileListParam.mp4_1080 = atoi(tmp->val); } else { sFileListParam.mp4_1080 = 0; } // for special video file if((tmp = CGI_Find_Parameter(input, "filename"))) { strncpy(sFileListParam.filename, tmp->val, (MAX_FILE_LENGTH-1)); } if((tmp = CGI_Find_Parameter(input, "sort"))) { strncpy(sFileListParam.sort, tmp->val, WFM2_SORT_MODE_LEN); } if((tmp = CGI_Find_Parameter(input, "dir"))) { strncpy(sFileListParam.dir, tmp->val, WFM2_SORT_TYPE_LEN); } if((tmp = CGI_Find_Parameter(input, "hidden_file"))) { sFileListParam.hidden_file = atoi(tmp->val); } else { sFileListParam.hidden_file = 0; } nRet = handle_file_list(&sFileListParam, NULL); //MARK: original handle list function //sFileListParam.end = sFileListParam.start + sFileListParam.limit - 1; //_get_file_list(full_path, &sFileListParam, NULL); if(full_path) __ax_free(full_path); if(sFileListParam.node != NULL) __ax_free(sFileListParam.node); return nRet; }
int op_search(INPUT *input) { int ret = 0; INPUT *keyword = NULL, *start = NULL, *limit = NULL; INPUT *source = NULL, *tmp = NULL, *time = NULL; char *full_path = NULL, *source_tmp = NULL, *sort_type = "ASC"; int exist = 0, end = 0, sort_mode = 0, permission = NO, is_iso = 0; //only for internal use ret = special_search(input); if (ret == 0) return 0; source = CGI_Find_Parameter(input, "source_path"); if (source == NULL) return -1; if(!Check_Illegal_Path(source->val)) { Status_To_JSON(WFM2_ILLEGAL_NAME); return -1; } time = CGI_Find_Parameter(input, "time"); if (time != NULL) { char *ptr = NULL, tmp[12]; struct tm *p; time_t timep; struct stat buf; struct passwd *user; struct group *data; int i; JSON_FILE_OBJECT *file; ptr = time->val; strncpy(tmp, ptr, 4); tmp[4] = 0x0; p = (struct tm *)__ax_malloc(sizeof(struct tm)); p->tm_year = atoi(tmp) - 1900; ptr = ptr + 4; strncpy(tmp, ptr, 2); tmp[2] = 0x0; p->tm_mon = atoi(tmp) - 1; ptr = ptr + 2; strncpy(tmp, ptr, 2); tmp[2] = 0x0; p->tm_mday = atoi(tmp); p->tm_hour = 0; p->tm_min = 0; p->tm_sec = 0; timep = mktime(p); if (p) __ax_free(p); full_path = (char *)__ax_malloc(strlen(source->val) + MAX_FILE_LENGTH + 15); exist = check_exist(source->val, full_path); if (exist < 0) { Status_To_JSON(WFM2_FILE_NO_EXIST); if (full_path) __ax_free(full_path); return -1; } _search_by_time(full_path, timep, 0); file = (JSON_FILE_OBJECT *)__ax_malloc( total_file * sizeof(JSON_FILE_OBJECT)); for (i=0;i<total_file;i++) { lstat(file_list[i], &buf); strcpy((file+i)->filename, file_list[i]); (file+i)->isfolder = 0; (file+i)->filesize = (unsigned long long)(buf.st_size); user = getpwuid(buf.st_uid); if (user == NULL) sprintf((file+i)->owner, "%d", buf.st_uid); else strcpy((file+i)->owner, user->pw_name); data = getgrgid(buf.st_gid); if (data == NULL) sprintf((file+i)->group, "%d", buf.st_gid); else strcpy((file+i)->group, data->gr_name); /* { char sDateStr[64]={0}; char sTimeStr[64]={0}; Change_Date_To_String_By_Format(buf.st_mtime, sDateStr, nDate_format); Change_Time_To_String_By_Format(buf.st_mtime, sTimeStr, 0, nTime_format); sprintf((file+i)->mt_str, "%s %s", sDateStr, sTimeStr); } */ sprintf((file+i)->privilege, "%o", (buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO))); } File_List_To_JSON(file, total_file, total_file, 0, 0); if (full_path) __ax_free(full_path); if (file) __ax_free(file); return 0; } if((tmp = CGI_Find_Parameter(input, "is_iso"))) is_iso = atoi(tmp->val); /* source_tmp = (char *)__ax_malloc(strlen(source->val) + 1); strcpy(source_tmp, source->val); g_access = Get_NAS_User_Security_For_Share_Ex(remote_user, strtok(source_tmp, delim)); if (g_access == SHARE_NOACCESS) { Status_To_JSON(WFM2_PERMISSION_DENY); if(source_tmp) __ax_free(source_tmp); return -1; } */ full_path = (char *)__ax_malloc(strlen(source->val) + MAX_FILE_LENGTH + 15); exist = check_exist(source->val, full_path); if (exist < 0) { Status_To_JSON(WFM2_FILE_NO_EXIST); if (full_path) __ax_free(full_path); return -1; } #ifdef ACL //if not iso folder, check permission if (Is_ACL_Enabled() && No_Support_ACL(source_tmp) == 0) { if (!is_iso) { permission= Get_ACL_User_Group_Security_For_Share(remote_user, full_path); if (permission < 5) { Status_To_JSON(WFM2_PERMISSION_DENY); if (full_path) __ax_free(full_path); return -1; } } } #endif if(source_tmp) __ax_free(source_tmp); keyword = CGI_Find_Parameter(input, "keyword"); if (keyword == NULL) { //CGI_Free_Input(source); if (full_path) __ax_free(full_path); return -1; } start = CGI_Find_Parameter(input, "start"); if (start == NULL) { if (full_path) __ax_free(full_path); return -1; } limit = CGI_Find_Parameter(input, "limit"); if (limit == NULL) { if (full_path) __ax_free(full_path); return -1; } _search(full_path, keyword); /* if (keyword!=NULL) CGI_Free_Input(keyword); if (source!=NULL) CGI_Free_Input(source); */ int i; end = atoi(start->val) + atoi(limit->val) - 1; if ((tmp = CGI_Find_Parameter(input, "sort"))) { for (i=0; i<sizeof(sort_func)/sizeof(SORT_FUNC); i++) { if (!strcmp(sort_func[i].sort_mode, tmp->val)) { sort_mode = i; break; } } } if ((tmp = CGI_Find_Parameter(input, "dir"))) sort_type = tmp->val; output_search_to_json(atoi(start->val), end, sort_mode, sort_type, permission); if (full_path) __ax_free(full_path); if (file_list) __ax_free(file_list); file_list = NULL; if(folder_list) __ax_free(folder_list); folder_list = NULL; total_match = 0; total_search = 0; total_file = 0; total_folder = 0; return ret; }
int special_search(INPUT *input) { INPUT *tmp = NULL; char *ptr = NULL, tmp_time[12], *folder = NULL; struct tm *p; time_t timep_begin, timep_end; int i; //SECTION_INFO *shareList=NULL; JSON_FILE_OBJECT *file; struct stat buf; struct passwd *user; struct group *data; tmp = CGI_Find_Parameter(input, "Time_begin"); if (tmp == NULL) return -1; else { ptr = tmp->val; strncpy(tmp_time, ptr, 4); tmp_time[4] = 0x0; p = (struct tm *)__ax_malloc(sizeof(struct tm)); p->tm_year = atoi(tmp_time) - 1900; ptr = ptr + 4; strncpy(tmp_time, ptr, 2); tmp_time[2] = 0x0; p->tm_mon = atoi(tmp_time) - 1; ptr = ptr + 2; strncpy(tmp_time, ptr, 2); tmp_time[2] = 0x0; p->tm_mday = atoi(tmp_time); p->tm_hour = 0; p->tm_min = 0; p->tm_sec = 0; timep_begin = mktime(p); if (p) __ax_free(p); } tmp = CGI_Find_Parameter(input, "Time_end"); if (tmp == NULL) return -1; else { ptr = tmp->val; strncpy(tmp_time, ptr, 4); tmp_time[4] = 0x0; p = (struct tm *)__ax_malloc(sizeof(struct tm)); p->tm_year = atoi(tmp_time) - 1900; ptr = ptr + 4; strncpy(tmp_time, ptr, 2); tmp_time[2] = 0x0; p->tm_mon = atoi(tmp_time) - 1; ptr = ptr + 2; strncpy(tmp_time, ptr, 2); tmp_time[2] = 0x0; p->tm_mday = atoi(tmp_time); p->tm_hour = 0; p->tm_min = 0; p->tm_sec = 0; timep_end = mktime(p); if (p) __ax_free(p); } tmp = CGI_Find_Parameter(input, "Folder_name"); if (tmp == NULL) return -1; else folder = tmp->val; /* Get_NAS_Share_List_V2(&shareList, 0, 0, NULL, &total_share); for (i=0; i<total_share; i++) { sprintf(buffer, "/%s/%s", shareList[i].section_name, folder); full_path = (char *)__ax_malloc(strlen(folder) + MAX_FILE_LENGTH + 15); exist = check_exist(buffer, full_path); if (exist < 0) { //Status_To_JSON(WFM2_FILE_NO_EXIST); //if (full_path) __ax_free(full_path); // return -1; } else _search_by_time(full_path, timep_begin, timep_end); if (full_path) __ax_free(full_path); } */ file = (JSON_FILE_OBJECT *)__ax_malloc( total_file * sizeof(JSON_FILE_OBJECT)); for (i=0;i<total_file;i++) { lstat(file_list[i], &buf); strcpy((file+i)->filename, file_list[i]); (file+i)->isfolder = 0; (file+i)->filesize = (unsigned long long)(buf.st_size); user = getpwuid(buf.st_uid); if (user == NULL) sprintf((file+i)->owner, "%d", buf.st_uid); else strcpy((file+i)->owner, user->pw_name); data = getgrgid(buf.st_gid); if (data == NULL) sprintf((file+i)->group, "%d", buf.st_gid); else strcpy((file+i)->group, data->gr_name); /* { char sDateStr[64]={0}; char sTimeStr[64]={0}; Change_Date_To_String_By_Format(buf.st_mtime, sDateStr, nDate_format); Change_Time_To_String_By_Format(buf.st_mtime, sTimeStr, 0, nTime_format); sprintf((file+i)->mt_str, "%s %s", sDateStr, sTimeStr); } */ sprintf((file+i)->privilege, "%o", (buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO))); } File_List_To_JSON(file, total_file, total_file, 0, 0); if (file) __ax_free(file); //if(shareList != NULL) Release_List(shareList); return 0; }
int op_chunked_upload(INPUT *input) { INPUT *tmp; int exist = 0, overwrite = 0, ret = 0; char *dest_path = "", src_name[256], *upload_id = "", *upload_dir = NULL, size_str[64] = "0"; char *path_tmp = NULL, *full_path, *full_upload_path, *full_src_path, *type, *progress; char *rename_string, *full_rename_path, *upload_name; int euid, egid, pid, multipart = 0; long long offset = 0, filesize = 0, cache_filesize = 0; FILE *fp = NULL; struct stat st_buf; time_t mtime = 0, actime = 0; if( (tmp=CGI_Find_Parameter(input, "dest_path")) ) dest_path = tmp->val; if( (tmp=CGI_Find_Parameter(input, "rename_dest")) ) { rename_string = tmp->val; if(strlen(rename_string) == 0) rename_string = NULL; } if( (tmp=CGI_Find_Parameter(input, "upload_name")) ) { upload_name = tmp->val; if(strlen(upload_name) == 0) upload_name = NULL; } //path_tmp = (char *)__ax_calloc(1, strlen(dest_path) + 1); //strcpy(path_tmp, dest_path); /* if(check_user_read_write_privilege(remote_user, path_tmp) < 0){ if(path_tmp) __ax_free(path_tmp); //Status_With_Size_To_JSON(WFM2_PERMISSION_DENY, size_str); return -1; } */ if( (tmp=CGI_Find_Parameter(input, "overwrite")) ) { overwrite = atoi(tmp->val); } if( (tmp=CGI_Find_Parameter(input, "type")) ) { type = tmp->val; } if( (tmp=CGI_Find_Parameter(input, "offset")) ) { offset = atoll(tmp->val); } if( (tmp=CGI_Find_Parameter(input, "filesize")) ) { filesize = atoll(tmp->val); } if( (tmp=CGI_Find_Parameter(input, "multipart")) ) { multipart = atoll(tmp->val); } if( (tmp=CGI_Find_Parameter(input, "upload_id")) ) { upload_id = tmp->val; } //if(path_tmp) __ax_free(path_tmp); if( (tmp=CGI_Find_Parameter(input, "progress")) ) { progress = (char *)__ax_calloc(1, strlen(tmp->val) + 6); if(strlen(tmp->val) > MAX_FILE_NAME_LENGTH) { // if progress name too long. //_get_progress_time_string(progress); } else { sprintf(progress, "/tmp/%s", tmp->val); } //sprintf(progress, "/tmp/%s", tmp->val); fp=fopen(progress, "w+"); if (fp == NULL) { if (progress) __ax_free(progress); // Status_With_Size_To_JSON(WFM2_FAIL, size_str); return -1; } fclose(fp); // Set_Private_Profile_Integer("", UPLOAD_PID, pid, progress); if (progress) __ax_free(progress); } // Become_ID(remote_user, &euid, &egid); if((tmp=CGI_Find_Parameter(input, "upload_root_dir")) ) { char uppath[1024]; snprintf(uppath, sizeof(uppath), "%s/%s", tmp->val, UPLOAD_CACHE_DIR); upload_dir = (char *)__ax_calloc(1, strlen(uppath) + MAX_FILE_LENGTH + 15); exist = check_exist(uppath, upload_dir); if (exist < 0) { //Status_With_Size_To_JSON(WFM2_FILE_NO_EXIST, size_str); if (upload_dir) __ax_free(upload_dir); return -1; } } // Finish uploading, now rename (move) it to real file and name if((tmp=CGI_Find_Parameter(input, "Filename")) && (upload_id != NULL) ) { char final_dest_path[2048], tmpfile[2048]; // Destination folder path strcpy(final_dest_path, "/tmp/mnt"); strcat(final_dest_path, dest_path); strcat(final_dest_path, "/"); char *file_name = tmp->val; if (file_name[0] == '\\') { file_name++; strcat(final_dest_path, file_name); } else strcat(final_dest_path, file_name); // Original temp file path strcpy(tmpfile, upload_dir); strcat(tmpfile, "/"); strcat(tmpfile, upload_id); ret = rename(tmpfile, final_dest_path) ; if(ret) FCGI_LOG("Fail to move from tmp file %s to %s\n", tmpfile, final_dest_path); } if (upload_dir) __ax_free(upload_dir); return ret; }