Merge remote-tracking branch 'origin/master' into all-workspace-load-metrics

This commit is contained in:
Tim Robinson 2016-10-03 17:49:54 +00:00
commit 1ddffa375d
116 changed files with 2804 additions and 374 deletions

View File

@ -92,3 +92,4 @@ To protect the interests of the Cloud9 contributors and users we require contrib
If you want to contribute to the Cloud9 SDK and/or open source plugins please go to the online form, fill it out and submit it.
Happy coding, Cloud9

140
configs/client-config_test.js Executable file
View File

@ -0,0 +1,140 @@
#!/usr/bin/env node
/*global describe it*/
"use strict";
"use server";
require("amd-loader");
require("c9/inline-mocha")(module);
var assert = require("assert");
var fs = require("fs");
describe("client config consistency", function(){
// this.timeout(60000);
var fileCache = Object.create(null);
var clientOptions;
var root = __dirname + "/../";
it("should get clientOptions from server", function(next) {
fetchClientOptions(function(err, clientOptions) {
assert(!err && clientOptions);
next();
});
});
fs.readdirSync(root + "/configs").forEach(function(name) {
if (!/client-(workspace|ssh|default)/.test(name)) return;
it("should not have missing plugins in config " + name, function(next) {
fetchClientOptions(function(err, clientOptions) {
if (err) return next();
checkConfig(name, clientOptions, next);
});
});
});
function fetchClientOptions(callback) {
if (clientOptions)
return callback(null, JSON.parse(JSON.stringify(clientOptions)));
var server = require(root + "/server.js");
server(["--_getConfig", "-l", "localhost", "--collab=true"], "", function(e, plugins) {
clientOptions = plugins.filter(function(p) {
return /standalone[\\\/]standalone/.test(p.packagePath);
})[0].options;
fetchClientOptions(callback);
});
}
function checkConfig(name, clientOptions, next) {
var hasError = false;
var configPath = root + "/configs/" + name;
var configPathReal = fs.realpathSync(configPath);
var clientPlugins = require(configPath)(clientOptions);
clientPlugins = clientPlugins.map(function(p, i) {
if (typeof p == "string")
return {packagePath: p};
return p;
});
clientPlugins.forEach(function(p) {
if (p.packagePath) {
if (!fileCache[p.packagePath]) {
var filePath;
try {
filePath = require.resolve(p.packagePath);
}
catch (e) {
try {
filePath = require.resolve(p.packagePath.replace(/^plugins\//, ""));
} catch (e) {
// TODO instead of quessing we need a simple way of getting pathmap
if (configPath != configPathReal)
filePath = require.resolve(configPathReal + "/../../node_modules/" + p.packagePath.replace(/^plugins\//, ""));
}
}
if (!filePath.match(/\.js$/))
filePath += ".js";
fileCache[p.packagePath] = fs.readFileSync(filePath, "utf8");
}
var source = fileCache[p.packagePath];
p.provides = getDeps("provides", source);
p.consumes = getDeps("consumes", source);
}
});
var provides = {"auth.bootstrap": 1, "hub": 1};
var paths = {};
clientPlugins.forEach(function(p) {
if (paths[p.packagePath]) {
console.error(name, paths[p.packagePath].packagePath, p.packagePath);
hasError = true;
}
paths[p.packagePath] = p;
p.provides && p.provides.forEach(function(name) {
if (provides[name]) {
// console.warn(name, p.packagePath, provides[name]);
}
provides[name] = p.packagePath;
});
});
var unresolved = [];
clientPlugins.forEach(function(p) {
var missing = (p.consumes || []).filter(function(name) {
return !provides[name];
});
if (missing.length) {
unresolved.push({
packagePath: p.packagePath,
missing: missing
});
}
});
if (unresolved.length) {
// not throwing an error to check all configs
hasError = true;
}
function getDeps(type, source) {
var re = new RegExp(type + /\s*=\s*(\[[^\[\]]*\])/.source);
var m = source.match(re);
if (!m) return [];
m = m[1].replace(/\/\/.*|\/\*[\s\S]*?\*\//g, "")
.replace(/,\s*\]/g, "]")
.replace(/'/g, "\"");
return JSON.parse(m);
}
assert(!unresolved.length, (
"unresolved plugins in /configs/" + name +
JSON.stringify(unresolved, null, 4)
).replace(/^/gm, "\t")
);
next();
}
});

View File

@ -112,7 +112,6 @@ module.exports.makeLocal = function(config, options) {
name: options.user.name,
fullname: options.user.fullname,
email: options.user.email,
pubkey: options.user.pubkey
},
project: {
id: options.project.id,

View File

@ -0,0 +1,45 @@
"use strict";
module.exports = function(options) {
var plugins = require("./client-default")(options);
// TODO: cleanup unneeded plugins?
var includes = [];
var excludes = {};
plugins.forEach(function(p) {
if (p.packagePath && p.packagePath.indexOf("c9.core/settings") >= 0) {
p.settings = "defaults";
p.template = {
user: {},
project: {},
state: {
console: {
"@maximized": true,
type: "pane",
nodes: []
}
}
};
}
else if (p.packagePath == "plugins/c9.ide.console/console") {
p.defaultState = {
type: "pane",
nodes: [{
type: "tab",
editorType: "terminal",
active: "true"
}]
};
}
});
plugins = plugins
.concat(includes)
.filter(function (p) {
return !excludes[p] && !excludes[p.packagePath];
});
return plugins;
};

View File

@ -674,7 +674,6 @@ module.exports = function(options) {
name: options.user.name,
fullname: options.user.fullname,
email: options.user.email,
pubkey: options.user.pubkey,
date_add: options.user.date_add,
active: options.user.active,
c9version: options.user.c9version,

11
configs/terminal.js Normal file
View File

@ -0,0 +1,11 @@
module.exports = function(options, optimist) {
var config = require("./standalone")(options, optimist);
// TODO: cleanup unneeded plugins?
options.client_config = "default-terminal";
return config;
};
if (!module.parent) require("../server")([__filename].concat(process.argv.slice(2)));

View File

@ -3,73 +3,139 @@ set -e
cd `dirname $0`/..
NAME=$1
URL=$2
shift
BRANCH=master
URL=
FORCE=
for i in "$@"; do
case $i in
-d|--debug)
set -x
shift
;;
-b=*|--branch=*)
BRANCH="${i#*=}"
shift
;;
-u=*|--url=*)
URL="${i#*=}"
shift
;;
-f|--force|--hard)
FORCE=1
shift
;;
*)
# unknown option
;;
esac
done
if [ "$NAME" == "" ]; then
echo "add name [url]"
echo "add name [--url=git@github.com:c9/NAME.git] [--branch=master]"
exit 0
fi
if [ "$URL" == "" ]; then
URL=git@github.com:c9/$NAME.git
fi
if [ -d $NAME/.git ]; then
update_one() {
echo adding name=$NAME url=$URL branch=refs/remotes/origin/$BRANCH
if [ "$URL" == "" ]; then
URL=git@github.com:c9/$NAME.git
fi
mkdir -p $NAME
pushd $NAME
if ! [ -d .git ]; then
git init .
git remote add origin "$URL"
fi
OLD_URL=$(git config --get remote.origin.url)
if [ "$OLD_URL" != "$URL" ]; then
echo "folder $NAME exists and points to $OLD_URL"
exit 1
fi
if ! $(git config --get-all remote.origin.fetch | grep -q pull); then
git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/pull/*";
fi
git fetch origin
git remote set-head origin -a
popd
pushd $NAME
HASH=$(git rev-parse --revs-only refs/remotes/origin/$BRANCH)
if [ "$FORCE" == "1" ]; then
echo "hard reset $NAME to $HASH"
git reset $HASH --hard
if $(grep -q dependencies "./package.json"); then
rm -rf node_modules npm-shrinkwrap.json
git reset --hard
npm i
npm shrinkwrap
fi
fi
popd
[ -f ./config.json ] || echo "{}" > ./config.json
node -e '
var name = "'$NAME'";
var url = "'$URL'";
var hash = "'$HASH'".trim();
var fs = require("fs");
function updateJSON(path, fn) {
var text = fs.readFileSync(path, "utf8");
var indent = text.match(/^\s*(?=")/m);
indent = indent && indent[0] || 4;
console.log(indent)
var r = JSON.parse(text);
r = fn(r) || r;
text = JSON.stringify(r, null, indent) + "\n";
fs.writeFileSync(path, text, "utf8");
}
updateJSON("./config.json", function(config) {
var packages = config.packages || (config.packages = {});
config.packages[name] = {
name: name,
hash: hash,
url: url,
};
});
updateJSON("../package.json", function(package) {
var deps = package.dependencies;
console.log(deps[name], hash);
deps[name] = deps[name].replace(/#[a-f\d]*$/i, "#" + hash);
console.log(deps[name], hash);
});
updateJSON("../npm-shrinkwrap.json", function(package) {
var deps = package.dependencies;
deps[name].from = deps[name].from.replace(/#[a-f\d]*$/i, "#" + hash);
deps[name].resolved = deps[name].resolved.replace(/#[a-f\d]*$/i, "#" + hash);
console.log(__dirname)
if (fs.existsSync(name + "/npm-shrinkwrap.json")) {
var shrinkwrap = JSON.parse(fs.readFileSync(name + "/npm-shrinkwrap.json", "utf8"));
deps[name].dependencies = shrinkwrap.dependencies;
}
});
'
rm -rf "../node_modules/$NAME"
ln -s `pwd`/$NAME `pwd`/../node_modules/$NAME
}
if [ "$NAME" == "all" ]; then
for i in $(ls .); do
if [ -d "./$i/.git" ] || [ -f "./$i/package.json" ]; then
NAME=$i
URL=
update_one;
fi;
done
else
mkdir -p $NAME
git clone $URL $NAME
update_one
fi
pushd $NAME
HASH=$(git rev-parse --revs-only refs/remotes/origin/master)
popd
[ -f ./config.json ] || echo "{}" > ./config.json
node -e '
var name = "'$NAME'";
var url = "'$URL'";
var hash = "'$HASH'"
var fs = require("fs");
function updateJSON(path, fn) {
var text = fs.readFileSync(path, "utf8");
var indent = text.match(/^\s*(?=")/m);
indent = indent && indent[0] || 4;
console.log(indent)
var r = JSON.parse(text);
r = fn(r) || r;
text = JSON.stringify(r, null, indent) + "\n";
fs.writeFileSync(path, text, "utf8");
}
updateJSON("./config.json", function(config) {
var packages = config.packages || (config.packages = {});
config.packages[name] = {
name: name,
hash: hash,
url: url,
};
});
updateJSON("../package.json", function(package) {
var deps = package.dependencies;
console.log(deps[name], hash)
deps[name] = deps[name].replace(/#[a-f\d]+$/i, "#" + hash)
console.log(deps[name], hash)
});
updateJSON("../npm-shrinkwrap.json", function(package) {
var deps = package.dependencies;
deps[name].from = deps[name].from.replace(/#[a-f\d]+$/i, "#" + hash);
deps[name].resolved = deps[name].resolved.replace(/#[a-f\d]+$/i, "#" + hash);
});
'
rm -rf "../node_modules/$NAME"
ln -s `pwd`/$NAME `pwd`/../node_modules/$NAME

View File

@ -38,12 +38,12 @@ define(function (require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var ABCHighlightRules = require("./abc_highlight_rules").ABCHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function () {
this.HighlightRules = ABCHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -39,12 +39,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var ActionScriptHighlightRules = require("./actionscript_highlight_rules").ActionScriptHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = ActionScriptHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -34,10 +34,10 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var AdaHighlightRules = require("./ada_highlight_rules").AdaHighlightRules;
var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = AdaHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -43,12 +43,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var ApacheConfHighlightRules = require("./apache_conf_highlight_rules").ApacheConfHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = ApacheConfHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -33,14 +33,13 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var AppleScriptHighlightRules = require("./applescript_highlight_rules").AppleScriptHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = AppleScriptHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -44,6 +44,7 @@ var FoldMode = require("./folding/coffee").FoldMode;
var Mode = function() {
this.HighlightRules = AssemblyX86HighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -38,12 +38,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var AutoHotKeyHighlightRules = require("./autohotkey_highlight_rules").AutoHotKeyHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = AutoHotKeyHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -48,6 +48,7 @@ var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = BatchFileHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -39,6 +39,7 @@ var CoffeeFoldMode = require("./folding/coffee").FoldMode;
var Mode = function() {
this.HighlightRules = CirruHighlightRules;
this.foldingRules = new CoffeeFoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -39,6 +39,7 @@ var MatchingParensOutdent = require("./matching_parens_outdent").MatchingParensO
var Mode = function() {
this.HighlightRules = ClojureHighlightRules;
this.$outdent = new MatchingParensOutdent();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -34,10 +34,10 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var CobolHighlightRules = require("./cobol_highlight_rules").CobolHighlightRules;
var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = CobolHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -41,7 +41,6 @@ var oop = require("../lib/oop");
// defines the parent mode
var HtmlMode = require("./html").Mode;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var HtmlFoldMode = require("./folding/html").FoldMode;
// defines the language specific highlighters and folding rules

1
node_modules/ace/lib/ace/mode/d.js generated vendored
View File

@ -43,6 +43,7 @@ var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = DHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -11,6 +11,7 @@ var Mode = function() {
this.HighlightRules = DotHighlightRules;
this.$outdent = new MatchingBraceOutdent();
this.foldingRules = new DotFoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -34,12 +34,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var DroolsHighlightRules = require("./drools_highlight_rules").DroolsHighlightRules;
var Range = require("../range").Range;
var DroolsFoldMode = require("./folding/drools").FoldMode;
var Mode = function() {
this.HighlightRules = DroolsHighlightRules;
this.foldingRules = new DroolsFoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -34,10 +34,10 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var EiffelHighlightRules = require("./eiffel_highlight_rules").EiffelHighlightRules;
var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = EiffelHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -38,12 +38,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var ElixirHighlightRules = require("./elixir_highlight_rules").ElixirHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/coffee").FoldMode;
var Mode = function() {
this.HighlightRules = ElixirHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -38,12 +38,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var HighlightRules = require("./elm_highlight_rules").ElmHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = HighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -38,12 +38,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var ErlangHighlightRules = require("./erlang_highlight_rules").ErlangHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = ErlangHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -39,12 +39,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var ForthHighlightRules = require("./forth_highlight_rules").ForthHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = ForthHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -41,6 +41,7 @@ var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = FortranHighlightRules;
this.foldingRules = new CStyleFoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -37,6 +37,7 @@ var FtlHighlightRules = require("./ftl_highlight_rules").FtlHighlightRules;
var Mode = function() {
this.HighlightRules = FtlHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -38,6 +38,7 @@ define(function(require, exports, module) {
var Mode = function() {
this.HighlightRules = GcodeHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -36,6 +36,7 @@ var GherkinHighlightRules = require("./gherkin_highlight_rules").GherkinHighligh
var Mode = function() {
this.HighlightRules = GherkinHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -8,6 +8,7 @@ var GitignoreHighlightRules = require("./gitignore_highlight_rules").GitignoreHi
var Mode = function() {
this.HighlightRules = GitignoreHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -8,6 +8,7 @@ var GobstonesHighlightRules = require("./gobstones_highlight_rules").GobstonesHi
var Mode = function() {
JavaScriptMode.call(this);
this.HighlightRules = GobstonesHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, JavaScriptMode);

View File

@ -48,6 +48,7 @@ var FoldMode = require("./folding/coffee").FoldMode;
var Mode = function() {
this.HighlightRules = HamlHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -49,6 +49,7 @@ var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = HaskellHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -47,6 +47,7 @@ var FoldMode = require("./folding/haskell_cabal").FoldMode;
var Mode = function() {
this.HighlightRules = CabalHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -40,6 +40,7 @@ var FoldMode = require("./folding/ini").FoldMode;
var Mode = function() {
this.HighlightRules = IniHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -37,13 +37,13 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var IoHighlightRules = require("./io_highlight_rules").IoHighlightRules;
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = IoHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);
@ -51,7 +51,7 @@ oop.inherits(Mode, TextMode);
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
// Extra logic goes here.
this.$id = "ace/mode/io"
this.$id = "ace/mode/io";
}).call(Mode.prototype);
exports.Mode = Mode;

View File

@ -43,8 +43,8 @@ var FoldMode = require("./folding/coffee").FoldMode;
var Mode = function() {
this.HighlightRules = JadeHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -35,7 +35,6 @@ var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var Range = require("../range").Range;
var WorkerClient = require("../worker/worker_client").WorkerClient;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;

View File

@ -171,6 +171,9 @@ var JavaScriptHighlightRules = function(options) {
token : "punctuation.operator",
regex : /[.](?![.])/,
next : "property"
}, {
token : "storage.type",
regex : /=>/
}, {
token : "keyword.operator",
regex : /--|\+\+|\.{3}|===|==|=|!=|!==|<+=?|>+=?|!|&&|\|\||\?\:|[!$%&*+\-~\/^]=?/,

View File

@ -49,6 +49,7 @@ var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = JuliaHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -5,11 +5,11 @@ var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var LatexHighlightRules = require("./latex_highlight_rules").LatexHighlightRules;
var LatexFoldMode = require("./folding/latex").FoldMode;
var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = LatexHighlightRules;
this.foldingRules = new LatexFoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -34,11 +34,11 @@ var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var LiquidHighlightRules = require("./liquid_highlight_rules").LiquidHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = LiquidHighlightRules;
this.$outdent = new MatchingBraceOutdent();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -42,6 +42,7 @@ var LispHighlightRules = require("./lisp_highlight_rules").LispHighlightRules;
var Mode = function() {
this.HighlightRules = LispHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -42,6 +42,7 @@ var Mode = function() {
this.HighlightRules = LuaHighlightRules;
this.foldingRules = new LuaFoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -7,6 +7,7 @@ var LuceneHighlightRules = require("./lucene_highlight_rules").LuceneHighlightRu
var Mode = function() {
this.HighlightRules = LuceneHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -43,6 +43,7 @@ var FoldMode = require("./folding/coffee").FoldMode;
var Mode = function() {
this.HighlightRules = MakefileHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -49,6 +49,7 @@ var Mode = function() {
});
this.foldingRules = new MarkdownFoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -34,10 +34,10 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var MatlabHighlightRules = require("./matlab_highlight_rules").MatlabHighlightRules;
var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = MatlabHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -40,6 +40,7 @@ var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = MazeHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -40,6 +40,7 @@ var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = MushCodeRules;
this.foldingRules = new PythonFoldMode("\\:");
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -33,10 +33,10 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("../mode/text").Mode;
var MysqlHighlightRules = require("./mysql_highlight_rules").MysqlHighlightRules;
var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = MysqlHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -49,6 +49,7 @@ var Mode = function() {
CMode.call(this);
this.HighlightRules = NixHighlightRules;
this.foldingRules = new CStyleFoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, CMode);

View File

@ -38,12 +38,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var NSISHighlightRules = require("./nsis_highlight_rules").NSISHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = NSISHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -48,6 +48,7 @@ var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = ObjectiveCHighlightRules;
this.foldingRules = new CStyleFoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -39,6 +39,7 @@ var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = OcamlHighlightRules;
this.$behaviour = this.$defaultBehaviour;
this.$outdent = new MatchingBraceOutdent();
};

View File

@ -49,6 +49,7 @@ var FoldMode = require("./folding/coffee").FoldMode;
var Mode = function() {
this.HighlightRules = PascalHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -35,7 +35,6 @@ var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var PerlHighlightRules = require("./perl_highlight_rules").PerlHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var Range = require("../range").Range;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
@ -43,6 +42,7 @@ var Mode = function() {
this.$outdent = new MatchingBraceOutdent();
this.foldingRules = new CStyleFoldMode({start: "^=(begin|item)\\b", end: "^=(cut)\\b"});
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -33,10 +33,10 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("../mode/text").Mode;
var PgsqlHighlightRules = require("./pgsql_highlight_rules").PgsqlHighlightRules;
var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = PgsqlHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);
@ -50,7 +50,7 @@ oop.inherits(Mode, TextMode);
} else {
return this.$getIndent(line); // Keep whatever indent the previous line has
}
}
};
this.$id = "ace/mode/pgsql";
}).call(Mode.prototype);

View File

@ -35,13 +35,13 @@ var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var PraatHighlightRules = require("./praat_highlight_rules").PraatHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var Range = require("../range").Range;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = PraatHighlightRules;
this.$outdent = new MatchingBraceOutdent();
this.foldingRules = new CStyleFoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -43,12 +43,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var PrologHighlightRules = require("./prolog_highlight_rules").PrologHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = PrologHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -37,6 +37,7 @@ var PropertiesHighlightRules = require("./properties_highlight_rules").Propertie
var Mode = function() {
this.HighlightRules = PropertiesHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -40,6 +40,7 @@ var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = PythonHighlightRules;
this.foldingRules = new PythonFoldMode("\\:");
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

5
node_modules/ace/lib/ace/mode/r.js generated vendored
View File

@ -44,12 +44,11 @@ define(function(require, exports, module) {
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var RHighlightRules = require("./r_highlight_rules").RHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var unicode = require("../unicode");
var Mode = function()
{
var Mode = function(){
this.HighlightRules = RHighlightRules;
this.$outdent = new MatchingBraceOutdent();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -40,13 +40,13 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var RDocHighlightRules = require("./rdoc_highlight_rules").RDocHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var Mode = function(suppressHighlighting) {
this.HighlightRules = RDocHighlightRules;
this.$outdent = new MatchingBraceOutdent();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -36,14 +36,14 @@ var TextMode = require("./text").Mode;
var RSTHighlightRules = require("./rst_highlight_rules").RSTHighlightRules;
var Mode = function() {
this.HighlightRules = RSTHighlightRules;
this.HighlightRules = RSTHighlightRules;
};
oop.inherits(Mode, TextMode);
(function() {
this.type = "text";
this.type = "text";
this.$id = "ace/mode/rst";
this.$id = "ace/mode/rst";
}).call(Mode.prototype);
exports.Mode = Mode;

View File

@ -39,12 +39,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var RustHighlightRules = require("./rust_highlight_rules").RustHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = RustHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -39,6 +39,7 @@ var FoldMode = require("./folding/coffee").FoldMode;
var Mode = function() {
this.HighlightRules = SassHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -35,7 +35,6 @@ var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var scadHighlightRules = require("./scad_highlight_rules").scadHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var Range = require("../range").Range;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;

View File

@ -7,7 +7,6 @@ var ScalaHighlightRules = require("./scala_highlight_rules").ScalaHighlightRules
var Mode = function() {
JavaScriptMode.call(this);
this.HighlightRules = ScalaHighlightRules;
};
oop.inherits(Mode, JavaScriptMode);

View File

@ -44,6 +44,7 @@ var MatchingParensOutdent = require("./matching_parens_outdent").MatchingParensO
var Mode = function() {
this.HighlightRules = SchemeHighlightRules;
this.$outdent = new MatchingParensOutdent();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -99,6 +99,7 @@ var FoldMode = require("./folding/coffee").FoldMode;
var Mode = function() {
this.HighlightRules = SnippetGroupHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -11,6 +11,7 @@ var Mode = function() {
// set everything up
this.HighlightRules = SpaceHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);
(function() {

View File

@ -34,10 +34,10 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var SqlHighlightRules = require("./sql_highlight_rules").SqlHighlightRules;
var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = SqlHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -34,12 +34,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var SqlServerHighlightRules = require("./sqlserver_highlight_rules").SqlHighlightRules;
var Range = require("../range").Range;
var SqlServerFoldMode = require("./folding/sqlserver").FoldMode;
var Mode = function() {
this.HighlightRules = SqlServerHighlightRules;
this.foldingRules = new SqlServerFoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -48,6 +48,7 @@ var FoldMode = require("./folding/coffee").FoldMode;
var Mode = function() {
this.HighlightRules = StylusHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -46,6 +46,7 @@ var Mode = function() {
this.HighlightRules = HighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = new CstyleBehaviour();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -42,6 +42,7 @@ var Mode = function() {
this.HighlightRules = TclHighlightRules;
this.$outdent = new MatchingBraceOutdent();
this.foldingRules = new CStyleFoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -50,6 +50,7 @@ var Mode = function(suppressHighlighting) {
else
this.HighlightRules = TexHighlightRules;
this.$outdent = new MatchingBraceOutdent();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -44,7 +44,7 @@ var Mode = function() {
};
(function() {
this.$behaviour = new CstyleBehaviour();
this.$defaultBehaviour = new CstyleBehaviour();
this.tokenRe = new RegExp("^["
+ unicode.packages.L

View File

@ -39,6 +39,7 @@ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutd
var Mode = function() {
this.HighlightRules = TextileHighlightRules;
this.$outdent = new MatchingBraceOutdent();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -44,6 +44,7 @@ var FoldMode = require("./folding/ini").FoldMode;
var Mode = function() {
this.HighlightRules = TomlHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -38,7 +38,7 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var tsMode = require("./typescript").Mode;
var Mode = function() {
var Mode = function() {
tsMode.call(this);
this.$highlightRuleConfig = {jsx: true};
};

View File

@ -46,6 +46,7 @@ var VBScriptHighlightRules = require("./vbscript_highlight_rules").VBScriptHighl
var Mode = function() {
this.HighlightRules = VBScriptHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -38,6 +38,7 @@ var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = VerilogHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -33,10 +33,10 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var VHDLHighlightRules = require("./vhdl_highlight_rules").VHDLHighlightRules;
var Range = require("../range").Range;
var Mode = function() {
this.HighlightRules = VHDLHighlightRules;
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

View File

@ -41,6 +41,7 @@ var Mode = function() {
this.HighlightRules = YamlHighlightRules;
this.$outdent = new MatchingBraceOutdent();
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

15
node_modules/c9/ssh.js generated vendored
View File

@ -16,18 +16,17 @@ function quote(str) {
return "'" + str.replace(/'/g, "'\\''") + "'";
}
function addProxyCommand(args, proxy) {
var m = /^(.+)(?::(\d+))?$/.exec(proxy);
if (!m)
return;
var proxyHost = m[1];
var proxyPort = parseInt(m[2], 10) || 22;
exports.quote = quote;
exports.addProxyCommand = function(args, proxy) {
var m = proxy.split(":");
var proxyHost = m[0];
var proxyPort = parseInt(m[1], 10) || 22;
var proxyCmd = "ProxyCommand=ssh -W %h:%p " + args.map(quote).join(" ");
proxyCmd += " -p " + proxyPort + " " + quote(proxyHost);
args.push(
"-o", proxyCmd
);
}
};
exports.buildArgs = function(prvkeyFile, host, proxy) {
var args = [
@ -45,7 +44,7 @@ exports.buildArgs = function(prvkeyFile, host, proxy) {
];
if (proxy)
addProxyCommand(args, proxy);
exports.addProxyCommand(args, proxy);
if (host) {
host = host.split(":");

47
node_modules/c9/ssh_test.js generated vendored Normal file
View File

@ -0,0 +1,47 @@
"use strict";
"use server";
var assert = require("assert");
var ssh = require("./ssh");
function arrayEqual(a, b) {
assert.equal(a.length, b.length);
for (var i = 0; i < a.length; i++)
assert.equal(a[i], b[i]);
}
module.exports = {
"test quote" : function() {
assert.equal(ssh.quote("a'b'c"), "'a'\\''b'\\''c'");
assert.equal(ssh.quote("abc"), "'abc'");
},
"test buildArgs": function() {
var expectedArgs = [
"-o","PasswordAuthentication=no",
"-o","IdentityFile=/key",
"-o","UserKnownHostsFile=/dev/null",
"-o","StrictHostKeyChecking=no",
"-o","IdentitiesOnly=yes",
"-F","/dev/null","-t","-t",
"-o","BatchMode=yes",
"-o","ConnectTimeout=10",
"-p",22,"foo12@124.255.121.12"
];
var proxyCmd = 'ProxyCommand=ssh -W %h:%p \'-o\' \'PasswordAuthentication=no\' \'-o\' \'IdentityFile=/key\' \'-o\' \'UserKnownHostsFile=/dev/null\' \'-o\' \'StrictHostKeyChecking=no\' \'-o\' \'IdentitiesOnly=yes\' \'-F\' \'/dev/null\' \'-t\' \'-t\' \'-o\' \'BatchMode=yes\' \'-o\' \'ConnectTimeout=10\' -p 22 \'24@100.20.12.12\'';
var args = ssh.buildArgs('/key', "foo12@124.255.121.12");
arrayEqual(args, expectedArgs);
args = ssh.buildArgs('/key', "foo12@124.255.121.12", "24@100.20.12.12");
expectedArgs.splice(expectedArgs.length - 3, 0, "-o", proxyCmd);
arrayEqual(args, expectedArgs);
args = ssh.buildArgs('/key', "foo12@124.255.121.12:1888", "24@100.20.12.12:88788");
expectedArgs[expectedArgs.length - 2] = 1888;
expectedArgs[expectedArgs.length - 4] = expectedArgs[expectedArgs.length - 4].replace(22, 88788);
arrayEqual(args, expectedArgs);
},
};
!module.parent && require("asyncjs").test.testcase(module.exports).exec();

View File

@ -0,0 +1,28 @@
"use strict";
var utils = require("./session/utils");
function decrypt(secret, rawCookie) {
// ensure secret is available or bail
if (!secret) throw new Error('`secret` option required for sessions');
// secret is always an array of secrets
secret = [].concat(secret);
for (var i = 0; i < secret.length; i++) {
var unsignedCookie = utils.parseSignedCookie(rawCookie, secret[i]);
if (unsignedCookie && unsignedCookie !== rawCookie) {
var usedSecret = secret[i];
return {
unsignedCookie: unsignedCookie,
usedSecret: usedSecret
};
}
}
return {};
}
module.exports.decrypt = decrypt;

View File

@ -0,0 +1,39 @@
#!/usr/bin/env node
/*global describe it before after beforeEach afterEach */
"use strict";
"use server";
require("c9/inline-mocha")(module);
require("c9/setup_paths");
var Cookie = require("cookie");
var assert = require("assert");
var ConnectCookie = require("./session/cookie");
var encrypt = require("./encrypt");
var decrypt = require("./decrypt");
describe("decrypt", function() {
it("Should decrypt when secret is a string", function(){
var sessionID = Math.random().toString(36);
var secret = Math.random().toString(36);
var cookieVal = encrypt(sessionID, "connect.sid", new ConnectCookie({}), secret);
var cookie = Cookie.parse(cookieVal);
var val = decrypt.decrypt(secret, cookie["connect.sid"]);
assert.deepEqual(val, { unsignedCookie: sessionID, usedSecret: secret });
});
it("Should decrypt when secret is an array", function(){
var sessionID = Math.random().toString(36);
var secret = [Math.random().toString(36), Math.random().toString(36), Math.random().toString(36)];
var cookieVal = encrypt(sessionID, "connect.sid", new ConnectCookie({}), secret[1]);
var cookie = Cookie.parse(cookieVal);
var val = decrypt.decrypt(secret, cookie["connect.sid"]);
assert.deepEqual(val, { unsignedCookie: sessionID, usedSecret: secret[1] });
});
});

View File

@ -0,0 +1,12 @@
"use strict";
var signature = require("cookie-signature");
function encrypt(sessionID, key, cookie, secret) {
var val = 's:' + signature.sign(sessionID, secret);
val = cookie.serialize(key, val);
return val;
}
module.exports = encrypt;

View File

@ -1,6 +1,5 @@
var Session = require("connect").session;
var Session = require("./session");
var assert = require("assert");
var error = require("http-error");
module.exports = function startup(options, imports, register) {

View File

@ -0,0 +1,338 @@
/**
* MVH 2016 Forked from connect/middleware/session
* - Added support for multiple secrets
* - Remove MemoryStore
*/
/*!
* Connect - session
* Copyright(c) 2010 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
* MIT Licensed
*/
/**
* Module dependencies.
*/
var Session = require('./session/session')
, debug = require('debug')('connect:session')
, Cookie = require('./session/cookie')
, Store = require('./session/store')
, utils = require('./session/utils')
, uid = require('uid2')
, parse = require('url').parse;
var decrypt = require("./decrypt");
var encrypt = require("./encrypt");
var hash = require("./session/hash");
/**
* Expose the middleware.
*/
exports = module.exports = session;
/**
* Expose constructors.
*/
exports.Store = Store;
exports.Cookie = Cookie;
exports.Session = Session;
/**
* Session:
*
* Setup session store with the given `options`.
*
* Session data is _not_ saved in the cookie itself, however
* cookies are used, so we must use the [cookieParser()](cookieParser.html)
* middleware _before_ `session()`.
*
* Examples:
*
* connect()
* .use(connect.cookieParser())
* .use(connect.session({ secret: 'keyboard cat', key: 'sid', cookie: { secure: true }}))
*
* Options:
*
* - `key` cookie name defaulting to `connect.sid`
* - `store` session store instance
* - `secret` session cookie is signed with this secret to prevent tampering
* - `cookie` session cookie settings, defaulting to `{ path: '/', httpOnly: true, maxAge: null }`
* - `proxy` trust the reverse proxy when setting secure cookies (via "x-forwarded-proto")
*
* Cookie option:
*
* By default `cookie.maxAge` is `null`, meaning no "expires" parameter is set
* so the cookie becomes a browser-session cookie. When the user closes the
* browser the cookie (and session) will be removed.
*
* ## req.session
*
* To store or access session data, simply use the request property `req.session`,
* which is (generally) serialized as JSON by the store, so nested objects
* are typically fine. For example below is a user-specific view counter:
*
* connect()
* .use(connect.favicon())
* .use(connect.cookieParser())
* .use(connect.session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
* .use(function(req, res, next){
* var sess = req.session;
* if (sess.views) {
* res.setHeader('Content-Type', 'text/html');
* res.write('<p>views: ' + sess.views + '</p>');
* res.write('<p>expires in: ' + (sess.cookie.maxAge / 1000) + 's</p>');
* res.end();
* sess.views++;
* } else {
* sess.views = 1;
* res.end('welcome to the session demo. refresh!');
* }
* }
* )).listen(3000);
*
* ## Session#regenerate()
*
* To regenerate the session simply invoke the method, once complete
* a new SID and `Session` instance will be initialized at `req.session`.
*
* req.session.regenerate(function(err){
* // will have a new session here
* });
*
* ## Session#destroy()
*
* Destroys the session, removing `req.session`, will be re-generated next request.
*
* req.session.destroy(function(err){
* // cannot access session here
* });
*
* ## Session#reload()
*
* Reloads the session data.
*
* req.session.reload(function(err){
* // session updated
* });
*
* ## Session#save()
*
* Save the session.
*
* req.session.save(function(err){
* // session saved
* });
*
* ## Session#touch()
*
* Updates the `.maxAge` property. Typically this is
* not necessary to call, as the session middleware does this for you.
*
* ## Session#cookie
*
* Each session has a unique cookie object accompany it. This allows
* you to alter the session cookie per visitor. For example we can
* set `req.session.cookie.expires` to `false` to enable the cookie
* to remain for only the duration of the user-agent.
*
* ## Session#maxAge
*
* Alternatively `req.session.cookie.maxAge` will return the time
* remaining in milliseconds, which we may also re-assign a new value
* to adjust the `.expires` property appropriately. The following
* are essentially equivalent
*
* var hour = 3600000;
* req.session.cookie.expires = new Date(Date.now() + hour);
* req.session.cookie.maxAge = hour;
*
* For example when `maxAge` is set to `60000` (one minute), and 30 seconds
* has elapsed it will return `30000` until the current request has completed,
* at which time `req.session.touch()` is called to reset `req.session.maxAge`
* to its original value.
*
* req.session.cookie.maxAge;
* // => 30000
*
* Session Store Implementation:
*
* Every session store _must_ implement the following methods
*
* - `.get(sid, callback)`
* - `.set(sid, session, callback)`
* - `.destroy(sid, callback)`
*
* Recommended methods include, but are not limited to:
*
* - `.length(callback)`
* - `.clear(callback)`
*
* For an example implementation view the [connect-redis](http://github.com/visionmedia/connect-redis) repo.
*
* @param {Object} options
* @return {Function}
* @api public
*/
function session(options){
var options = options || {}
, key = options.key || 'connect.sid'
, store = options.store
, cookie = options.cookie || {}
, trustProxy = options.proxy
, storeReady = true
, rollingSessions = options.rolling || false;
// generates the new session
store.generate = function(req){
req.sessionID = uid(24);
req.session = new Session(req);
req.session.cookie = new Cookie(cookie);
};
store.on('disconnect', function(){ storeReady = false; });
store.on('connect', function(){ storeReady = true; });
return function session(req, res, next) {
// self-awareness
if (req.session) return next();
// Handle connection as if there is no session if
// the store has temporarily disconnected etc
if (!storeReady) return debug('store is disconnected'), next();
// pathname mismatch
var originalPath = parse(req.originalUrl).pathname;
if (0 != originalPath.indexOf(cookie.path || '/')) return next();
// backwards compatibility for signed cookies
// req.secret is passed from the cookie parser middleware
var secret = options.secret || req.secret;
// ensure secret is available or bail
if (!secret) throw new Error('`secret` option required for sessions');
// normalize secret to be an array
secret = [].concat(secret);
var originalHash
, originalId;
// expose store
req.sessionStore = store;
// grab the session cookie value and check the signature
var rawCookie = req.cookies[key];
// get signedCookies for backwards compat with signed cookies
var unsignedCookie = req.signedCookies[key];
var usedSecret;
if (!unsignedCookie && rawCookie) {
var values = decrypt.decrypt(secret, rawCookie);
usedSecret = values.usedSecret;
unsignedCookie = values.unsignedCookie;
}
// set-cookie
res.on('header', function(){
if (!req.session) return;
var cookie = req.session.cookie
, proto = (req.headers['x-forwarded-proto'] || '').split(',')[0].toLowerCase().trim()
, tls = req.connection.encrypted || (trustProxy && 'https' == proto)
, isNew = unsignedCookie != req.sessionID;
// only send secure cookies via https
if (cookie.secure && !tls) return debug('not secured');
var masterSecret = secret[1] || secret[0];
// in case of rolling session, always reset the cookie
if (usedSecret == masterSecret && !rollingSessions) {
// browser-session length cookie
if (null == cookie.expires) {
if (!isNew) return debug('already set browser-session cookie');
// compare hashes and ids
} else if (originalHash == hash.hash(req.session) && originalId == req.session.id) {
return debug('unmodified session');
}
}
var val = encrypt(req.sessionID, key, cookie, masterSecret);
debug('set-cookie %s', val);
res.setHeader('Set-Cookie', val);
});
// proxy end() to commit the session
var end = res.end;
res.end = function(data, encoding){
res.end = end;
if (!req.session) return res.end(data, encoding);
debug('saving');
req.session.resetMaxAge();
req.session.save(function(err){
if (err) console.error(err.stack);
debug('saved');
res.end(data, encoding);
});
};
// generate the session
function generate() {
store.generate(req);
}
// get the sessionID from the cookie
req.sessionID = unsignedCookie;
// generate a session if the browser doesn't send a sessionID
if (!req.sessionID) {
debug('no SID sent, generating session');
generate();
next();
return;
}
// generate the session object
var pause = utils.pause(req);
debug('fetching %s', req.sessionID);
store.get(req.sessionID, function(err, sess){
// proxy to resume() events
var _next = next;
next = function(err){
_next(err);
pause.resume();
};
// error handling
if (err) {
debug('error %j', err);
if ('ENOENT' == err.code) {
generate();
next();
} else {
next(err);
}
// no session
} else if (!sess) {
debug('no session found');
generate();
next();
// populate req.session
} else {
debug('session found');
store.createSession(req, sess);
originalId = req.sessionID;
originalHash = hash.hash(sess);
next();
}
});
};
};

View File

@ -0,0 +1,128 @@
/*!
* Connect - session - Cookie
* Copyright(c) 2010 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
* MIT Licensed
*/
/**
* Module dependencies.
*/
var utils = require('./utils')
, cookie = require('cookie');
/**
* Initialize a new `Cookie` with the given `options`.
*
* @param {IncomingMessage} req
* @param {Object} options
* @api private
*/
var Cookie = module.exports = function Cookie(options) {
this.path = '/';
this.maxAge = null;
this.httpOnly = true;
if (options) utils.merge(this, options);
this.originalMaxAge = undefined == this.originalMaxAge
? this.maxAge
: this.originalMaxAge;
};
/*!
* Prototype.
*/
Cookie.prototype = {
/**
* Set expires `date`.
*
* @param {Date} date
* @api public
*/
set expires(date) {
this._expires = date;
this.originalMaxAge = this.maxAge;
},
/**
* Get expires `date`.
*
* @return {Date}
* @api public
*/
get expires() {
return this._expires;
},
/**
* Set expires via max-age in `ms`.
*
* @param {Number} ms
* @api public
*/
set maxAge(ms) {
this.expires = 'number' == typeof ms
? new Date(Date.now() + ms)
: ms;
},
/**
* Get expires max-age in `ms`.
*
* @return {Number}
* @api public
*/
get maxAge() {
return this.expires instanceof Date
? this.expires.valueOf() - Date.now()
: this.expires;
},
/**
* Return cookie data object.
*
* @return {Object}
* @api private
*/
get data() {
return {
originalMaxAge: this.originalMaxAge
, expires: this._expires
, secure: this.secure
, httpOnly: this.httpOnly
, domain: this.domain
, path: this.path
}
},
/**
* Return a serialized cookie string.
*
* @return {String}
* @api public
*/
serialize: function(name, val){
return cookie.serialize(name, val, this.data);
},
/**
* Return JSON representation of this cookie.
*
* @return {Object}
* @api private
*/
toJSON: function(){
return this.data;
}
};

View File

@ -0,0 +1,18 @@
var crc32 = require('buffer-crc32');
/**
* Hash the given `sess` object omitting changes
* to `.cookie`.
*
* @param {Object} sess
* @return {String}
* @api private
*/
function hash(sess) {
return crc32.signed(JSON.stringify(sess, function(key, val){
if ('cookie' != key) return val;
}));
}
module.exports.hash = hash;

View File

@ -0,0 +1,129 @@
/*!
* Connect - session - MemoryStore
* Copyright(c) 2010 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
* MIT Licensed
*/
/**
* Module dependencies.
*/
var Store = require('./store');
/**
* Initialize a new `MemoryStore`.
*
* @api public
*/
var MemoryStore = module.exports = function MemoryStore() {
this.sessions = {};
};
/**
* Inherit from `Store.prototype`.
*/
MemoryStore.prototype.__proto__ = Store.prototype;
/**
* Attempt to fetch session by the given `sid`.
*
* @param {String} sid
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.get = function(sid, fn){
var self = this;
process.nextTick(function(){
var expires
, sess = self.sessions[sid];
if (sess) {
sess = JSON.parse(sess);
expires = 'string' == typeof sess.cookie.expires
? new Date(sess.cookie.expires)
: sess.cookie.expires;
if (!expires || new Date < expires) {
fn(null, sess);
} else {
self.destroy(sid, fn);
}
} else {
fn();
}
});
};
/**
* Commit the given `sess` object associated with the given `sid`.
*
* @param {String} sid
* @param {Session} sess
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.set = function(sid, sess, fn){
var self = this;
process.nextTick(function(){
self.sessions[sid] = JSON.stringify(sess);
fn && fn();
});
};
/**
* Destroy the session associated with the given `sid`.
*
* @param {String} sid
* @api public
*/
MemoryStore.prototype.destroy = function(sid, fn){
var self = this;
process.nextTick(function(){
delete self.sessions[sid];
fn && fn();
});
};
/**
* Invoke the given callback `fn` with all active sessions.
*
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.all = function(fn){
var arr = []
, keys = Object.keys(this.sessions);
for (var i = 0, len = keys.length; i < len; ++i) {
arr.push(this.sessions[keys[i]]);
}
fn(null, arr);
};
/**
* Clear all sessions.
*
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.clear = function(fn){
this.sessions = {};
fn && fn();
};
/**
* Fetch number of sessions.
*
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.length = function(fn){
fn(null, Object.keys(this.sessions).length);
};

View File

@ -0,0 +1,116 @@
/*!
* Connect - session - Session
* Copyright(c) 2010 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
* MIT Licensed
*/
/**
* Module dependencies.
*/
var utils = require('./utils');
/**
* Create a new `Session` with the given request and `data`.
*
* @param {IncomingRequest} req
* @param {Object} data
* @api private
*/
var Session = module.exports = function Session(req, data) {
Object.defineProperty(this, 'req', { value: req });
Object.defineProperty(this, 'id', { value: req.sessionID });
if ('object' == typeof data) utils.merge(this, data);
};
/**
* Update reset `.cookie.maxAge` to prevent
* the cookie from expiring when the
* session is still active.
*
* @return {Session} for chaining
* @api public
*/
Session.prototype.touch = function(){
return this.resetMaxAge();
};
/**
* Reset `.maxAge` to `.originalMaxAge`.
*
* @return {Session} for chaining
* @api public
*/
Session.prototype.resetMaxAge = function(){
this.cookie.maxAge = this.cookie.originalMaxAge;
return this;
};
/**
* Save the session data with optional callback `fn(err)`.
*
* @param {Function} fn
* @return {Session} for chaining
* @api public
*/
Session.prototype.save = function(fn){
this.req.sessionStore.set(this.id, this, fn || function(){});
return this;
};
/**
* Re-loads the session data _without_ altering
* the maxAge properties. Invokes the callback `fn(err)`,
* after which time if no exception has occurred the
* `req.session` property will be a new `Session` object,
* although representing the same session.
*
* @param {Function} fn
* @return {Session} for chaining
* @api public
*/
Session.prototype.reload = function(fn){
var req = this.req
, store = this.req.sessionStore;
store.get(this.id, function(err, sess){
if (err) return fn(err);
if (!sess) return fn(new Error('failed to load session'));
store.createSession(req, sess);
fn();
});
return this;
};
/**
* Destroy `this` session.
*
* @param {Function} fn
* @return {Session} for chaining
* @api public
*/
Session.prototype.destroy = function(fn){
delete this.req.session;
this.req.sessionStore.destroy(this.id, fn);
return this;
};
/**
* Regenerate this request's session.
*
* @param {Function} fn
* @return {Session} for chaining
* @api public
*/
Session.prototype.regenerate = function(fn){
this.req.sessionStore.regenerate(this.req, fn);
return this;
};

View File

@ -0,0 +1,84 @@
/*!
* Connect - session - Store
* Copyright(c) 2010 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
* MIT Licensed
*/
/**
* Module dependencies.
*/
var EventEmitter = require('events').EventEmitter
, Session = require('./session')
, Cookie = require('./cookie');
/**
* Initialize abstract `Store`.
*
* @api private
*/
var Store = module.exports = function Store(options){};
/**
* Inherit from `EventEmitter.prototype`.
*/
Store.prototype.__proto__ = EventEmitter.prototype;
/**
* Re-generate the given requests's session.
*
* @param {IncomingRequest} req
* @return {Function} fn
* @api public
*/
Store.prototype.regenerate = function(req, fn){
var self = this;
this.destroy(req.sessionID, function(err){
self.generate(req);
fn(err);
});
};
/**
* Load a `Session` instance via the given `sid`
* and invoke the callback `fn(err, sess)`.
*
* @param {String} sid
* @param {Function} fn
* @api public
*/
Store.prototype.load = function(sid, fn){
var self = this;
this.get(sid, function(err, sess){
if (err) return fn(err);
if (!sess) return fn();
var req = { sessionID: sid, sessionStore: self };
sess = self.createSession(req, sess);
fn(null, sess);
});
};
/**
* Create session from JSON `sess` data.
*
* @param {IncomingRequest} req
* @param {Object} sess
* @return {Session}
* @api private
*/
Store.prototype.createSession = function(req, sess){
var expires = sess.cookie.expires
, orig = sess.cookie.originalMaxAge;
sess.cookie = new Cookie(sess.cookie);
if ('string' == typeof expires) sess.cookie.expires = new Date(expires);
sess.cookie.originalMaxAge = orig;
req.session = new Session(req, sess);
return req.session;
};

Some files were not shown because too many files have changed in this diff Show More