Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added onion_handler_opack, easy use of opack results. Fixed bug when …

…sending data and break in the middle of send. oterm now uses internal resources instead of external, for !__DEBUG__. Added README.rst to oterm.

onion_handler_opack can be used to easy use opack results, only needs the opack writer and a path. Actually it can be used with your own writers, check onion_opack_render signature and do a funtion like that.

There was a bug when sending on SSL a big file, as it send max 16kB. Now it tries harder.

Opack now when compiled in non-debug mode returns the internal resources, that is, internal files, instead of using the directory handler.

The oterm README.rst file gives insight on how to use oterm, and where to find more information.
  • Loading branch information...
commit 000c0eeed44b797be89043498fd1a8301f77cbe1 1 parent b101d81
@davidmoreno authored
View
6 examples/oterm/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_definitions(-D__DEBUG__)
+#add_definitions(-D__DEBUG__)
include_directories (${CMAKE_SOURCE_DIR}/src/onion/ ${CMAKE_SOURCE_DIR}/src/handlers/ ${CMAKE_SOURCE_DIR}/src/onionssl/)
@@ -6,11 +6,11 @@ add_custom_command(
OUTPUT oterm_data.c
COMMAND opack ${CMAKE_CURRENT_SOURCE_DIR}/index.html ${CMAKE_CURRENT_SOURCE_DIR}/oterm.js
${CMAKE_CURRENT_SOURCE_DIR}/oterm_input.js ${CMAKE_CURRENT_SOURCE_DIR}/oterm_data.js
- ${CMAKE_CURRENT_SOURCE_DIR}/jquery-1.4.3.min.js
+ ${CMAKE_CURRENT_SOURCE_DIR}/oterm_parser.js ${CMAKE_CURRENT_SOURCE_DIR}/jquery-1.4.3.min.js
-o ${CMAKE_CURRENT_BINARY_DIR}/oterm_data.c
DEPENDS opack ${CMAKE_CURRENT_SOURCE_DIR}/index.html ${CMAKE_CURRENT_SOURCE_DIR}/oterm.js
${CMAKE_CURRENT_SOURCE_DIR}/oterm_input.js ${CMAKE_CURRENT_SOURCE_DIR}/oterm_data.js
- ${CMAKE_CURRENT_SOURCE_DIR}/jquery-1.4.3.min.js
+ ${CMAKE_CURRENT_SOURCE_DIR}/oterm_parser.js ${CMAKE_CURRENT_SOURCE_DIR}/jquery-1.4.3.min.js
)
add_executable(oterm oterm.c oterm_handler.c oterm_data.c)
View
45 examples/oterm/README.rst
@@ -0,0 +1,45 @@
+Onion web-based GNU/Linux terminal
+==================================
+
+With Oterm you can acces with a standard compilant browser to a remote terminal,
+using SSL and authenticated.
+
+It has a server component, that is as light as possible, that is the container of
+the processes, and redirects all inforamtion to the web based terminal.
+
+The terminal uses HTML/Javascript to emulate all the terminal commands and
+control characters, and serves all that as if it were a web page.
+
+Usage
+-----
+
+You need the libonion http web server library, and compile it all. To execute it
+just run the command oterm, and connect to the given address.
+
+More help is provided with --help.
+
+Current features
+----------------
+
+* Understand most linux terminal commands, and allow to use many terminal based
+ programs as htop, atop, mc, vi, emacs
+
+Planned features
+----------------
+
+* Make it behave like a screen for web, allowing to create new sessions, recover
+ old ones...
+* Make it multiuser, each with its own sessions.
+* Make it RESTfull, now it does polling, so its not as efficient as could be.
+* More terminal functionalities: It does not do yet all that a xterm do, for example
+ it does not resize yet.
+* Fix bugs.
+
+Contact
+-------
+
+There is a github page at https://github.com/davidmoreno/onion, where you can fill new
+issues and feature request. Also you can send emails to dmoreno (works at) coralbits.com.
+
+Last if you need prefesional guidance about oterm or onion, you can contact the upper
+email address to ask for more information about consulting.
View
21 examples/oterm/oterm.c
@@ -27,10 +27,21 @@
#include <onion_handler_path.h>
#include <onion_handler_static.h>
#include <onion_handler_auth_pam.h>
+#include <onion_handler_opack.h>
+#ifdef __DEBUG__
+#include <onion_handler_directory.h>
+#endif
#include "oterm_handler.h"
-#include <onion_handler_directory.h>
+
+
+void opack_index_html(onion_response *res);
+void opack_oterm_js(onion_response *res);
+void opack_oterm_input_js(onion_response *res);
+void opack_oterm_data_js(onion_response *res);
+void opack_oterm_parser_js(onion_response *res);
+void opack_jquery_1_4_3_min_js(onion_response *res);
onion_ssl *o=NULL;
@@ -95,8 +106,12 @@ int main(int argc, char **argv){
#ifdef __DEBUG__
onion_handler *dir=onion_handler_directory(".");
#else
- onion_handler *dir=onion_handler_path("^/$",oterm_handler_index());
- onion_handler_add(dir, onion_handler_path("^/oterm.js$",oterm_handler_oterm()));
+ onion_handler *dir=onion_handler_opack("/",opack_index_html);
+ onion_handler_add(dir, onion_handler_opack("/jquery-1.4.3.min.js",opack_jquery_1_4_3_min_js));
+ onion_handler_add(dir, onion_handler_opack("/oterm.js",opack_oterm_js));
+ onion_handler_add(dir, onion_handler_opack("/oterm_input.js",opack_oterm_input_js));
+ onion_handler_add(dir, onion_handler_opack("/oterm_parser.js",opack_oterm_parser_js));
+ onion_handler_add(dir, onion_handler_opack("/oterm_data.js",opack_oterm_data_js));
#endif
onion_handler_add(dir, onion_handler_path("^/term$",oterm_handler_data()));
View
31 examples/oterm/oterm_handler.c
@@ -31,37 +31,6 @@
#include <onion_response.h>
#include <onion_handler.h>
-void opack_index_html(onion_response *res);
-void opack_oterm_js(onion_response *res);
-void opack_oterm_input_js(onion_response *res);
-void opack_oterm_data_js(onion_response *res);
-void opack_jquery_1_4_3_min_js(onion_response *res);
-
-int oterm_index(void *d, onion_request *req){
- onion_response *res=onion_response_new(req);
- onion_response_write_headers(res);
- opack_index_html(res);
- return 1;
-}
-int oterm_oterm(void *d, onion_request *req){
- onion_response *res=onion_response_new(req);
- onion_response_set_header(res,"Content-Type","text/javascript");
- onion_response_write_headers(res);
-
- opack_jquery_1_4_3_min_js(res);
- opack_oterm_js(res);
- opack_oterm_input_js(res);
- opack_oterm_data_js(res);
-
- return 1;
-}
-onion_handler *oterm_handler_index(){
- return onion_handler_new((onion_handler_handler)oterm_index, NULL, NULL);
-}
-onion_handler *oterm_handler_oterm(){
- return onion_handler_new((onion_handler_handler)oterm_oterm, NULL, NULL);
-}
-
typedef struct{
int fd;
View
2  src/handlers/CMakeLists.txt
@@ -2,6 +2,6 @@
include_directories (${CMAKE_SOURCE_DIR}/src/onion/)
add_library(onion_handlers STATIC onion_handler_static.c onion_handler_path.c onion_handler_directory.c
- onion_handler_regexp.c onion_handler_auth_pam.c)
+ onion_handler_regexp.c onion_handler_auth_pam.c onion_handler_opack.c)
target_link_libraries(onion_handlers pam pam_misc)
View
70 src/handlers/onion_handler_opack.c
@@ -0,0 +1,70 @@
+/*
+ Onion HTTP server library
+ Copyright (C) 2010 David Moreno Montero
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+#include <malloc.h>
+#include <unistd.h>
+#include <regex.h>
+
+#include <onion_handler.h>
+#include <onion_response.h>
+
+#include "onion_handler_opack.h"
+
+struct onion_handler_opack_data_t{
+ char *path;
+ onion_opack_renderer render;
+};
+
+typedef struct onion_handler_opack_data_t onion_handler_opack_data;
+
+int onion_handler_opack_handler(onion_handler_opack_data *d, onion_request *request){
+ if (strcmp(d->path, onion_request_get_path(request))!=0)
+ return 0;
+
+ onion_response *res=onion_response_new(request);
+ onion_response_write_headers(res);
+
+ d->render(res);
+
+ onion_response_free(res);
+ return 1;
+}
+
+
+void onion_handler_opack_delete(onion_handler_opack_data *data){
+ free(data->path);
+ free(data);
+}
+
+/**
+ * @short Creates an path handler. If the path matches the regex, it reomves that from the regexp and goes to the inside_level.
+ *
+ * If on the inside level nobody answers, it just returns NULL, so ->next can answer.
+ */
+onion_handler *onion_handler_opack(const char *path, onion_opack_renderer render){
+ onion_handler_opack_data *priv_data=malloc(sizeof(onion_handler_opack_data));
+
+ priv_data->path=strdup(path);
+ priv_data->render=render;
+
+ onion_handler *ret=onion_handler_new((onion_handler_handler)onion_handler_opack_handler,
+ priv_data, (onion_handler_private_data_free) onion_handler_opack_delete);
+ return ret;
+}
+
View
37 src/handlers/onion_handler_opack.h
@@ -0,0 +1,37 @@
+/*
+ Onion HTTP server library
+ Copyright (C) 2010 David Moreno Montero
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ONION_HANDLER_OPACK__
+#define __ONION_HANDLER_OPACK__
+
+#include <onion_types.h>
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+typedef void (*onion_opack_renderer)(onion_response *res);
+
+/// Creates an path handler. If the path matches the regex, it reomves that from the regexp and goes to the inside_level.
+onion_handler *onion_handler_opack(const char *path, onion_opack_renderer opack);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
View
13 src/onion/onion_response.c
@@ -21,7 +21,7 @@
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
-//#include <time.h>
+#include <libgen.h>
#include "onion_dict.h"
#include "onion_request.h"
@@ -97,7 +97,16 @@ void onion_response_write_headers(onion_response *res){
int onion_response_write(onion_response *res, const char *data, unsigned int length){
void *fd=onion_response_get_socket(res);
onion_write write=onion_response_get_writer(res);
- int w=write(fd, data, length);
+ int w;
+ int pos=0;
+ while ( (w=write(fd, &data[pos], length)) != length){
+ if (w==0){
+ fprintf(stderr,"%s:%d Error writing. Maybe closed connection.\n",basename(__FILE__),__LINE__);
+ break;
+ }
+ pos+=w;
+ length-=w;
+ }
res->sent_bytes+=length;
return w;
}
View
6 tools/opack/opack.c
@@ -100,12 +100,13 @@ void parse_file(const char *filename, FILE *outfd){
exit(3);
}
char *fname=funcname(basename((char*)filename));
- char buffer[1024];
+ char buffer[4097];
+ buffer[4096]=0;
fprintf(stderr, "Parsing: %s to 'int %s(onion_response *res);'.\n",filename, fname);
fprintf(outfd,"int %s(onion_response *res){\n char data[]={\n",fname);
int r, i;
- while ( (r=fread(buffer,1,sizeof(buffer),fd)) !=0 ){
+ while ( (r=fread(buffer,1,sizeof(buffer)-1,fd)) !=0 ){
for (i=0;i<r;i++){
fprintf(outfd,"0x%02X, ", buffer[i]&0x0FF);
}
@@ -128,3 +129,4 @@ void print_help(const char *name){
fprintf(stderr,"This way this function is very easily used from onion handlers as needed.\n");
exit(1);
}
+
Please sign in to comment.
Something went wrong with that request. Please try again.