English | Italiano
by InRete.com

Caronte Scripting
Introduction -
The language -
Develope a Plug-in -


Structure of the language (Caronte Pcode Language)


In the software Caronte Antispam v2, exists four "enviroment of developement":

  1. ENV ANTISPAM
  2. ENV ADMIN
  3. ENV CRON
  4. ENV WEB

 

Every enviroment of developement ,in "Carontese P.L.", inherits class settings predefined in common with other enviroments, but develops also its own operating characteristics, visible only in that enviroment.

The enviroments at RUN TIME have defined contexts and their initialization is done by creating an instance of environment:

// ENV ANTISPAM
CS_ANTISPAM_SCRIPT this = new CS_ANTISPAM_SCRIPT($_this);

//ENV ADMIN
CS_ADMIN_SCRIPT this = new CS_ADMIN_SCRIPT($_this);

//ENV CRON
CS_CRON_SCRIPT this = new CS_CRON_SCRIPT($_this);

// ENV WEB
CS_WEB_SCRIPT this = new CS_WEB_SCRIPT($_this);

 

The instance of enviroment can be initialized only if the script is ,clearly, inside the context of that enviroment, for a pratical example it is not possible to initialize a WEB script inside the enviroment CS_ANTISPAM_SCRIPT or other enviroment that is outside the WEB context.

Every context of instance is generated automatically from “Core di Caronte Antispam v2”, inserting the relative pointer in the special variable “$_this”.
This , once initialized with the "new" operator, generates the enviroment instance, where it's possible to work , calling the base class functions or the context functions.

Before enter in the heart of programming, is right for us explain the mechanisms that trigger when a script runs, which basically are three stages:

“PRE-COMPILE”. (precompiler before run-time)
Is analyzed the syntax of the source, the ESCAPE sequences, and executed the MACRO functions as:
#ifdef
#ifndef
#else
#endif
#undef
#include
#import

 

“COMPILE STACK”.
Is compiled the source code in Pcode, doing the STACK , analysing the basic instructions as:
if ()  {} else {}
while () {}
do {} while ()
for () {}
continue
break
return
new
delete
sin
asin
cos
acos
tan
atan
log
exp
sqrt
rsq
rcp
fabs
rand
pow
floor

“RUN TIME”
The script is executed, processing the STACK.

In every phase of the mechanism is possible to receive syntax error, compilation error or run time error.
The script in case of errors stops its own work at any phase it is and also the enviroment linked to it stops working raising exceptions.

Every enviroment has event functions "raised" at RUN TIME from Caronte Antispam.
The events change according to the enviroment and are "raised" if exist in source code.

EVENTS in ANTISPAM enviroment

OnStartClientConnection(int [id_connection]);
OnClientTimeOut();
OverWriteCommandError(int [count num error]);
OnAuthenticatedToMTA();
OnReplyMTA(string [command from MTA server]);
OnAllClientData( string [command from client email]);
OnHelo(string [greeting],string [type]);
OnMailFrom(string [mail from]);
OnRcptToError(string [rpct considerato errore]);
OnCommandNOOP();
OnCommandRSET();
OnCommandData(int [buffer length]);
OnAllDataMessage(string [buffer message], int [1 this is the end]);
OnEmailMessagesToAnalyzer();
OnDoneAntispamFilter();
OnDestroyThis();

EVENTS in CRON enviroment

main();

EVENTS in ADMIN enviroment

Main( CAdminRequest, CAdminResponse);

EVENTS in WEB enviroment

html();


Basic instance functions common to all enviroments:

string this->Format(string,...);
void this->Exit();
void this->Print(string,...);
string this->SubStr(string,int,int);
string this->Trim(string);
string this->TrimLeft(string);
string this->TrimRight(string);
string this->TrimInternal(string);
string this->Lc(string);
string this->Uc(string);
string this->Split(string, char, int);
string this->Replace(string,string,string);
int this->StrLen(string);
char this->Chr(int);
in this->Ord(char);
float this->CharToFloat(string)
int this->CharToInt(string);
string this->FloatToChar(float)
string this->IntToChar(int);
in this->FloatToInt(float)
float this->IntToFloat(int)
int this->CompareStringNoCase(string, string);
string this->Encode64(string)
string this->Decode64(string);
string this->MD5(string);
string this->MD5File(string,string,int);
void this->MD5StartStream(void);
void this->MD5UpdateStreamB(pointer,int)
void this->MD5UpdateStream(string)
string this->MD5FinalStream(void);
string this->DecodeHtmlSpecialChar(string);
string this->EncodeHtmlSpecialChar(string);
string this->DeOfuscate(string);
string this->HtmlToText(string);
string this->URLDecode(string);
string this->URLEncode(string);
int this->HextoInt(string);
int this->Time(void);
string this->DateTimeFormat(string,int)
int this->GetTickCount(void)
void this->Sleep(int);
int this->REeq(string,string,int);
string $1();
string $2();
string $3();
string $4();
string $5();

Enviroments ADMIN and CRON, instance functions

void this->WriteLog(int,string,string);
string this->GetConfig(string,string):
int this->GetConfigToArray(class HashArray,string)
void this->SetConfig(string,string,string);
void this->DeleteFromConfig(string,string,string);
void this->WaitForReplaceConfig(void);
void this->SaveConfig(void);

float this->DNSBL_Score(string);
string this->DNSBL_Ns(string);

string this->DNS_Reverse(string);
string this->DNS_Resolve(string);
string this->DNS_MX(string)
string this->DNS_NS(string);
string this->DNS_TXT(string);

void this->SetLevelReBootConfig(int);
void this->SetRebootConfig(int);

string this->GetClientIP(void);
string this->GetClientReverseDns(void);
int this->IsAllowIpAdmin(string);
int this->InsertDomain(string);
CDomainConf this->GetDomain(string);
int this->DeleteDomain(string);
CDB_Ram this->GetDBRamDomains(void);
void this->SaveDomains();
void this->LoadDomainsConfig(void);
void this->AddVarToDomainTemplate(string,string,string);
void this->DeleteVarFromDomainTemplate(string,string);

CDB_Ram this->GetDBRamSpamTrap();
CDB_Ram this->GetDBRamIpInferno();
CDB_Ram this->GetDBRamHelo();
CS_RulesDB this->GetRulesDB();
bool this->SetHeloRefresh();
CS_Bayes  this->GetDBBayes();
int this->ViewGreyListDB(HashArray, int,int,string,int)
int this->ViewALWLDB(HashArray,int,int,string,int);
void this->AddALWL(string,string);
int this->IsALWL(string,string);
void this->LoadALWL();
int this->DCTest(string);
int this->DCRefreshServer();
void this->DCGetServer(HashArray);
void this->ViewPhishingDB(HashArray);
int this->AddDomainPhishing(string);
int this->UpDateDomainPhishing(string,string);
int this->DeleteDomainPhishing(string);
int this->UpDateDBPhishingFromWWW();
void this->LoadDBPhishing();
string this->GetDBPhishingDate()
int this->RunScript(string)

Only ADMIN

int this->AddCronJob(string,string);
int this->DeleteCronJob(string, string);
void this->ViewCronJob(HashArray ,string,int);
int this->PlugInInstall(string,string);
int this->PlugInUninstall(string,string);
void this->GetPlugInInstalled(HashArray );
int this->AddAntispamScript(string,int);
int this->DeleteAntispamScript(string);

class CAdminRequest {

void CAdminRequest();
int GetCmd();
int GetRecordCount();
int GetColCount();
void Reset();
HashArry GetRow();

};

class CAdminResponse {
void CAdminResponse();
int GetRecordCount();
int GetColCount();
void Reset();
void Addnew();
void SetFieldAt(string,int);
void SetFieldBinaryAt(int, pointer,int);
int Send(int,int);

} ;

Only CRON

pointer this->GetPersistentOBJ(string,string);
pointer this->CreatePersistentOBJ(string,string);
void this->DeletePersistentOBJ(string);

WEB

string this->CGI_GET_VAR(string);
string this->CGI_POST_VAR(string);
string this->CGI_COOKIE_VAR(string);
void this->CGI_TO_ARRAY(HashArray ,string);
string this->GETENV(string);
void this->Echo(string);
void this->echo(string);
string this->includeHTML(string,int);
Void this->SetCookie(string,string,int,string,string,int)
Void this->HeaderOption(string);
Void this->HeaderRedirect(string);
Void this->HeaderContentType(string);

void CGI_SESSION_START(string,int);
void CGI_SESSION_DELETE(string);
void CGI_SESSION_VAR(string,string);
void CGI_SESSION_WRITE_VAR(string,string,string);

ANTISPAM

string this->GetClientIP(void);
string this->GetClientReverseDns();
string this->GetMTAIP();
int this->IsIpInferno(string);
void this->AddIpInferno(string,int);
int this->IsIpWhiteList(string);
int this->IsIpMaxSession(string);
void this->RegisterSessionIp();
int this->ConnectToDefaultMTA();
int this->ConnectToMTA(string,string);
string this->GetNameServerMTA();
string this->GetReplaceNameServerMTA();
void this->InjectionExtensionMTA(string);
void this->DropExtensionMTA(string);
int this->IsRelayIp(string);
int this->IsLanIp(string);
int this->ClientIsRelay();
void this->SendToMTA(string);
void this->SendToClient(string);
void this->CloseClientConnection();
void this->CloseMTAConnection();
void this->CloseAllConnection();
void this->DropBufferToMTA();
void this->DropBufferToClient();
void this->CloseClientConnAfterSendingQueue();

