kopia lustrzana https://github.com/c9/core
commit
75be123fb0
|
@ -0,0 +1,158 @@
|
|||
var join = require("path").join;
|
||||
|
||||
module.exports = function(options) {
|
||||
var config = require("./client-default")(options);
|
||||
return module.exports.makeLocal(config, options);
|
||||
};
|
||||
|
||||
module.exports.makeLocal = function(config, options) {
|
||||
var c9Ws = options.remoteWorkspace; // true when opening c9 workspace as local
|
||||
var root = options.workspaceDir;
|
||||
|
||||
var nodeBin = options.nodeBin || ["node"];
|
||||
var settingDir = options.settingDir || options.installPath;
|
||||
|
||||
if (!c9Ws) {
|
||||
// Local version
|
||||
options.local = true;
|
||||
options.projectName = root.substr(root.lastIndexOf("/") + 1);
|
||||
options.debug = 2;
|
||||
options.env = "local";
|
||||
}
|
||||
|
||||
for (var i = config.length - 1; i >= 0; i--) {
|
||||
// if (config[i].packagePath == "plugins/c9.cli.bridge/bridge")
|
||||
// config[i].port = 55556;
|
||||
if (config[i].packagePath == "plugins/c9.ide.welcome/welcome" && !c9Ws) {
|
||||
config[i].intro =
|
||||
"Welcome to your brand new Cloud9. Use this welcome screen "
|
||||
+ "to tweak the look & feel of the Cloud9 user interface. "
|
||||
+ "If you prefer a more advanced IDE experience, you can choose "
|
||||
+ "to change the layout below. "
|
||||
+ "\n\n"
|
||||
+ "On the right you can find videos and documentation for Cloud9 "
|
||||
+ "IDE. Happy Coding!";
|
||||
}
|
||||
// else if (config[i].packagePath == "plugins/c9.ide.login/login") {
|
||||
// config.splice(i, 1);
|
||||
// }
|
||||
else if (config[i].packagePath == "plugins/c9.ide.run/run" && !c9Ws) {
|
||||
config[i].runnerPath = join(settingDir, "/runners");
|
||||
}
|
||||
else if (config[i].packagePath == "plugins/c9.ide.ui/menus") {
|
||||
config[i].autoInit = false;
|
||||
}
|
||||
else if (config[i].packagePath == "plugins/c9.ide.save/autosave") {
|
||||
config[i].slowChangeTimeout = 500;
|
||||
}
|
||||
else if (config[i].packagePath == "plugins/c9.ide.run.build/build" && !c9Ws) {
|
||||
config[i].builderPath = join(settingDir, "/builders");
|
||||
}
|
||||
else if (config[i].packagePath == "plugins/c9.ide.editors/metadata" && !c9Ws) {
|
||||
config[i].path = join(settingDir, "/metadata");
|
||||
config[i].changeCheckInterval = 2000;
|
||||
}
|
||||
else if (config[i].packagePath == "plugins/c9.ide.feedback/feedback") {
|
||||
config[i].screenshotSupport = false;
|
||||
}
|
||||
// else if (config[i].packagePath == "plugins/c9.ide.feedback/feedback") {
|
||||
// config[i] = {
|
||||
// packagePath : "plugins/c9.ide.help/help",
|
||||
// staticPrefix : options.staticPrefix + "/plugins/c9.ide.help"
|
||||
// };
|
||||
// }
|
||||
|
||||
else if (config[i].packagePath == "plugins/c9.core/c9") {
|
||||
config[i].local = true;
|
||||
}
|
||||
else if (config[i].packagePath == "plugins/c9.ide.clipboard/html5")
|
||||
config[i].packagePath = "plugins/c9.ide.local/clipboard";
|
||||
else if (config[i].packagePath == "plugins/c9.ide.configuration/configure")
|
||||
config[i].pathFromFavorite = true;
|
||||
else if (config[i].packagePath == "plugins/c9.core/settings" && !c9Ws) {
|
||||
// todo: Don't show console when opening a file?
|
||||
// config[i].template = ;
|
||||
config[i].projectConfigPath = join(settingDir, "");
|
||||
config[i].userConfigPath = join(settingDir, "");
|
||||
config[i].stateConfigPath = join(settingDir, "");
|
||||
} else if (config[i].packagePath == "plugins/c9.ide.log/log" && !c9Ws) {
|
||||
config[i].source = "desktop";
|
||||
} else if (config[i].packagePath == "plugins/c9.ide.info/info" && c9Ws) {
|
||||
config[i].packagePath = "plugins/c9.ide.local/info";
|
||||
} else if (config[i].packagePath == "plugins/c9.ide.ui/menus" && c9Ws) {
|
||||
config[i].autoInit = false;
|
||||
} else if (config[i].packagePath == "plugins/c9.ide.tree/tree") {
|
||||
config[i].defaultExpanded = !config.hosted;
|
||||
}
|
||||
}
|
||||
|
||||
// Add local modules
|
||||
var includes = [{
|
||||
packagePath: "plugins/c9.ide.local/local",
|
||||
options: options,
|
||||
}, {
|
||||
packagePath: "plugins/c9.ide.local/windowframe",
|
||||
staticPrefix: options.staticPrefix + "/plugins/c9.ide.local"
|
||||
}, {
|
||||
packagePath: "plugins/c9.ide.local/update",
|
||||
host: options.update && options.update.host || "localhost", // "update.c9.io",
|
||||
port: options.update && options.update.port || "8888", // "443"
|
||||
path: options.update && options.update.path,
|
||||
protocol: options.update && options.update.protocol,
|
||||
installPath: options.correctedInstallPath,
|
||||
bashBin: options.bashBin,
|
||||
nodeBin: nodeBin
|
||||
}, {
|
||||
packagePath: "plugins/c9.ide.local/projectmanager"
|
||||
}, {
|
||||
packagePath: "plugins/c9.ide.local/open"
|
||||
}, {
|
||||
packagePath: "plugins/c9.ide.local/nativemenus"
|
||||
}, !c9Ws && {
|
||||
packagePath: "plugins/c9.ide.local/info",
|
||||
installPath: options.correctedInstallPath,
|
||||
settingDir: settingDir,
|
||||
cookie: options.user.cookie,
|
||||
user: {
|
||||
id: options.user.id,
|
||||
name: options.user.name,
|
||||
fullname: options.user.fullname,
|
||||
email: options.user.email,
|
||||
pubkey: options.user.pubkey
|
||||
},
|
||||
project: {
|
||||
id: options.project.id,
|
||||
name: options.project.name,
|
||||
contents: options.project.contents,
|
||||
descr: options.project.descr
|
||||
}
|
||||
}].filter(Boolean);
|
||||
|
||||
var excludes = c9Ws ? {} : {
|
||||
"plugins/c9.ide.newresource/open": true,
|
||||
"plugins/c9.ide.info/info": true,
|
||||
// "plugins/c9.ide.login/login": true,
|
||||
"plugins/c9.ide.collab/connect": true,
|
||||
"plugins/c9.ide.collab/collab": true,
|
||||
"plugins/c9.ide.collab/collabpanel": true,
|
||||
"plugins/c9.ide.collab/workspace": true,
|
||||
"plugins/c9.ide.collab/util": true,
|
||||
"plugins/c9.ide.collab/ot/document": true,
|
||||
"plugins/c9.ide.collab/cursor_layer": true,
|
||||
"plugins/c9.ide.collab/author_layer": true,
|
||||
"plugins/c9.ide.collab/timeslider/timeslider": true,
|
||||
"plugins/c9.ide.notifications/notifications": true,
|
||||
"plugins/c9.ide.collab/members/members_panel": true,
|
||||
"plugins/c9.ide.collab/share/share": true,
|
||||
"plugins/c9.ide.collab/members/members": true,
|
||||
"plugins/c9.ide.collab/chat/chat": true,
|
||||
"plugins/c9.ide.feedback/nps": true,
|
||||
"plugins/c9.ide.download/download": true
|
||||
};
|
||||
|
||||
config = config.concat(includes).filter(function (p) {
|
||||
return !excludes[p] && !excludes[p.packagePath];
|
||||
});
|
||||
|
||||
return config;
|
||||
};
|
242
local/install.sh
242
local/install.sh
|
@ -1,242 +0,0 @@
|
|||
#!/bin/bash -e
|
||||
set -e
|
||||
has() {
|
||||
type "$1" > /dev/null 2>&1
|
||||
return $?
|
||||
}
|
||||
|
||||
# Redirect stdout ( > ) into a named pipe ( >() ) running "tee"
|
||||
exec > >(tee /tmp/installlog.txt)
|
||||
|
||||
# Without this, only stdout would be captured - i.e. your
|
||||
# log file would not contain any error messages.
|
||||
exec 2>&1
|
||||
|
||||
NODE_VERSION=v0.10.28
|
||||
APPSUPPORT_USER=$HOME/.c9
|
||||
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
RUNTIME=$SCRIPT/..
|
||||
INSTALL_DIR=/tmp/c9-`date '+%s'`
|
||||
ORIGINAL_USER=`basename $HOME`
|
||||
OSX_INSTALLER_PATH=$2
|
||||
|
||||
start() {
|
||||
if [ $# -lt 1 ]; then
|
||||
start base
|
||||
return
|
||||
fi
|
||||
|
||||
# Try to figure out the os and arch for binary fetching
|
||||
local uname="$(uname -a)"
|
||||
local os=
|
||||
local arch="$(uname -m)"
|
||||
case "$uname" in
|
||||
Linux\ *) os=linux ;;
|
||||
Darwin\ *) os=darwin ;;
|
||||
SunOS\ *) os=sunos ;;
|
||||
FreeBSD\ *) os=freebsd ;;
|
||||
esac
|
||||
case "$uname" in
|
||||
*x86_64*) arch=x64 ;;
|
||||
*i*86*) arch=x86 ;;
|
||||
*armv6l*) arch=arm-pi ;;
|
||||
esac
|
||||
|
||||
if [ $os != "linux" ] && [ $os != "darwin" ]; then
|
||||
echo "Unsupported Platform: $os $arch" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $arch != "x64" ] && [ $arch != "x86" ]; then
|
||||
echo "Unsupported Architecture: $os $arch" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $os == "darwin" ]; then
|
||||
APPSUPPORT_USER="$HOME/Library/Application Support/Cloud9"
|
||||
APPTARGET=$OSX_INSTALLER_PATH
|
||||
APPSUPPORT="/Library/Application Support/Cloud9"
|
||||
RUNTIME="${APPTARGET}/Contents/Resources/app.nw"
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
"help" )
|
||||
echo
|
||||
echo "Cloud9 Installer"
|
||||
echo
|
||||
echo "Usage:"
|
||||
echo " install help Show this message"
|
||||
echo " install install [name [name ...]] Download and install a set of packages"
|
||||
echo " install ls List available packages"
|
||||
echo
|
||||
;;
|
||||
|
||||
"ls" )
|
||||
echo "!node - Node.js"
|
||||
echo "!tmux_install - TMUX"
|
||||
echo "!nak - NAK"
|
||||
echo "!vfsextend - VFS extend"
|
||||
echo "!ptyjs - pty.js"
|
||||
echo "!c9cli - C9 CLI"
|
||||
echo "!sc - Sauce Connect"
|
||||
echo "coffee - Coffee Script"
|
||||
echo "less - Less"
|
||||
echo "sass - Sass"
|
||||
echo "typescript - TypeScript"
|
||||
echo "stylus - Stylus"
|
||||
# echo "go - Go"
|
||||
# echo "heroku - Heroku"
|
||||
# echo "rhc - RedHat OpenShift"
|
||||
# echo "gae - Google AppEngine"
|
||||
;;
|
||||
|
||||
"install" )
|
||||
shift
|
||||
|
||||
# make sure dirs are around
|
||||
mkdir -p "$APPSUPPORT/bin"
|
||||
mkdir -p "$APPSUPPORT/node_modules"
|
||||
cd "$APPSUPPORT"
|
||||
|
||||
cp -a "$SCRIPT" "$INSTALL_DIR"
|
||||
|
||||
# install packages
|
||||
while [ $# -ne 0 ]
|
||||
do
|
||||
time eval ${1} $os $arch
|
||||
shift
|
||||
done
|
||||
|
||||
# finalize
|
||||
#pushd $APPSUPPORT/node_modules/.bin
|
||||
#for FILE in $APPSUPPORT/node_modules/.bin/*; do
|
||||
# if [ `uname` == Darwin ]; then
|
||||
# sed -i "" -E s:'#!/usr/bin/env node':"#!$NODE":g $(readlink $FILE)
|
||||
# else
|
||||
# sed -i -E s:'#!/usr/bin/env node':"#!$NODE":g $(readlink $FILE)
|
||||
# fi
|
||||
#done
|
||||
#popd
|
||||
|
||||
VERSION=`cat $RUNTIME/version || echo 1`
|
||||
echo 1 > "$APPSUPPORT/installed"
|
||||
echo $VERSION > "$APPSUPPORT/version"
|
||||
|
||||
# set chown/chmod of application dirs for update
|
||||
echo "Testing existence of APPTARGET (${APPTARGET})"
|
||||
if [ -d "$APPTARGET" ]; then
|
||||
echo "Updating permissions of APPTARGET (${APPTARGET})"
|
||||
chown -R root:admin "$APPTARGET" || chown -R root:staff "$APPTARGET"
|
||||
chmod -R 775 "$APPTARGET"
|
||||
fi
|
||||
|
||||
echo "Testing existence of APPSUPPORT (${APPSUPPORT})"
|
||||
if [ -d "$APPSUPPORT" ]; then
|
||||
echo "Updating permissions of APPSUPPORT (${APPSUPPORT})"
|
||||
chown -R root:admin "$APPSUPPORT" || chown -R root:staff "$APPSUPPORT"
|
||||
chmod -R 775 "$APPSUPPORT"
|
||||
fi
|
||||
|
||||
echo "Testing existence of APPSUPPORT_USER (${APPSUPPORT_USER})"
|
||||
if [ -n "$ORIGINAL_USER" ] && [ -d "$APPSUPPORT_USER" ]; then
|
||||
echo "Updating permissions of APPSUPPORT_USER (${APPSUPPORT_USER})"
|
||||
chown -R $ORIGINAL_USER "$APPSUPPORT_USER"
|
||||
fi
|
||||
|
||||
rm -Rf $INSTALL_DIR
|
||||
|
||||
echo :Done.
|
||||
;;
|
||||
|
||||
"base" )
|
||||
echo "Installing base packages. Use '`basename $0` help' for more options"
|
||||
start install node tmux_install nak ptyjs sc vfsextend c9cli
|
||||
;;
|
||||
|
||||
* )
|
||||
start base
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# NodeJS
|
||||
|
||||
node(){
|
||||
# clean up
|
||||
rm -rf node
|
||||
rm -rf node-$NODE_VERSION*
|
||||
|
||||
echo :Installing Node $NODE_VERSION
|
||||
|
||||
cd "$INSTALL_DIR"
|
||||
tar xvfz node-$NODE_VERSION-$1-$2.tar.gz
|
||||
rm -Rf "$APPSUPPORT/node"
|
||||
mv node-$NODE_VERSION-$1-$2 "$APPSUPPORT/node"
|
||||
}
|
||||
|
||||
tmux_install(){
|
||||
echo :Installing TMUX
|
||||
mkdir -p "$APPSUPPORT/bin"
|
||||
|
||||
if [ $os = "darwin" ]; then
|
||||
cd "$INSTALL_DIR"
|
||||
python rudix.py -i libevent-2.0.21-0.pkg
|
||||
python rudix.py -i tmux-1.9-0.pkg
|
||||
|
||||
if ! type "/usr/local/bin/tmux"; then
|
||||
echo "Installation Failed"
|
||||
exit 100
|
||||
fi
|
||||
|
||||
ln -sf "/usr/local/bin/tmux" "$APPSUPPORT/bin/tmux"
|
||||
# Linux
|
||||
else
|
||||
echo "Unsupported"
|
||||
fi
|
||||
}
|
||||
|
||||
vfsextend(){
|
||||
echo :Installing VFS extend
|
||||
cd "$INSTALL_DIR"
|
||||
tar xvfz c9-vfs-extend.tar.gz
|
||||
rm -Rf "$APPSUPPORT/c9-vfs-extend"
|
||||
mv c9-vfs-extend "$APPSUPPORT"
|
||||
}
|
||||
|
||||
sc(){
|
||||
echo :Installing Sauce Connect
|
||||
cd "$INSTALL_DIR"
|
||||
tar xvzf sc-4.0-latest.tar.gz
|
||||
rm -rf "$APPSUPPORT/sc"
|
||||
mv sc-4.0-latest "$APPSUPPORT/sc"
|
||||
}
|
||||
|
||||
nak(){
|
||||
echo :Installing Nak
|
||||
cd "$INSTALL_DIR"
|
||||
tar -zxvf nak.tar.gz
|
||||
mkdir -p "$APPSUPPORT/node_modules/.bin"
|
||||
rm -Rf "$APPSUPPORT/node_modules/nak"
|
||||
mv nak "$APPSUPPORT/node_modules"
|
||||
ln -s "$APPSUPPORT/node_modules/nak/bin/nak" "$APPSUPPORT/node_modules/.bin/nak" &2> /dev/null
|
||||
}
|
||||
|
||||
ptyjs(){
|
||||
echo :Installing pty.js
|
||||
cd "$INSTALL_DIR"
|
||||
tar -zxvf pty-$NODE_VERSION-$1-$2.tar.gz
|
||||
mkdir -p "$APPSUPPORT/node_modules"
|
||||
rm -Rf "$APPSUPPORT/node_modules/pty.js"
|
||||
mv pty.js "$APPSUPPORT/node_modules"
|
||||
}
|
||||
|
||||
c9cli(){
|
||||
if [ -d "/usr/local/bin/" ]; then
|
||||
chmod +x "$RUNTIME/bin/c9"
|
||||
ln -s -f "$RUNTIME/bin/c9" /usr/local/bin/c9
|
||||
else
|
||||
echo "unable to add c9cli to the path"
|
||||
fi
|
||||
}
|
||||
|
||||
start $@
|
48
package.json
48
package.json
|
@ -47,31 +47,31 @@
|
|||
},
|
||||
"licenses": [],
|
||||
"c9plugins": {
|
||||
"c9.ide.language": "#9f588f9152",
|
||||
"c9.ide.language.css": "#89deece6c0",
|
||||
"c9.ide.language.generic": "#50161ba888",
|
||||
"c9.ide.language.html": "#e393db66ae",
|
||||
"c9.ide.language.html.diff": "#31965d98b3",
|
||||
"c9.ide.language.javascript": "#5b6237f875",
|
||||
"c9.ide.language.javascript.immediate": "#0f7c640825",
|
||||
"c9.ide.language.javascript.eslint": "#8fbaa9cc96",
|
||||
"c9.ide.language.javascript.tern": "#3d678a103a",
|
||||
"c9.ide.language.javascript.infer": "#1ae097af44",
|
||||
"c9.ide.language.jsonalyzer": "#45a20496be",
|
||||
"c9.ide.language": "#854575579b",
|
||||
"c9.ide.language.css": "#afda1f867c",
|
||||
"c9.ide.language.generic": "#87a4a44671",
|
||||
"c9.ide.language.html": "#fa4833e117",
|
||||
"c9.ide.language.html.diff": "#a7311cfc9f",
|
||||
"c9.ide.language.javascript": "#26cf518b28",
|
||||
"c9.ide.language.javascript.immediate": "#9a2cce9121",
|
||||
"c9.ide.language.javascript.eslint": "#1baacc275b",
|
||||
"c9.ide.language.javascript.tern": "#a65ad88dd9",
|
||||
"c9.ide.language.javascript.infer": "#ebb2daf81a",
|
||||
"c9.ide.language.jsonalyzer": "#c5dfe5fb7e",
|
||||
"c9.ide.collab": "#116fe74942",
|
||||
"c9.ide.local": "#d5c324ee5b",
|
||||
"c9.ide.find": "#be3bca94b7",
|
||||
"c9.ide.find.infiles": "#462928475c",
|
||||
"c9.ide.find.replace": "#fe41fa768d",
|
||||
"c9.ide.run.debug": "#9a05fadc55",
|
||||
"c9.ide.local": "#2bfd7ff051",
|
||||
"c9.ide.find": "#989c06e6a7",
|
||||
"c9.ide.find.infiles": "#f98dfef554",
|
||||
"c9.ide.find.replace": "#e4daf722b8",
|
||||
"c9.ide.run.debug": "#f5d664c787",
|
||||
"c9.ide.ace.emmet": "#e5f1a92ac3",
|
||||
"c9.ide.ace.gotoline": "#4d1a93172c",
|
||||
"c9.ide.ace.keymaps": "#422e83553b",
|
||||
"c9.ide.ace.repl": "#26bca9ee17",
|
||||
"c9.ide.ace.keymaps": "#6c4bb65b1f",
|
||||
"c9.ide.ace.repl": "#ada99852fa",
|
||||
"c9.ide.ace.split": "#0ae0151c78",
|
||||
"c9.ide.ace.statusbar": "#d7b45bb7c3",
|
||||
"c9.ide.ace.stripws": "#34426a03d1",
|
||||
"c9.ide.behaviors": "#f5aaf10aff",
|
||||
"c9.ide.behaviors": "#6aad7006a0",
|
||||
"c9.ide.closeconfirmation": "#a28bfd8272",
|
||||
"c9.ide.configuration": "#b8470f4107",
|
||||
"c9.ide.dialog.wizard": "#a588b64050",
|
||||
|
@ -81,21 +81,21 @@
|
|||
"c9.ide.imgeditor": "#08bbc53578",
|
||||
"c9.ide.immediate": "#e9ba147cc2",
|
||||
"c9.ide.installer": "#24e7d6f399",
|
||||
"c9.ide.mount": "#c9d598b254",
|
||||
"c9.ide.navigate": "#7985b5a50b",
|
||||
"c9.ide.mount": "#32e79866ee",
|
||||
"c9.ide.navigate": "#64156c7f4a",
|
||||
"c9.ide.newresource": "#9a7464cc47",
|
||||
"c9.ide.openfiles": "#28a4f5af16",
|
||||
"c9.ide.preview": "#3c4dded23f",
|
||||
"c9.ide.preview.browser": "#be197b0464",
|
||||
"c9.ide.preview.markdown": "#bf952685f6",
|
||||
"c9.ide.pubsub": "#7dd0a37571",
|
||||
"c9.ide.pubsub": "#92ec19ed3a",
|
||||
"c9.ide.readonly": "#f6f07bbe42",
|
||||
"c9.ide.recentfiles": "#7c099abf40",
|
||||
"c9.ide.remote": "#37773d905b",
|
||||
"c9.ide.run": "#0a8cc7f0a9",
|
||||
"c9.ide.run.build": "#6726030127",
|
||||
"c9.ide.run.build": "#915e48b363",
|
||||
"c9.ide.save": "#a32a8f4346",
|
||||
"c9.ide.terminal.monitor": "#8e025b3ae1",
|
||||
"c9.ide.terminal.monitor": "#df9936daa2",
|
||||
"c9.ide.theme.flat": "#5c7c27ab74",
|
||||
"c9.ide.threewaymerge": "#229382aa0b",
|
||||
"c9.ide.undo": "#b028bcb4d5",
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
.c9-menu-btn.titlebar{
|
||||
position: absolute;
|
||||
z-index: 100000000;
|
||||
right: 24px;
|
||||
top: 1px;
|
||||
height: 19px;
|
||||
}
|
||||
|
||||
.c9-menu-btn.titlebar:not(.c9-menu-btnDown){
|
||||
height: 18px;
|
||||
border-bottom: 1px solid black;
|
||||
}
|
||||
|
||||
.fullscreen>.btnName{
|
||||
display: none;
|
||||
}
|
||||
|
||||
.btnName.c9-menu-btnIcon{
|
||||
text-indent: -2000px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.btnName{
|
||||
padding: @menu-name-button-padding;
|
||||
margin-left: @menu-name-button-diff !important;
|
||||
}
|
||||
.btnName.c9-menu-btnmenuDown{
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
.btnName .icon{
|
||||
background-size: @menu-name-button-icon-width @menu-name-button-icon-height !important;
|
||||
top: @menu-name-button-icon-top !important;
|
||||
left: @menu-name-button-icon-left !important;
|
||||
width: @menu-name-button-icon-width;
|
||||
height: @menu-name-button-icon-height;
|
||||
border-radius: @menu-name-button-icon-border-radius;
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
define(function(require, exports, module) {
|
||||
main.consumes = [
|
||||
"Plugin", "ui", "menus", "info", "layout", "http", "util",
|
||||
"vfs.endpoint", "auth", "dialog.alert", "c9"
|
||||
];
|
||||
main.provides = ["login"];
|
||||
return main;
|
||||
|
||||
function main(options, imports, register) {
|
||||
var Plugin = imports.Plugin;
|
||||
var ui = imports.ui;
|
||||
var c9 = imports.c9;
|
||||
var menus = imports.menus;
|
||||
var layout = imports.layout;
|
||||
var http = imports.http;
|
||||
var util = imports.util;
|
||||
var info = imports.info;
|
||||
var auth = imports.auth;
|
||||
var alert = imports["dialog.alert"].show;
|
||||
|
||||
var vfsEndpoint = imports["vfs.endpoint"];
|
||||
|
||||
/***** Initialization *****/
|
||||
|
||||
var ideBaseUrl = options.ideBaseUrl;
|
||||
var dashboardUrl = options.dashboardUrl;
|
||||
var accountUrl = options.accountUrl;
|
||||
var lastUser, mnuUser;
|
||||
|
||||
var plugin = new Plugin("Ajax.org", main.consumes);
|
||||
var emit = plugin.getEmitter();
|
||||
|
||||
var loaded = false;
|
||||
function load() {
|
||||
if (loaded) return false;
|
||||
loaded = true;
|
||||
|
||||
info.getUser(function(err, user) {
|
||||
updateButton({user: user});
|
||||
});
|
||||
|
||||
auth.on("relogin", onReLogin);
|
||||
}
|
||||
|
||||
/***** Methods *****/
|
||||
|
||||
function updateButton(e) {
|
||||
var user = e.user;
|
||||
if (lastUser && lastUser.id == user.id)
|
||||
return;
|
||||
plugin.cleanUp();
|
||||
info.on("change", updateButton, plugin);
|
||||
createButton(user);
|
||||
lastUser = user;
|
||||
|
||||
emit.sticky("ready", { name: user.fullname, id: user.id }, plugin);
|
||||
}
|
||||
|
||||
function createButton(user) {
|
||||
var name = "user_" + user.id;
|
||||
|
||||
// todo cleanup seems to not work well
|
||||
// without this menu is empty after logging out and back in
|
||||
if (lastUser)
|
||||
menus.remove("user_" + lastUser.id);
|
||||
menus.remove(name);
|
||||
|
||||
var parent = layout.findParent(plugin);
|
||||
|
||||
// Insert CSS
|
||||
ui.insertCss(require("text!./login.css"), plugin);
|
||||
|
||||
// Create Menu
|
||||
mnuUser = new ui.menu();
|
||||
plugin.addElement(mnuUser);
|
||||
|
||||
// Add named button
|
||||
var icon = util.getGravatarUrl(user.email, 32, "");
|
||||
menus.addItemByPath(name + "/", mnuUser, 110000, plugin);
|
||||
|
||||
// Add Divider
|
||||
ui.insertByIndex(parent, new ui.divider({
|
||||
skin: "c9-divider-double",
|
||||
"class" : "extrasdivider"
|
||||
}), 870, plugin);
|
||||
|
||||
// Add sub menu items
|
||||
var c = 500;
|
||||
menus.addItemByPath(name + "/Dashboard", new ui.item({
|
||||
onclick: function() { window.open(dashboardUrl); }
|
||||
}), c += 100, plugin);
|
||||
menus.addItemByPath(name + "/Account", new ui.item({
|
||||
onclick: function() { window.open(accountUrl); }
|
||||
}), c += 100, plugin);
|
||||
menus.addItemByPath(name + "/Home", new ui.item({
|
||||
onclick: function() { window.open(ideBaseUrl); }
|
||||
}), c += 100, plugin);
|
||||
|
||||
if (!options.noLogout) {
|
||||
menus.addItemByPath(name + "/~", new ui.divider(), c += 100, plugin);
|
||||
menus.addItemByPath(name + "/Log out", new ui.item({
|
||||
onclick: function() {
|
||||
if (!c9.local)
|
||||
return signout();
|
||||
auth.logout(function() {
|
||||
info.login(true);
|
||||
});
|
||||
}
|
||||
}), c += 100, plugin);
|
||||
}
|
||||
|
||||
var button = menus.get(name).item;
|
||||
button.setAttribute("class", "btnName");
|
||||
button.setAttribute("icon", icon);
|
||||
button.setAttribute("iconsize", "16px 16px");
|
||||
button.setAttribute("tooltip", user.fullname);
|
||||
button.setAttribute("caption", user.fullname);
|
||||
ui.insertByIndex(parent, button, 600, plugin);
|
||||
|
||||
if (c9.local) {
|
||||
function minimize(){
|
||||
apf.document.documentElement.appendChild(button);
|
||||
ui.setStyleClass(button.$ext, "titlebar");
|
||||
}
|
||||
function restore(){
|
||||
ui.insertByIndex(parent, button, 870, plugin);
|
||||
ui.setStyleClass(button.$ext, "", ["titlebar"]);
|
||||
}
|
||||
|
||||
menus.on("minimize", minimize, plugin);
|
||||
menus.on("restore", restore, plugin);
|
||||
|
||||
if (menus.minimized)
|
||||
minimize();
|
||||
}
|
||||
}
|
||||
|
||||
function signout() {
|
||||
vfsEndpoint.clearCache();
|
||||
auth.logout(function() { location.href = ideBaseUrl; });
|
||||
}
|
||||
|
||||
function onReLogin() {
|
||||
if (!c9.local) {
|
||||
alert("Logged out",
|
||||
"You have been logged in as a different user",
|
||||
"Please hit OK to reload the IDE.",
|
||||
function() {
|
||||
vfsEndpoint.clearCache();
|
||||
auth.logout(function() {
|
||||
document.location.reload();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/***** Lifecycle *****/
|
||||
|
||||
plugin.on("load", function() {
|
||||
load();
|
||||
});
|
||||
plugin.on("enable", function() {
|
||||
|
||||
});
|
||||
plugin.on("disable", function() {
|
||||
|
||||
});
|
||||
plugin.on("unload", function() {
|
||||
loaded = false;
|
||||
});
|
||||
|
||||
/***** Register and define API *****/
|
||||
|
||||
/**
|
||||
*
|
||||
**/
|
||||
plugin.freezePublicAPI({
|
||||
get menu(){ return mnuUser; },
|
||||
|
||||
_events: [
|
||||
/**
|
||||
* @event ready
|
||||
*/
|
||||
"ready"
|
||||
],
|
||||
createButton: createButton,
|
||||
updateButton: updateButton
|
||||
});
|
||||
|
||||
register(null, {
|
||||
login: plugin
|
||||
});
|
||||
}
|
||||
});
|
|
@ -1,123 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
var assert = require("assert");
|
||||
var url = require("url");
|
||||
var Cloud9LegayStrategy = require("./legacy_strategy");
|
||||
var cookieSignature = require("cookie-signature");
|
||||
var decrypt = require("c9/crypt").decrypt;
|
||||
var login = require("connect-ensure-login");
|
||||
|
||||
plugin.consumes = [
|
||||
"db",
|
||||
"passport",
|
||||
"connect.redirect",
|
||||
"connect.cookieparser",
|
||||
"session-store"
|
||||
];
|
||||
plugin.provides = ["c9.login"];
|
||||
|
||||
module.exports = plugin;
|
||||
|
||||
function plugin(options, imports, register) {
|
||||
assert(options.appId, "Option 'appId' is required");
|
||||
assert(options.ideBaseUrl, "Option 'ideBaseUrl' is required");
|
||||
assert(options.baseUrl, "Option 'baseUrl' is required");
|
||||
assert(options.ssoCookie, "Option 'ssoCookie' is required");
|
||||
assert(options.ssoSecret, "Option 'ssoSecret' is required");
|
||||
|
||||
var db = imports.db;
|
||||
var passport = imports.passport;
|
||||
var sessionStore = imports["session-store"];
|
||||
|
||||
// use the 'proxy' cookie to have federated logout
|
||||
passport.useStart(function(req, res, next) {
|
||||
var hash;
|
||||
// anonymous login
|
||||
if (!req.cookies || !(hash = req.cookies[options.ssoCookie]))
|
||||
return done();
|
||||
|
||||
var encrypted = cookieSignature.unsign(hash, options.ssoSecret);
|
||||
if (!encrypted)
|
||||
return done();
|
||||
|
||||
var sessionId = decrypt(encrypted, options.ssoSecret);
|
||||
|
||||
sessionStore.get(sessionId, function(err, session) {
|
||||
if (err) return done(err);
|
||||
done(null, session && session.uid);
|
||||
});
|
||||
|
||||
function done(err, ssoUid) {
|
||||
if (err) return next(err);
|
||||
ssoUid = ssoUid || -1;
|
||||
var session = req.session;
|
||||
if (session && session.passport && session.passport.user && session.passport.user != ssoUid) {
|
||||
return req.session.regenerate(function(err) {
|
||||
if (err) return next(err);
|
||||
|
||||
if (session.returnTo)
|
||||
req.session.returnTo = session.returnTo;
|
||||
|
||||
delete req.user;
|
||||
next();
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (!req.session.passport)
|
||||
req.session.passport = {};
|
||||
|
||||
req.session.passport.user = ssoUid;
|
||||
next();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var cloud9Strategy = new Cloud9LegayStrategy({
|
||||
clientID: options.appId,
|
||||
ideBaseUrl: options.ideBaseUrl,
|
||||
callback: options.baseUrl + "/auth/c9l/callback",
|
||||
db: db
|
||||
});
|
||||
|
||||
passport.use(cloud9Strategy);
|
||||
|
||||
passport.section.get("/c9l", passport.authenticate("c9l"));
|
||||
passport.section.get("/c9l/callback", [
|
||||
passport.authenticate("c9l"),
|
||||
function(req, res, next) {
|
||||
var user = req.user;
|
||||
|
||||
if (user) {
|
||||
req.login(user, function(err) {
|
||||
if (err) return next(err);
|
||||
res.returnTo(req, "/");
|
||||
});
|
||||
}
|
||||
else {
|
||||
res.redirect("/auth/c9l");
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
register(null, {
|
||||
"c9.login": {
|
||||
ensureLoggedIn: function() {
|
||||
return function(req, res, next) {
|
||||
var redirect = options.baseUrl + "/_auth/c9l";
|
||||
var nonce = req.parsedUrl.query.__c9_preview_id__;
|
||||
|
||||
if (nonce) {
|
||||
redirect += "?nonce=" + encodeURIComponent(nonce);
|
||||
delete req.parsedUrl.query.__c9_preview_id__;
|
||||
delete req.parsedUrl.search;
|
||||
req.originalUrl = url.format(req.parsedUrl);
|
||||
}
|
||||
|
||||
login.ensureLoggedIn({
|
||||
redirectTo: redirect
|
||||
})(req, res, next);
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
var passport = require('passport');
|
||||
var util = require('util');
|
||||
var InternalOAuthError = require("passport-oauth").InternalOAuthError;
|
||||
|
||||
|
||||
function Cloud9Legacy(options) {
|
||||
passport.Strategy.call(this);
|
||||
this.name = 'c9l';
|
||||
|
||||
this.clientID = options.clientID;
|
||||
this.ideBaseUrl = options.ideBaseUrl;
|
||||
this.callback = options.callback;
|
||||
this.db = options.db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `passport.Strategy`.
|
||||
*/
|
||||
util.inherits(Cloud9Legacy, passport.Strategy);
|
||||
|
||||
/**
|
||||
* Authenticate request based on the contents of a HTTP Basic authorization
|
||||
* header.
|
||||
*
|
||||
* @param {Object} req
|
||||
* @api protected
|
||||
*/
|
||||
Cloud9Legacy.prototype.authenticate = function(req, options) {
|
||||
var that = this;
|
||||
options = options || {};
|
||||
|
||||
// the callback handler
|
||||
if (req.query && req.query.code) {
|
||||
this.db.AccessToken
|
||||
.findOne({
|
||||
token: req.query.code
|
||||
})
|
||||
.populate("user")
|
||||
.exec(function(err, token) {
|
||||
if (err)
|
||||
return that.error(new InternalOAuthError('failed to obtain access token', err));
|
||||
|
||||
req.session.token = req.query.code;
|
||||
that.success(token.user);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var nonce = req.parsedUrl.query.nonce;
|
||||
if (nonce) {
|
||||
this.redirect(
|
||||
this.ideBaseUrl +
|
||||
"/api/nc/auth" +
|
||||
"?response_type=nonce" +
|
||||
"&client_id=" + encodeURIComponent(this.clientID + "_nonce") +
|
||||
"&nonce=" + encodeURIComponent(nonce)
|
||||
);
|
||||
}
|
||||
else {
|
||||
this.redirect(
|
||||
this.ideBaseUrl +
|
||||
"/api/nc/auth" +
|
||||
"?response_type=token" +
|
||||
"&client_id=" + encodeURIComponent(this.clientID) +
|
||||
"&login_hint=" + encodeURIComponent(options.loginHint || "")
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose `Cloud9Legacy`.
|
||||
*/
|
||||
module.exports = Cloud9Legacy;
|
|
@ -1,135 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
var assert = require("assert");
|
||||
var frontdoor = require("frontdoor");
|
||||
var cookie = require("cookie");
|
||||
var Passport = require("passport").Passport;
|
||||
var Cloud9Strategy = require("./strategy");
|
||||
|
||||
plugin.consumes = [
|
||||
"session",
|
||||
"connect.redirect"
|
||||
];
|
||||
plugin.provides = ["c9.login"];
|
||||
|
||||
module.exports = plugin;
|
||||
|
||||
function plugin(options, imports, register) {
|
||||
assert(options.appId, "Option 'appId' is required");
|
||||
assert(options.appSecret, "Option 'appSecret' is required");
|
||||
assert(options.callback, "Option 'callback' is required");
|
||||
assert(options.logout, "Option 'logout' is required");
|
||||
assert(options.baseUrl, "Option 'baseUrl' is required");
|
||||
assert(options.domain, "Option 'domain' is required");
|
||||
assert(options.ssoCookie, "Option 'ssoCookie' is required");
|
||||
assert(options.ssoCookie.name, "Option 'ssoCookie.name' is required");
|
||||
assert(options.ssoCookie.maxAge, "Option 'ssoCookie.maxAge' is required");
|
||||
|
||||
var session = imports.session;
|
||||
var passport = new Passport();
|
||||
|
||||
session.use(passport.initialize());
|
||||
session.use(function(req, res, next) {
|
||||
passport.session()(req, res, function(err) {
|
||||
if (err) return next(err);
|
||||
if (!req.user) return next();
|
||||
|
||||
var uid = req.cookies[options.ssoCookie.name];
|
||||
if (uid != req.user.id) {
|
||||
req.logout();
|
||||
return next();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
passport.serializeUser(function(user, done) {
|
||||
var id;
|
||||
try {
|
||||
id = JSON.stringify(user);
|
||||
}
|
||||
catch (e) {
|
||||
return done(e);
|
||||
}
|
||||
done(null, id);
|
||||
});
|
||||
|
||||
passport.deserializeUser(function(id, done) {
|
||||
var user;
|
||||
try {
|
||||
user = JSON.parse(id);
|
||||
}
|
||||
catch (e) {
|
||||
return done(e);
|
||||
}
|
||||
done(null, user);
|
||||
});
|
||||
|
||||
var cloud9Strategy = new Cloud9Strategy({
|
||||
clientID: options.appId,
|
||||
clientSecret: options.appSecret,
|
||||
callbackURL: options.callback,
|
||||
userProfileURL: options.userProfileURL,
|
||||
baseUrl: options.baseUrl,
|
||||
}, function(accessToken, refreshToken, params, profile, done) {
|
||||
var user = {
|
||||
id: profile.id,
|
||||
username: profile.username,
|
||||
fullname: profile.displayName ? profile.displayName.trim() : profile.username,
|
||||
token: accessToken
|
||||
};
|
||||
done(null, user);
|
||||
});
|
||||
|
||||
passport.use(cloud9Strategy);
|
||||
|
||||
var api = frontdoor();
|
||||
passport.section = api.section("auth");
|
||||
session.use(api);
|
||||
|
||||
passport.section.get("/logout", function(req, res, next) {
|
||||
res.redirect(options.baseUrl + "/logout?redirect_uri=" + encodeURIComponent(options.logout));
|
||||
});
|
||||
passport.section.get("/cloud9", passport.authenticate("cloud9"));
|
||||
passport.section.get("/cloud9/callback", function(req, res, next) {
|
||||
passport.authenticate("cloud9", function(err, user, info) {
|
||||
if (err) return next(err);
|
||||
|
||||
if (user) {
|
||||
req.login(user, function(err) {
|
||||
if (err) return next(err);
|
||||
setCookie(res, req.user.id, options.ssoCookie.maxAge);
|
||||
res.returnTo(req, "/");
|
||||
});
|
||||
}
|
||||
else {
|
||||
res.redirect("/auth/cloud9");
|
||||
}
|
||||
|
||||
})(req, res, next);
|
||||
});
|
||||
|
||||
passport.section.get("/cloud9/logout", function(req, res, next) {
|
||||
req.logout();
|
||||
clearCookie(res);
|
||||
res.redirect("/");
|
||||
});
|
||||
|
||||
function clearCookie(res) {
|
||||
setCookie(res, "", new Date(1));
|
||||
}
|
||||
function setCookie(res, value, ttl) {
|
||||
res.setHeader("Set-Cookie", cookie.serialize(options.ssoCookie.name, value, {
|
||||
domain: "." + options.domain,
|
||||
path: "/",
|
||||
expires: ttl instanceof Date ? ttl : new Date(Date.now() + ttl),
|
||||
secure: true,
|
||||
httpOnly: true
|
||||
}));
|
||||
}
|
||||
|
||||
register(null, {
|
||||
"c9.login": passport
|
||||
});
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
var util = require('util');
|
||||
var OAuth2Strategy = require('passport-oauth').OAuth2Strategy;
|
||||
var InternalOAuthError = require('passport-oauth').InternalOAuthError;
|
||||
|
||||
function Strategy(options, verify) {
|
||||
options = options || {};
|
||||
var baseUrl = options.baseUrl || "https://auth.c9.io/oauth";
|
||||
|
||||
options.authorizationURL = baseUrl + "/authorize";
|
||||
options.tokenURL = baseUrl + "/access_token";
|
||||
options.scopeSeparator = ",";
|
||||
|
||||
OAuth2Strategy.call(this, options, verify);
|
||||
this.name = "cloud9";
|
||||
this._userProfileURL = options.userProfileURL || "https://api.c9.io/user";
|
||||
}
|
||||
|
||||
util.inherits(Strategy, OAuth2Strategy);
|
||||
|
||||
Strategy.prototype.userProfile = function(accessToken, done) {
|
||||
this._oauth2.useAuthorizationHeaderforGET(true);
|
||||
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
|
||||
if (err)
|
||||
return done(new InternalOAuthError('failed to fetch user profile', err));
|
||||
|
||||
try {
|
||||
var json = JSON.parse(body);
|
||||
|
||||
var profile = { provider: "cloud9" };
|
||||
profile.id = json.id;
|
||||
profile.displayName = json.name;
|
||||
profile.username = json.login;
|
||||
profile.emails = [{ value: json.email }];
|
||||
|
||||
profile._raw = body;
|
||||
profile._json = json;
|
||||
|
||||
done(null, profile);
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Strategy;
|
Ładowanie…
Reference in New Issue