Permalink
Browse files

Got remote copy to work, but need to type password in the server term…

…ninal window. A bit awkward.
  • Loading branch information...
1 parent 106b292 commit fc9c151b657c83e4b958366a9ad8825312a8c27f @jrburke committed Oct 13, 2011
Showing with 204 additions and 25 deletions.
  1. +25 −11 modules/api/setup.js
  2. +1 −1 modules/generate.js
  3. +65 −0 modules/remoteCopy.js
  4. +6 −0 tasks.txt
  5. +58 −12 web/index.html
  6. +48 −0 web/js/index.js
  7. +1 −1 web/setup.html
View
@@ -11,7 +11,8 @@ define(function (require) {
var path = require('path'),
fs = require('fs'),
file = require('../file'),
- generate = require('../generate');
+ generate = require('../generate'),
+ remoteCopy = require('../remoteCopy');
function setup(data, load, config, request, response) {
var dir = data.localDir;
@@ -46,6 +47,29 @@ define(function (require) {
try {
file.copyDir('./scaffold', dir, null, true);
generate(dir);
+ remoteCopy(data.name, data.password, data.remoteServer, path.join(dir, 'web'), data.remoteDir,
+ function (err, status) {
+ if (err) {
+ load({
+ status: 'error',
+ field: 'all',
+ code: 'cannotRemote',
+ error: err.error
+ });
+ return;
+ }
+
+ //Save the data to the config file.
+ if (data && data.password) {
+ config.data = data;
+ config.save();
+ }
+
+ load({
+ status: 'ok'
+ });
+ }
+ );
} catch (e2) {
load({
status: 'error',
@@ -55,16 +79,6 @@ define(function (require) {
});
return;
}
-
- //Save the data to the config file.
- if (data && data.password) {
- config.data = data;
- config.save();
- }
-
- load({
- status: 'ok'
- });
}
return setup;
View
@@ -19,7 +19,7 @@ define(function (require) {
var dataFile, data, templateFile, template, webFile;
//Copy all the miscellaneous files to to web directory.
- file.copyDir(path.join(dir, 'templates'), path.join(dir, 'web'), /$[^_]/, true);
+ file.copyDir(path.join(dir, 'templates'), path.join(dir, 'web'), /\/[^_][^\/]+$/, true);
//Generate the index.html file
dataFile = path.join(dir, 'content', 'index.json');
View
@@ -0,0 +1,65 @@
+/**
+ * @license mcdrop Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
+ * Available via the MIT or new BSD license.
+ * see: http://github.com/jrburke/mcdrop for details
+ */
+
+/*jslint strict: false, regexp: false */
+/*global define: false, console: false */
+
+define(function (require) {
+ var path = require('path'),
+ fs = require('fs'),
+ spawn = require('child_process').spawn;
+
+ function remoteCopy(name, password, host, localDir, remoteDir, callback) {
+ //Build up args for the scp command. Grab all the top level files/directories
+ //in localDir and pass, since just passing localDir creates a directory
+ //named for the last part of localDir on the remote host, but instead,
+ //we just want the contents of the localDir copied up.
+ var args = ['-r'],
+ scp;
+
+ fs.readdirSync(localDir).forEach(function (name) {
+ args.push(path.join(localDir, name));
+ });
+
+ //Add the final args
+ args = args.concat([name + '@' + host + ':' + remoteDir]);
+
+ scp = spawn('scp', args);
+
+ scp.stdout.on('data', function (data) {
+ console.log('stdout: ' + data);
+
+ if (data.indexOf('assword:') !== -1) {
+ //Password is needed, pass it.
+ scp.stdin.write(password);
+ } else {
+ //Some sort of error
+ callback({
+ error: data
+ });
+
+ //Stop the command
+ scp.stdin.end();
+ }
+ });
+
+ scp.stderr.on('data', function (data) {
+ console.log('stderr: ' + data);
+
+ callback({
+ error: data
+ });
+ });
+
+ scp.on('exit', function (code) {
+ callback(undefined, code);
+ });
+
+ }
+
+ return remoteCopy;
+
+});
View
@@ -0,0 +1,6 @@
+* Turns out cannot pass password via the streams on child process, one suggestion
+ was to use unix "expect":
+ http://comments.gmane.org/gmane.comp.lang.javascript.nodejs/17578
+
+ A code example using expect:
+ https://github.com/FlashFan/NodeSSH/tree/master/lib
View
@@ -2,35 +2,81 @@
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
- <title>Sign In : Untitled Blog</title>
+ <title>Dashboard : Untitled Blog</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen">
- <script src="js/jquery-1.6.4.min.js" type="text/javascript" charset="utf-8"></script>
- <script src="js/functions.js" type="text/javascript" charset="utf-8"></script>
+ <script data-main="js/index" src="js/require.js"></script>
</head>
<body>
<div id="wrapper" class="cf">
<div id="header" class="cf">
- <h1 id="title"><a href="#">Untitled Blog</a> : Sign In</h1> <!-- link to blog -->
+ <h1 id="title"><a href="#">Untitled Blog</a> : Dashboard</h1> <!-- link to blog -->
+ <ul id="nav" class="view_posts">
+ <div class="highlight"></div>
+ <li class="sign_out"><a href="/demos/blog/admin">Sign Out</a></li>
+ <li class="posts">Posts</li>
+ <li class="profile">Profile</li>
+ </ul>
</div>
- <div id="sign_in">
+ <div id="posts">
+ <div id="upload" class="cf">
+ <button class="sans">Upload New Post</button>
+ </div>
+
+ <ul id="post_list" class="cf">
+
+ <li class="post draft cf">
+ <div class="status">
+ <span class="publish"><button>publish</button></span>
+ </div>
+ <div class="filename mono"><a href="#">my_second_post_is_a_draft.md</a></div>
+ <ul class="actions">
+ <li class="delete"><input type="checkbox"></li>
+ <li class="replace"><a href="#">replace</a></li>
+ <li class="view"><a href="#">preview</a></li>
+ </ul>
+ </li>
+
+ <li class="post published cf">
+ <div class="date">Sep 28, 2011</div>
+ <div class="filename mono"><a href="#">getting_started.md</a></div>
+ <ul class="actions">
+ <li class="delete"><input type="checkbox"></li>
+ <li class="replace"><a href="#">replace</a></li>
+ <li class="view"><a href="#">view</a></li>
+ </ul>
+ </li>
+
+ </ul>
+ </div>
+
+ <div id="profile">
<form id="inputs">
+ <ul class="name">
+ <li>
+ <label for="blog_title">Blog Title</label>
+ <input id="blog_title" class="sans" type="text" placeholder="Untitled Blog">
+ </li>
+ </ul>
- <ul class="sign_in_form">
+ <ul class="password">
<li>
<label for="username">Username</label>
- <input id="username" class="sans" type="text" placeholder="admin">
+ <input id="username" class="sans" type="text" placeholder="Admin">
</li>
<li>
- <label for="password">Password</label>
- <input id="password" class="sans" type="text" placeholder="●●●●●●●●">
-
+ <label for="new_password">New Password</label>
+ <input id="new_password" class="sans" type="text" placeholder="●●●●●●●●">
+ </li>
+ <li>
+ <label for="confirm">Confirm Password</label>
+ <input id="confirm" class="sans" type="text" placeholder="●●●●●●●●">
</li>
</ul>
- <!-- temporarily using anchor tag to link to dashboard -->
- <a class="temp" href="dashboard.html"><input type="submit" value="Sign In"></a>
+
+ <input type="submit" value="Save Changes">
</form>
</div>
View
@@ -0,0 +1,48 @@
+/**
+ * @license mcdrop Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
+ * Available via the MIT or new BSD license.
+ * see: http://github.com/jrburke/mcdrop for details
+ */
+
+/*jslint strict: false */
+/*global define: false, require: false, console: false, location: true */
+
+
+define(function (require) {
+ //This code executes once DOM is ready.
+ var doc = require('domReady!'),
+ $ = require('jquery');
+
+
+ var $profile = $('#profile')
+ var $posts = $('#posts')
+
+ $profile.hide()
+
+ $('#nav li.posts').click(function() {
+ $(this).parent().addClass('view_posts');
+ $(this).parent().removeClass('view_profile');
+ $posts.fadeIn(200);
+
+ // temporarily give position absolute to overlap tabs, then remove once transition is finished
+ $profile
+ .css({ 'position' : 'absolute', 'top' : 96 })
+ .fadeOut(200, function() {
+ $(this).css({ 'position' : '', 'top' : '' });
+ });
+ });
+
+ $('#nav li.profile').click(function() {
+ $(this).parent().addClass('view_profile');
+ $(this).parent().removeClass('view_posts');
+ $profile.fadeIn(200);
+
+ // temporarily give position absolute to overlap tabs, then remove once transition is finished
+ $posts
+ .css({ 'position' : 'absolute', 'top' : 96 })
+ .fadeOut(200, function() {
+ $(this).css({ 'position' : '', 'top' : '' });
+ });
+ });
+
+});
View
@@ -39,7 +39,7 @@ <h1 id="title"><a href="#">Untitled Blog</a> : Setup</h1> <!-- link to blog -->
</li>
<li>
<label for="password">Remote password</label>
- <input name="password" class="sans" type="password" placeholder="●●●●●●●●">
+ <input name="password" class="sans" type="password" placeholder="">
</li>

0 comments on commit fc9c151

Please sign in to comment.