ews

package module
v0.0.0-...-9155bf6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

README

ews-proxy

Reverse proxy that allows using an EWS XML client on an OWA endpoint.

Compilation requirements

Despite this being a golang package, there is an autogenerated piece that is written using Python. You must have python 2 installed, and you must have xmlschema 0.9.9 installed. On Windows:

py -2 -m pip install xmlschema==0.9.9

On Linux/OSX:

python2 -m pip install xmlschema==0.9.9

Once that is installed, you should be able to run go generate to generate the needed files.

Compilation

This package requires autogenerated pieces, which can be generated using the 'go generate' command.

go generate
go install

If you are using this package as a library, then you would need to run the following from your application source code directory:

go get
go generate github.com/virtuald/ews-proxy

Documentation

Index

Constants

View Source
const (
	T_BOOL = iota
	T_NUM  = iota
	T_STR  = iota
	T_ENUM = iota
	T_LIST = iota
)

simple type definitions

View Source
const NSMSG = "http://schemas.microsoft.com/exchange/services/2006/messages"
View Source
const NSSOAP = "http://schemas.xmlsoap.org/soap/envelope/"

namespaces

View Source
const NSTYPE = "http://schemas.microsoft.com/exchange/services/2006/types"

Variables

This section is empty.

Functions

func JSON2SOAP

func JSON2SOAP(r io.Reader, op *OpDescriptor, w io.Writer, indent bool) (err error)

JSON2SOAP converts a json message to a SOAP message .. always server -> client .. and we always know what type we're expecting

func SetupOwaRequest

func SetupOwaRequest(translator *TranslationMiddleware, request *http.Request, json []byte, action string, canary string)

Types

type EwsJsonElement

type EwsJsonElement struct {
	JsonName string

	// key is the json type
	Types map[string]*EwsJsonType
	// key is the xml local element name (only used in hooks)
	Elements map[string]*EwsJsonType

	SingleType *EwsJsonType
	IsList     bool

	// used to determine which type should be used
	XmlChoiceHook XmlChoiceFunc
}

EwsJsonElement is used for JSON -> XML conversion

func NewEwsJsonElement

func NewEwsJsonElement(xmlName string, jsonName string, isList bool) *EwsJsonElement

func (*EwsJsonElement) IsCharData

func (e *EwsJsonElement) IsCharData() bool

type EwsJsonType

type EwsJsonType struct {
	Type   *EwsType
	XmlTag xml.Name
	// contains filtered or unexported fields
}

func NewEwsJsonType

func NewEwsJsonType(xmlLocal string, typ *EwsType) *EwsJsonType

func (*EwsJsonType) EmitEnd

func (this *EwsJsonType) EmitEnd(enc *xml.Encoder) error

func (*EwsJsonType) EmitStart

func (this *EwsJsonType) EmitStart(enc *xml.Encoder, attrs []xml.Attr) error

type EwsType

type EwsType struct {
	Name string

	Attributes []element

	// lookup for XML -> JSON
	TypeByElementName map[string]*EwsXmlElement
	JsonDefaults      []EwsXmlJsonDefault

	// lookup for JSON -> XML
	// -> list is for ordering, map is for when type lookup is required
	JsonElementList []*EwsJsonElement
	JsonExtra       []string

	// XML attributes, key is XmlName
	Attrs map[string]*EwsType
	// key is XmlName, value is JsonName
	AttrsNames map[string]string

	AnyAttr    bool
	IsSimple   bool
	SimpleType int
	TextAttr   string
	JsonType   string

	IsList          bool
	JsonListName    string
	JsonListElement *EwsJsonElement // only set if JsonListName/IsList is
	JsonHook        JsonHookFunc    // only set if special function is needed

	EnumValues []string // if this is an eumeration, these are the values

	ListItemTypeStr string   // the type of the listObj
	ListItemType    *EwsType // ListItemTypeStr converted to a type
	// contains filtered or unexported fields
}

func (*EwsType) Initialize

func (v *EwsType) Initialize()

type EwsXmlElement

type EwsXmlElement struct {
	JsonName string
	Type     *EwsType
	IsList   bool
}

EwsXmlElement is used for XML -> JSON conversion

type EwsXmlJsonDefault

type EwsXmlJsonDefault struct {
	JsonName    string
	JsonDefault interface{}
}

