added restore feature

This commit is contained in:
SJ 2011-12-13 17:05:22 +01:00
parent b58ff0886b
commit 0ba5bcc778
8 changed files with 33 additions and 11 deletions

3
README
View File

@ -14,6 +14,5 @@ init:
indexer delta1 --rotate
indexer --merge main1 delta1 --rotate
indexer --merge main1 delta1 --rotate --merge-dst-range deleted 0 0

View File

@ -2,7 +2,7 @@
sphinx cronjob:
*/2 * * * * /usr/local/bin/indexer --quiet delta1 --rotate && sleep 2 && /usr/local/bin/indexer --quiet --merge main1 delta1 --rotate
*/2 * * * * /usr/local/bin/indexer --quiet delta1 --rotate && sleep 2 && /usr/local/bin/indexer --quiet --merge main1 delta1 --merge-dst-range deleted 0 0 --rotate
*/5 * * * * /usr/local/bin/indexer --quiet tag1 --rotate

View File

@ -11,13 +11,15 @@ source main
sql_pass = sphinx
sql_query_pre = SET NAMES utf8
sql_query = SELECT id, `from`, `to`, `subject`, `arrived`, `sent`, `body`, `size`, `attachments` FROM sph_index \
sql_query = SELECT id, `from`, `to`, `subject`, `arrived`, `sent`, `body`, `size`, `attachments`, `deleted` FROM sph_index \
WHERE id<=( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 )
sql_attr_uint = size
sql_attr_uint = arrived
sql_attr_uint = sent
sql_attr_uint = attachments
sql_attr_bool = deleted
}
source delta
@ -31,13 +33,14 @@ source delta
sql_query_pre = SET NAMES utf8
sql_query_pre = REPLACE INTO sph_counter SELECT 1, MAX(id) FROM sph_index
sql_query_post_index = DELETE FROM sph_index WHERE id<=(SELECT max_doc_id FROM sph_counter WHERE counter_id=1)
sql_query = SELECT id, `from`, `to`, `subject`, `arrived`, `sent`, `body`, `size`, `attachments` FROM sph_index \
sql_query = SELECT id, `from`, `to`, `subject`, `arrived`, `sent`, `body`, `size`, `attachments`, `deleted` FROM sph_index \
WHERE id <= (SELECT max_doc_id FROM sph_counter WHERE counter_id=1)
sql_attr_uint = size
sql_attr_uint = arrived
sql_attr_uint = sent
sql_attr_uint = attachments
sql_attr_bool = deleted
}

View File

@ -128,7 +128,7 @@ struct _state {
struct session_data {
char ttmpfile[SMALLBUFSIZE], tmpframe[SMALLBUFSIZE], tre;
char ttmpfile[SMALLBUFSIZE], tmpframe[SMALLBUFSIZE], tre, restored_copy;
char mailfrom[SMALLBUFSIZE], rcptto[MAX_RCPT_TO][SMALLBUFSIZE], client_addr[SMALLBUFSIZE];
char acceptbuf[SMALLBUFSIZE];
char whitelist[MAXBUFSIZE], blacklist[MAXBUFSIZE];

View File

@ -82,6 +82,10 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, stru
state->line_num++;
len = strlen(buf);
if(state->is_1st_header == 1 && (strncmp(buf, "Received: by piler", strlen("Received: by piler")) == 0 || strncmp(buf, "X-piler-id: ", strlen("X-piler-id: ")) == 0) ){
sdata->restored_copy = 1;
}
//printf("buf: %s", buf);
if(state->message_rfc822 == 0 && (buf[0] == '\r' || buf[0] == '\n') ){

View File

@ -180,7 +180,11 @@ void handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
if(db_conn == 1){
if(AVIR_VIRUS == sdata.rav){
if(sdata.restored_copy == 1){
syslog(LOG_PRIORITY, "%s: discarding restored copy", sdata.ttmpfile);
inj = OK;
}
else if(AVIR_VIRUS == sdata.rav){
syslog(LOG_PRIORITY, "%s: found virus: %s", sdata.ttmpfile, virusinfo);
counters.c_virus++;
inj = OK;
@ -501,6 +505,7 @@ void initSessionData(struct session_data *sdata){
memset(sdata->whitelist, 0, MAXBUFSIZE);
memset(sdata->blacklist, 0, MAXBUFSIZE);
sdata->restored_copy = 0;
sdata->hdr_len = 0;
sdata->tot_len = 0;

View File

@ -12,6 +12,7 @@
#include <unistd.h>
#include <time.h>
#include <locale.h>
#include <syslog.h>
#include <piler.h>
@ -44,6 +45,9 @@ int main(int argc, char **argv){
return 0;
}
mysql_real_query(&(sdata.mysql), "SET NAMES utf8", strlen("SET NAMES utf8"));
mysql_real_query(&(sdata.mysql), "SET CHARACTER SET utf8", strlen("SET CHARACTER SET utf8"));
printf("locale: %s\n", setlocale(LC_MESSAGES, cfg.locale));
setlocale(LC_CTYPE, cfg.locale);
@ -71,21 +75,27 @@ int main(int argc, char **argv){
//printf("body: *%s*\n", state.b_body);
make_body_digest(&sdata, &cfg);
printf("hdr len: %d\n", sdata.hdr_len);
rule = check_againt_ruleset(data.rules, &state, st.st_size);
//printf("body digest: %s\n", sdata.bodydigest);
printf("body digest: %s\n", sdata.bodydigest);
printf("rules check: %s\n", rule);
mysql_close(&(sdata.mysql));
free_rule(data.rules);
for(i=1; i<=state.n_attachments; i++){
printf("i:%d, name=*%s*, type: *%s*, size: %d, int.name: %s, digest: %s\n", i, state.attachments[i].filename, state.attachments[i].type, state.attachments[i].size, state.attachments[i].internalname, state.attachments[i].digest);
}
printf("\n\n");
mysql_close(&(sdata.mysql));
return 0;
}

View File

@ -32,7 +32,7 @@ create table if not exists `metadata` (
`subject` text(512) default null,
`arrived` int not null,
`sent` int not null,
`deleted` int default 0,
`deleted` tinyint(1) default 0,
`size` int default 0,
`hlen` int default 0,
`attachments` int default 0,
@ -46,6 +46,7 @@ create table if not exists `metadata` (
create index metadata_idx on metadata(`piler_id`);
create index metadata_idx2 on metadata(`message_id`);
create index metadata_idx3 on metadata(`bodydigest`);
create index metadata_idx4 on metadata(`deleted`);
drop table if exists `rcpt`;