/*
* Copyright 2010 NCHOVY
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.krakenapps.malwaredomains.impl;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.krakenapps.api.Script;
import org.krakenapps.api.ScriptArgument;
import org.krakenapps.api.ScriptContext;
import org.krakenapps.api.ScriptUsage;
import org.krakenapps.malwaredomains.MalwareDomain;
import org.krakenapps.malwaredomains.MalwareDomainService;
public class MalwareDomainScript implements Script {
private ScriptContext context;
private MalwareDomainService md;
public MalwareDomainScript(MalwareDomainService md) {
this.md = md;
}
@Override
public void setScriptContext(ScriptContext context) {
this.context = context;
}
@ScriptUsage(description = "check malware domain", arguments = { @ScriptArgument(name = "url", type = "string", description = "url (e.g. http://nchovy.com") })
public void check(String[] args) {
try {
MalwareDomain domain = md.match(new URL(args[0]));
if (domain != null)
context.println(domain.toString());
else
context.println("safe domain");
} catch (MalformedURLException e) {
context.println("invalid url");
}
}
public void reload(String[] args) {
md.reload();
context.println("reloaded all malware domains");
}
public void update(String[] args) {
try {
md.update();
} catch (IOException e) {
context.println("cannot update malware domains: " + e.getMessage());
}
}
public void count(String[] args) {
int count = md.getDomainCount();
context.println(count + " domains");
}
}