type JsonHookFunc

type JsonHookFunc func(*EwsType, *OrderedObject)

type JsonList

type JsonList []interface{}

type JsonObject

type JsonObject map[string]interface{}

only use these for deserialization, need ordered type for serialization

type JsonSoapMessage

type JsonSoapMessage struct {
	Type   string `json:"__type"`
	Header map[string]interface{}
	Body   map[string]interface{}
}

type LoginMiddleware

type LoginMiddleware struct {
	Translator *TranslationMiddleware
	Redirector *proxyutils.RedirectorMiddleware

	// string contains on path; typically /owa/
	CheckPath string

	// used for ews client
	Transport http.RoundTripper

	// disabled if 0
	KeepAlivePeriod time.Duration

	CanaryFinder func(*http.Response) (string, error)
	// contains filtered or unexported fields
}

this middleware needs to be first in the chain

func (*LoginMiddleware) CheckLogin

func (this *LoginMiddleware) CheckLogin(canary string) bool

CheckLogin returns false if login is required, and will invalidate the canary if the server responds that it is invalid

func (*LoginMiddleware) CookieCanaryFinder

func (this *LoginMiddleware) CookieCanaryFinder(response *http.Response) (string, error)

func (*LoginMiddleware) OwaKeepalive

func (this *LoginMiddleware) OwaKeepalive()

func (*LoginMiddleware) RequestModifier

func (this *LoginMiddleware) RequestModifier(request *http.Request, cctx proxyutils.ChainContext) error

func (*LoginMiddleware) ResponseModifier

func (this *LoginMiddleware) ResponseModifier(response *http.Response, cctx proxyutils.ChainContext) error

This processes /owa/ pages and searches for a valid OWA canary in the page cookies. Once the canary has been found, then it redirects to the /close page

type OpDescriptor

type OpDescriptor struct {
	Action   string
	Request  *EwsType
	Response EwsJsonElement

	BodyType    string
	RequestType string
}

func SOAP2JSON

func SOAP2JSON(r io.Reader) (ret []byte, op *OpDescriptor, err error)

SOAP2JSON converts a SOAP message to a json message. This returns a JSON message as a buffer of bytes, and the OpDescriptor that can be used to decode the returned message via Json2Soap .. always client -> server

type OrderedObject

type OrderedObject struct {
	Object json.OrderedObject
	// contains filtered or unexported fields
}

OrderedObject is only used for adding items, because json.OrderedObject is actually a slice

func NewOrderedObject

func NewOrderedObject() *OrderedObject

func (*OrderedObject) Get

func (obj *OrderedObject) Get(key string) (value interface{}, exists bool)

func (*OrderedObject) Set

func (obj *OrderedObject) Set(key string, value interface{}) (exists bool)

Set returns true if item added, false if it already exists

type TranslationMiddleware

type TranslationMiddleware struct {
	// Set to true if you want to see additional logging
	Debug bool

	// default is "/ews/exchange.asmx"
	EwsPath string

	// default is "/owa/service.svc"
	OwaServicePath string

	// OWA Canary value, required for the OWA service to work
	OwaCanary string

	// function pointers controlling various aspects of the transport
	OnEwsLogin            func() // called whenever a login occurs. probably.
	OnEwsSuccess          func() // called whenever a successful EWS transaction occurs
	OnEwsTimeout          func() // called whenever an EWS timeout is detected
	OnEwsTranslationError func(transactionLog *bytes.Buffer)
	// contains filtered or unexported fields
}

TranslationMiddleware implements a reverse proxy that allows EWS clients to talk to an OWA endpoint

func NewTranslationMiddleware

func NewTranslationMiddleware() *TranslationMiddleware

Creates an TranslationMiddleware object with lots of defaults filled in

func (*TranslationMiddleware) RequestModifier

func (this *TranslationMiddleware) RequestModifier(request *http.Request, cctx proxyutils.ChainContext) error

func (*TranslationMiddleware) ResponseModifier

func (this *TranslationMiddleware) ResponseModifier(response *http.Response, cctx proxyutils.ChainContext) error

type XmlChoiceFunc

type XmlChoiceFunc func(*EwsJsonElement, map[string]interface{}) (*EwsJsonType, error)

Directories

Path Synopsis
cmd
ews-proxy command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL