account.inc.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. <?php
  2. /**
  3. * User account management
  4. *
  5. * @package siteadm
  6. */
  7. class account_manager extends db_object_manager
  8. {
  9. static protected $name = "account";
  10. }
  11. /**
  12. * User account
  13. *
  14. * @package siteadm
  15. */
  16. class account extends db_object
  17. {
  18. static protected $_name = "account";
  19. static protected $_db_table = "account";
  20. protected $password;
  21. public $language_bin_list = array();
  22. static public $_f = array
  23. (
  24. "type" => array("type"=>"select", "list"=>array("user", "manager", "admin", 'shared'), "nonempty"=>true),
  25. "name" => array("type"=>"string", "nonempty"=>true),
  26. "folder" => array("type"=>"string"),
  27. "actif" => array("type"=>"bool"),
  28. "manager_id" => array("type"=>"object", "otype"=>"account"),
  29. "offre_id" => array("type"=>"object", "otype"=>"offer"),
  30. "civilite" => array("type"=>"select", "list"=>array('m', 'mme', 'mlle')),
  31. "nom" => array("type"=>"string"),
  32. "prenom" => array("type"=>"string"),
  33. "email" => array("type"=>"string"),
  34. "societe" => array("type"=>"string"),
  35. "disk_quota_soft" => array("type"=>"int"),
  36. "disk_quota_hard" => array("type"=>"int"),
  37. );
  38. /**
  39. * @see db_object::__toString()
  40. */
  41. function __toString()
  42. {
  43. return "$this->nom $this->prenom [$this->name]";
  44. }
  45. /**
  46. * @see db_object::url()
  47. */
  48. function url()
  49. {
  50. return "account.php?id=$this->id";
  51. }
  52. // ACCESS
  53. function manager()
  54. {
  55. return account()->get($this->manager_id);
  56. }
  57. /**
  58. * @return offer
  59. */
  60. function offer()
  61. {
  62. return offer()->get($this->offre_id);
  63. }
  64. function language_bin_list()
  65. {
  66. if (!$this->id)
  67. return array();
  68. $list = array();
  69. $query_string = "SELECT `language_bin_id` FROM `account_language_bin_ref` WHERE `account_id`='$this->id'";
  70. $query = mysql_query($query_string);
  71. while (list($id)=mysql_fetch_row($query))
  72. {
  73. $list[] = language_bin($id);
  74. }
  75. return $list;
  76. }
  77. function phpapp_list()
  78. {
  79. $list = array();
  80. $query_string = "SELECT t1.id FROM phpapp as t1 WHERE t1.account_id IS NULL OR t1.account_id = '$this->id'";
  81. $query = mysql_query($query_string);
  82. while(list($id)=mysql_fetch_row($query))
  83. $list[] = phpapp($id);
  84. return $list;
  85. }
  86. function phppool_list()
  87. {
  88. $list = array();
  89. $query_string = "SELECT t1.id FROM phppool as t1 LEFT JOIN phpapp AS t2 ON t2.id=t1.phpapp_id AND (t2.account_id IS NULL OR t2.account_id='$this->id') WHERE t1.account_id IS NULL OR t1.account_id = '$this->id'";
  90. $query = mysql_query($query_string);
  91. while(list($id)=mysql_fetch_row($query))
  92. $list[] = phppool($id);
  93. return $list;
  94. }
  95. function phpext_list($language_bin_id=null)
  96. {
  97. $list = array();
  98. $query_string = "SELECT language_php_ext.*, if(language_php_bin_ext_ref.phpext_id, 1, 0) as `already`, if (account_php_ext_ref.account_id, 1, 0) as `authorized`
  99. FROM language_php_ext
  100. LEFT JOIN account_php_ext_ref ON language_php_ext.id=account_php_ext_ref.phpext_id AND account_php_ext_ref.account_id='".$this->id."'
  101. LEFT JOIN language_php_bin_ext_ref ON language_php_ext.id=language_php_bin_ext_ref.phpext_id AND language_php_bin_ext_ref.language_bin_id='".$language_bin_id."'
  102. WHERE language_php_ext.type='extension'
  103. ORDER BY language_php_ext.description";
  104. $query = mysql_query($query_string);
  105. while($row=mysql_fetch_assoc($query))
  106. {
  107. $list[$row["id"]] = $row;
  108. }
  109. return $list;
  110. }
  111. /**
  112. * OS (Linux) system user id (uid) and group id (gid)
  113. *
  114. * @return int
  115. */
  116. public function system_id()
  117. {
  118. return (ACCOUNT_UID_MIN+$this->id);
  119. }
  120. /**
  121. * OS (Linux) system user name
  122. *
  123. * @return string
  124. */
  125. public function system_user()
  126. {
  127. return "$this->name$this->id";
  128. }
  129. /**
  130. * OS (Linux) system group name
  131. *
  132. * @return string
  133. */
  134. public function system_group()
  135. {
  136. return $this->system_user();
  137. }
  138. /**
  139. * PHP user ID
  140. * @return int
  141. */
  142. function php_id()
  143. {
  144. return (PHP_UID_MIN+$this->id);
  145. }
  146. function php_user()
  147. {
  148. return "php_".$this->name;
  149. }
  150. function php_group()
  151. {
  152. return $this->system_group();
  153. }
  154. /**
  155. * Email user ID
  156. * @return int
  157. */
  158. function email_id()
  159. {
  160. return (EMAIL_UID_MIN+$this->id);
  161. }
  162. function email_user()
  163. {
  164. return "email_".$this->name;
  165. }
  166. function email_group()
  167. {
  168. return $this->system_group();
  169. }
  170. /**
  171. * Update usergroup relative to account
  172. * @param string $usergroup
  173. */
  174. function usergroup(&$usergroup)
  175. {
  176. if (is_null($usergroup))
  177. $usergroup = $this->system_user().":".$this->system_group();
  178. elseif (!is_numeric($pos=strpos($usergroup, ":")))
  179. $usergroup = $usergroup.":".$this->system_group();
  180. elseif ($pos == 0)
  181. $usergroup = $this->system_user().":".$usergroup;
  182. }
  183. /* FOLDERS */
  184. /**
  185. * Returns root folder
  186. *
  187. * @return string
  188. */
  189. function folder()
  190. {
  191. return SITEADM_USER_DIR."/$this->folder";
  192. }
  193. /**
  194. * Update folder relative to account
  195. * @param string $folder
  196. * @return string
  197. */
  198. function subfolder(&$folder)
  199. {
  200. if (substr($folder, 0, 1) != "/")
  201. $folder = $this->folder()."/".$folder;
  202. }
  203. /**
  204. * Log folder
  205. *
  206. * @return string
  207. */
  208. function log_folder()
  209. {
  210. return $this->folder()."/log";
  211. }
  212. /**
  213. * Conf folder
  214. *
  215. * @return string
  216. */
  217. function conf_folder()
  218. {
  219. return $this->folder()."/conf";
  220. }
  221. /**
  222. * PHP sockets folder
  223. *
  224. * @return string
  225. */
  226. function socket_folder()
  227. {
  228. return $this->folder()."/socket";
  229. }
  230. /**
  231. * Public folder
  232. *
  233. * @return string
  234. */
  235. function public_folder()
  236. {
  237. return $this->folder()."/public";
  238. }
  239. /**
  240. * Private folder
  241. *
  242. * @return string
  243. */
  244. function private_folder()
  245. {
  246. return $this->folder()."/private";
  247. }
  248. /**
  249. * CGI-BIN folder
  250. *
  251. * @return string
  252. */
  253. function cgi_folder()
  254. {
  255. return $this->folder()."/cgi-bin";
  256. }
  257. /**
  258. * Temp folder
  259. *
  260. * @return string
  261. */
  262. function tmp_folder()
  263. {
  264. return $this->folder()."/tmp";
  265. }
  266. /**
  267. * Sessions folder
  268. *
  269. * @return string
  270. */
  271. function session_folder()
  272. {
  273. return $this->folder()."/cookies";
  274. }
  275. /**
  276. * Dossier de stockage des emails associés au compte
  277. * @return string
  278. */
  279. function email_folder()
  280. {
  281. return $this->folder()."/mail";
  282. }
  283. /**
  284. * Dossier de stockage des backup
  285. * @return string
  286. */
  287. function backup_folder()
  288. {
  289. return $this->folder()."/backup";
  290. }
  291. // PERM
  292. /**
  293. * @see db_object::insert_perm()
  294. */
  295. static function insert_perm()
  296. {
  297. // Admin
  298. if (login()->perm("admin"))
  299. {
  300. return "admin";
  301. }
  302. // Manager
  303. elseif (login()->perm("manager"))
  304. {
  305. return "manager";
  306. }
  307. // Other (user or not connected)
  308. else
  309. {
  310. return false;
  311. }
  312. }
  313. /**
  314. * @see db_object::update_perm()
  315. */
  316. function update_perm()
  317. {
  318. // Admin
  319. if (login()->perm("admin"))
  320. {
  321. return "admin";
  322. }
  323. // Manager
  324. elseif (($manager=$this->manager()) && $manager->id == login()->id)
  325. {
  326. return "manager";
  327. }
  328. // User
  329. elseif ($this->id && $this->id == login()->id)
  330. {
  331. return "user";
  332. }
  333. // Bad User or not connected
  334. else
  335. {
  336. return false;
  337. }
  338. }
  339. /**
  340. * Returns if the account has the permission $name
  341. *
  342. * @param string $name
  343. * @return boolean
  344. */
  345. public function perm($name)
  346. {
  347. if ($name == "manager")
  348. return (in_array($this->type, array("manager", "admin")));
  349. elseif ($name == "admin")
  350. return ($this->type == "admin");
  351. }
  352. // UPDATE
  353. /**
  354. * @see db_object::insert()
  355. */
  356. public function insert($infos)
  357. {
  358. if (!($perm=static::insert_perm()) || !is_array($infos))
  359. return false;
  360. if ($perm == "manager")
  361. {
  362. $infos["manager_id"] = login()->id;
  363. $infos["type"] = "user";
  364. }
  365. if (!isset($infos["name"]) || !is_string($infos["name"]) || !strlen($infos["name"]))
  366. return false;
  367. $infos["folder"] = $infos["name"];
  368. return db_object::insert($infos);
  369. }
  370. /**
  371. * @see db_object::update()
  372. */
  373. public function update($infos)
  374. {
  375. if (!($perm=$this->update_perm()))
  376. return false;
  377. if ($perm == "user" || $perm == "manager")
  378. {
  379. if (isset($infos["manager_id"]))
  380. unset($infos["manager_id"]);
  381. if (isset($infos["type"]))
  382. unset($infos["type"]);
  383. }
  384. if ($perm == "user")
  385. {
  386. if (isset($infos["actif"]))
  387. unset($infos["actif"]);
  388. if (isset($infos["offre_id"]))
  389. unset($infos["offre_id"]);
  390. }
  391. if (isset($infos["folder"]))
  392. unset($infos["folder"]);
  393. return db_object::update($infos);
  394. }
  395. // DB
  396. /**
  397. * @see db_object::db_retrieve()
  398. */
  399. protected function db_retrieve($id)
  400. {
  401. if (!db_object::db_retrieve($id))
  402. return false;
  403. $this->language_bin_list = array();
  404. $query_string = "SELECT `language_bin_id` FROM `account_language_bin_ref` WHERE `account_id`='$this->id'";
  405. $query = mysql_query($query_string);
  406. while(list($lang_id)=mysql_fetch_row($query))
  407. $this->language_bin_list[] = $lang_id;
  408. return true;
  409. }
  410. /**
  411. * @see db_object::db_insert()
  412. */
  413. protected function db_insert($infos)
  414. {
  415. if (db_object::db_insert($infos))
  416. {
  417. if (isset($infos["language_bin_list"]) && is_array($infos["language_bin_list"]))
  418. {
  419. $query_list = array();
  420. foreach($infos["language_bin_list"] as $lang_id)
  421. $query_list[] = "('$this->id', '$lang_id')";
  422. if (count($query_list))
  423. {
  424. $query_string = "INSERT INTO account_language_bin_ref (account_id, language_bin_id) VALUES ".implode(" , ",$query_list);
  425. mysql_query($query_string);
  426. }
  427. }
  428. return true;
  429. }
  430. else
  431. {
  432. return false;
  433. }
  434. }
  435. /**
  436. * @see db_object::db_update()
  437. */
  438. protected function db_update($infos)
  439. {
  440. $return = false;
  441. if (isset($infos["language_bin_list"]))
  442. {
  443. mysql_query("DELETE FROM `account_language_bin_ref` WHERE `account_id`='$this->id'");
  444. if (is_array($infos["language_bin_list"]))
  445. {
  446. $query_list = array();
  447. foreach($infos["language_bin_list"] as $lang_id)
  448. $query_list[] = "('$this->id', '$lang_id')";
  449. if (count($query_list))
  450. {
  451. $query_string = "INSERT INTO account_language_bin_ref (account_id, language_bin_id) VALUES ".implode(" , ",$query_list);
  452. mysql_query($query_string);
  453. }
  454. }
  455. $return = true;
  456. }
  457. return (db_object::db_update($infos) || $return);
  458. }
  459. /* REPLACE MAP */
  460. /**
  461. * Create replacement map for template files
  462. *
  463. * @return array
  464. */
  465. function replace_map()
  466. {
  467. $map = array
  468. (
  469. "{ACCOUNT_ID}" => $this->id,
  470. "{ACCOUNT_NAME}" => $this->name,
  471. "{ACCOUNT_SYSTEM_ID}" => $this->system_id(),
  472. "{ACCOUNT_SYSTEM_USER}" => $this->system_user(),
  473. "{ACCOUNT_SYSTEM_GROUP}" => $this->system_group(),
  474. "{ACCOUNT_EMAIL}" => $this->email,
  475. "{ACCOUNT_ROOT}" => $this->folder(),
  476. "{ACCOUNT_PUBLIC}" => $this->public_folder(),
  477. "{ACCOUNT_TMP_DIR}" => $this->tmp_folder(),
  478. "{ACCOUNT_CGI_DIR}" => $this->cgi_folder(),
  479. "{PHP_TMP_DIR}" => $this->tmp_folder(),
  480. "{PHP_BASEDIR}" => $this->public_folder(),
  481. );
  482. replace_map_merge($map, replace_map());
  483. return $map;
  484. }
  485. /* ROOT METHODS */
  486. /**
  487. * Update OS account password
  488. *
  489. * This method will also save the password in /path/to/account/private
  490. * @param string $passwd
  491. */
  492. protected function password_update($passwd=null)
  493. {
  494. $passfile = $this->folder()."/private/passwd";
  495. $passfile_crypt = $this->folder()."/private/passwd_crypt";
  496. if (!$passwd) // TODO : tests de robustesse de mot de passe
  497. {
  498. exec("makepasswd --chars 8 > $passfile");
  499. $passwd = file_get_contents($passfile);
  500. $passwd = str_replace(array("\r\n","\n","\r"), "", $passwd);
  501. }
  502. else
  503. {
  504. filesystem::write($passfile_crypt, $passwd);
  505. }
  506. $this->passwd = $passwd;
  507. // Encrypt password
  508. exec("makepasswd --crypt --clearfrom $passfile > $passfile_crypt");
  509. unlink($passfile);
  510. filesystem::chmod($passfile_crypt, "600");
  511. $passwd_crypt = array_pop(explode(" ",fread(fopen($passfile_crypt,"r"),filesize($passfile_crypt))));
  512. $passwd_crypt = str_replace(array("\r\n","\n","\r"), "", $passwd_crypt);
  513. // Update password in database
  514. mysql_query("UPDATE `account` SET `password`='$passwd' WHERE `id`='$this->id'");
  515. // Update system password
  516. exec("usermod -p $passwd_crypt ".$this->system_user());
  517. }
  518. /**
  519. * Update quota
  520. */
  521. protected function quota_update()
  522. {
  523. // Limitations by offer
  524. if ($offer=$this->offer())
  525. {
  526. if ($offer->disk_quota_soft)
  527. exec("quotatool -u ".$this->system_user()." -b -q ".($offer->disk_quota_soft*1024)."MB /");
  528. else
  529. exec("quotatool -u ".$this->system_user()." -b -q 0 /");
  530. if ($offer->disk_quota_hard)
  531. exec("quotatool -u ".$this->system_user()." -b -l ".($offer->disk_quota_soft*1024)."MB /");
  532. else
  533. exec("quotatool -u ".$this->system_user()." -b -l 0 /");
  534. }
  535. // No limitations
  536. else
  537. {
  538. exec("quotatool -u ".$this->system_user()." -b -q 0 -l 0 /");
  539. }
  540. }
  541. /**
  542. * Create a subfolder in the account root and eventually chown it
  543. *
  544. * @param string $folder
  545. * @param string $mode
  546. * @param string $usergroup
  547. */
  548. function mkdir($folder, $mode="750", $usergroup=null)
  549. {
  550. $this->subfolder($folder);
  551. $this->usergroup($usergroup);
  552. filesystem::mkdir($folder);
  553. $this->chmod($folder, $mode);
  554. $this->chown($folder, $usergroup);
  555. }
  556. /**
  557. * Delete a folder and all subfolders
  558. *
  559. * @param string $folder
  560. */
  561. function rmdir($folder)
  562. {
  563. $this->subfolder($folder);
  564. if ($folder && $folder!= "/")
  565. filesystem::rmdir($folder);
  566. }
  567. /**
  568. * Delete a folder and all subfolders
  569. *
  570. * @param string $folder
  571. */
  572. function rm($file)
  573. {
  574. $this->subfolder($file);
  575. filesystem::unlink($file);
  576. }
  577. /**
  578. * Chown a file in the account root
  579. *
  580. * @param string $file
  581. * @param string $usergroup
  582. */
  583. function chown($file, $usergroup=null, $recursive=false)
  584. {
  585. $this->subfolder($file);
  586. $this->usergroup($usergroup);
  587. filesystem::chown($file, $usergroup, $recursive);
  588. }
  589. /**
  590. * Chown a file in the account root
  591. *
  592. * @param string $file
  593. * @param string $usergroup
  594. */
  595. function chmod($file, $mode="750")
  596. {
  597. $this->subfolder($file);
  598. filesystem::chmod($file, $mode);
  599. }
  600. /**
  601. * Copy a template file into the account root
  602. *
  603. * @param string $file_from
  604. * @param string $file_to
  605. * @param array $replace_map
  606. * @param string $mode
  607. * @param string $usergroup
  608. */
  609. function copy_tpl($file_from, $file_to, $replace_map=array(), $mode="0640", $usergroup=null)
  610. {
  611. $this->subfolder($file_to);
  612. $this->usergroup($usergroup);
  613. copy_tpl($file_from, $file_to, $replace_map, $mode, $usergroup);
  614. }
  615. /* ROOT ACCESS SCRIPTS */
  616. function root_foldersize($folder)
  617. {
  618. $this->subfolder($folder);
  619. $command = "sudo ".SITEADM_SCRIPT_DIR."/db_object.psh account $this->id foldersize $folder";
  620. return shell_exec($command);
  621. }
  622. function root_tail($filename)
  623. {
  624. $this->subfolder($filename);
  625. $command = "sudo ".SITEADM_SCRIPT_DIR."/db_object.psh account $this->id tail $filename";
  626. return shell_exec($command);
  627. }
  628. function root_quota()
  629. {
  630. $command = "sudo ".SITEADM_SCRIPT_DIR."/db_object.psh account $this->id quota";
  631. return shell_exec($command);
  632. }
  633. /* ROOT SCRIPTS */
  634. /**
  635. * Update account password
  636. * @param string $password
  637. */
  638. function script_password_update($password=null)
  639. {
  640. $this->password_update($password);
  641. }
  642. /**
  643. * Create directory structure
  644. */
  645. public function script_structure()
  646. {
  647. $this->mkdir("", "750", "root");
  648. filesystem::setacl($this->folder(), WEBSERVER_USER);
  649. // SSH
  650. $this->mkdir(".ssh", "700");
  651. // Config files
  652. $this->mkdir("conf", "750", "root");
  653. filesystem::setacl($this->conf_folder(), WEBSERVER_USER);
  654. filesystem::setacl($this->conf_folder(), AWSTATS_USER);
  655. // Awstats
  656. $this->mkdir("conf/awstats", "750", "root");
  657. filesystem::setacl($this->conf_folder()."/awstats", AWSTATS_USER);
  658. // Apache
  659. $this->mkdir("conf/apache", "750", "root");
  660. filesystem::setacl($this->folder()."/conf/apache", WEBSERVER_USER);
  661. // PHP
  662. $this->mkdir("conf/php", "750", "root");
  663. $this->mkdir("conf/php/pool", "755", "root");
  664. $this->mkdir("conf/php/ext", "755", "root");
  665. $this->mkdir("conf/php/vhost", "755", "root");
  666. // Fetchmail
  667. $this->mkdir("conf/fetchmail", "750", "root");
  668. // CRON
  669. $this->mkdir("conf/cron", "750", "root");
  670. // CGI-BIN
  671. $this->mkdir("cgi-bin", "750", "root");
  672. filesystem::setacl($this->cgi_folder(), WEBSERVER_USER);
  673. // Backup
  674. $this->mkdir("backup", "750", "root");
  675. $this->mkdir("backup/mysql", "755", "root");
  676. // Logs
  677. $this->mkdir("log", "750", "root");
  678. filesystem::setacl($this->log_folder(), WEBSERVER_USER);
  679. filesystem::setacl($this->log_folder(), AWSTATS_USER);
  680. $this->mkdir("log/apache", "1750", "root");
  681. filesystem::setacl($this->log_folder()."/apache", WEBSERVER_USER);
  682. filesystem::setacl($this->log_folder()."/apache", AWSTATS_USER);
  683. $this->mkdir("log/php", "1750", $this->php_user());
  684. $this->mkdir("log/awstats", "1770", "root");
  685. filesystem::setacl($this->log_folder()."/awstats", AWSTATS_USER, "rwx");
  686. exec("setfacl -m m::rwx ".$this->log_folder()."/awstats");
  687. exec("setfacl -m g::rx ".$this->log_folder()."/awstats");
  688. // Temp (PHP)
  689. $this->mkdir("tmp", "1777", "root");
  690. // Cookies (PHP)
  691. $this->mkdir("cookies", "700", $this->php_user());
  692. // Socket (PHP)
  693. $this->mkdir("socket", "750", "root:root");
  694. filesystem::setacl($this->socket_folder(), $this->php_user());
  695. filesystem::setacl($this->socket_folder(), WEBSERVER_USER);
  696. // Private data & config
  697. $this->mkdir("private", "750", "root");
  698. $this->mkdir("private/data", "750");
  699. $this->mkdir("private/ftp", "750");
  700. // Public websites
  701. $this->mkdir("public", "750", "root");
  702. filesystem::setacl($this->public_folder(), WEBSERVER_USER);
  703. $this->mkdir("public/data", "750");
  704. $this->mkdir("public/ftp", "755");
  705. // eMail
  706. $this->mkdir("mail", "700", $this->email_user());
  707. }
  708. /**
  709. * @see db_object::script_update()
  710. */
  711. function script_update()
  712. {
  713. $disk_quota_soft = ($this->disk_quota_soft)?$this->disk_quota_soft:0;
  714. $disk_quota_hard = ($this->disk_quota_hard)?$this->disk_quota_hard:0;
  715. // gestion de quota
  716. if ($offer=$this->offer)
  717. {
  718. if ($offer->disk_quota_soft && !$disk_quota_soft)
  719. $disk_quota_soft = $offer->disk_quota_soft;
  720. if ($offer->disk_quota_hard && !$disk_quota_hard)
  721. $disk_quota_hard = $offer->disk_quota_hard;
  722. }
  723. exec("quotatool -g ".$this->system_group()." -b -q ".(1024*$disk_quota_soft)."MB ".QUOTA_DISK);
  724. exec("quotatool -g ".$this->system_group()." -b -q ".(1024*$disk_quota_hard)."MB ".QUOTA_DISK);
  725. }
  726. /**
  727. * @see db_object::script_insert()
  728. */
  729. function script_insert()
  730. {
  731. // Add system group
  732. exec("groupadd -g ".$this->system_id()." ".$this->system_group());
  733. // Add system user
  734. exec("useradd -u ".$this->system_id()." -g ".$this->system_id()." -d ".$this->public_folder()." -s /bin/bash ".$this->system_user());
  735. // Add system php user
  736. exec("useradd -u ".$this->php_id()." -g ".$this->system_id()." -d ".$this->public_folder()." -s /bin/false ".$this->php_user());
  737. // Add system email user
  738. exec("useradd -u ".$this->email_id()." -g ".$this->system_id()." -d ".$this->email_folder()." -s /bin/false ".$this->email_user());
  739. // Add user in siteadm_account group,
  740. // so that sshd_config section authorize only internal-sftp for users matching group ACCOUNT_SYSTEM_GROUP
  741. exec("addgroup ".$this->system_user()." ".ACCOUNT_SYSTEM_GROUP);
  742. // User Root folder
  743. $this->mkdir("", "750", "root");
  744. $this->script_structure();
  745. $this->script_password_update();
  746. $this->script_update();
  747. }
  748. /**
  749. * Returns the quota used by the user's group
  750. */
  751. function script_quota()
  752. {
  753. echo shell_exec("quota -vlws -g ".$this->system_group());
  754. }
  755. /**
  756. * Returns the size of a folder
  757. * @param string $folder
  758. */
  759. function script_foldersize($folder)
  760. {
  761. echo filesystem::foldersize($folder);
  762. }
  763. /**
  764. * Returns the size of a folder
  765. * @param string $folder
  766. */
  767. function script_tail($filename)
  768. {
  769. echo filesystem::tail($filename);
  770. }
  771. }
  772. ?>