void this->AddALWL(string,string);
int this->IsALWL(string,string);
int this->ViewALWLDB(HashArray ,int,int,string,int);

void this->StatisticValue(string,int,int,float,int);

int this->IsForgetHelo(string);

int this->SPFQuery(string,string,string);
string this->SPFResultString(int);

int this->GetErrorCountRFC();
void this->SetErrorCountRFC(int);
int this->IsLocalDomainByRCPT_TO(string);
int this->IsWhiteBlackList(string,string);
int this->IsSpamLover(string,string);

int this->GetSessionProperty();
void this->RegisterSessionProperty();
float this->RecalculatingScoreByUser(float,float,string);

int this->IsSpamTrap(string);
string this->GetSpamTrapResponse();

int this->IsValidKeyDanteCommunity();
void this->DanteCommunityAnnunce(string,string,string);
float this->DanteCommunityQuery(string,string,string);
string this->DanteCommunityGetEnumStringFormScore(float);

Int this->IsWhiteIpGreyList(string);
string this->PrepareTriplesGreyList(string,string,string,string,string);

int this->PassGreyList(string);
int this->GetForgedCountGreyList(string);
void this->ResetForgedCountGreyList(string);
void this->AddToGreyList(string);
int this->ViewGreyListDB(HashArray,int,int,string,int);

int this->BayesianCheck(string);
void this->AddToBayesianQuarantine(string,string,int, CS_ParseMail );
 
int this->IsPhishing(CS_ParseMail)
string this->GetFakePhishingDomain();

string this->GetEmailBody();
string this->GetEmailHeader();
string this->GetEmailSubject();
string this->GetEmailMailFrom();
string this->GetEmailMailTo();
string this->GetEmailMailTo();
string this->GetEmailContentType();
string this->GetEmailRaw();
int this->GetEmailAttachmentCount();
int this->GetEmailLen();
string this->GetEmailAttachmentBuffer(int);
string this->GetEmailAttachmentContentType(int);

float this->RegularExpressionCheck(CS_ParseMail = 0, CS_RulesResult = 0)

pointer this->GetPersistentOBJ(string,string);
pointer this->CreatePersistentOBJ(string,string);
void this->DeletePersistentOBJ(string);

void this->WriteHeaderMessage(string);
void this->ModifyHeaderSubject(string);

pointer this->GetPersistentOBJ(string,string);
pointer this->CreatePersistentOBJ(string,string);
void this->DeletePersistentOBJ(string);

Classes for all enviroments


CLASS HashArray
void HashArray();
void AddValueS(string,string);
void AddValueI(string,int);
void AddValueF(string,float);
string GetS(string);
int GetI(string);
float GetF(string);
int GetLenValue(string);
string GetByIndexS(int);
int GetByIndexI(int);
float GetByIndexF(int);
int GetIndexByKey(string);
string GetKeyByIndex(int);
void Reset();
int GetRecordCount();
void Merge(HashArray)
int KeyExists(string);

CLASS CDB_Ram
void CDB_Ram();
bool Open(string);
bool Load();
int Query(string, HashArray ,int,int);
int Insert(string,string,int);
int Update(string,string);
int Delete(string);
int GetCount();
int Save();
void Reset();
int Close();

CLASS  CS_ParseMail
void CS_ParseMail();
void AddStreaming(string);
string GetBody();
string GetHeader();
string GetSubject();
string GetRawEmail();
string GetMailFrom();
string GetMailTo();
string GetContentTransferEncoding();
string GetCharset();
string GetContentType();
int GetAttachmentCount();
int GetLen();
int Parse();
string GetAttachmentBuffer(int);
string GetAttachmentContentType(int);
string GetAttachmentContentTransferEncoding(int);
string GetAttachmentCharset(int);
int LoadMail(string);
int LoadFromFile(string);

CLASS  CS_BayesWord
void CS_BayesWord();
int Elaborate(CS_ParseMail)

CLASS  CS_Bayes
void CS_Bayes();
void SetMinOccurrences(float);
void PopolateDB(CS_BayesWord,int);
voit RemoveNeutral(int);
int  AddQuarantine(CS_ParseMail,string,string,int,CS_Statistic);
CDB_Ram GetDBRam(string);
int GetWordsCount(string);
int IsSpam(CS_BayesWord, HashArray );
void Load();

CLASS  XMLChild
void XMLChild();
bool AddValue(string,string);
string GetValue(string);
int GetCount();

CLASS  XMLParse
void XMLParse();
int  LoadFile(string,string,string);
void SetMaxChild(int);
void SetStreamingTimeOut(int);
void SetPartSeek(int);
int  GetCountChild();
XMLChild GetChild(int);

CLASS  CaronteServerConn
void CaronteServerConn(string,string,string);
void SetOptions(string,string,string);
int  Connect();
bool IsConnected();
void Disconnect();
void SetTimeOut(int);

CLASS  CaronteRecordSet
void CaronteRecordSet(CaronteServerConn);
void AddNew();
void SetFieldAt(int,string);
void SetFieldBinaryAt(int,pointer,int);
bool Query(int);
void Reset();
HashArray GetRow();
int GetLastError();
int RecordCount();
int ColCount();

CLASS  CDomainConf
void CDomainConf();
void WaitForSession();
void StartSession();
void EndSession();
string GetVar(string);
void SetVar(string,string);
string GetDomainName();
CDB_Ram GetDBRam(string);
void Save();
void Delete();

CLASS  CS_RulesResult
void CS_RulesResult();
int GetRulesCount();
string GetRulesName(int);
string GetRulesRE(int)
float GetRulesScore(int);

CLASS  CS_RulesDB
void CS_RulesDB();
bool Open(string);
bool Load();
bool Save();
int AddRule(string,string,int,float,int);
void ViewRules(HashArray);
string RuleTest(CS_ParseMail,string,int,int,HashArray);
bool DeleteRule(string);
float RegularExpressionCheck(CS:PArseMail,Cs_RulesResult);

CLASS  CNetInfo
void CNetInfo();
int BuildNetInfo(HashArray);

CLASS  CS_Dns
 void CS_Dns();
string DNS_Reverse(string);
string DNS_Resolve(string);
string DNS_MX(string);
string DNS_NS(string),
string DNS_TXT(string);
void AddNameServerDNS(string);
void SetTimeOut(int);

CLASS  CS_Buffer
void CS_Buffer();
void Allocate(int);
int  GetLen();
string ToString();
void Write(string,int);
CS_buffer GetBuffer();
pointer GetPointer();
string GetAt(int);

CLASS  CS_Socket
void CS_Socket(int);
int IsOpen();
void Close();
int ConnectTo(string,string,string);
int Send(string,int,int);
int SendB(pointer,int,int);
int Riceve(CS_Buffer,int);

CLASS  CS_FileSystem
void CS_FileSystem();
int UnLink(string);
int FileExists(string);
int DirExists(string);
int CopyFile(string,string,int);
int ReadDir(string,HashArray);
int FileSize(string);
int Exec(string);
string AppPath();

CLASS  CS_File
void CS_File();
bool Open(string,int);
void WriteB(pointer,int);
void Write(string,int);
int Read(CS_Buffer);
int Seek(int,int);
void Flush();
void Close();

CLASS  CS_MemoryFile
void CS_MemoryFile(int);
void Close();
void Flush();
int Read(CS_Buffer);
void Write(string,int);
void WriteB(pointer,int);
string ToString(),
pointer GetPointer();
int GetLength();

CLASS  CS_Statistic
void CS_Statistic();
void AddItem(string,int,int,float,int);
void Reset();
int Load(string);
int Save();
void PopulatedArray(HashArray);

CLASS  CS_HttpClient
void CS_HttpClient();
int SendRequest(int,string,string);
string GetHeader();
string GetResult();
void SetTimeOut(int);
void SetAgentName(string);
void SetMaxBufferLen(int);
void SetIPAdatper(string);

CLASS  CS_MySqlConn
void CS_MySqlConn();
int Connect(string,string,string,string,int);
void Close();
int State();
void Execute(string);
string GetError();

CLASS  CS_MySqlRecordSet
void CS_MySqlRecordSet();
int Open(string,CS_MySqlConn);
void Close();
int RecordCount();
HashArray FetchRow();

CLASS  CS_FileCfg
void CS_FileCfg();
int Load(string);
bool LoadByString(string);
boll Save(string);
string ReadVar(string,string);
void WriteVar(string,string,string);
int IsKeyExist(string,string);
void DeleteKey(string,string);
int GetConfigToArray(HashArray);

CLASS  CS_Flag
void CS_Flag();
void SetFloat(float);
void SetInt(int);
void SetBool(bool);
void SetString(string);
float GetFloat();
int   GetInt();
bool  GetBool();
string GetString()


Start project 10-10-2003 - Copyright © 2000-2015 C&G Servizi Web s.rl. All rights reserved. VAT N. : 01404430470 .