github.com/Ne0nd0g/gophish@v0.7.1-0.20190220040016-11493024a07d/static/js/src/app/autocomplete.js (about) 1 var TEMPLATE_TAGS = [{ 2 id: 1, 3 name: 'RId', 4 description: 'The unique ID for the recipient.' 5 }, 6 { 7 id: 2, 8 name: 'FirstName', 9 description: 'The recipient\'s first name.' 10 }, 11 { 12 id: 3, 13 name: 'LastName', 14 description: 'The recipient\'s last name.' 15 }, 16 { 17 id: 4, 18 name: 'Position', 19 description: 'The recipient\'s position.' 20 }, 21 { 22 id: 5, 23 name: 'From', 24 description: 'The address emails are sent from.' 25 }, 26 { 27 id: 6, 28 name: 'TrackingURL', 29 description: 'The URL to track emails being opened.' 30 }, 31 { 32 id: 7, 33 name: 'Tracker', 34 description: 'An HTML tag that adds a hidden tracking image (recommended instead of TrackingURL).' 35 }, 36 { 37 id: 8, 38 name: 'URL', 39 description: 'The URL to your Gophish listener.' 40 }, 41 { 42 id: 9, 43 name: 'BaseURL', 44 description: 'The base URL with the path and rid parameter stripped. Useful for making links to static files.' 45 } 46 ]; 47 48 var textTestCallback = function (range) { 49 if (!range.collapsed) { 50 return null; 51 } 52 53 return CKEDITOR.plugins.textMatch.match(range, matchCallback); 54 } 55 56 var matchCallback = function (text, offset) { 57 var pattern = /\{{2}\.?([A-z]|\})*$/, 58 match = text.slice(0, offset) 59 .match(pattern); 60 61 if (!match) { 62 return null; 63 } 64 65 return { 66 start: match.index, 67 end: offset 68 }; 69 } 70 71 /** 72 * 73 * @param {regex} matchInfo - The matched text object 74 * @param {function} callback - The callback to execute with the matched data 75 */ 76 var dataCallback = function (matchInfo, callback) { 77 var data = TEMPLATE_TAGS.filter(function (item) { 78 var itemName = '{{.' + item.name.toLowerCase() + '}}'; 79 return itemName.indexOf(matchInfo.query.toLowerCase()) == 0; 80 }); 81 82 callback(data); 83 } 84 85 /** 86 * 87 * @param {CKEditor} editor - The CKEditor instance. 88 * 89 * Installs the autocomplete plugin to the CKEditor. 90 */ 91 var setupAutocomplete = function (editor) { 92 editor.on('instanceReady', function (evt) { 93 var itemTemplate = '<li data-id="{id}">' + 94 '<div><strong class="item-title">{name}</strong></div>' + 95 '<div><i>{description}</i></div>' + 96 '</li>', 97 outputTemplate = '[[.{name}]]'; 98 99 var autocomplete = new CKEDITOR.plugins.autocomplete(evt.editor, { 100 textTestCallback: textTestCallback, 101 dataCallback: dataCallback, 102 itemTemplate: itemTemplate, 103 outputTemplate: outputTemplate 104 }); 105 106 // We have to use brackets for the output template tag and 107 // then manually replace them due to the way CKEditor's 108 // templating works. 109 autocomplete.getHtmlToInsert = function (item) { 110 var parsedTemplate = this.outputTemplate.output(item); 111 parsedTemplate = parsedTemplate.replace("[[", "{{").replace("]]", "}}") 112 return parsedTemplate 113 } 114 }); 115 }