[Commits] r680 - trunk/daemon/src
new-commit at lists.openvcp.org
new-commit at lists.openvcp.org
Tue Dec 1 20:21:21 UTC 2009
Author: cryptronic
Date: 2009-12-01 20:21:20 +0000 (Tue, 01 Dec 2009)
New Revision: 680
Modified:
trunk/daemon/src/get.c
trunk/daemon/src/node.c
trunk/daemon/src/set.c
Log:
little bugfixes and apply localhost to new linux vserver api
Modified: trunk/daemon/src/get.c
===================================================================
--- trunk/daemon/src/get.c 2009-11-08 15:01:34 UTC (rev 679)
+++ trunk/daemon/src/get.c 2009-12-01 20:21:20 UTC (rev 680)
@@ -146,7 +146,7 @@
struct ovcp_response_st *response;
struct ovcp_data_st *arg0;
char *name, *rescuefile;
-
+
arg0 = ovcp_request_get_arg(request, 0);
name = (char *)ovcp_data_get(arg0);
@@ -157,15 +157,15 @@
response = ovcp_response_new();
-
-
-
+
+
+
if(vserver_isrunning(name))
ovcp_response_add_string(response, "Online");
else
ovcp_response_add_string(response, "Offline");
-
+
rescuefile = concat(global_settings.config_dir, "/", name, "/rescue", NULL);
if(file_exist(rescuefile))
ovcp_response_add_string(response, "rescue");
@@ -821,6 +821,8 @@
}
+ ovcp_response_struct_new(response);
+
ovcp_response_struct_add_string(response, "path", "/");
ovcp_response_struct_add_int(response, "total", space_total);
Modified: trunk/daemon/src/node.c
===================================================================
--- trunk/daemon/src/node.c 2009-11-08 15:01:34 UTC (rev 679)
+++ trunk/daemon/src/node.c 2009-12-01 20:21:20 UTC (rev 680)
@@ -42,9 +42,9 @@
char vserver_version[10];
char *utiloutput;
int i;
-
+
memset(util_version, 0, 10);
-
+
response = ovcp_response_new();
kernel_version = file_read("/proc/version");
@@ -53,39 +53,39 @@
if(kernel_version[i] == '(') kernel_version[i-1] = 0;
snprintf(vserver_version, 10, "0x%x", kernel_vci_version);
-
+
utiloutput = exec_cmd("vserver-info", 10, "vserver-info", NULL);
if(utiloutput != NULL)
sscanf(utiloutput, "%*s %*s %*s %*s %*s util-vserver: %10s", util_version);
if(strlen(util_version) != 0)
util_version[strlen(util_version)-1] = 0;
-
+
ovcp_response_add_string(response, PACKAGE_VERSION);
-
- if(strlen(REVISION) > 1)
+
+ if(strlen(REVISION) > 1)
ovcp_response_add_string(response, "r"REVISION);
else ovcp_response_add_string(response, "");
-
+
if(strlen(kernel_version) > 14)
ovcp_response_add_string(response, kernel_version+14);
ovcp_response_add_string(response, vserver_version);
ovcp_response_add_string(response, util_version);
-
+
if(utiloutput != NULL)
free(utiloutput);
if(kernel_version != NULL)
free(kernel_version);
-
- return response;
+
+ return response;
}
struct ovcp_response_st *node_halt(struct ovcp_request_st *request)
{
struct ovcp_response_st *response;
int ret;
-
+
response = ovcp_response_new();
-
+
if((ret = fork()) == 0)
{
execlp ("shutdown", "shutdown", "-h", "+1", NULL);
@@ -100,17 +100,17 @@
{
ovcp_response_add_boolean(response, TRUE);
}
-
- return response;
+
+ return response;
}
struct ovcp_response_st *node_reboot(struct ovcp_request_st *request)
{
struct ovcp_response_st *response;
int ret;
-
+
response = ovcp_response_new();
-
+
if((ret = fork()) == 0)
{
execlp ("shutdown", "shutdown", "-r", "+1", NULL);
@@ -125,7 +125,7 @@
{
ovcp_response_add_boolean(response, TRUE);
}
-
+
return response;
}
@@ -137,14 +137,14 @@
char path[BUF_SIZE];
struct ovcp_response_st *response;
int total=0, online=0, offline=0;
-
+
if((dir_ptr = opendir(global_settings.config_dir)) != NULL)
{
-
+
while((dir_entry = readdir(dir_ptr)) != NULL)
{
-
+
if(dir_entry->d_name[0] != '.')
{
sconcat(path, BUF_SIZE, global_settings.config_dir, "/", dir_entry->d_name, NULL);
@@ -152,36 +152,36 @@
if(dir_exist(path))
{
sconcat(path, BUF_SIZE, global_settings.run_dir, "/", dir_entry->d_name, NULL);
-
+
if(file_exist(path))
online++;
else offline++;
-
+
total++;
}
}
-
+
}
closedir(dir_ptr);
}
-
-
+
+
response = ovcp_response_new();
-
-
+
+
ovcp_response_struct_new(response);
-
+
ovcp_response_struct_add_int(response, "total", total);
ovcp_response_struct_add_int(response, "online", online);
ovcp_response_struct_add_int(response, "offline", offline);
-
+
ovcp_response_struct_end(response);
-
+
return response;
}
@@ -191,40 +191,40 @@
struct ovcp_response_st *response;
struct ovcp_data_st *arg0, *arg1, *arg2;
-
- char *sql_error;
+
+ char *sql_error;
char sql_query[BUF_SIZE+1];
int i = 0, ret;
-
+
int nrow, ncolumn;
char **sql_result;
int *month, *year, *day;
-
+
arg0 = ovcp_request_get_arg(request, 0);
month = (int *)ovcp_data_get(arg0);
-
+
if(!ovcp_data_is_int(arg0) || month == NULL)
return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
-
+
arg1 = ovcp_request_get_arg(request, 1);
year = (int *)ovcp_data_get(arg1);
-
+
if(!ovcp_data_is_int(arg1) || year == NULL)
return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
-
+
arg2 = ovcp_request_get_arg(request, 2);
day = (int *)ovcp_data_get(arg2);
-
+
if(!ovcp_data_is_int(arg2) || day == NULL)
return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
-
-
+
+
snprintf(sql_query, BUF_SIZE, "SELECT * FROM node_hour_traffic WHERE (month=%d and day=%d and year=%d)", *month, *day, *year);
-
+
ret = sqlite3_get_table(ovcp_db, sql_query, &sql_result, &nrow, &ncolumn, &sql_error);
if(ret != SQLITE_OK)
@@ -233,18 +233,18 @@
sqlite3_free(sql_error);
exit(-1);
}
-
+
ovcp_log(OVCP_DEBUG, "SQL QUERY: %s", sql_query);
i = 1;
-
+
response = ovcp_response_new();
while(i != nrow+1)
{
ovcp_response_struct_new(response);
-
+
ovcp_response_struct_add_string(response, "month", sql_result[i*(ncolumn)+0]);
ovcp_response_struct_add_string(response, "hour", sql_result[i*(ncolumn)+1]);
ovcp_response_struct_add_string(response, "day", sql_result[i*(ncolumn)+2]);
@@ -253,16 +253,16 @@
ovcp_response_struct_add_string(response, "out", sql_result[i*(ncolumn)+5]);
ovcp_response_struct_add_string(response, "total", sql_result[i*(ncolumn)+6]);
-
+
ovcp_response_struct_end(response);
-
- i++;
+
+ i++;
}
-
+
sqlite3_free_table(sql_result);
-
+
return response;
}
@@ -272,35 +272,35 @@
struct ovcp_response_st *response;
struct ovcp_data_st *arg0, *arg1;
-
- char *sql_error;
+
+ char *sql_error;
char sql_query[BUF_SIZE+1];
int i = 0, ret;
-
+
int nrow, ncolumn;
char **sql_result;
int *month, *year;
-
+
arg0 = ovcp_request_get_arg(request, 0);
month = (int *)ovcp_data_get(arg0);
-
+
if(!ovcp_data_is_int(arg0) || month == NULL)
return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
-
+
arg1 = ovcp_request_get_arg(request, 1);
year = (int *)ovcp_data_get(arg1);
-
+
if(!ovcp_data_is_int(arg1) || year == NULL)
return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
-
-
+
+
snprintf(sql_query, BUF_SIZE, "SELECT * FROM node_traffic WHERE (month=%d and year=%d)", *month, *year);
-
+
ret = sqlite3_get_table(ovcp_db, sql_query, &sql_result, &nrow, &ncolumn, &sql_error);
if(ret != SQLITE_OK)
@@ -311,14 +311,14 @@
}
i = 1;
-
+
response = ovcp_response_new();
while(i != nrow+1)
{
ovcp_response_struct_new(response);
-
+
ovcp_response_struct_add_string(response, "month", sql_result[i*(ncolumn)+0]);
ovcp_response_struct_add_string(response, "day", sql_result[i*(ncolumn)+1]);
ovcp_response_struct_add_string(response, "year", sql_result[i*(ncolumn)+2]);
@@ -326,16 +326,16 @@
ovcp_response_struct_add_string(response, "out", sql_result[i*(ncolumn)+4]);
ovcp_response_struct_add_string(response, "total", sql_result[i*(ncolumn)+5]);
-
+
ovcp_response_struct_end(response);
-
- i++;
+
+ i++;
}
-
+
sqlite3_free_table(sql_result);
-
+
return response;
}
@@ -345,11 +345,11 @@
{
struct ovcp_response_st *response;
struct ovcp_data_st *arg0, *arg1;
-
- char *sql_error;
+
+ char *sql_error;
char sql_query[BUF_SIZE];
int i = 0, ret;
-
+
int nrow, ncolumn;
char **sql_result;
int *month, *year;
@@ -361,23 +361,23 @@
arg0 = ovcp_request_get_arg(request, 0);
month = (int *)ovcp_data_get(arg0);
-
+
if(!ovcp_data_is_int(arg0) || month == NULL)
return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
-
+
arg1 = ovcp_request_get_arg(request, 1);
year = (int *)ovcp_data_get(arg1);
-
+
if(!ovcp_data_is_int(arg1) || year == NULL)
return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
-
-
+
+
snprintf(sql_query, BUF_SIZE, "SELECT \"in\",\"out\",\"total\" FROM node_traffic WHERE (month=%d and year=%d)", *month, *year);
-
+
ret = sqlite3_get_table(ovcp_db, sql_query, &sql_result, &nrow, &ncolumn, &sql_error);
if(ret != SQLITE_OK)
@@ -388,13 +388,13 @@
}
i = 1;
-
-
+
+
while(i != nrow+1)
{
-
+
day_traffic_in = strtod(sql_result[i*(ncolumn)], NULL);
day_traffic_out = strtod(sql_result[i*(ncolumn)+1], NULL);
day_traffic_total = strtod(sql_result[i*(ncolumn)+2], NULL);
@@ -402,22 +402,22 @@
month_traffic_in += day_traffic_in;
month_traffic_out += day_traffic_out;
month_traffic_total += day_traffic_total;
-
- i++;
+
+ i++;
}
-
+
sqlite3_free_table(sql_result);
-
+
response = ovcp_response_new();
ovcp_response_struct_new(response);
-
+
ovcp_response_struct_add_double(response, "in", month_traffic_in);
ovcp_response_struct_add_double(response, "out", month_traffic_out);
ovcp_response_struct_add_double(response, "total", month_traffic_total);
-
+
ovcp_response_struct_end(response);
return response;
@@ -430,15 +430,15 @@
FILE *dev_file;
char word[500+1];
int i = 0;
-
+
dev_file = fopen("/proc/net/dev", "r");
if(dev_file != NULL)
{
response = ovcp_response_new();
-
+
ovcp_response_array_new(response);
-
+
while(!feof(dev_file))
{
word[0] = 0;
@@ -459,23 +459,23 @@
break;
}
-
+
i++;
}
}
}
-
+
ovcp_response_array_end(response);
-
+
fclose(dev_file);
}
else
{
- response = ovcp_response_error(OVCP_ERROR_FILEMISSING, "node.get_interfaces: "OVCP_ERROR_FILEMISSING_DESC);
+ response = ovcp_response_error(OVCP_ERROR_FILEMISSING, "node.get_interfaces: "OVCP_ERROR_FILEMISSING_DESC);
}
-
+
return response;
}
@@ -488,8 +488,8 @@
struct image_st image;
response = ovcp_response_new();
-
-
+
+
if((image_dir = opendir(global_settings.image_dir)) != NULL)
{
@@ -504,23 +504,23 @@
if(dir_exist(path))
{
ovcp_response_struct_new(response);
-
+
if(parse_image(entry->d_name, &image))
{
ovcp_response_struct_add_string(response, "id", entry->d_name);
-
+
if(image.name != NULL)
ovcp_response_struct_add_string(response, "name", image.name);
if(image.initstyle != NULL)
ovcp_response_struct_add_string(response, "initstyle", image.initstyle);
-
+
free_image(&image);
}
else
{
ovcp_response_struct_add_string(response, "id", entry->d_name);
}
-
+
ovcp_response_struct_end(response);
}
@@ -530,8 +530,8 @@
closedir(image_dir);
}
-
+
return response;
}
@@ -541,9 +541,9 @@
struct ovcp_response_st *response;
char path[] = "/proc/loadavg";
char *load;
-
+
load = file_read(path);
-
+
if(load == NULL)
{
response = ovcp_response_error(OVCP_ERROR_FILEMISSING, "node.get_load: "OVCP_ERROR_FILEMISSING_DESC);
@@ -565,10 +565,10 @@
struct ovcp_response_st *response;
char path[] = "/proc/uptime";
char *uptime;
-
+
uptime = file_read(path);
-
+
if(uptime == NULL)
{
response = ovcp_response_error(OVCP_ERROR_FILEMISSING, "node.get_uptime: "OVCP_ERROR_FILEMISSING_DESC);
@@ -580,8 +580,8 @@
ovcp_response_add_string(response, uptime);
free(uptime);
}
-
-
+
+
return response;
}
@@ -589,23 +589,23 @@
struct ovcp_response_st *node_get_space(struct ovcp_request_st *request)
{
struct ovcp_response_st *response;
- struct statvfs vfsinfo;
-
+ struct statvfs64 vfsinfo;
+
if(statvfs(global_settings.root_dir, &vfsinfo) == -1)
return ovcp_response_error(OVCP_ERROR_UNABLSPACE, "node.get_space: "OVCP_ERROR_UNABLSPACE_DESC);
-
+
response = ovcp_response_new();
-
+
ovcp_response_struct_new(response);
-
+
ovcp_response_struct_add_int(response, "space_total", vfsinfo.f_blocks/1024*vfsinfo.f_bsize);
ovcp_response_struct_add_int(response, "space_free", vfsinfo.f_bfree/1024*vfsinfo.f_bsize);
ovcp_response_struct_add_int(response, "inodes_total", vfsinfo.f_files);
-
+
ovcp_response_struct_end(response);
-
-
+
+
return response;
}
@@ -616,12 +616,12 @@
char *meminfo, **lines, *word;
unsigned int lcount;
int i = 0;
-
+
int memtotal = 0, memfree = 0, memcached = 0, membuffered = 0;
int swaptotal = 0, swapfree = 0;
-
+
meminfo = file_read(path);
-
+
if(meminfo == NULL)
{
response = ovcp_response_error(OVCP_ERROR_FILEMISSING, "node.get_mem: "OVCP_ERROR_FILEMISSING_DESC);
@@ -629,13 +629,13 @@
else
{
lines = split_string(meminfo, '\n', &lcount);
-
+
while(i < lcount)
{
word = strtok(lines[i], " ");
trim_string(word);
-
-
+
+
if(strcmp(word, "MemTotal:") == 0)
{
word = strtok(NULL, " ");
@@ -677,32 +677,32 @@
trim_string(word);
swapfree = atoi(word);
}
-
-
-
+
+
+
i++;
}
-
+
response = ovcp_response_new();
-
+
ovcp_response_struct_new(response);
-
+
ovcp_response_struct_add_int(response, "memtotal", memtotal);
ovcp_response_struct_add_int(response, "memfree", memfree);
ovcp_response_struct_add_int(response, "buffers", membuffered);
ovcp_response_struct_add_int(response, "cached", memcached);
ovcp_response_struct_add_int(response, "swaptotal", swaptotal);
ovcp_response_struct_add_int(response, "swapfree", swapfree);
-
+
ovcp_response_struct_end(response);
-
+
free_strings(lines, lcount);
free(meminfo);
}
-
-
+
+
return response;
}
Modified: trunk/daemon/src/set.c
===================================================================
--- trunk/daemon/src/set.c 2009-11-08 15:01:34 UTC (rev 679)
+++ trunk/daemon/src/set.c 2009-12-01 20:21:20 UTC (rev 680)
@@ -1074,19 +1074,1154 @@
{
sconcat(path, BUF_SIZE, global_settings.root_dir, "/", name, "/etc/hosts", NULL);
trim_string(ip);
+ /* OpenVCP
+ * Copyright (C) 2006 Gerrit Wyen <gerrit at t4a.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
- if(i != len)
+
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <dirent.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
+ #include <sys/vfs.h>
+ #include <sys/wait.h>
+ #include <unistd.h>
+ #include <stdarg.h>
+ #include <fcntl.h>
+
+ #include "fs.h"
+ #include "set.h"
+ #include "main.h"
+ #include "config.h"
+ #include "strings.h"
+ #include "error.h"
+ #include "filter.h"
+ #include "misc.h"
+
+ typedef unsigned int xid_t;
+ typedef unsigned int nid_t;
+ typedef unsigned int tag_t;
+
+ #include <vserver.h>
+
+ struct ovcp_response_st *set_rlimit(struct ovcp_request_st *request)
{
- hosts = concat(ip, "\t", hostname, "\t", subhostname,"\tlocalhost\n", NULL);
+ struct ovcp_response_st *response;
+ struct ovcp_data_st *arg0, *arg1, *arg2;
+ char *filepath, *limitname, *limit, *name, *dir;
+ int i = 0, ret;
+ char rlimit_name[BUF_SIZE];
+
+ struct vc_rlimit current_limit;
+
+ current_limit.hard = 0;
+ current_limit.soft = 0;
+ current_limit.min = 0;
+
+ xid_t xid;
+
+ struct vlimit_st
+ {
+ unsigned int id;
+ char *name;
+ };
+
+ struct vlimit_st rlimit_params[] =
+ {
+ {0, "cpu"},{1, "fsize"},{2, "data"}, {3, "stack"},
+ {4, "core"},{5, "rss"},{6, "nproc"},{7, "nofile"},
+ {8, "memlock"}, {9, "as"},{10, "locks"}, {-1, NULL}
+ };
+
+ arg0 = ovcp_request_get_arg(request, 0);
+ name = (char *)ovcp_data_get(arg0);
+
+ if(!ovcp_data_is_string(arg0) || name == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+ if(!vserver_exist(name))
+ return ovcp_response_error(OVCP_ERROR_VSNOTEXIST, OVCP_ERROR_VSNOTEXIST_DESC);
+
+ arg1 = ovcp_request_get_arg(request, 1);
+ limitname = (char *)ovcp_data_get(arg1);
+
+ if(!ovcp_data_is_string(arg1) || limitname == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+
+ arg2 = ovcp_request_get_arg(request, 2);
+ limit = (char *)ovcp_data_get(arg2);
+
+ if(!ovcp_data_is_string(arg2) || limit == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+
+
+ while(rlimit_params[i].name != NULL)
+ {
+ sconcat(rlimit_name, BUF_SIZE, rlimit_params[i].name, ".hard", NULL);
+
+ if(strcmp(rlimit_name, limitname) == 0)
+ break;
+
+ sconcat(rlimit_name, BUF_SIZE, rlimit_params[i].name, ".soft", NULL);
+
+ if(strcmp(rlimit_name, limitname) == 0)
+ break;
+
+ sconcat(rlimit_name, BUF_SIZE, rlimit_params[i].name, ".min", NULL);
+
+ if(strcmp(rlimit_name, limitname) == 0)
+ break;
+
+ i++;
+ }
+
+ if(rlimit_params[i].name == NULL)
+ return ovcp_response_error(OVCP_ERROR_WRONGRLIMIT, "set_rlimit: "OVCP_ERROR_WRONGRLIMIT_DESC);
+
+
+
+ xid = vserver_xid(name);
+
+
+ if((ret = vc_get_rlimit (xid, rlimit_params[i].id, ¤t_limit)) != -1)
+ {
+
+ if(strcmp(rlimit_name+strlen(rlimit_name)-4, "hard") == 0)
+ {
+ ovcp_log(OVCP_DEBUG, "Current HARD: %X", (unsigned int)current_limit.hard);
+ current_limit.hard = atoi(limit);
+ }
+ else
+ if(strcmp(rlimit_name+strlen(rlimit_name)-4, "soft") == 0)
+ {
+ ovcp_log(OVCP_DEBUG, "Current SOFT: %X", (unsigned int)current_limit.soft);
+ current_limit.soft = atoi(limit);
+ }
+ else
+ if(strcmp(rlimit_name+strlen(rlimit_name)-3, "min") == 0)
+ {
+ ovcp_log(OVCP_DEBUG, "Current MIN: %X", (unsigned int)current_limit.min);
+ current_limit.min = atoi(limit);
+ }
+
+ vc_set_rlimit (xid, rlimit_params[i].id, ¤t_limit);
+ }
+
+
+ response = ovcp_response_new();
+
+
+ dir = concat(global_settings.config_dir, "/", name, "/rlimits", NULL);
+ filepath = concat(dir, "/", limitname, NULL);
+
+ if(!dir_exist(dir))
+ mkdir(dir, 0755);
+
+
+ if(strcmp(limit, "0") == 0)
+ {
+ if (file_exist(filepath))
+ unlink(filepath);
+ }
+ else
+ {
+ file_write_many(filepath, limit, "\n", NULL);
+ }
+
+ ovcp_response_add_boolean(response, TRUE);
+
+ free(filepath);
+ free(dir);
+
+ return response;
}
+
+
+ struct ovcp_response_st *set_filter(struct ovcp_request_st *request)
+ {
+ struct ovcp_response_st *response;
+ int i=0, ips_num;
+ struct ovcp_ipt_rule rule;
+ struct ovcp_data_st *arg0, *arg1, *struct_element;
+ char *name, *value, **ips;
+
+
+ char *filter_params[] = {"direction", "proto", "srcip",
+ "srcport", "destip", "destport",
+ "target", "match", "match-value",
+ NULL};
+
+
+ memset(&rule, 0, sizeof(struct ovcp_ipt_rule));
+ rule.srcport = -1;
+ rule.destport = -1;
+
+ arg0 = ovcp_request_get_arg(request, 0);
+ name = (char *)ovcp_data_get(arg0);
+
+ if(!ovcp_data_is_string(arg0) || name == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+ if(!vserver_exist(name))
+ return ovcp_response_error(OVCP_ERROR_VSNOTEXIST, OVCP_ERROR_VSNOTEXIST_DESC);
+
+
+ arg1 = ovcp_request_get_arg(request, 1);
+
+
+ if(ovcp_data_is_struct(arg1))
+ {
+ while(filter_params[i] != NULL)
+ {
+ struct_element = ovcp_struct_get_element(arg1, filter_params[i]);
+
+ if(struct_element != NULL)
+ {
+ if(ovcp_data_is_string(struct_element))
+ {
+ value = ovcp_data_get(struct_element);
+
+ if(strcmp("direction", filter_params[i]) == 0)
+ {
+ if(strcmp("INPUT", value) == 0)
+ {
+ rule.direction = IPT_DIRECTION_IN;
+ }
+ else
+ {
+ rule.direction = IPT_DIRECTION_OUT;
+ }
+
+ }
+ else
+ if(strcmp("proto", filter_params[i]) == 0)
+ {
+ if(strcmp("tcp", value) == 0)
+ {
+ rule.proto = IPT_PROTO_TCP;
+ }
+ else if(strcmp("udp", value) == 0)
+ {
+ rule.proto = IPT_PROTO_UDP;
+ }
+ else
+ {
+ rule.proto = IPT_PROTO_ICMP;
+ }
+ }
+ else
+ if(strcmp("srcip", filter_params[i]) == 0)
+ {
+ rule.srcip = value;
+ }
+ else
+ if(strcmp("srcport", filter_params[i]) == 0)
+ {
+ rule.srcport = atoi(value);
+ }
+ else
+ if(strcmp("destip", filter_params[i]) == 0)
+ {
+ rule.destip = value;
+ }
+ else
+ if(strcmp("destport", filter_params[i]) == 0)
+ {
+ rule.destport = atoi(value);
+ }
+ else
+ if(strcmp("target", filter_params[i]) == 0)
+ {
+ if(strcmp("DROP", value) == 0)
+ {
+ rule.target = IPT_TARGET_DROP;
+ }
+ else if(strcmp("REJECT", value) == 0)
+ {
+ rule.target = IPT_TARGET_REJECT;
+ }
+ else
+ {
+ rule.target = IPT_TARGET_ACCEPT;
+ }
+ }
+ else
+ if(strcmp("match", filter_params[i]) == 0)
+ {
+
+ if(strcmp("LIMIT", value) == 0)
+ {
+ rule.match = IPT_MATCH_LIMIT;
+ }
+ else if(strcmp("ICMP", value) == 0)
+ {
+ rule.match = IPT_MATCH_ICMP;
+ }
+ else
+ {
+ rule.match = IPT_MATCH_STATE;
+ }
+ }
+ else
+ if(strcmp("match-value", filter_params[i]) == 0)
+ {
+
+ rule.match_value = 0;
+
+ if(rule.match == IPT_MATCH_STATE)
+ {
+ if(strstr(value, "ESTABLISHED"))
+ {
+ rule.match_value = rule.match_value ^ IPT_STATE_ESTABLISHED;
+ }
+ if(strstr(value, "NEW"))
+ {
+ rule.match_value = rule.match_value ^ IPT_STATE_NEW;
+ }
+ if(strstr(value, "RELATED"))
+ {
+ rule.match_value = rule.match_value ^ IPT_STATE_RELATED;
+ }
+ }
+ else
+ {
+ rule.match_value = atoi(value);
+ }
+ printf("Match Value: %d", rule.match_value);
+ }
+
+ }
+ else
+ {
+ response = ovcp_response_error(OVCP_ERROR_WRONGTYPE,
+ "vserver.set_rule: "OVCP_ERROR_WRONGTYPE_DESC);
+ break;
+ }
+ }
+
+ i++;
+ }
+
+ }
+ else
+ {
+ response = ovcp_response_error(OVCP_ERROR_WRONGTYPE,
+ "vserver.set_rule: "OVCP_ERROR_WRONGTYPE_DESC);
+ }
+
+
+ ips = parse_ips(name, &ips_num);
+
+
+
+ i=0;
+ while(i < ips_num)
+ {
+ if(rule.srcip != NULL && strcmp(ips[i], rule.srcip) == 0)
+ break;
+ if(rule.destip != NULL && strcmp(ips[i], rule.destip) == 0)
+ break;
+ i++;
+ }
+
+ free_strings(ips, ips_num);
+
+ if((rule.srcip == NULL && rule.destip == NULL) || i == ips_num)
+ {
+ response = ovcp_response_error(OVCP_ERROR_RULENPERM,
+ "vserver.set_rule: "OVCP_ERROR_RULENPERM_DESC);
+ }
+ else
+ {
+ ovcp_iptable_rule(&rule);
+ ovcp_store_rule(name, rule);
+
+ response = ovcp_response_new();
+ ovcp_response_add_boolean(response, TRUE);
+ }
+
+ return response;
+ }
+
+ struct ovcp_response_st *del_filter(struct ovcp_request_st *request)
+ {
+ struct ovcp_response_st *response;
+ struct ovcp_data_st *arg0, *arg1;
+ char *name, *id, *sql_error;
+ char sql_query[BUF_SIZE];
+ int ret;
+
+ arg0 = ovcp_request_get_arg(request, 0);
+ name = (char *)ovcp_data_get(arg0);
+
+ if(!ovcp_data_is_string(arg0) || name == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+ if(!vserver_exist(name))
+ return ovcp_response_error(OVCP_ERROR_VSNOTEXIST, OVCP_ERROR_VSNOTEXIST_DESC);
+
+ arg1 = ovcp_request_get_arg(request, 1);
+ id = (char *)ovcp_data_get(arg1);
+
+ if(!ovcp_data_is_string(arg1) || id == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+
+
+
+ snprintf(sql_query, BUF_SIZE, "DELETE FROM iptable_rules where name='%s' and id=%d", name, atoi(id));
+
+ ret = sqlite3_exec(ovcp_db, sql_query, NULL, 0, &sql_error);
+
+ if(ret != SQLITE_OK)
+ {
+ ovcp_log(OVCP_ERROR, "SQL error (%s)", sql_error);
+ sqlite3_free(sql_error);
+ return NULL;
+ }
+
+ ovcp_create_tables(ovcp_db);
+
+
+ response = ovcp_response_new();
+ ovcp_response_add_boolean(response, TRUE);
+
+
+ return response;
+ }
+
+
+ struct ovcp_response_st *set_flag_add(struct ovcp_request_st *request)
+ {
+ struct ovcp_response_st *response;
+ struct ovcp_data_st *arg0, *arg1;
+ char *filepath, *flag, *name;
+
+
+ arg0 = ovcp_request_get_arg(request, 0);
+ name = (char *)ovcp_data_get(arg0);
+
+ if(!ovcp_data_is_string(arg0) || name == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+ if(!vserver_exist(name))
+ return ovcp_response_error(OVCP_ERROR_VSNOTEXIST, OVCP_ERROR_VSNOTEXIST_DESC);
+
+ arg1 = ovcp_request_get_arg(request, 1);
+ flag = (char *)ovcp_data_get(arg1);
+ string_toupper(flag);
+
+ if(!ovcp_data_is_string(arg1) || flag == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+
+ response = ovcp_response_new();
+
+
+ filepath = concat(global_settings.config_dir, "/", name, "/cflags", NULL);
+
+ file_attach(filepath, flag);
+ file_attach(filepath, "\n");
+
+ ovcp_response_add_boolean(response, TRUE);
+
+ free(filepath);
+
+
+ return response;
+ }
+
+ struct ovcp_response_st *set_flag_remove(struct ovcp_request_st *request)
+ {
+ struct ovcp_response_st *response;
+ struct ovcp_data_st *arg0, *arg1;
+ char *filepath, *flagfile, *flag, *p, *name;
+ int flagfile_fd, ret;
+
+
+ arg0 = ovcp_request_get_arg(request, 0);
+ name = (char *)ovcp_data_get(arg0);
+
+ if(!ovcp_data_is_string(arg0) || name == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+ if(!vserver_exist(name))
+ return ovcp_response_error(OVCP_ERROR_VSNOTEXIST, OVCP_ERROR_VSNOTEXIST_DESC);
+
+ arg1 = ovcp_request_get_arg(request, 1);
+ flag = (char *)ovcp_data_get(arg1);
+
+ if(!ovcp_data_is_string(arg1) || flag == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+
+
+
+ filepath = concat(global_settings.config_dir, "/", name, "/cflags", NULL);
+ flagfile = file_read(filepath);
+
+ flagfile_fd = open(filepath, O_CREAT | O_TRUNC | O_WRONLY, 0644);
+
+ if(flagfile_fd != -1 && flagfile != NULL)
+ {
+ p = strstr(flagfile, flag);
+ if(p != NULL)
+ {
+ ret = write(flagfile_fd, flagfile, p-flagfile);
+ ret = write(flagfile_fd, p+strlen(flag)+1, strlen(p+strlen(flag)+1));
+
+ response = ovcp_response_new();
+ ovcp_response_add_boolean(response, TRUE);
+
+ }
+ else
+ {
+ response = ovcp_response_error(OVCP_ERROR_FLAGNFOUND,
+ "vserver.remove_flag: "OVCP_ERROR_FLAGNFOUND_DESC);
+ ret = write(flagfile_fd, flagfile, strlen(flagfile));
+ }
+
+ }
+ else
+ {
+ response = ovcp_response_error(OVCP_ERROR_FILEMISSING,
+ "vserver.remove_flag: "OVCP_ERROR_FILEMISSING_DESC);
+ }
+
+
+ if(flagfile != NULL) free(flagfile);
+ free(filepath);
+
+
+
+ return response;
+ }
+
+
+ struct ovcp_response_st *set_mark(struct ovcp_request_st *request)
+ {
+ struct ovcp_response_st *response = NULL;
+ struct ovcp_data_st *arg0, *arg1;
+ char path[BUF_SIZE], *name;
+ int *value;
+
+ arg0 = ovcp_request_get_arg(request, 0);
+ name = (char *)ovcp_data_get(arg0);
+
+ if(!ovcp_data_is_string(arg0) || name == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+ if(!vserver_exist(name))
+ return ovcp_response_error(OVCP_ERROR_VSNOTEXIST, OVCP_ERROR_VSNOTEXIST_DESC);
+
+ arg1 = ovcp_request_get_arg(request, 1);
+ value = (int *)ovcp_data_get(arg1);
+
+ if(!ovcp_data_is_boolean(arg1))
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+
+
+ sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name,"/apps/", NULL);
+
+ if(!dir_exist(path))
+ mkdir(path, 0755);
+
+ sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name,"/apps/init/", NULL);
+
+ if(!dir_exist(path))
+ mkdir(path, 0755);
+
+
+
+ sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name,"/apps/init/mark", NULL);
+
+
+ response = ovcp_response_new();
+
+ if(*value == 1)
+ {
+
+ if(file_write(path, "default\n") != -1)
+ ovcp_response_add_boolean(response, TRUE);
+ else
+ ovcp_response_add_boolean(response, FALSE);
+ }
+ else
+ {
+
+ if(unlink(path) != -1)
+ ovcp_response_add_boolean(response, TRUE);
+ else
+ ovcp_response_add_boolean(response, FALSE);
+ }
+
+
+
+ return response;
+ }
+
+
+ struct ovcp_response_st *set_schedule(struct ovcp_request_st *request)
+ {
+ struct ovcp_response_st *response = NULL;
+ struct ovcp_data_st *arg0, *arg1, *struct_element;
+ char filepath[BUF_SIZE], *value, *name;
+ int i = 0;
+
+ char *sched_params[] = {"fill-rate", "fill-rate2",
+ "interval", "interval2",
+ "priority-bias", "tokens",
+ "tokens-max", "tokens-min",
+ "idle-time", NULL};
+
+
+ arg0 = ovcp_request_get_arg(request, 0);
+ name = (char *)ovcp_data_get(arg0);
+
+ if(!ovcp_data_is_string(arg0) || name == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+ if(!vserver_exist(name))
+ return ovcp_response_error(OVCP_ERROR_VSNOTEXIST, OVCP_ERROR_VSNOTEXIST_DESC);
+
+ sconcat(filepath, BUF_SIZE, global_settings.config_dir, "/", name, "/sched/", NULL);
+ if(!dir_exist(filepath))
+ mkdir(filepath, 0755);
+
+
+ arg1 = ovcp_request_get_arg(request, 1);
+
+
+ if(ovcp_data_is_struct(arg1))
+ {
+ while(sched_params[i] != NULL)
+ {
+ struct_element = ovcp_struct_get_element(arg1, sched_params[i]);
+
+ if(struct_element != NULL)
+ {
+ if(ovcp_data_is_string(struct_element))
+ {
+ value = ovcp_data_get(struct_element);
+ sconcat(filepath, BUF_SIZE, global_settings.config_dir, "/", name, "/sched/", sched_params[i], NULL);
+
+ file_write_many(filepath, value, "\n", NULL);
+ }
+ else
+ {
+ response = ovcp_response_error(OVCP_ERROR_WRONGTYPE,
+ "vserver.set_schedule: "OVCP_ERROR_WRONGTYPE_DESC);
+ break;
+ }
+ }
+
+ i++;
+ }
+
+ }
+ else
+ {
+ response = ovcp_response_error(OVCP_ERROR_WRONGTYPE,
+ "vserver.set_schedule: "OVCP_ERROR_WRONGTYPE_DESC);
+ }
+
+
+ if(response == NULL)
+ {
+ response = ovcp_response_new();
+ ovcp_response_add_boolean(response, TRUE);
+ }
+
+
+
+ return response;
+ }
+
+
+
+ struct ovcp_response_st *add_ip(struct ovcp_request_st *request)
+ {
+ struct ovcp_response_st *response = NULL;
+ struct ovcp_data_st *arg0, *arg1, *struct_element, *struct_member;
+ char path[BUF_SIZE], *name, *value;
+ int i = 0, iface_id = 0;
+
+ char *iface_params[] = { "bcast", "dev", "disabled", "ip",
+ "mask", "name", "nodev", "novlandev",
+ "prefix", "scope", "vlandev", "tun",
+ "tap", "linktype", "nocsum", "shared", NULL };
+
+
+
+ arg0 = ovcp_request_get_arg(request, 0);
+ name = (char *)ovcp_data_get(arg0);
+
+ if(!ovcp_data_is_string(arg0) || name == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+ if(!vserver_exist(name))
+ return ovcp_response_error(OVCP_ERROR_VSNOTEXIST, OVCP_ERROR_VSNOTEXIST_DESC);
+
+ arg1 = ovcp_request_get_arg(request, 1);
+
+ snprintf(path, BUF_SIZE, "%s/%s/interfaces", global_settings.config_dir, name);
+ if(!dir_exist(path))
+ {
+ if(mkdir(path, 0755) != 0)
+ return ovcp_response_error(OVCP_ERROR_DIRNCREATED,
+ "vserver.add_ip: "OVCP_ERROR_DIRNCREATED_DESC);
+ }
+
+ if(ovcp_data_is_struct(arg1))
+ {
+
+ snprintf(path, BUF_SIZE, "%s/%s/interfaces/%d", global_settings.config_dir, name, i);
+
+ while(dir_exist(path))
+ {
+ i++;
+ snprintf(path, BUF_SIZE, "%s/%s/interfaces/%d", global_settings.config_dir, name, i);
+ }
+
+ iface_id = i;
+
+ if(mkdir(path, 0755) != 0)
+ return ovcp_response_error(OVCP_ERROR_DIRNCREATED,
+ "vserver.add_ip: "OVCP_ERROR_DIRNCREATED_DESC);
+
+ i = 0;
+
+ while(iface_params[i] != NULL)
+ {
+ struct_member = ovcp_struct_get_member(arg1, iface_params[i]);
+
+ if(struct_member != NULL)
+ {
+
+ struct_element = ovcp_member_get(struct_member);
+
+ snprintf(path, BUF_SIZE, "%s/%s/interfaces/%d/%s", global_settings.config_dir, name, iface_id, iface_params[i]);
+
+ if(ovcp_data_is_string(struct_element))
+ {
+ value = ovcp_data_get(struct_element);
+ file_write_many(path, value, "\n", NULL);
+ }
+ else
+ {
+ file_touch(path);
+ }
+
+ }
+
+ i++;
+ }
+ }
+ else
+ {
+ response = ovcp_response_error(OVCP_ERROR_WRONGTYPE,
+ "vserver.add_ip: "OVCP_ERROR_WRONGTYPE_DESC);
+ }
+
+
+ if(response == NULL)
+ {
+ response = ovcp_response_new();
+ ovcp_response_add_int(response, iface_id);
+ }
+
+
+
+ return response;
+ }
+
+
+
+ struct ovcp_response_st *remove_ip(struct ovcp_request_st *request)
+ {
+ struct ovcp_response_st *response = NULL;
+ struct ovcp_data_st *arg0, *arg1;
+ char path[BUF_SIZE], *name, *iface_id;
+
+
+
+ arg0 = ovcp_request_get_arg(request, 0);
+ name = (char *)ovcp_data_get(arg0);
+
+ if(!ovcp_data_is_string(arg0) || name == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+ if(!vserver_exist(name))
+ return ovcp_response_error(OVCP_ERROR_VSNOTEXIST, OVCP_ERROR_VSNOTEXIST_DESC);
+
+ arg1 = ovcp_request_get_arg(request, 1);
+ iface_id = (char *)ovcp_data_get(arg1);
+
+ if(!ovcp_data_is_string(arg1) || iface_id == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+
+
+ sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name, "/interfaces/", iface_id, NULL);
+
+ if(dir_exist(path))
+ {
+ dir_remove(path);
+ response = ovcp_response_new();
+ ovcp_response_add_boolean(response, TRUE);
+ }
+ else
+ {
+ response = ovcp_response_error(OVCP_ERROR_IFACENEXIST,
+ "vserver.remove_ip: "OVCP_ERROR_IFACENEXIST_DESC);
+ }
+
+ return response;
+
+
+ }
+
+
+ struct ovcp_response_st *set_space(struct ovcp_request_st *request)
+ {
+ struct ovcp_response_st *response = NULL;
+ struct ovcp_data_st *arg0, *arg1, *struct_element;
+ char path[BUF_SIZE+1], *name;
+ char *directory, *space_total, *inodes_total, *reserved;
+ char *pathoflimit, *limit_id = NULL;
+ int i;
+
+ DIR *dlimitdir;
+ struct dirent *dlimitentry;
+
+ arg0 = ovcp_request_get_arg(request, 0);
+ name = (char *)ovcp_data_get(arg0);
+
+ if(!ovcp_data_is_string(arg0) || name == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+ if(!vserver_exist(name))
+ return ovcp_response_error(OVCP_ERROR_VSNOTEXIST, OVCP_ERROR_VSNOTEXIST_DESC);
+
+
+ arg1 = ovcp_request_get_arg(request, 1);
+
+ if(!ovcp_data_is_struct(arg1))
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+
+
+ struct_element = ovcp_struct_get_element(arg1, "directory");
+
+ if(struct_element != NULL && ovcp_data_is_string(struct_element))
+ directory = (char *)ovcp_data_get(struct_element);
+ else
+ return ovcp_response_error(OVCP_ERROR_ARGMISS,
+ "vserver.set_space: "OVCP_ERROR_ARGMISS_DESC);
+
+ if(directory[0] != '/')
+ return ovcp_response_error(OVCP_ERROR_DIRNOSLASH,
+ "vserver.set_space: "OVCP_ERROR_DIRNOSLASH_DESC);
+
+ struct_element = ovcp_struct_get_element(arg1, "space_total");
+
+ if(struct_element != NULL && ovcp_data_is_string(struct_element))
+ space_total = (char *)ovcp_data_get(struct_element);
+ else
+ return ovcp_response_error(OVCP_ERROR_ARGMISS,
+ "vserver.set_space: "OVCP_ERROR_ARGMISS_DESC);
+
+
+ struct_element = ovcp_struct_get_element(arg1, "inodes_total");
+
+ if(struct_element != NULL && ovcp_data_is_string(struct_element))
+ inodes_total = (char *)ovcp_data_get(struct_element);
+ else
+ return ovcp_response_error(OVCP_ERROR_ARGMISS,
+ "vserver.set_space: "OVCP_ERROR_ARGMISS_DESC);
+
+
+
+ struct_element = ovcp_struct_get_element(arg1, "reserved");
+
+ if(struct_element != NULL && ovcp_data_is_string(struct_element))
+ reserved = (char *)ovcp_data_get(struct_element);
+ else
+ return ovcp_response_error(OVCP_ERROR_ARGMISS,
+ "vserver.set_space: "OVCP_ERROR_ARGMISS_DESC);
+
+
+
+ sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name, "/dlimits", NULL);
+
+ if(!dir_exist(path))
+ mkdir(path, 0755);
+
+
+ directory = concat(global_settings.root_dir, "/", name, directory, NULL);
+ trim_slashes(directory);
+
+ dlimitdir = opendir(path);
+
+ while((dlimitentry = readdir(dlimitdir)) != NULL)
+ {
+ if(dlimitentry->d_name[0] == '.')
+ continue;
+
+ sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name, "/dlimits/", dlimitentry->d_name, "/directory", NULL);
+ pathoflimit = file_read(path);
+
+ if(pathoflimit == NULL)
+ continue;
+
+ trim_string(pathoflimit);
+ trim_slashes(pathoflimit);
+
+
+ if(strcmp(pathoflimit, directory) == 0)
+ {
+ free(pathoflimit);
+ limit_id = strdup(dlimitentry->d_name);
+ break;
+ }
+
+ free(pathoflimit);
+ }
+
+ if(limit_id == NULL)
+ {
+ i = 0;
+
+ do
+ {
+ sprintf(path, "%s/%s/dlimits/%d", global_settings.config_dir, name, i);
+ i++;
+ }
+ while(dir_exist(path));
+
+ limit_id = dec2str(i-1);
+ }
+ closedir(dlimitdir);
+
+
+ sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name, "/dlimits/", limit_id, NULL);
+
+ if(!dir_exist(path))
+ {
+ mkdir(path, 0755);
+ }
+ else
+ {
+
+ if(atoi(space_total) == 0)
+ {
+ dir_remove(path);
+
+ response = ovcp_response_new();
+ ovcp_response_add_boolean(response, TRUE);
+
+ free(directory);
+ free(limit_id);
+
+ return response;
+ }
+ }
+
+ sconcat(path, BUF_SIZE,global_settings.config_dir, "/", name, "/dlimits/", limit_id, "/directory", NULL);
+ file_write_many(path, directory, "\n", NULL);
+
+ sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name, "/dlimits/", limit_id, "/space_total", NULL);
+ file_write_many(path, space_total, "\n", NULL);
+
+ sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name, "/dlimits/", limit_id, "/inodes_total", NULL);
+ file_write_many(path, inodes_total, "\n", NULL);
+
+ sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name, "/dlimits/", limit_id, "/reserved", NULL);
+ file_write_many(path, reserved, "\n", NULL);
+
+
+
+ response = ovcp_response_new();
+ ovcp_response_add_boolean(response, TRUE);
+
+ free(directory);
+ free(limit_id);
+
+ return response;
+ }
+
+ struct ovcp_response_st *set_rootpw(struct ovcp_request_st *request)
+ {
+ struct ovcp_response_st *response = NULL;
+ struct ovcp_data_st *arg0, *arg1;
+ char *name, *pw;
+ char cmd[BUF_SIZE];
+ FILE *cmdp;
+
+ arg0 = ovcp_request_get_arg(request, 0);
+ name = (char *)ovcp_data_get(arg0);
+
+ if(!ovcp_data_is_string(arg0) || name == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+ if(!vserver_exist(name))
+ return ovcp_response_error(OVCP_ERROR_VSNOTEXIST, OVCP_ERROR_VSNOTEXIST_DESC);
+
+ arg1 = ovcp_request_get_arg(request, 1);
+ pw = (char *)ovcp_data_get(arg1);
+
+ if(!ovcp_data_is_string(arg1) || pw == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+
+
+ snprintf(cmd, BUF_SIZE, "vserver %s exec chpasswd", name);
+
+ cmdp = popen(cmd, "w");
+
+ if(cmdp != NULL)
+ {
+ fprintf(cmdp, "root:%s\n", pw);
+ pclose(cmdp);
+
+ response = ovcp_response_new();
+ ovcp_response_add_boolean(response, TRUE);
+ }
+ else
+ {
+ response = ovcp_response_error(OVCP_ERROR_CODNSETPW,
+ "vserver.set_rootpw: "OVCP_ERROR_CODNSETPW_DESC);
+ }
+
+
+
+ return response;
+ }
+
+
+
+ struct ovcp_response_st *set_hostname(struct ovcp_request_st *request)
+ {
+ struct ovcp_response_st *response = NULL;
+ struct ovcp_data_st *arg0, *arg1, *arg2;
+ char path[BUF_SIZE+1], subhostname[BUF_SIZE+1];
+ char *ip = NULL, *hosts, *hostname, *name;
+ int i = 0, len;
+
+
+
+ arg0 = ovcp_request_get_arg(request, 0);
+ name = (char *)ovcp_data_get(arg0);
+
+ if(!ovcp_data_is_string(arg0) || name == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+ if(!vserver_exist(name))
+ return ovcp_response_error(OVCP_ERROR_VSNOTEXIST, OVCP_ERROR_VSNOTEXIST_DESC);
+
+ arg1 = ovcp_request_get_arg(request, 1);
+ hostname = (char *)ovcp_data_get(arg1);
+
+ if(!ovcp_data_is_string(arg1) || hostname == NULL)
+ return ovcp_response_error(OVCP_ERROR_ARGMISS, OVCP_ERROR_ARGMISS_DESC);
+
+ arg2 = ovcp_request_get_arg(request, 2);
+
+ if(ovcp_data_is_string(arg2))
+ {
+ ip = (char *)ovcp_data_get(arg2);
+ }
+ else
+ {
+ sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name, "/interfaces/0/ip", NULL);
+ ip = file_read(path);
+ }
+
+ len = strlen(hostname);
+
+ while(hostname[i] != '.' && i < len && i < BUF_SIZE)
+ {
+ subhostname[i] = hostname[i];
+ i++;
+ }
+
+ subhostname[i] = 0;
+
+
+ if(ip != NULL)
+ {
+ sconcat(path, BUF_SIZE, global_settings.root_dir, "/", name, "/etc/hosts", NULL);
+ trim_string(ip);
+
+ if(kernel_vci_version <= 0x20200)
+ {
+ if(i != len)
+ {
+ hosts = concat("# Warning this file is changed when set hostname is called from openvcp webinterface #\n", ip, "\t", hostname, "\t", subhostname,"\tlocalhost\n", NULL);
+ }
+ else
+ {
+ hosts = concat("# Warning this file is changed when set hostname is called from openvcp webinterface #\n", ip, "\t", hostname,"\tlocalhost\n", NULL);
+ }
+ }
+ else
+ {
+ if(i != len)
+ {
+ hosts = concat("# Warning this file is changed when set hostname is called from openvcp webinterface #\n", ip, "\t", hostname, "\t", subhostname,"\n127.0.0.1\tlocalhost.localdomain\tlocalhost\n", NULL);
+ }
+ else
+ {
+ hosts = concat("# Warning this file is changed when set hostname is called from openvcp webinterface #\n", ip, "\t", hostname,"\n127.0.0.1\tlocalhost.localdomain\tlocalhost\n", NULL);
+ }
+ }
+
+ file_write(path, hosts);
+
+ free(ip);
+ free(hosts);
+ }
+
+ sconcat(path, BUF_SIZE, global_settings.root_dir, "/", name,"/etc/hostname", NULL);
+ file_write(path, subhostname); file_attach(path, "\n");
+
+ sconcat(path, BUF_SIZE, global_settings.config_dir, "/", name,"/uts/nodename", NULL);
+ file_write(path, hostname); file_attach(path, "\n");
+
+
+ response = ovcp_response_new();
+ ovcp_response_add_boolean(response, TRUE);
+
+
+ return response;
+ }
+
+
+ if(kernel_vci_version <= 0x20200)
+ {
+ if(i != len)
+ {
+ hosts = concat("# Warning this file is changed when set hostname is called from openvcp webinterface #\n", ip, "\t", hostname, "\t", subhostname,"\tlocalhost\n", NULL);
+ }
+ else
+ {
+ hosts = concat("# Warning this file is changed when set hostname is called from openvcp webinterface #\n", ip, "\t", hostname,"\tlocalhost\n", NULL);
+ }
+ }
else
{
- hosts = concat(ip, "\t", hostname,"\tlocalhost\n", NULL);
+ if(i != len)
+ {
+ hosts = concat("# Warning this file is changed when set hostname is called from openvcp webinterface #\n", ip, "\t", hostname, "\t", subhostname,"\n127.0.0.1\tlocalhost.localdomain\tlocalhost\n", NULL);
+ }
+ else
+ {
+ hosts = concat("# Warning this file is changed when set hostname is called from openvcp webinterface #\n", ip, "\t", hostname,"\n127.0.0.1\tlocalhost.localdomain\tlocalhost\n", NULL);
+ }
}
file_write(path, hosts);
- free(ip); free(hosts);
+ free(ip);
+ free(hosts);
}
sconcat(path, BUF_SIZE, global_settings.root_dir, "/", name,"/etc/hostname", NULL);
More information about the Commits
mailing list