-
Notifications
You must be signed in to change notification settings - Fork 0
/
clonosdb
executable file
·161 lines (141 loc) · 8 KB
/
clonosdb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/local/bin/cbsd
MYARG=""
MYOPTARG=""
MYDESC="Generate/reset initial DB for ClonOS"
CBSDMODULE="clonos"
ADDHELP="
${H3_COLOR}Description${N0_COLOR}:
Generate initial ClonOS db.
${H3_COLOR}Options${N0_COLOR}:
${H3_COLOR}Examples${N0_COLOR}:
# cbsd clonosdb
"
. ${subrdir}/nc.subr
. ${system}
. ${strings}
. ${tools}
. ${cbsdinit}
MYPATH="${distmoduledir}/clonosdb.d"
DBFILE="/var/db/clonos/clonos.sqlite"
SALT_FILE="/var/db/clonos/salt"
if [ ! -r ${SALT_FILE} ]; then
# ZNINkHErdLQ0JjfhnkdTP33KXL4Sh2RaVJ6qF9lE
# hz165sD+NPlXhqCeGV233jzNIdWNHRApD2y7nNAN
SALT=$( random_password_gen -l 40 )
echo ${SALT} > ${SALT_FILE}
${CHMOD_CMD} 0440 ${SALT_FILE}
${CHOWN_CMD} www:cbsd ${SALT_FILE}
fi
# sys_helpers_list, jails_helper_wl
/usr/local/bin/cbsd ${miscdir}/updatesql ${DBFILE} ${MYPATH}/sys_helpers_list.schema sys_helpers_list
/usr/local/bin/cbsd ${miscdir}/updatesql ${DBFILE} ${MYPATH}/sys_helpers_list.schema jails_helpers_list
/usr/local/bin/cbsd ${miscdir}/updatesql ${DBFILE} ${MYPATH}/auth_user.schema auth_user
/usr/local/bin/cbsd ${miscdir}/updatesql ${DBFILE} ${MYPATH}/auth_list.schema auth_list
${SQLITE3_CMD} ${DBFILE} << EOF
BEGIN TRANSACTION;
DELETE FROM sys_helpers_list;
INSERT INTO sys_helpers_list ( module ) VALUES ( 'elasticsearch' );
INSERT INTO sys_helpers_list ( module ) VALUES ( 'memcached' );
INSERT INTO sys_helpers_list ( module ) VALUES ( 'php' );
INSERT INTO sys_helpers_list ( module ) VALUES ( 'postgresql' );
INSERT INTO sys_helpers_list ( module ) VALUES ( 'prometheus' );
INSERT INTO sys_helpers_list ( module ) VALUES ( 'rabbitmq' );
INSERT INTO sys_helpers_list ( module ) VALUES ( 'redis' );
INSERT INTO sys_helpers_list ( module ) VALUES ( 'rtorrent' );
COMMIT;
BEGIN TRANSACTION;
DELETE FROM jails_helpers_list;
INSERT INTO jails_helpers_list ( module ) VALUES ( 'elasticsearch' );
INSERT INTO jails_helpers_list ( module ) VALUES ( 'memcached' );
INSERT INTO jails_helpers_list ( module ) VALUES ( 'php' );
INSERT INTO jails_helpers_list ( module ) VALUES ( 'postgresql' );
INSERT INTO jails_helpers_list ( module ) VALUES ( 'prometheus' );
INSERT INTO jails_helpers_list ( module ) VALUES ( 'rabbitmq' );
INSERT INTO jails_helpers_list ( module ) VALUES ( 'redis' );
INSERT INTO jails_helpers_list ( module ) VALUES ( 'rtorrent' );
COMMIT;
EOF
admin_user=$( ${SQLITE3_CMD} ${DBFILE} "SELECT username FROM auth_user WHERE username='admin' LIMIT 1" 2>/dev/null )
if [ -z "${admin_user}" ]; then
SALT=$( ${CAT_CMD} ${SALT_FILE} | ${AWK_CMD} '{printf $1}' )
${ECHO} "${N1_COLOR}${CBSD_APP}: added new admin login/password (salt: ${SALT}): ${N2_COLOR}admin/admin${N0_COLOR}"
echo ${SALT} > ${SALT_FILE}
password="admin"
hash1=$( ${SHA256_CMD} -qs "${password}" )
hash2="${hash1}${SALT}"
salted_hash=$( ${SHA256_CMD} -qs "${hash2}" )
${SQLITE3_CMD} ${DBFILE} << EOF
BEGIN TRANSACTION;
INSERT INTO auth_user ( username,password,first_name,last_name,is_active ) VALUES ( 'admin', '${salted_hash}', 'Admin', 'Admin', 1 );
COMMIT;
EOF
else
${ECHO} "${N1_COLOR}${CBSD_APP}: admin account already exist${NORMAL}"
fi
#### temporary, for test purposes only
${SQLITE3_CMD} ${DBFILE} << EOF
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS 'lang_en' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'text' TEXT, 'modify' INTEGER DEFAULT CURRENT_TIMESTAMP);
INSERT INTO lang_en VALUES(1,'Summary statistics for cloud:','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(2,'Param','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(3,'Num of nodes:','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(4,'Online nodes:','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(5,'Offline nodes:','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(6,'Num of jails:','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(7,'Num of cores:','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(8,'Average freq. Mhz:','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(9,'Summary RAM:','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(10,'Summary storage size:','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(11,'Unable to fetch net info!','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(12,'Current node CPU usage:','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(13,'Current node RAM usage:','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(14,'It is an open source and free product which powered by other project (major importance list):','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(15,'FreeBSD OS virtual environment management framework','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(16,'FreeBSD is a free and open source Unix-like operating system descended from Research Unix created in <a href="https://en.wikipedia.org/wiki/Berkeley_Software_Distribution">University of California, Berkeley, U.S.','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(17,'Puppet is an open-source configuration management tool.','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(18,'and many other..','2024-11-24 00:08:06');
INSERT INTO lang_en VALUES(19,'Can not be empty. Name must begin with a letter / a-z / and not have any special symbols: -,.=%','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(20,'This field can not be empty','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(21,'Write correct ip address, e.g: 10.0.0.2','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(22,'Password can not be less than 3 symbols','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(23,'Please retype password correctly','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(24,'Create jail','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(25,'Edit jail','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(26,'Jail Settings','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(27,'Jail name','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(28,'Hostname','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(29,'available on the jail is not running','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(30,'IP address','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(31,'Root password','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(32,'Root password (again)','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(33,'Net Interface','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(34,'Parameters','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(35,'Base writable','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(36,'Mount','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(37,'Autostart jail at system startup','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(38,'Virtual network stack (VIMAGE)','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(39,'Enabled services','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(40,'Create','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(41,'Save','2024-12-04 21:16:03');
INSERT INTO lang_en VALUES(42,'Cancel','2024-12-04 21:16:03');
CREATE TABLE IF NOT EXISTS 'lang_other' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'en_id' INTEGER, 'text' TEXT, 'lang' TEXT, 'modify' INTEGER DEFAULT CURRENT_TIMESTAMP, 'type' TEXT NOT NULL DEFAULT 'system');
INSERT INTO lang_other VALUES(1,1,'Общая статистика облака:','ru','2024-11-24 21:14:53','system');
INSERT INTO lang_other VALUES(2,2,'Параметр','ru','2024-11-24 21:16:17','system');
INSERT INTO lang_other VALUES(3,3,'Количество нод:','ru','2024-11-24 21:17:21','system');
INSERT INTO lang_other VALUES(4,27,'Имя контейнера','ru','2024-12-04 22:19:35','system');
CREATE TABLE IF NOT EXISTS 'lang_other_types' ('type' TEXT PRIMARY KEY NOT NULL, 'seq' INTEGER);
INSERT INTO lang_other_types VALUES('system',1);
INSERT INTO lang_other_types VALUES('pages',2);
INSERT INTO lang_other_types VALUES('dialogs',3);
DELETE FROM sqlite_sequence;
INSERT INTO sqlite_sequence VALUES('sys_helpers_list',8);
INSERT INTO sqlite_sequence VALUES('jails_helpers_list',8);
INSERT INTO sqlite_sequence VALUES('auth_user',1);
INSERT INTO sqlite_sequence VALUES('auth_list',4);
INSERT INTO sqlite_sequence VALUES('lang_en',42);
INSERT INTO sqlite_sequence VALUES('lang_other',4);
CREATE INDEX 'lo_ind' ON "lang_other" ("en_id", "lang");
COMMIT;
EOF
${CHOWN_CMD} www:www ${DBFILE}
exit 0