@@ -26,6 +26,7 @@ public function getRequiredPermissions(string $method): array {
2626 public function getFormFields (): array {
2727 return [
2828 Hashlist::HASHLIST_ID => ["type " => "int " ],
29+ "sourceType " => ['type ' => 'str ' ],
2930 "sourceData " => ['type ' => 'str ' ],
3031 "separator " => ['type ' => 'str ' ],
3132 "overwrite " => ['type ' => 'int ' ],
@@ -47,13 +48,38 @@ public static function getResponse(): array {
4748 /**
4849 * Endpoint to import cracked hashes into a hashlist.
4950 * @throws HTException
51+ * @throws HttpError
5052 */
5153 public function actionPost ($ data ): object |array |null {
5254 $ hashlist = self ::getHashlist ($ data [Hashlist::HASHLIST_ID ]);
5355
54- $ importData = base64_decode ($ data ["sourceData " ]);
56+ // Cast to processZap compatible upload format
57+ $ dummyPost = [];
58+ switch ($ data ["sourceType " ]) {
59+ case "paste " :
60+ $ dummyPost ["hashfield " ] = base64_decode ($ data ["sourceData " ]);
61+ break ;
62+ case "import " :
63+ $ dummyPost ["importfile " ] = $ data ["sourceData " ];
64+ break ;
65+ case "url " :
66+ $ dummyPost ["url " ] = $ data ["sourceData " ];
67+ break ;
68+ default :
69+ // TODO: Choice validation are model based checks
70+ throw new HttpErrorException ("sourceType value ' " . $ data ["sourceType " ] . "' is not supported (choices paste, import, url " );
71+ }
72+
73+ if ($ data ["sourceType " ] == "paste " ) {
74+ if (strlen ($ data ["sourceData " ]) == 0 ) {
75+ throw new HttpError ("sourceType=paste, requires sourceData to be non-empty " );
76+ }
77+ else if ($ dummyPost ["hashfield " ] === false ) {
78+ throw new HttpError ("sourceData not valid base64 encoding " );
79+ }
80+ }
5581
56- $ result = HashlistUtils::processZap ($ hashlist ->getId (), $ data ["separator " ], " paste " , [ " hashfield " => $ importData ] , [], $ this ->getCurrentUser (), (isset ($ data ["overwrite " ]) && intval ($ data ["overwrite " ]) == 1 ) ? true : false );
82+ $ result = HashlistUtils::processZap ($ hashlist ->getId (), $ data ["separator " ], $ data [ " sourceType " ], $ dummyPost , [], $ this ->getCurrentUser (), (isset ($ data ["overwrite " ]) && intval ($ data ["overwrite " ]) == 1 ) ? true : false );
5783
5884 return [
5985 "totalLines " => $ result [0 ],
0 commit comments