Skip to content

Commit

Permalink
NEW FEATURE: Specify port of connection + .deb package
Browse files Browse the repository at this point in the history
  • Loading branch information
hosembafer committed Jan 18, 2017
1 parent 5260596 commit 56fc5ae
Show file tree
Hide file tree
Showing 8 changed files with 796 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
INSTALL = /usr/bin/install -c

CC = gcc
CPARAMS = -g -o
CPARAMS = -o
NAME = justup

CFLAGS = `pkg-config --cflags --libs sqlite3` -lftp -lssl -lcrypto -lssh
CFLAGS = `pkg-config --cflags --libs sqlite3` -lftp -lssl -lcrypto -lssh -lm
SOURCES = src/justup.c
EXECUTABLE = $(NAME)

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# justup
Justup is a deployment tool written in C.

Current status: **TESTING**

Transfer protocols: **FTP**, **SFTP**

The project is created for simple sites, that usually don't use servers with SFTP, WebDAV or something like that, when there isn't any other way except use FTP.
Expand Down Expand Up @@ -32,6 +30,7 @@ $ justup profile `master/dev/something_else`
```ini
protocol = ftp # ftp/sftp
host = localhost # host/domain/ip of server
port = 21 # optional, if not set, so port choose automatically
user = user # user
pass = root123 # password
basedir = /var/www/site/ # path to project root hosted on remote server
Expand Down
722 changes: 722 additions & 0 deletions deb-project.dbp

Large diffs are not rendered by default.

Binary file modified justup
Binary file not shown.
Binary file added justup_1.2.0_all.deb
Binary file not shown.
35 changes: 35 additions & 0 deletions src/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,39 @@ int answer_yn(char *question)
{
return 1;
}
}

int md5file(char *filename, char *md5hash)
{
unsigned char c[MD5_DIGEST_LENGTH];
char temp_sybmols[3];
FILE *inFile = fopen(filename, "rb");
int i;
MD5_CTX mdContext;
int bytes;
unsigned char data[1024];

if(inFile == NULL)
{
memset(md5hash, 0, 32);
return 0;
}

MD5_Init(&mdContext);
while((bytes = fread(data, 1, 1024, inFile)) != 0)
{
MD5_Update(&mdContext, data, bytes);
}
MD5_Final(c, &mdContext);
fclose(inFile);

for(i = 0; i < MD5_DIGEST_LENGTH; i++)
{
sprintf(temp_sybmols, "%02x", c[i]);

md5hash[i*2] = temp_sybmols[0];
md5hash[i*2+1] = temp_sybmols[1];
}

return 1;
}
72 changes: 35 additions & 37 deletions src/justup.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <dirent.h>
#include <libgen.h>

#include <math.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
Expand All @@ -32,41 +33,6 @@
#include "helpers.c"
#include "justup.h"

int md5file(char *filename, char *md5hash)
{
unsigned char c[MD5_DIGEST_LENGTH];
char temp_sybmols[3];
FILE *inFile = fopen(filename, "rb");
int i;
MD5_CTX mdContext;
int bytes;
unsigned char data[1024];

if(inFile == NULL)
{
memset(md5hash, 0, 32);
return 0;
}

MD5_Init(&mdContext);
while((bytes = fread(data, 1, 1024, inFile)) != 0)
{
MD5_Update(&mdContext, data, bytes);
}
MD5_Final(c, &mdContext);
fclose(inFile);

for(i = 0; i < MD5_DIGEST_LENGTH; i++)
{
sprintf(temp_sybmols, "%02x", c[i]);

md5hash[i*2] = temp_sybmols[0];
md5hash[i*2+1] = temp_sybmols[1];
}

return 1;
}

static int inih_handler(void* user, const char* section, const char* name, const char* value)
{
if(!strcmp(name, "protocol"))
Expand All @@ -77,6 +43,10 @@ static int inih_handler(void* user, const char* section, const char* name, const
{
strcpy(profile_host, value);
}
else if(!strcmp(name, "port"))
{
profile_port = atoi(value);
}
else if(!strcmp(name, "user"))
{
strcpy(profile_user, value);
Expand Down Expand Up @@ -466,12 +436,30 @@ void proceed()
{
if(TRANSFER_PROTOCOL_FTP)
{
char *profile_host_and_port;
profile_host_and_port = (char *) malloc(sizeof(char) * strlen(profile_host));
strcpy(profile_host_and_port, profile_host);

if(profile_port)
{
profile_host_and_port = (char *) realloc(profile_host_and_port, sizeof(char) * (strlen(profile_host) + 1 + floor(log10(abs(profile_port))) + 1));
sprintf(profile_host_and_port, "%s:%i", profile_host_and_port, profile_port);
}

FtpInit();
if(!FtpConnect(profile_host, &ftp_conn) || !FtpLogin(profile_user, profile_pass, ftp_conn))
if(!FtpConnect(profile_host_and_port, &ftp_conn) || !FtpLogin(profile_user, profile_pass, ftp_conn))
{
free(profile_host_and_port);

printf("FTP Client can't establishe connection or after connecting can't authorize FTP Server\n");
exit(EXIT_FAILURE);
}
free(profile_host_and_port);

if(profile_port)
{
FtpOptions(FTPLIB_PORT, profile_port, ftp_conn);
}

FtpChdir(profile_basedir, ftp_conn);
}
Expand All @@ -480,7 +468,16 @@ void proceed()
my_ssh_session = ssh_new();
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, profile_host);

ssh_connect(my_ssh_session);
if(profile_port)
{
ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &profile_port);
}

if(ssh_connect(my_ssh_session) == SSH_ERROR)
{
printf("SFTP Client can't establishe connection or after connecting can't authorize SFTP Server\n");
exit(EXIT_FAILURE);
}
ssh_userauth_password(my_ssh_session, profile_user, profile_pass);

sftp_conn = sftp_new(my_ssh_session);
Expand Down Expand Up @@ -698,6 +695,7 @@ void proceed_profile(char *new_profile)

const char *profileExample = "protocol = ftp\n"
"host = localhost\n"
"#port = 21\n"
"user = user\n"
"pass = root123\n"
"basedir = /var/www/site/";
Expand Down
1 change: 1 addition & 0 deletions src/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int fp_cvsignore_size;
char profile[20];
char profile_protocol[7];
char profile_host[80];
unsigned int profile_port = 0;
char profile_user[40];
char profile_pass[80];
char profile_basedir[80];
Expand Down

0 comments on commit 56fc5ae

Please sign in to comment.