Example #1
0
func scanWatchpoints() error {
	fmt.Printf("[watcher] kicked off scan\n")

	watchpoints, err := dba.GetAllWatchpoints()
	if err != nil {
		return fmt.Errorf("cant get watchpoints from db: %s", err.Error())
	}

	for _, w := range watchpoints {
		unit_paths, err := scanDirRecursive(w.Path)
		if err != nil {
			return fmt.Errorf("error while recursively scanning directories: %s", err.Error())
		}

		new_unit_paths, err := checkForNewUnits(unit_paths)
		if err != nil {
			return fmt.Errorf("error while checking for new units: %s", err)
		}

		for _, u := range new_unit_paths {
			virgin_id, err := utils.GenerateIdString()
			if err != nil {
				return err
			}

			var format string
			switch filepath.Ext(u) {
			case "":
				format = "dir"
			case ".rar":
				format = "archive"
			case ".zip":
				format = "archive"
			default:
				format = "unknown"
			}

			v := dba.VirginUnitDesc{
				VirginUnitId: virgin_id,
				Filepath:     u,
				Hash:         "<hash>",
				Format:       format,
			}

			err = dba.AddVirginUnit(v)
			if err != nil {
				return fmt.Errorf("cant add virgin unit to db: %s", err.Error())
			}
			fmt.Printf("[watcher] added virgin unit: %s\n", u)
		}
	}

	fmt.Printf("[watcher] scan finished\n")

	return nil
}
Example #2
0
func handleAddUnitMsg(msg AddUnitMsg, db *sql.DB) {
	resp_msg := AddUnitRspMsg{}

	new_unit_id, err := utils.GenerateIdString()
	if err != nil {
		fmt.Printf("[handleAddUnitOk] cant generate id string\n")
		resp_msg.success = false
		msg.response_channel <- resp_msg
		return
	}

	ok := addUnitToDb(db, new_unit_id, msg.unit_info)
	if !ok {
		resp_msg.success = false
		msg.response_channel <- resp_msg
		return
	}

	resp_msg.success = true
	resp_msg.unit_id = new_unit_id
	msg.response_channel <- resp_msg
}
Example #3
0
func handleGroupAdd(w http.ResponseWriter, r *http.Request) {
	group_name := r.FormValue("group_name")

	group_id, err := utils.GenerateIdString()
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	err = dba.InsertGroup(group_id, group_name)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	w.Header().Add("Content-Type", "application/json")
	enc := json.NewEncoder(w)
	err = enc.Encode(struct{}{})
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}
}