Skip to content

Commit 50b8906

Browse files
committed
Merge branch 'master' of [email protected]:/DoliCloud/sellyoursaas
2 parents 8a8f286 + 357c316 commit 50b8906

File tree

11 files changed

+320
-15
lines changed

11 files changed

+320
-15
lines changed

admin/setup_register_security.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@
147147
if (GETPOSTISSET("SELLYOURSAAS_BLOCK_DISPOSABLE_EMAIL_ENABLED")) {
148148
dolibarr_set_const($db, "SELLYOURSAAS_BLOCK_DISPOSABLE_EMAIL_ENABLED", GETPOST("SELLYOURSAAS_BLOCK_DISPOSABLE_EMAIL_ENABLED", 'alpha'), 'chaine', 0, '', $conf->entity);
149149
}
150-
150+
if (getDolGlobalInt("SELLYOURSAAS_BLOCK_DISPOSABLE_EMAIL_ENABLED")) {
151+
dolibarr_set_const($db, "SELLYOURSAAS_BLOCK_DISPOSABLE_EMAIL_API_KEY", GETPOST("SELLYOURSAAS_BLOCK_DISPOSABLE_EMAIL_API_KEY", 'alpha'), 'chaine', 0, '', $conf->entity);
152+
}
151153

152154
// Google recaptcha
153155
if (GETPOSTISSET("SELLYOURSAAS_GOOGLE_RECAPTCHA_ON")) {

class/packages.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class Packages extends CommonObject
114114
'sqlafter' => array('type'=>'text', 'label'=>'Sql after deployment', 'visible'=>3, 'enabled'=>1, 'position'=>70, 'notnull'=>-1, 'help'=>'Sql executed after deployment.<br><br>Can use substitution vars like<br>__APPORGNAME__<br>__APPEMAIL__<br>__APPDOMAIN__<br>__APPCOUNTRYIDCODELABEL__<br>__SMTP_SPF_STRING__<br>__OSUSERNAME__<br>__APPPASSWORD0__<br>__APPPASSWORD0SALTED__<br>__APPPASSWORDSHA256__<br>__APPPASSWORDSHA256SALTED__<br>...'),
115115
'sqlpasswordreset' => array('type'=>'text', 'label'=>'Sql to reset password of a deployed instance user', 'visible'=>3, 'enabled'=>1, 'position'=>71, 'notnull'=>-1, 'help'=>'Sql executed after clicking on cogs on backoffice/instance_users.php after a deployment <br><br> Can use substitution vars like<br>__REMOTEUSERID__<br>__NEWUSERPASSWORD__<br>__NEWUSERPASSWORDCRYPTED__'),
116116
'sqlafterpaid' => array('type'=>'text', 'label'=>'Sql after switch to paid', 'visible'=>3, 'enabled'=>1, 'position'=>72, 'notnull'=>-1, 'help'=>'Sql executed after entering a payment (or after a deployment if customer is already a paying customer)'),
117+
'sqlafterundeployoption' => array('type'=>'text', 'label'=>'Sql after option undeployment', 'visible'=>3, 'enabled'=>1, 'position'=>73, 'notnull'=>-1, 'help'=>'Sql executed after an option is undeployed'),
117118
'allowoverride' => array('type'=>'varchar(255)', 'label'=>'Option string for virtual host', 'visible'=>-1, 'enabled'=>1, 'position'=>75, 'notnull'=>-1, 'help'=>'Any string to add into the Apache virtual host file. For example, keep empty to not allow apache override<br>Use "AllowOverride All" to allow override.'),
118119
'version_formula' => array('type'=>'text', 'label'=>"VersionFormula", 'visible'=>3, 'enabled'=>1, 'position'=>76, 'help'=>'VersionFormulaExamples', 'lang'=>'sellyoursaas@sellyoursaas'),
119120
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
@@ -150,6 +151,7 @@ class Packages extends CommonObject
150151
public $sqlafter;
151152
public $sqlpasswordreset;
152153
public $sqlafterpaid;
154+
public $sqlafterundeployoption;
153155
public $allowoverride;
154156
public $register_text;
155157
public $status;

class/sellyoursaasutils.class.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4302,6 +4302,12 @@ public function sellyoursaasRemoteAction($remoteaction, $object, $appusername =
43024302
$doremoteaction = 2;
43034303
$listoflinesqualified[] = array('tmpobject' => $tmpobject, 'position' => 10, 'doremoteaction' => $doremoteaction, 'remoteaction' => $remoteaction, 'producttmp' => $producttmp, 'tmppackage' => $tmppackage);
43044304
}
4305+
if (in_array($remoteaction, array('undeployoption')) &&
4306+
($producttmp->array_options['options_app_or_option'] == 'option') && $tmppackage->id > 0) {
4307+
$doremoteaction = 1;
4308+
$newremoteaction = 'undeployoption'; // force on deployoption for options services
4309+
$listoflinesqualified[] = array('tmpobject' => $tmpobject, 'position' => 20, 'doremoteaction' => $doremoteaction, 'remoteaction' => $newremoteaction, 'producttmp' => $producttmp, 'tmppackage' => $tmppackage);
4310+
}
43054311
}
43064312

43074313
$listoflinesqualified = dol_sort_array($listoflinesqualified, 'position', 'asc');
@@ -4649,7 +4655,7 @@ public function sellyoursaasRemoteAction($remoteaction, $object, $appusername =
46494655
}
46504656

46514657
// Execute personalized SQL requests (sqlafter), (sqlafterpaid)
4652-
if (! $error && in_array($remoteaction, array('deploy', 'deployall', 'deployoption', 'actionafterpaid'))) {
4658+
if (! $error && in_array($remoteaction, array('deploy', 'deployall', 'deployoption', 'actionafterpaid', 'undeployoption'))) {
46534659
if (! $error) {
46544660
dol_syslog("Try to connect to customer instance database to execute personalized requests");
46554661

@@ -4679,6 +4685,9 @@ public function sellyoursaasRemoteAction($remoteaction, $object, $appusername =
46794685
if ($remoteaction == 'actionafterpaid') {
46804686
$sqltoexecute = make_substitutions($tmppackage->sqlafterpaid, $substitarrayforsql);
46814687
}
4688+
if ($remoteaction == 'undeployoption') {
4689+
$sqltoexecute = make_substitutions($tmppackage->sqlafterundeployoption, $substitarrayforsql);
4690+
}
46824691

46834692
$arrayofsql=explode(';', $sqltoexecute);
46844693
foreach ($arrayofsql as $sqltoexecuteline) {

langs/en_US/sellyoursaas.lang

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,11 @@ ModulesToIgnoreForAutoUpgrade=Modules to ignore for auto-upgrade
969969
PleaseFillContactInfoFirst=Please fill your contact an dorganization information first
970970
GoToYourResellerMenuTogetInformation=Go to menu "%s" for more information
971971
AccessIsReservedTofinalCustomerOnly=Access is reserved to final customer only (ask him if yo need it)
972+
FailedToUninstallOption=An error occurred while uninstalling option
973+
ServiceCannotBeUninstalled=This service cannot be uninstalled
974+
ServiceCannotBeInstalled=This service cannot be installed
975+
OptionSuccessfullyUninstalled=The option has been successfully uninstalled
976+
OptionSuccessfullyInstalled=The option has been successfully installed
972977
SELLYOURSAAS_SUPPORT_TICKET_CREATE=Enable automatic ticket creation when the contact form is used
973978
UpcomingInvoice=Upcoming invoice
974979
WaitingInvoice=Waiting invoice

myaccount/index.php

Lines changed: 251 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@
913913
$tickettocreate->fk_soc = $mythirdpartyaccount->id;
914914
$tickettocreate->socid = $mythirdpartyaccount->id;
915915
$tickettocreate->origin_replyto = $replyto;
916-
$tickettocreate->origin_email = $emailfrom;
916+
$tickettocreate->origin_email = $replyto;
917917
$tickettocreate->ip = $ipaddress;
918918
if (is_object($tmpcontract)) {
919919
$tickettocreate->fk_contract = $tmpcontract->id;
@@ -2325,10 +2325,260 @@
23252325

23262326
header("Location: ".$backtourl);
23272327
exit;
2328+
} elseif ($action == 'uninstall') {
2329+
$error = 0;
2330+
$sellyoursaasutils = new SellYourSaasUtils($db);
2331+
$deletedlinecontract = 0; $deletedlinefacturerec = 0;
2332+
$contractid = GETPOSTINT("instanceid");
2333+
$productid = GETPOSTINT("productid");
2334+
if ($contractid <= 0) {
2335+
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Id")), null, 'errors');
2336+
header("Location: ".$backtourl);
2337+
exit;
2338+
}
2339+
if ($productid <= 0) {
2340+
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductId")), null, 'errors');
2341+
header("Location: ".$backtourl);
2342+
exit;
2343+
}
2344+
$tmpproduct = new Product($db);
2345+
$res = $tmpproduct->fetch($productid);
2346+
if ($res <= 0) {
2347+
setEventMessages($tmpproduct->error, null, 'errors');
2348+
header("Location: ".$backtourl);
2349+
exit;
2350+
}
2351+
if ($tmpproduct->array_options["options_app_or_option"] != "option") {
2352+
setEventMessages($langs->trans("ServiceCannotBeUninstalled"), null, 'errors');
2353+
header("Location: ".$backtourl);
2354+
exit;
2355+
}
2356+
2357+
$db->begin();
2358+
$tmpcontract = new Contrat($db);
2359+
$res = $tmpcontract->fetch($contractid);
2360+
if ($res <= 0) {
2361+
setEventMessages($tmpcontract->error, null, 'errors');
2362+
$error++;
2363+
}
2364+
if (!$error) {
2365+
foreach ($tmpcontract->lines as $key => $line) {
2366+
// Remove service line(s) from contract
2367+
if ($line->fk_product == $productid) {
2368+
$res = $tmpcontract->deleteLine($line->id, $user);
2369+
if ($res <= 0) {
2370+
setEventMessages($tmpcontract->error, null, 'errors');
2371+
$error++;
2372+
} else {
2373+
$deletedlinecontract ++;
2374+
}
2375+
}
2376+
}
2377+
2378+
if (!$error) {
2379+
// Remove service line(s) from recurring invoice
2380+
$tmpcontract->fetchObjectLinked();
2381+
$arrayfacturerec = array_values($tmpcontract->linkedObjects["facturerec"]);
2382+
2383+
if (count($arrayfacturerec) != 1) {
2384+
// TODO: Send mail auto to inform admins of multiples faturerec contract
2385+
$error ++;
2386+
} else {
2387+
$facturerec = $arrayfacturerec[0];
2388+
foreach ($facturerec->lines as $key => $line) {
2389+
if ($line->fk_product == $productid) {
2390+
$res = $line->delete($user);
2391+
if ($res <= 0) {
2392+
setEventMessages($line->error, null, 'errors');
2393+
$error++;
2394+
} else {
2395+
$deletedlinefacturerec ++;
2396+
}
2397+
}
2398+
}
2399+
}
2400+
}
2401+
}
2402+
2403+
// Call to remoteaction to undeploy option
2404+
if (!$error) {
2405+
$object = $tmpcontract;
2406+
$type_db = $conf->db->type;
2407+
$hostname_db = $object->array_options['options_hostname_db'];
2408+
$username_db = $object->array_options['options_username_db'];
2409+
$password_db = $object->array_options['options_password_db'];
2410+
$database_db = $object->array_options['options_database_db'];
2411+
$port_db = (!empty($object->array_options['options_port_db']) ? $object->array_options['options_port_db'] : 3306);
2412+
$prefix_db = (!empty($object->array_options['options_prefix_db']) ? $object->array_options['options_prefix_db'] : 'llx_');
2413+
$hostname_os = $object->array_options['options_hostname_os'];
2414+
$username_os = $object->array_options['options_username_os'];
2415+
$password_os = $object->array_options['options_password_os'];
2416+
$username_web = $object->thirdparty->email;
2417+
$password_web = $object->thirdparty->array_options['options_password'];
2418+
2419+
$tmp = explode('.', $object->ref_customer, 2);
2420+
$object->instance = $tmp[0];
2421+
2422+
$object->hostname_db = $hostname_db;
2423+
$object->username_db = $username_db;
2424+
$object->password_db = $password_db;
2425+
$object->database_db = $database_db;
2426+
$object->port_db = $port_db;
2427+
$object->prefix_db = $prefix_db;
2428+
$object->username_os = $username_os;
2429+
$object->password_os = $password_os;
2430+
$object->hostname_os = $hostname_os;
2431+
$object->username_web = $username_web;
2432+
$object->password_web = $password_web;
2433+
2434+
$result = $sellyoursaasutils->sellyoursaasRemoteAction("undeployoption", $object);
2435+
if ($result <= 0) {
2436+
$error++;
2437+
setEventMessages($sellyoursaasutils->error, $sellyoursaasutils->errors, 'errors');
2438+
}
2439+
}
2440+
2441+
if (!$deletedlinecontract || !$deletedlinefacturerec) {
2442+
$error ++;
2443+
setEventMessages("FailedToUninstallOption", null, 'errors');
2444+
}
2445+
2446+
if ($error) {
2447+
$db->rollback();
2448+
} else {
2449+
$db->commit();
2450+
setEventMessages($langs->trans("OptionSuccessfullyUninstalled"), null, 'mesgs');
2451+
}
2452+
2453+
header('Location: '.$_SERVER["PHP_SELF"].'?mode=instances&tab=resources_'.$object->id);
2454+
exit();
2455+
} elseif ($action == 'install') {
2456+
$error = 0;
2457+
$sellyoursaasutils = new SellYourSaasUtils($db);
2458+
$contractid = GETPOSTINT("instanceid");
2459+
$productid = GETPOSTINT("productid");
2460+
if ($contractid <= 0) {
2461+
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Id")), null, 'errors');
2462+
header("Location: ".$backtourl);
2463+
exit;
2464+
}
2465+
if ($productid <= 0) {
2466+
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductId")), null, 'errors');
2467+
header("Location: ".$backtourl);
2468+
exit;
2469+
}
2470+
$tmpproduct = new Product($db);
2471+
$res = $tmpproduct->fetch($productid);
2472+
if ($res <= 0) {
2473+
setEventMessages($tmpproduct->error, null, 'errors');
2474+
header("Location: ".$backtourl);
2475+
exit;
2476+
}
2477+
if ($tmpproduct->array_options["options_app_or_option"] != "option") {
2478+
setEventMessages($langs->trans("ServiceCannotBeInstalled"), null, 'errors');
2479+
header("Location: ".$backtourl);
2480+
exit;
2481+
}
2482+
2483+
$db->begin();
2484+
$tmpcontract = new Contrat($db);
2485+
$res = $tmpcontract->fetch($contractid);
2486+
if ($res <= 0) {
2487+
setEventMessages($tmpcontract->error, null, 'errors');
2488+
$error++;
2489+
}
2490+
if (!$error) {
2491+
$tmparray = sellyoursaasGetExpirationDate($tmpcontract, 0);
2492+
$duration_value = $tmparray['duration_value'];
2493+
$duration_unit = $tmparray['duration_unit'];
2494+
$date_start = dol_now();
2495+
$date_end = dol_time_plus_duree($now, $duration_value, $duration_unit) - 1;
2496+
// Create service line(s) from contract
2497+
$idlinecontract = $tmpcontract->addline($tmpproduct->description, $tmpproduct->price, 1, $tmpproduct->tva_tx, $tmpproduct->localtax1_tx, $tmpproduct->localtax2_tx, $productid, 0, $date_start, $date_end);
2498+
if ($idlinecontract <= 0) {
2499+
setEventMessages($contract->error, null, 'errors');
2500+
$error++;
2501+
}
2502+
if (!$error) {
2503+
$tmpcontract->fetch($contractid);
2504+
$result = $tmpcontract->active_line($user, $idlinecontract, $date_start, '', 'Activation after option deployment');
2505+
if (!$result) {
2506+
// TODO: Send mail auto to inform admins of error activation line
2507+
$error ++;
2508+
}
2509+
}
2510+
if (!$error) {
2511+
// create service line(s) from recurring invoice
2512+
$tmpcontract->fetchObjectLinked();
2513+
$arrayfacturerec = array_values($tmpcontract->linkedObjects["facturerec"]);
2514+
2515+
if (count($arrayfacturerec) != 1) {
2516+
// TODO: Send mail auto to inform admins of multiples faturerec contract
2517+
$error ++;
2518+
} else {
2519+
$facturerec = $arrayfacturerec[0];
2520+
$result = $facturerec->addLine($tmpproduct->description, $tmpproduct->price, 1, $tmpproduct->tva_tx, $tmpproduct->localtax1_tx, $tmpproduct->localtax2_tx, $productid, 0, 'HT', 0, '', 0, 0, -1, 0, '', null, 0, 1, 1);
2521+
if (!$result) {
2522+
// TODO: Send mail auto to inform admins of error line creation facturRec
2523+
$error ++;
2524+
}
2525+
}
2526+
}
2527+
}
2528+
2529+
// Call to remoteaction to deploy option
2530+
if (!$error) {
2531+
$object = $tmpcontract;
2532+
$type_db = $conf->db->type;
2533+
$hostname_db = $object->array_options['options_hostname_db'];
2534+
$username_db = $object->array_options['options_username_db'];
2535+
$password_db = $object->array_options['options_password_db'];
2536+
$database_db = $object->array_options['options_database_db'];
2537+
$port_db = (!empty($object->array_options['options_port_db']) ? $object->array_options['options_port_db'] : 3306);
2538+
$prefix_db = (!empty($object->array_options['options_prefix_db']) ? $object->array_options['options_prefix_db'] : 'llx_');
2539+
$hostname_os = $object->array_options['options_hostname_os'];
2540+
$username_os = $object->array_options['options_username_os'];
2541+
$password_os = $object->array_options['options_password_os'];
2542+
$username_web = $object->thirdparty->email;
2543+
$password_web = $object->thirdparty->array_options['options_password'];
2544+
2545+
$tmp = explode('.', $object->ref_customer, 2);
2546+
$object->instance = $tmp[0];
2547+
2548+
$object->hostname_db = $hostname_db;
2549+
$object->username_db = $username_db;
2550+
$object->password_db = $password_db;
2551+
$object->database_db = $database_db;
2552+
$object->port_db = $port_db;
2553+
$object->prefix_db = $prefix_db;
2554+
$object->username_os = $username_os;
2555+
$object->password_os = $password_os;
2556+
$object->hostname_os = $hostname_os;
2557+
$object->username_web = $username_web;
2558+
$object->password_web = $password_web;
2559+
2560+
//$object->context["options_websitename"] = $website->ref;
2561+
$result = $sellyoursaasutils->sellyoursaasRemoteAction("deployoption", $object); // Why "rename" and not "deploycustomurl" ?
2562+
if ($result <= 0) {
2563+
$error++;
2564+
setEventMessages($sellyoursaasutils->error, $sellyoursaasutils->errors, 'errors');
2565+
}
2566+
}
2567+
2568+
if ($error) {
2569+
$db->rollback();
2570+
} else {
2571+
$db->commit();
2572+
setEventMessages($langs->trans("OptionSuccessfullyInstalled"), null, 'mesgs');
2573+
}
2574+
2575+
header('Location: '.$_SERVER["PHP_SELF"].'?mode=instances&tab=resources_'.$object->id);
2576+
exit();
23282577
}
23292578

23302579

23312580

2581+
23322582
/*
23332583
* View
23342584
*/

myaccount/tpl/instances.tpl.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,25 @@
974974
continue;
975975
}
976976

977+
$productalreadyininstance = 0;
978+
if (!empty($tmpproduct->array_options['options_package'])) {
979+
// If there is a package, test if module already depoyed on instance
980+
foreach ($arrayoflines as $keyline => $line) {
981+
if ($tmpproduct->id == $line->fk_product) {
982+
$productalreadyininstance = 1;
983+
break;
984+
}
985+
}
986+
}
987+
988+
if (!$productalreadyininstance && !empty($tmpproduct->array_options["options_only_for_country"])) {
989+
$optioncountries = preg_split("/[\s,;]+/", $tmpproduct->array_options["options_only_for_country"]);
990+
if (!in_array(dol_strtolower($mythirdpartyaccount->country_code), $optioncountries)) {
991+
// Thirdparty country code isn't in options_only_for_country array so we don't show option
992+
continue;
993+
}
994+
}
995+
977996
print '<div class="tagtable centpercent divdolibarroptionfromservices"><div class="tagtr">';
978997
print '<div class="tagtd paddingleft paddingright marginrightonly valignmiddle">';
979998

@@ -988,8 +1007,8 @@
9881007
print $htmlforphoto;
9891008
}
9901009

991-
$label = $tmpprod->label;
992-
$desc = $tmpprod->description;
1010+
$label = $tmpproduct->label;
1011+
$desc = $tmpproduct->description;
9931012
$producturl = $tmpproduct->url;
9941013
if (!empty($tmpproduct->multilangs[$langs->defaultlang])) {
9951014
$label = $tmpproduct->multilangs[$langs->defaultlang]['label'];
@@ -1034,10 +1053,10 @@
10341053
print '<div class="divforbutton">';
10351054
if (!$productalreadyininstance) {
10361055
// Show link to subscribe
1037-
print '<a class="btn btn-primary wordbreak" href="/index.php?mode=instances&action=install&instanceid='.$contract->id.'&productid='.$tmpproduct->id.'&token='.newToken().'" target="_blank" rel="noopener">'.$langs->trans("Install").'...</a><br>';
1056+
print '<a class="btn btn-primary wordbreak" href="/index.php?mode=instances&action=install&instanceid='.$contract->id.'&productid='.$tmpproduct->id.'&token='.newToken().'" rel="noopener">'.$langs->trans("Install").'...</a><br>';
10381057
} else {
10391058
// Show link to unsubscribe
1040-
print '<a class="btn btn-warning wordbreak" href="/index.php?mode=instances&action=uninstall&instanceid='.$contract->id.'&productid='.$tmpproduct->id.'&token='.newToken().'#tab_domain_'.$contract->id.'" target="_blank" rel="noopener">'.$langs->trans("Uninstall").'...</a><br>';
1059+
print '<a class="btn btn-warning wordbreak" href="/index.php?mode=instances&action=uninstall&instanceid='.$contract->id.'&productid='.$tmpproduct->id.'&token='.newToken().'" rel="noopener">'.$langs->trans("Uninstall").'...</a><br>';
10411060
}
10421061
print '</div>';
10431062
} else {

0 commit comments

Comments
 (0)