Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Guilherme Filippo
ISPConfig 3
Commits
55da9053
Commit
55da9053
authored
Nov 11, 2007
by
bpssoft
Browse files
- Add comments to system.inc.php (PEAR) and cleanup wrong tabs
- Add some functionallity to MySQL class
parent
3eeed9bd
Changes
3
Show whitespace changes
Inline
Side-by-side
TODO.txt
View file @
55da9053
...
...
@@ -73,6 +73,3 @@ General tasks
- Add, extend or modify comments in PEAR syntax so that they can be read with phpdocumentor.
- Add a function to prevent brute force password attacks to the login script. E.g. by
logging all login attempts and allowing only 5 logins every 15 minutes.
Task assigned to: BPSsoft
interface/lib/classes/db_mysql.inc.php
View file @
55da9053
...
...
@@ -217,10 +217,21 @@ class db
public
function
closeConn
()
{
if
(
$this
->
linkId
)
{
mysql_close
(
$this
->
linkId
);
return
true
;
}
else
{
return
false
;
}
}
public
function
freeResult
()
public
function
freeResult
(
$query
)
{
if
(
mysql_free_result
(
$query
))
{
return
true
;
}
else
{
return
false
;
}
}
public
function
delete
()
...
...
server/lib/classes/system.inc.php
View file @
55da9053
...
...
@@ -30,21 +30,31 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class
system
{
var
$FILE
=
"/root/ispconfig/scripts/lib/classes/ispconfig_system.lib.php"
;
var
$server_id
;
var
$server_conf
;
var
$data
;
function
system
(){
var
$FILE
=
"/root/ispconfig/scripts/lib/classes/ispconfig_system.lib.php"
;
var
$server_id
;
var
$server_conf
;
var
$data
;
/**
* Construct for this class
*
* @return system
*/
public
function
system
(){
global
$go_info
;
$this
->
server_id
=
$go_info
[
"isp"
][
"server_id"
];
$this
->
server_conf
=
$go_info
[
"isp"
][
"server_conf"
];
$this
->
server_conf
[
"passwd_datei"
]
=
'/etc/passwd'
;
$this
->
server_conf
[
"shadow_datei"
]
=
'/etc/shadow'
;
$this
->
server_conf
[
"group_datei"
]
=
'/etc/group'
;
}
}
function
hostname
(){
/**
* Get the hostname from the server
*
* @return string
*/
public
function
hostname
(){
$dist
=
$this
->
server_conf
[
"dist"
];
ob_start
();
...
...
@@ -65,9 +75,13 @@ function hostname(){
if
(
!
strstr
(
$hostname
,
$domainname
))
$hostname
.
=
"."
.
$domainname
;
}
return
$hostname
;
}
}
function
adduser
(
$user_username
,
$uid
,
$gid
,
$username
,
$homedir
,
$shell
,
$passwort
=
'*'
){
/**
* Add an user to the system
*
*/
public
function
adduser
(
$user_username
,
$uid
,
$gid
,
$username
,
$homedir
,
$shell
,
$passwort
=
'*'
){
global
$app
;
if
(
$this
->
is_user
(
$user_username
)){
return
false
;
...
...
@@ -88,7 +102,6 @@ function adduser($user_username, $uid, $gid, $username, $homedir, $shell, $passw
$new_passwd
=
"
\n
$user_username
:
$passwort
:
$uid
:
$gid
::0:0:
$username
:
$homedir
:
$shell
\n
"
;
}
$app
->
file
->
af
(
$shadow_datei
,
$new_passwd
);
// TB: leere Zeilen entfernen
$app
->
file
->
remove_blank_lines
(
$shadow_datei
);
$app
->
file
->
remove_blank_lines
(
$user_datei
);
...
...
@@ -96,24 +109,31 @@ function adduser($user_username, $uid, $gid, $username, $homedir, $shell, $passw
//$this->order_users_groups();
if
(
$shadow_datei
!=
"/etc/shadow"
){
$app
->
file
->
af
(
$shadow_datei
,
"
\n
"
);
// TB: leere Zeilen entfernen
$app
->
file
->
remove_blank_lines
(
$shadow_datei
);
$app
->
log
->
caselog
(
"pwd_mkdb
$shadow_datei
&> /dev/null"
,
$this
->
FILE
,
__LINE__
);
}
return
true
;
}
}
}
}
function
updateuser
(
$user_username
,
$uid
,
$gid
,
$username
,
$homedir
,
$shell
,
$passwort
=
'*'
){
/**
* Update users when someone edit it
*
*/
function
updateuser
(
$user_username
,
$uid
,
$gid
,
$username
,
$homedir
,
$shell
,
$passwort
=
'*'
){
//* First delete the users
$this
->
deluser
(
$user_username
);
//* Add the user again
$this
->
adduser
(
$user_username
,
$uid
,
$gid
,
$username
,
$homedir
,
$shell
,
$passwort
);
}
}
function
deactivateuser
(
$user_username
){
/**
* Lock the user
*
*/
function
deactivateuser
(
$user_username
){
$passwort
=
str_rot13
(
$this
->
getpasswd
(
$user_username
));
$user_attr
=
$this
->
get_user_attributes
(
$user_username
);
$uid
=
$user_attr
[
"uid"
];
...
...
@@ -123,9 +143,12 @@ function deactivateuser($user_username){
$shell
=
"/dev/null"
;
$this
->
deluser
(
$user_username
);
$this
->
adduser
(
$user_username
,
$uid
,
$gid
,
$username
,
$homedir
,
$shell
,
$passwort
);
}
function
deluser
(
$user_username
){
}
/**
* Delete a user from the system
*
*/
function
deluser
(
$user_username
){
global
$app
;
if
(
$this
->
is_user
(
$user_username
)){
$user_datei
=
$this
->
server_conf
[
"passwd_datei"
];
...
...
@@ -195,9 +218,13 @@ function deluser($user_username){
}
else
{
return
false
;
}
}
}
function
addgroup
(
$group
,
$gid
,
$members
=
''
){
/**
* Add a usergroup to the system
*
*/
function
addgroup
(
$group
,
$gid
,
$members
=
''
){
global
$app
;
if
(
$this
->
is_group
(
$group
)){
return
false
;
...
...
@@ -214,14 +241,22 @@ function addgroup($group, $gid, $members = ''){
}
return
true
;
}
}
}
function
updategroup
(
$group
,
$gid
,
$members
=
''
){
/**
* Update usersgroup in way to delete and add it again
*
*/
function
updategroup
(
$group
,
$gid
,
$members
=
''
){
$this
->
delgroup
(
$group
);
$this
->
addgroup
(
$group
,
$gid
,
$members
);
}
}
function
delgroup
(
$group
){
/**
* Delete a usergroup from the system
*
*/
function
delgroup
(
$group
){
global
$app
;
if
(
$this
->
is_group
(
$group
)){
$group_datei
=
$this
->
server_conf
[
"group_datei"
];
...
...
@@ -251,9 +286,12 @@ function delgroup($group){
}
else
{
return
false
;
}
}
function
order_users_groups
(){
}
/**
* Order usergroups
*
*/
function
order_users_groups
(){
global
$app
;
$user_datei
=
$this
->
server_conf
[
"passwd_datei"
];
$shadow_datei
=
$this
->
server_conf
[
"shadow_datei"
];
...
...
@@ -316,9 +354,13 @@ function order_users_groups(){
reset
(
$arr
);
$app
->
file
->
wf
(
$shadow_datei
,
$app
->
file
->
remove_blank_lines
(
implode
(
"
\n
"
,
$arr
),
0
));
unset
(
$arr
);
}
}
function
find_uid_gid
(
$min
,
$max
){
/**
* Find a user / group id
*
*/
function
find_uid_gid
(
$min
,
$max
){
global
$app
;
if
(
$min
<
$max
&&
$min
>=
0
&&
$max
>=
0
&&
$min
<=
65536
&&
$max
<=
65536
&&
is_int
(
$min
)
&&
is_int
(
$max
)){
for
(
$i
=
$min
;
$i
<=
$max
;
$i
++
){
...
...
@@ -380,9 +422,13 @@ function find_uid_gid($min, $max){
}
else
{
return
false
;
}
}
}
function
is_user
(
$user
){
/**
* Check if the users is really a user into the system
*
*/
function
is_user
(
$user
){
global
$app
;
$user_datei
=
$this
->
server_conf
[
"passwd_datei"
];
$users
=
$app
->
file
->
no_comments
(
$user_datei
);
...
...
@@ -396,9 +442,13 @@ function is_user($user){
}
}
return
false
;
}
}
function
is_group
(
$group
){
/**
* Check if the group is on this system
*
*/
function
is_group
(
$group
){
global
$app
;
$group_datei
=
$this
->
server_conf
[
"group_datei"
];
$groups
=
$app
->
file
->
no_comments
(
$group_datei
);
...
...
@@ -412,9 +462,9 @@ function is_group($group){
}
}
return
false
;
}
}
function
root_group
(){
function
root_group
(){
global
$app
;
$group_datei
=
$this
->
server_conf
[
"group_datei"
];
$groups
=
$app
->
file
->
no_comments
(
$group_datei
);
...
...
@@ -428,9 +478,13 @@ function root_group(){
}
}
return
false
;
}
}
function
get_user_groups
(
$username
){
/**
* Get the groups of an user
*
*/
function
get_user_groups
(
$username
){
global
$app
;
$user_groups
=
array
();
$group_datei
=
$this
->
server_conf
[
"group_datei"
];
...
...
@@ -450,9 +504,13 @@ function get_user_groups($username){
}
if
(
!
empty
(
$user_groups
))
return
implode
(
','
,
$user_groups
);
return
''
;
}
}
function
getpasswd
(
$user
){
/**
* Get a user password
*
*/
function
getpasswd
(
$user
){
global
$app
;
if
(
$this
->
is_user
(
$user
)){
$shadow_datei
=
$this
->
server_conf
[
"shadow_datei"
];
...
...
@@ -469,9 +527,13 @@ function getpasswd($user){
}
else
{
return
false
;
}
}
}
function
getuid
(
$user
){
/**
* Get the user id from an user
*
*/
function
getuid
(
$user
){
global
$app
;
if
(
$this
->
is_user
(
$user
)){
$user_datei
=
$this
->
server_conf
[
"passwd_datei"
];
...
...
@@ -488,9 +550,13 @@ function getuid($user){
}
else
{
return
false
;
}
}
}
function
get_user_attributes
(
$user
){
/**
* Get all information from a user
*
*/
function
get_user_attributes
(
$user
){
global
$app
;
if
(
$this
->
is_user
(
$user
)){
$user_datei
=
$this
->
server_conf
[
"passwd_datei"
];
...
...
@@ -516,9 +582,13 @@ function get_user_attributes($user){
}
else
{
return
false
;
}
}
}
function
chown
(
$file
,
$owner
,
$group
=
''
){
/**
* Edit the owner of a file
*
*/
function
chown
(
$file
,
$owner
,
$group
=
''
){
$owner_change
=
@
chown
(
$file
,
$owner
);
if
(
$group
!=
""
){
$group_change
=
@
chgrp
(
$file
,
$group
);
...
...
@@ -530,9 +600,13 @@ function chown($file, $owner, $group = ''){
}
else
{
return
false
;
}
}
}
function
add_user_to_group
(
$group
,
$user
=
'admispconfig'
){
/**
* Add an user to a specific group
*
*/
function
add_user_to_group
(
$group
,
$user
=
'admispconfig'
){
global
$app
;
$group_file
=
$app
->
file
->
rf
(
$this
->
server_conf
[
"group_datei"
]);
$group_file_lines
=
explode
(
"
\n
"
,
$group_file
);
...
...
@@ -555,9 +629,9 @@ function add_user_to_group($group, $user = 'admispconfig'){
if
(
$this
->
server_conf
[
"shadow_datei"
]
!=
"/etc/shadow"
){
$app
->
log
->
caselog
(
"pwd_mkdb "
.
$this
->
server_conf
[
"shadow_datei"
]
.
" &> /dev/null"
,
$this
->
FILE
,
__LINE__
);
}
}
}
function
usermod
(
$user
,
$groups
){
function
usermod
(
$user
,
$groups
){
global
$app
;
if
(
$this
->
is_user
(
$user
)){
$groups
=
explode
(
","
,
str_replace
(
" "
,
""
,
$groups
));
...
...
@@ -595,9 +669,12 @@ function usermod($user, $groups){
}
else
{
return
false
;
}
}
}
function
rc_edit
(
$service
,
$rl
,
$action
){
/**boot autostart etc
*
*/
function
rc_edit
(
$service
,
$rl
,
$action
){
// $action = "on|off";
global
$app
;
$dist_init_scripts
=
$app
->
system
->
server_conf
[
"dist_init_scripts"
];
...
...
@@ -649,9 +726,13 @@ function rc_edit($service, $rl, $action){
}
}
}
}
}
function
grep
(
$content
,
$string
,
$params
=
''
){
/**
* Filter information from the commands
*
*/
function
grep
(
$content
,
$string
,
$params
=
''
){
global
$app
;
// params: i, v, w
$content
=
$app
->
file
->
unix_nl
(
$content
);
...
...
@@ -695,9 +776,13 @@ function grep($content, $string, $params = ''){
}
else
{
return
false
;
}
}
}
function
cut
(
$content
,
$field
,
$delimiter
=
':'
){
/**
* Strip content from fields
*
*/
function
cut
(
$content
,
$field
,
$delimiter
=
':'
){
global
$app
;
$content
=
$app
->
file
->
unix_nl
(
$content
);
$lines
=
explode
(
"
\n
"
,
$content
);
...
...
@@ -713,15 +798,23 @@ function cut($content, $field, $delimiter = ':'){
}
else
{
return
false
;
}
}
}
function
cat
(
$file
){
/**
* Get the content off a file
*
*/
function
cat
(
$file
){
global
$app
;
return
$app
->
file
->
rf
(
$file
);
}
}
function
daemon_init
(
$daemon
,
$action
){
// $action = start|stop|restart|reload
/**
* Control services to restart etc
*
*/
function
daemon_init
(
$daemon
,
$action
){
//* $action = start|stop|restart|reload
global
$app
;
$dist
=
$this
->
server_conf
[
"dist"
];
$dist_init_scripts
=
$this
->
server_conf
[
"dist_init_scripts"
];
...
...
@@ -758,9 +851,9 @@ function daemon_init($daemon, $action){
}
}
}
}
}
function
netmask
(
$netmask
){
function
netmask
(
$netmask
){
list
(
$f1
,
$f2
,
$f3
,
$f4
)
=
explode
(
"."
,
trim
(
$netmask
));
$bin
=
str_pad
(
decbin
(
$f1
),
8
,
"0"
,
STR_PAD_LEFT
)
.
str_pad
(
decbin
(
$f2
),
8
,
"0"
,
STR_PAD_LEFT
)
.
str_pad
(
decbin
(
$f3
),
8
,
"0"
,
STR_PAD_LEFT
)
.
str_pad
(
decbin
(
$f4
),
8
,
"0"
,
STR_PAD_LEFT
);
$parts
=
explode
(
"0"
,
$bin
);
...
...
@@ -768,16 +861,16 @@ function netmask($netmask){
$bin
=
wordwrap
(
$bin
,
8
,
"."
,
1
);
list
(
$f1
,
$f2
,
$f3
,
$f4
)
=
explode
(
"."
,
trim
(
$bin
));
return
bindec
(
$f1
)
.
"."
.
bindec
(
$f2
)
.
"."
.
bindec
(
$f3
)
.
"."
.
bindec
(
$f4
);
}
}
function
binary_netmask
(
$netmask
){
function
binary_netmask
(
$netmask
){
list
(
$f1
,
$f2
,
$f3
,
$f4
)
=
explode
(
"."
,
trim
(
$netmask
));
$bin
=
str_pad
(
decbin
(
$f1
),
8
,
"0"
,
STR_PAD_LEFT
)
.
str_pad
(
decbin
(
$f2
),
8
,
"0"
,
STR_PAD_LEFT
)
.
str_pad
(
decbin
(
$f3
),
8
,
"0"
,
STR_PAD_LEFT
)
.
str_pad
(
decbin
(
$f4
),
8
,
"0"
,
STR_PAD_LEFT
);
$parts
=
explode
(
"0"
,
$bin
);
return
substr_count
(
$parts
[
0
],
"1"
);
}
}
function
network
(
$ip
,
$netmask
){
function
network
(
$ip
,
$netmask
){
$netmask
=
$this
->
netmask
(
$netmask
);
list
(
$f1
,
$f2
,
$f3
,
$f4
)
=
explode
(
"."
,
$netmask
);
$netmask_bin
=
str_pad
(
decbin
(
$f1
),
8
,
"0"
,
STR_PAD_LEFT
)
.
str_pad
(
decbin
(
$f2
),
8
,
"0"
,
STR_PAD_LEFT
)
.
str_pad
(
decbin
(
$f3
),
8
,
"0"
,
STR_PAD_LEFT
)
.
str_pad
(
decbin
(
$f4
),
8
,
"0"
,
STR_PAD_LEFT
);
...
...
@@ -789,9 +882,13 @@ function network($ip, $netmask){
$network_bin
=
wordwrap
(
$network_bin
,
8
,
"."
,
1
);
list
(
$f1
,
$f2
,
$f3
,
$f4
)
=
explode
(
"."
,
trim
(
$network_bin
));
return
bindec
(
$f1
)
.
"."
.
bindec
(
$f2
)
.
"."
.
bindec
(
$f3
)
.
"."
.
bindec
(
$f4
);
}
}
function
broadcast
(
$ip
,
$netmask
){
/**
* Make a broadcast address from an IP number in combination with netmask
*
*/
function
broadcast
(
$ip
,
$netmask
){
$netmask
=
$this
->
netmask
(
$netmask
);
$binary_netmask
=
$this
->
binary_netmask
(
$netmask
);
list
(
$f1
,
$f2
,
$f3
,
$f4
)
=
explode
(
"."
,
$ip
);
...
...
@@ -800,9 +897,13 @@ function broadcast($ip, $netmask){
$broadcast_bin
=
wordwrap
(
$broadcast_bin
,
8
,
"."
,
1
);
list
(
$f1
,
$f2
,
$f3
,
$f4
)
=
explode
(
"."
,
trim
(
$broadcast_bin
));
return
bindec
(
$f1
)
.
"."
.
bindec
(
$f2
)
.
"."
.
bindec
(
$f3
)
.
"."
.
bindec
(
$f4
);
}
}
function
network_info
(){
/**
* Get the network address information
*
*/
function
network_info
(){
$dist
=
$this
->
server_conf
[
"dist"
];
ob_start
();
passthru
(
"ifconfig"
);
...
...
@@ -822,7 +923,7 @@ function network_info(){
ob_start
();
if
(
!
strstr
(
$dist
,
"freebsd"
)){
passthru
(
"ifconfig "
.
$interface
.
" | grep -iw 'inet' | cut -f2 -d: | cut -f1 -d' '"
);
}
else
{
}
else
{
passthru
(
"ifconfig "
.
$interface
.
" | grep -iw 'inet' | grep -iv 'inet6' | cut -f2 -d' '"
);
}
$output
=
trim
(
ob_get_contents
());
...
...
@@ -840,9 +941,13 @@ function network_info(){
}
else
{
return
false
;
}
}
}
function
network_config
(){
/**
* Configure the network settings from the system
*
*/
function
network_config
(){
$ifconfig
=
$this
->
network_info
();
if
(
$ifconfig
){
$main_interface
=
$ifconfig
[
"IP"
][
$this
->
server_conf
[
"server_ip"
]];
...
...
@@ -886,9 +991,9 @@ function network_config(){
}
}
}
}
}
function
quota_dirs
(){
function
quota_dirs
(){
global
$app
;
$content
=
$app
->
file
->
unix_nl
(
$app
->
file
->
no_comments
(
"/etc/fstab"
));
$lines
=
explode
(
"
\n
"
,
$content
);
...
...
@@ -910,9 +1015,13 @@ function quota_dirs(){
}
else
{
return
false
;
}
}
}
function
make_trashscan
(){
/**
* Scan the trash for virusses infection
*
*/
function
make_trashscan
(){
global
$app
;
//trashscan erstellen
// Template ffnen
...
...
@@ -939,9 +1048,13 @@ function make_trashscan(){
exec
(
"chown admispconfig:admispconfig
$datei
&> /dev/null"
);
exec
(
"chmod 755
$datei
"
);
}
}
function
get_time
(){
/**
* Get the current time
*
*/
function
get_time
(){
$addr
=
"http://www.ispconfig.org/"
;
$timeout
=
1
;
$url_parts
=
parse_url
(
$addr
);
...
...
@@ -993,7 +1106,7 @@ function get_time(){
@
fclose
(
$urlHandle
);
return
false
;
}
}
}
}
?>
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment